refactor: use string-backed enum for variant selection
This commit is contained in:
parent
a59155e3d6
commit
744077f0fd
@ -6,4 +6,14 @@ namespace OCA\PrideFlags;
|
||||
|
||||
abstract class AppConstants {
|
||||
public const APP_ID = 'pride_flags';
|
||||
public enum Variants: string {
|
||||
case PRIDE = "Pride";
|
||||
case TRANS = "Trans Pride";
|
||||
case PAN = "Pansexual Pride";
|
||||
case BI = "Bisexual Pride";
|
||||
case ASEXUAL = "Asexual Pride";
|
||||
case LESBIAN = "Lesbian Pride";
|
||||
case NONBINARY = "Non-binary Pride";
|
||||
case NONE = "No customisation";
|
||||
}
|
||||
}
|
||||
|
@ -18,11 +18,16 @@ class AppSettings {
|
||||
}
|
||||
|
||||
public function setStringSetting($userId, string $key, string $value): void {
|
||||
$this->config->setUserValue(AppConstants::APP_ID, $userId, $key, $value);
|
||||
// Check for valid Variant here
|
||||
if (AppConstants\Variants::tryFrom($value) != null) {
|
||||
$this->config->setUserValue(AppConstants::APP_ID, $userId, $key, $value);
|
||||
}
|
||||
}
|
||||
|
||||
public function setAppStringSetting(string $key, string $value): void {
|
||||
$this->config->setAppValue(AppConstants::APP_ID, $key, $value);
|
||||
if (AppConstants\Variants::tryFrom($value) != null) {
|
||||
$this->config->setAppValue(AppConstants::APP_ID, $key, $value);
|
||||
}
|
||||
}
|
||||
|
||||
public function getAll($userId): array {
|
||||
|
@ -1,5 +1,8 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types = 1);
|
||||
use OCA\PrideFlags\AppConstants;
|
||||
|
||||
?>
|
||||
<div class="pride_flags_user_settings">
|
||||
<div class="settings-section section hidden">
|
||||
@ -7,25 +10,17 @@
|
||||
<div class="user-settings folder-flavour" style="margin-left: 40px; display: flex;">
|
||||
<label for="user-settings-folder-flavour-select" style="display: flex; width: 100px;">Folders</label>
|
||||
<select id="user-settings-folder-flavour-select" style="display: flex; width: 200px;">
|
||||
<option value='pride'>Pride</option>
|
||||
<option value='trans'>Trans Pride</option>
|
||||
<option value='pan'>Pansexual Pride</option>
|
||||
<option value='nonbinary'>Non-binary Pride</option>
|
||||
<option value='bi'>Bisexual Pride</option>
|
||||
<option value='asexual'>Asexual Pride</option>
|
||||
<option value='lesbian'>Lesbian Pride</option>
|
||||
<?php foreach (AppConstants\Variants::cases() as $variant): ?>
|
||||
<option value="<?= strtolower($variant->name) ?>"><?= $variant->value ?></option>
|
||||
<?php endforeach ?>
|
||||
</select>
|
||||
</div>
|
||||
<div class="user-settings button-flavour" style="margin-left: 40px; display: flex;">
|
||||
<label for="user-settings-button-flavour-select" style="display: flex; width: 100px;">Buttons</label>
|
||||
<select id="user-settings-button-flavour-select" style="display: flex; width: 200px;">
|
||||
<option value='pride'>Pride</option>
|
||||
<option value='trans'>Trans Pride</option>
|
||||
<option value='pan'>Pansexual Pride</option>
|
||||
<option value='nonbinary'>Non-binary Pride</option>
|
||||
<option value='bi'>Bisexual Pride</option>
|
||||
<option value='asexual'>Asexual Pride</option>
|
||||
<option value='lesbian'>Lesbian Pride</option>
|
||||
<?php foreach (AppConstants\Variants::cases() as $variant): ?>
|
||||
<option value="<?= strtolower($variant->name) ?>"><?= $variant->value ?></option>
|
||||
<?php endforeach ?>
|
||||
</select>
|
||||
</div>
|
||||
<button class="settings-pride-submit button primary" style="margin-left: 40px; display: flex; width: 80px; text-align: center;">Save</button>
|
||||
|
Loading…
x
Reference in New Issue
Block a user