diff options
| author | winter | 2025-01-18 20:02:39 +0000 |
|---|---|---|
| committer | winter | 2025-01-18 20:02:39 +0000 |
| commit | 66bdcf04f431d615b5fac93e7677e7304888e90c (patch) | |
| tree | d75f1b299e8ed2ff8d2fd6ccd42185cfb06b6729 /templates | |
| parent | 00ab9734e880219fa68fed98cefda5ce12958e4b (diff) | |
implement settings editor page
Diffstat (limited to 'templates')
| -rw-r--r-- | templates/global_settings_page.php | 6 | ||||
| -rw-r--r-- | templates/settings_editor.php | 27 | ||||
| -rw-r--r-- | templates/settings_field.php | 31 | ||||
| -rw-r--r-- | templates/skeleton.php | 23 |
4 files changed, 77 insertions, 10 deletions
diff --git a/templates/global_settings_page.php b/templates/global_settings_page.php new file mode 100644 index 0000000..fcaf7ab --- /dev/null +++ b/templates/global_settings_page.php @@ -0,0 +1,6 @@ +<?php call_template('skeleton', [ + 'pageTitle' => sprintf(__('globalSettings.pageTitle'), $prefix) +], function () { + global $prefix; + call_template('settings_editor', ['prefix' => $prefix]); +});
\ No newline at end of file diff --git a/templates/settings_editor.php b/templates/settings_editor.php new file mode 100644 index 0000000..1bf72b7 --- /dev/null +++ b/templates/settings_editor.php @@ -0,0 +1,27 @@ +<?php +use Digitigrade\GlobalSettings; + +$settings = GlobalSettings::getInstance(); +?> +<form class="settings nopanel" action="/todo" hx-post="/fragment/admin/settings/<?= $prefix ?>" hx-swap="outerHTML" + hx-disabled-elt="find button"> + <?php foreach ($settings->getAllInPrefix($prefix) as $key => $value) { + $info = $settings->getInfo($key); + call_template('settings_field', [ + 'key' => $key, + 'value' => $value, + 'name' => $info['name'] ?? $key, + 'description' => $info['description'] ?? '', + 'options' => $info['options'] ?? null, + 'type' => $info['type'] ?? 'string' + ]); + } ?> + <div class="row"> + <div> + <?php if ($saved ?? false): ?> + <span class="temporaryIndicator"><?= __('form.saved') ?></span> + <?php endif; ?> + </div> + <button class="primary"><?= __('form.saveChanges') ?></button> + </div> +</form>
\ No newline at end of file diff --git a/templates/settings_field.php b/templates/settings_field.php new file mode 100644 index 0000000..15b6c71 --- /dev/null +++ b/templates/settings_field.php @@ -0,0 +1,31 @@ +<?php +$id = "setting-$key"; +$inputType = 'text'; +if (($type ?? null) == 'boolean') { + $inputType = 'select'; + $options = ['true', 'false']; +} +// php converts . to _ in $_POST for some mikuforsaken reason so i'm working around it like this +$fieldName = str_replace('.', '<DOT>', $key); +?> +<div class="row"> + + <label for="<?= $id ?>"> + <strong><?= $name ?></strong><br> + <?= $description ?> + </label> + + <?php if ($inputType == 'select'): ?> + + <select id="<?= $id ?>" name="<?= $fieldName ?>"> + <?php foreach ($options as $o): ?> + <option <?= $value == $o ? 'selected' : '' ?>><?= $o ?></option> + <?php endforeach; ?> + </select> + + <?php else: ?> + + <input id="<?= $id ?>" name="<?= $fieldName ?>" value="<?= $value ?>" type="<?= $inputType ?>" autocomplete="off"> + + <?php endif; ?> +</div>
\ No newline at end of file diff --git a/templates/skeleton.php b/templates/skeleton.php index b274484..3aaf132 100644 --- a/templates/skeleton.php +++ b/templates/skeleton.php @@ -1,5 +1,6 @@ <?php +use Digitigrade\GlobalSettings; use Digitigrade\Model\FollowRelation; $user = Digitigrade\Model\UserAccount::findByCurrentSession(); ?> @@ -28,7 +29,7 @@ $user = Digitigrade\Model\UserAccount::findByCurrentSession(); ]); call_template('navigation_links', ['links' => $links]); ?> - <span id="siteTitle"><?= __('digitigrade') ?></span> + <span id="siteTitle"><?= GlobalSettings::getInstance()->get('instance.name') ?></span> <img id="loadingIndicator" class="htmx-indicator" src="/static/tail-spin.svg"> <?php if ($user == null): call_template('navigation_links', ['links' => [ @@ -47,15 +48,17 @@ $user = Digitigrade\Model\UserAccount::findByCurrentSession(); <?php if ($user != null) { call_template('write_note_form'); - call_template('side_navigation', ['links' => [ - [ - 'href' => '/followrequests', - 'icon' => 'person_add', - 'label' => __('navigation.followRequests'), - 'unreadCount' => FollowRelation::countWhere("object = ? AND status = 'pending'", [$user->actor->id]) - ], - ['href' => '/logout', 'icon' => 'logout', 'label' => __('navigation.logout')] - ]]); + $links = [[ + 'href' => '/followrequests', + 'icon' => 'person_add', + 'label' => __('navigation.followRequests'), + 'unreadCount' => FollowRelation::countWhere("object = ? AND status = 'pending'", [$user->actor->id]) + ]]; + if ($user->isAdmin) { + $links[] = ['href' => '/admin/settings/instance', 'icon' => 'settings', 'label' => __('navigation.instanceSettings')]; + } + $links[] = ['href' => '/logout', 'icon' => 'logout', 'label' => __('navigation.logout')]; + call_template('side_navigation', ['links' => $links]); } ?> </section> |
