diff --git a/src/Controllers/SettingsController.cs b/src/Controllers/SettingsController.cs index fa01430..2bf2d9b 100644 --- a/src/Controllers/SettingsController.cs +++ b/src/Controllers/SettingsController.cs @@ -33,7 +33,15 @@ public class SettingsController : Controller public async Task AdminAsync() { AdminSettingsModel adminSettingsModel = await _ldap.GetAdminSettingsModelAsync(); - return View(); + return View(adminSettingsModel); + } + + [Authorize] + [HttpGet("Presets")] + public async Task> PresetsAsync() + { + AdminSettingsModel adminSettingsModel = await _ldap.GetAdminSettingsModelAsync(); + return adminSettingsModel.Presets; } [Authorize(Roles = "CanManageSettings")] diff --git a/src/Resources/Views.Home.Assets.de.resx b/src/Resources/Views.Home.Assets.de.resx index ee05dec..8a80ddd 100644 --- a/src/Resources/Views.Home.Assets.de.resx +++ b/src/Resources/Views.Home.Assets.de.resx @@ -178,4 +178,13 @@ Datum + + Vorlage + + + Vorlage auswählen + + + Vorlage anwenden + diff --git a/src/Resources/Views.Settings.Admin.resx b/src/Resources/Views.Settings.Admin.resx new file mode 100644 index 0000000..1915c86 --- /dev/null +++ b/src/Resources/Views.Settings.Admin.resx @@ -0,0 +1,91 @@ + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, ... + + + System.Resources.ResXResourceWriter, System.Windows.Forms, ... + + + + Benutzer + + + + Allgemeine Einstellungen + + + + Standard-Hashalgorithmus + + + + Barcode-Typ + + + + Barcode-Text + + + + Maximale Download-Größe für Benutzerbilder + + + + Vorlagen + + + + Name der Vorlage + + + + Attribute + + + + Name + + + + Wert + + + + Attribut löschen + + + + Attribut hinzufügen + + + + Vorlage löschen + + + + Vorlage hinzufügen + + + + Einstellungen übernehmen und Vorlagen aktualisieren + + + + Einstellungen erfolgreich aktualisiert + + + + Unbekannter Fehler + + + + Fehler bei der Kommunikation mit dem Server + + diff --git a/src/Resources/Views.Shared._Layout.de.resx b/src/Resources/Views.Shared._Layout.de.resx index 54a4121..174cddd 100644 --- a/src/Resources/Views.Shared._Layout.de.resx +++ b/src/Resources/Views.Shared._Layout.de.resx @@ -43,7 +43,13 @@ Fehler beim Laden der Orte + + Fehler beim Laden der Vorlagen + Benutzer auswählen + + Vorlage auswählen + diff --git a/src/Views/Home/Assets.cshtml b/src/Views/Home/Assets.cshtml index 5aca7a3..a477187 100644 --- a/src/Views/Home/Assets.cshtml +++ b/src/Views/Home/Assets.cshtml @@ -1,11 +1,14 @@ +@using Berufsschule_HAM.Services @using Microsoft.AspNetCore.Mvc.Localization @using Berufsschule_HAM.Models @model HomeIndexViewModel @inject IViewLocalizer T -@inject IConfiguration Configuration +@inject LdapService ldap @{ ViewData["Title"] = T["Assets"]; - string barcodeType = Configuration["BarcodeType"] ?? "EAN13"; + var adminSettingsModel = await ldap.GetAdminSettingsModelAsync(); + string barcodeType = adminSettingsModel.BarcodeType ?? "EAN13"; + string barcodeText = adminSettingsModel.BarcodeText ?? "HAM"; } @@ -192,6 +195,18 @@
+

@T["Preset"]

+
+ +
+
+ +
+ +
+

@T["Description"]

@@ -254,7 +269,7 @@
- diff --git a/src/Views/Home/Users.cshtml b/src/Views/Home/Users.cshtml index 4e6d35e..47770e8 100644 --- a/src/Views/Home/Users.cshtml +++ b/src/Views/Home/Users.cshtml @@ -235,33 +235,6 @@ + + \ No newline at end of file diff --git a/src/Views/Shared/_Layout.cshtml b/src/Views/Shared/_Layout.cshtml index 1629a42..29761ed 100644 --- a/src/Views/Shared/_Layout.cshtml +++ b/src/Views/Shared/_Layout.cshtml @@ -25,7 +25,9 @@ selectLocation: '@T["Select location"]', errorLoadingLocations: '@T["Error loading locations"]', selectUser: '@T["Select user"]', - errorLoadingUsers: '@T["Error loading users"]' + selectPreset: '@T["Select preset"]', + errorLoadingUsers: '@T["Error loading users"]', + errorLoadingPresets: '@T["Error loading presets"]' }; diff --git a/src/wwwroot/js/site.js b/src/wwwroot/js/site.js index bfdde28..c1bd0c8 100644 --- a/src/wwwroot/js/site.js +++ b/src/wwwroot/js/site.js @@ -239,4 +239,66 @@ function validatePassword(password) { const strongPasswordRegex = /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[!@#$%^&*()_\-+=\[{\]};:'",<.>/?\\|`~]).{8,}$/; return strongPasswordRegex.test(password); +} + +function unflatten(obj) { + const result = {}; + for (const [key, value] of Object.entries(obj)) { + const parts = key.split("."); + let current = result; + for (let i = 0; i < parts.length; i++) { + const part = parts[i]; + if (i === parts.length - 1) { + if (typeof value === "string" && /^[\[{]/.test(value.trim())) { + try { + current[part] = JSON.parse(value); + } catch { + current[part] = value; + } + } else { + current[part] = value; + } + } else { + current[part] = current[part] || {}; + current = current[part]; + } + } + } + return result; +} + +function sleep(ms) { + return new Promise(resolve => setTimeout(resolve, ms)); +} + +async function loadPresetsIntoSelect(selectElement, selectedValue = null) { + try { + const response = await fetch('/Settings/Presets'); + const responseJson = await response.json(); + var presets = []; + for (var key in responseJson) { + presets.push(key); + } + console.log(presets); + const ts = selectElement.tomselect; + if (!ts) { + selectElement.innerHTML = ``; + presets.forEach(u => { + const opt = document.createElement('option'); + opt.value = u; + opt.textContent = u; + selectElement.appendChild(opt); + }); + return; + } + + ts.clearOptions(); + ts.addOption(presets.map(u => ({ value: u, text: u }))); + ts.refreshOptions(false); + + if (selectedValue) ts.setValue(selectedValue); + } catch (err) { + console.error('Error loading presets:', err); + showToast(appTranslations.errorLoadingPresets, 'danger'); + } } \ No newline at end of file