From d7f00e2653ec7393d1dacf348823cda825046635 Mon Sep 17 00:00:00 2001 From: Tomas Dvorak Date: Fri, 30 May 2025 09:33:42 +0200 Subject: [PATCH] rr --- admin-dashboard.html | 102 ++++++++++++++++++++++++++++++++----------- 1 file changed, 76 insertions(+), 26 deletions(-) diff --git a/admin-dashboard.html b/admin-dashboard.html index de0a0ea..ca28a5a 100644 --- a/admin-dashboard.html +++ b/admin-dashboard.html @@ -1426,35 +1426,68 @@ const HARDCODED_APPS = [ ]; // Load hardcoded apps -function loadHardcodedApps() { +async function loadHardcodedApps() { const hardcodedAppsList = document.getElementById('hardcodedAppsList'); - if (HARDCODED_APPS.length === 0) { + try { + // Get the list of dynamic apps to check for duplicates + const token = localStorage.getItem('token'); + if (!token) { + window.location.href = '/login.html'; + return; + } + + const response = await fetch('/api/apps', { + headers: { + 'Authorization': `Bearer ${token}`, + 'Content-Type': 'application/json' + } + }); + + if (!response.ok) { + throw new Error(`HTTP error! status: ${response.status}`); + } + + const dynamicApps = await response.json(); + const dynamicAppIds = new Set(dynamicApps.map(app => app.id)); + + // Filter out hardcoded apps that are already in the dynamic apps list + const uniqueHardcodedApps = HARDCODED_APPS.filter(app => !dynamicAppIds.has(app.id)); + + if (uniqueHardcodedApps.length === 0) { + hardcodedAppsList.innerHTML = ` +
+ Žádné přednastavené aplikace k zobrazení +
+ `; + return; + } + + hardcodedAppsList.innerHTML = uniqueHardcodedApps.map(app => ` +
+
+
+ +
+
+

${app.name}

+

${app.url}

+

${app.description}

+
+
+ + Přednastaveno + +
+ `).join(''); + } catch (error) { + console.error('Error loading hardcoded apps:', error); hardcodedAppsList.innerHTML = `
- Žádné přednastavené aplikace nebyly nalezeny + Chyba při načítání přednastavených aplikací
`; - return; } - - hardcodedAppsList.innerHTML = HARDCODED_APPS.map(app => ` -
-
-
- -
-
-

${app.name}

-

${app.url}

-

${app.description}

-
-
- - Přednastaveno - -
- `).join(''); } // Load dynamic apps @@ -1498,8 +1531,20 @@ async function loadDynamicApps() { return; } - // Map all apps to HTML, including hardcoded ones - const dynamicApps = apps.map(app => ` + // Filter out hardcoded apps and map only custom apps to HTML + const customApps = apps.filter(app => !app.id || !app.id.startsWith('hardcoded-')); + + if (customApps.length === 0) { + dynamicAppsList.innerHTML = ` +
+ +

Žádné vlastní aplikace nebyly nalezeny

+
+ `; + return; + } + + const dynamicApps = customApps.map(app => `
${app.icon ? @@ -1556,8 +1601,13 @@ async function loadDynamicApps() { // Load all apps (both hardcoded and dynamic) async function loadApps() { - loadHardcodedApps(); - await loadDynamicApps(); + try { + // Load hardcoded apps first, then dynamic apps + await loadHardcodedApps(); + await loadDynamicApps(); + } catch (error) { + console.error('Error loading apps:', error); + } } async function saveApp(event) {