Skip to content

Commit

Permalink
Remove externalLoading setting and build it in properly
Browse files Browse the repository at this point in the history
  • Loading branch information
austinwbest committed Sep 18, 2024
1 parent a0f985a commit 469888f
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 28 deletions.
10 changes: 0 additions & 10 deletions root/app/www/public/ajax/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -357,16 +357,6 @@
<td><input class="form-check-input" type="checkbox" id="globalSetting-overrideBlacklist" <?= ($settingsTable['overrideBlacklist'] ? 'checked' : '') ?>></td>
<td>Generally not recommended, it's at your own risk.</td>
</tr>
<tr>
<th scope="row">Page loading<sup>3</sup></th>
<td>
<select class="form-select" id="globalSetting-externalLoading">
<option <?= $settingsTable['externalLoading'] == 0 ? 'selected' : '' ?> value="0">Internal</option>
<option <?= $settingsTable['externalLoading'] == 1 ? 'selected' : '' ?> value="1">External</option>
</select>
</td>
<td>Internal: On a full page refresh you will go back to the overview. (state lost)<br>External: On a full page refresh you will stay on this current page. (state saved in URL)</td>
</tr>
<tr>
<th scope="row">Environment</th>
<td>
Expand Down
4 changes: 4 additions & 0 deletions root/app/www/public/ajax/shared.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
}
}

$ajaxFile = str_replace('/config/www/ajax/', '', debug_backtrace()[0]['file']);
$page = str_replace('.php', '', $ajaxFile);
$database->setSetting('currentPage', $page);

if (IS_MIGRATION_RUNNING) {
?>
<div class="text-center">
Expand Down
21 changes: 10 additions & 11 deletions root/app/www/public/includes/header.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,10 @@
<link href="css/style.css" rel="stylesheet">

<script type="text/javascript">
const USE_EXTERNAL_LOADING = '<?= $settingsTable['externalLoading'] && in_array($_GET['page'], $pages) ? $_GET['page'] : 'overview' ?>';
const CURRENT_PAGE = '<?= $settingsTable['currentPage'] ?: 'overview' ?>';
let USE_SSE = <?= $settingsTable['sseEnabled'] ? 'true' : 'false' ?>;
const SSE_SETTING = <?= intval($settingsTable['sseEnabled']) ?>;
const APP_SERVER_ID = <?= APP_SERVER_ID ?>;
const EXTERNAL_LOADING = <?= $settingsTable['externalLoading'] ?>;
</script>
</head>

Expand All @@ -70,10 +69,10 @@
<div class="mb-4 w-100" align="center"><div id="activeInstanceContainer"><?= $serverList ?></div></div>
<?php if ($_SESSION['authenticated']) { ?>
<div class="navbar-nav w-100">
<a id="menu-overview" onclick="initPage('overview', true)" style="cursor: pointer;" class="nav-item nav-link active"><i class="fas fa-heartbeat me-2"></i>Overview</a>
<a id="menu-overview" onclick="initPage('overview')" style="cursor: pointer;" class="nav-item nav-link active"><i class="fas fa-heartbeat me-2"></i>Overview</a>
<a id="menu-containers" class="nav-item nav-link" onmouseover="$('#menu-containers-label').addClass('text-primary')" onmouseout="containerMenuMouseOut()">
<div style="cursor: pointer;">
<div id="menu-containers-label" onclick="initPage('containers', true)">
<div id="menu-containers-label" onclick="initPage('containers')">
<i class="fas fa-th me-2"></i>Containers
</div>
<div class="w-100 text-white ms-5 conatiner-links" style="display: none;">
Expand All @@ -82,13 +81,13 @@
</div>
</div>
</a>
<a id="menu-compose" onclick="initPage('compose', true)" style="cursor: pointer;" class="nav-item nav-link"><i class="fab fa-octopus-deploy me-2"></i>Compose</a>
<a id="menu-orphans" onclick="initPage('orphans', true)" style="cursor: pointer;" class="nav-item nav-link"><i class="fas fa-th me-2"></i>Orphans</a>
<a id="menu-notification" onclick="initPage('notification', true)" style="cursor: pointer;" class="nav-item nav-link"><i class="fas fa-comment-dots me-2"></i>Notifications</a>
<a id="menu-settings" onclick="initPage('settings', true)" style="cursor: pointer;" class="nav-item nav-link"><i class="fas fa-tools me-2"></i>Settings</a>
<a id="menu-tasks" onclick="initPage('tasks', true)" style="cursor: pointer;" class="nav-item nav-link"><i class="fas fa-tasks me-2"></i>Tasks</a>
<a id="menu-commands" onclick="initPage('commands', true)" style="cursor: pointer;" class="nav-item nav-link"><i class="fab fa-docker me-2"></i>Commands</a>
<a id="menu-logs" onclick="initPage('logs', true)" style="cursor: pointer;" class="nav-item nav-link"><i class="fas fa-file-code me-2"></i>Logs</a>
<a id="menu-compose" onclick="initPage('compose')" style="cursor: pointer;" class="nav-item nav-link"><i class="fab fa-octopus-deploy me-2"></i>Compose</a>
<a id="menu-orphans" onclick="initPage('orphans')" style="cursor: pointer;" class="nav-item nav-link"><i class="fas fa-th me-2"></i>Orphans</a>
<a id="menu-notification" onclick="initPage('notification')" style="cursor: pointer;" class="nav-item nav-link"><i class="fas fa-comment-dots me-2"></i>Notifications</a>
<a id="menu-settings" onclick="initPage('settings')" style="cursor: pointer;" class="nav-item nav-link"><i class="fas fa-tools me-2"></i>Settings</a>
<a id="menu-tasks" onclick="initPage('tasks')" style="cursor: pointer;" class="nav-item nav-link"><i class="fas fa-tasks me-2"></i>Tasks</a>
<a id="menu-commands" onclick="initPage('commands')" style="cursor: pointer;" class="nav-item nav-link"><i class="fab fa-docker me-2"></i>Commands</a>
<a id="menu-logs" onclick="initPage('logs')" style="cursor: pointer;" class="nav-item nav-link"><i class="fas fa-file-code me-2"></i>Logs</a>
<?php if (USE_AUTH) { ?>
<a onclick="logout()" style="cursor: pointer;" class="nav-item nav-link"><i class="fas fa-sign-out-alt me-2"></i>Logout</a>
<?php } ?>
Expand Down
9 changes: 2 additions & 7 deletions root/app/www/public/js/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ let currentPage = 'overview';

$(document).ready(function () {
if ($('#menu-overview').length) {
initPage(USE_EXTERNAL_LOADING);
initPage(CURRENT_PAGE);
}

$('#loading-modal').modal({
Expand Down Expand Up @@ -35,19 +35,14 @@ function clearInitPage(page)
$('#content-' + page).html('The <code>init</code> variable has been set to false, you can load a page without waiting now');
}
// -------------------------------------------------------------------------------------------
function initPage(page, menu = false)
function initPage(page)
{
$('.conatiner-links').hide();

if (page == 'containers') {
$('.conatiner-links').show();
}

if (menu && EXTERNAL_LOADING) {
window.location.href = '?page=' + page
return;
}

if (init) {
toast('Loading', '<span ondblclick="clearInitPage(\'' + page + '\')">A previous page load is still finishing, try again in a second</span>', 'info');
return;
Expand Down
34 changes: 34 additions & 0 deletions root/app/www/public/migrations/004_track_viewing_page.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

/*
----------------------------------
------ Created: 091724 ------
------ Austin Best ------
----------------------------------
*/

$q[] = "INSERT INTO " . SETTINGS_TABLE . "
(`name`, `value`)
VALUES
('currentPage', 'overview')
ON CONFLICT(`name`) DO UPDATE SET value = 'overview' WHERE name = 'currentPage'";

$q[] = "DELETE FROM " . SETTINGS_TABLE . "
WHERE name = 'externalLoading'";

//-- ALWAYS NEED TO BUMP THE MIGRATION ID
$q[] = "UPDATE " . SETTINGS_TABLE . "
SET value = '004'
WHERE name = 'migration'";

foreach ($q as $query) {
logger(MIGRATION_LOG, '<span class="text-success">[Q]</span> ' . preg_replace('!\s+!', ' ', $query));

$database->query($query);

if ($database->error() != 'not an error') {
logger(MIGRATION_LOG, '<span class="text-info">[R]</span> ' . $database->error(), 'error');
} else {
logger(MIGRATION_LOG, '<span class="text-info">[R]</span> query applied!');
}
}

0 comments on commit 469888f

Please sign in to comment.