Skip to content

Commit

Permalink
Add a UI setting to group templates by starr or 3rd party app
Browse files Browse the repository at this point in the history
  • Loading branch information
austinwbest committed Nov 15, 2024
1 parent 506e462 commit 7c166c8
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 9 deletions.
6 changes: 5 additions & 1 deletion root/app/www/public/ajax/templates.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,9 @@
}

if ($_POST['m'] == 'deleteCustomTemplate') {
unlink(APP_USER_TEMPLATES_PATH . $_POST['starr'] . '/' . $_POST['app'] . '.json');
if (TEMPLATE_ORDER == 1) {
unlink(APP_USER_TEMPLATES_PATH . $_POST['item'] . '/' . $_POST['app'] . '.json');
} elseif (TEMPLATE_ORDER == 2) {
unlink(APP_USER_TEMPLATES_PATH . $_POST['app'] . '/' . $_POST['item'] . '.json');
}
}
13 changes: 11 additions & 2 deletions root/app/www/public/functions/templates.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@ function getTemplateOptions()

foreach ($appTemplates as $appTemplate) {
$custom = str_contains($appTemplate['location'], APP_USER_TEMPLATES_PATH);
$templateOptions .= '<option value="' . $appTemplate['location'] . $appTemplate['starr'] . '/' . $app . '.json">' . $appTemplate['starr'] . ($custom ? ' [Custom]' : '') . '</option>';

if (TEMPLATE_ORDER == 1) {
$templateOptions .= '<option value="' . $appTemplate['location'] . $appTemplate['item'] . '/' . $app . '.json">' . $appTemplate['item'] . ($custom ? ' [Custom]' : '') . '</option>';
} elseif (TEMPLATE_ORDER == 2) {
$templateOptions .= '<option value="' . $appTemplate['location'] . $app . '/' . $appTemplate['item'] . '.json">' . $appTemplate['item'] . ($custom ? ' [Custom]' : '') . '</option>';
}
}
$templateOptions .= '</optgroup>';
}
Expand All @@ -39,7 +44,11 @@ function getTemplateList()
}

$template = str_replace('.json', '', $template);
$list[$template][] = ['location' => $templateLocation, 'starr' => $starrApp];
if (TEMPLATE_ORDER == 1) {
$list[$template][] = ['location' => $templateLocation, 'item' => $starrApp];
} elseif (TEMPLATE_ORDER == 2) {
$list[$starrApp][] = ['location' => $templateLocation, 'item' => $template];
}
}
closedir($dir);
ksort($list);
Expand Down
7 changes: 5 additions & 2 deletions root/app/www/public/js/templates.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
function viewTemplate(template, index)
{
loadingStart();

$('[class^=app-index-]').removeClass('text-info');
$('.app-index-' + index).addClass('text-info');

Expand All @@ -9,6 +11,7 @@ function viewTemplate(template, index)
data: '&m=viewTemplate&template=' + template,
success: function (resultData) {
$('#template-viewer').html(resultData)
loadingStop();
}
});
}
Expand Down Expand Up @@ -46,13 +49,13 @@ function applyTemplateOptions()
});
}
// ---------------------------------------------------------------------------------------------
function deleteCustomTemplate(app, starr)
function deleteCustomTemplate(app, item)
{
if (confirm('Are you sure you want to delete this template?')) {
$.ajax({
type: 'POST',
url: 'ajax/templates.php',
data: '&m=deleteCustomTemplate&app=' + app + '&starr=' + starr,
data: '&m=deleteCustomTemplate&app=' + app + '&item=' + item,
success: function () {
reload();
}
Expand Down
2 changes: 2 additions & 0 deletions root/app/www/public/loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,5 @@
define('LOG_ROTATE_SIZE', $settingsTable['logRotationSize'] ?: $LOG_ROTATE_SIZE);
define('LOG_AGE', $settingsTable['logRetentionLength'] ?: $LOG_AGE);
define('BACKUP_AGE', $settingsTable['backupRetentionLength'] ?: $BACKUP_AGE);

define('TEMPLATE_ORDER', $settingsTable['templateOrder'] ?: 1);
41 changes: 41 additions & 0 deletions root/app/www/public/migrations/006_ui_template_order.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

/*
----------------------------------
------ Created: 111424 ------
------ Austin Best ------
----------------------------------
*/

//-- RESET THE LIST
$q = [];

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

$settings = [
'templateOrder' => 1
];

$settingRows = [];
foreach ($settings as $key => $val) {
$settingRows[] = "('" . $key . "', '" . $val . "')";
}

$q[] = "INSERT INTO " . SETTINGS_TABLE . "
(`name`, `value`)
VALUES " . implode(', ', $settingRows);

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

$proxyDb->query($query);

if ($proxyDb->error() != 'not an error') {
logger(MIGRATION_LOG, '<span class="text-info">[R]</span> ' . $proxyDb->error(), 'error');
} else {
logger(MIGRATION_LOG, '<span class="text-info">[R]</span> query applied!');
}
}
19 changes: 19 additions & 0 deletions root/app/www/public/pages/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@
<div class="card-body">
<div class="table-responsive">
<table class="table table-bordered table-hover">
<thead>
<tr>
<th colspan="2">Navigation</th>
</tr>
</thead>
<tbody>
<?php
foreach (StarrApps::LIST as $index => $starrApp) {
Expand Down Expand Up @@ -96,6 +101,20 @@
</td>
</tr>
</tbody>
<thead>
<tr>
<th colspan="2">Templates</th>
</tr>
<tr>
<td class="w-25">Order</td>
<td>
<select id="setting-templateOrder" class="form-select w-50">
<option <?= $settingsTable['templateOrder'] == 1 ? 'selected ' : '' ?>value="1">Group by app</option>
<option <?= $settingsTable['templateOrder'] == 2 ? 'selected ' : '' ?>value="2">Group by starr</option>
</select>
</td>
</tr>
</thead>
</table>
<br>** Refresh the page after changing UI settings
</div>
Expand Down
12 changes: 8 additions & 4 deletions root/app/www/public/pages/templates.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
?>

<div class="row p3">
<div class="col-sm-1">
<div class="col-sm-2">
<?php
$index = 0;
foreach ($templateList as $app => $appTemplates) {
Expand All @@ -30,16 +30,20 @@
?>
<ul style="margin-bottom: 0px; padding-bottom: 0px;">
<li class="app-index-<?= $index ?>">
<span style="cursor: pointer;" onclick="viewTemplate('<?= $appTemplate['location'] . $appTemplate['starr'] ?>/<?= $app ?>.json', <?= $index ?>)"><?= $appTemplate['starr'] ?></span>
<?= $custom ? ' <i class="far fa-user text-warning" title="Custom user template"></i> <i class="far fa-trash-alt text-danger" title="Delete custom template" style="cursor:pointer;" onclick="deleteCustomTemplate(\'' . $app . '\', \'' . $appTemplate['starr'] . '\')"></i>' : '' ?>
<?php if (TEMPLATE_ORDER == 1) { ?>
<span style="cursor: pointer;" onclick="viewTemplate('<?= $appTemplate['location'] . $appTemplate['item'] ?>/<?= $app ?>.json', <?= $index ?>)"><?= $appTemplate['item'] ?></span>
<?php } elseif (TEMPLATE_ORDER == 2) { ?>
<span style="cursor: pointer;" onclick="viewTemplate('<?= $appTemplate['location'] . $app ?>/<?= $appTemplate['item'] ?>.json', <?= $index ?>)"><?= $appTemplate['item'] ?></span>
<?php } ?>
<?= $custom ? ' <i class="far fa-user text-warning" title="Custom user template"></i> <i class="far fa-trash-alt text-danger" title="Delete custom template" style="cursor:pointer;" onclick="deleteCustomTemplate(\'' . $app . '\', \'' . $appTemplate['item'] . '\')"></i>' : '' ?>
</li>
</ul>
<?php
}
}
?>
</div>
<div class="col-sm-11">
<div class="col-sm-10">
<div id="template-viewer" class="mt-3"></div>
</div>
</div>

0 comments on commit 7c166c8

Please sign in to comment.