mirror of
https://github.com/Dvorinka/PPve.git
synced 2026-06-05 04:52:58 +00:00
rr
This commit is contained in:
+57
-7
@@ -1426,19 +1426,44 @@ const HARDCODED_APPS = [
|
|||||||
];
|
];
|
||||||
|
|
||||||
// Load hardcoded apps
|
// Load hardcoded apps
|
||||||
function loadHardcodedApps() {
|
async function loadHardcodedApps() {
|
||||||
const hardcodedAppsList = document.getElementById('hardcodedAppsList');
|
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 = `
|
hardcodedAppsList.innerHTML = `
|
||||||
<div class="text-center py-4 text-gray-500">
|
<div class="text-center py-4 text-gray-500">
|
||||||
Žádné přednastavené aplikace nebyly nalezeny
|
Žádné přednastavené aplikace k zobrazení
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
hardcodedAppsList.innerHTML = HARDCODED_APPS.map(app => `
|
hardcodedAppsList.innerHTML = uniqueHardcodedApps.map(app => `
|
||||||
<div class="bg-white rounded-lg shadow p-4 flex items-center justify-between">
|
<div class="bg-white rounded-lg shadow p-4 flex items-center justify-between">
|
||||||
<div class="flex items-center space-x-4">
|
<div class="flex items-center space-x-4">
|
||||||
<div class="w-12 h-12 rounded-full bg-${app.color}-100 text-${app.color}-600 flex items-center justify-center">
|
<div class="w-12 h-12 rounded-full bg-${app.color}-100 text-${app.color}-600 flex items-center justify-center">
|
||||||
@@ -1455,6 +1480,14 @@ function loadHardcodedApps() {
|
|||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
`).join('');
|
`).join('');
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error loading hardcoded apps:', error);
|
||||||
|
hardcodedAppsList.innerHTML = `
|
||||||
|
<div class="text-center py-4 text-gray-500">
|
||||||
|
Chyba při načítání přednastavených aplikací
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load dynamic apps
|
// Load dynamic apps
|
||||||
@@ -1498,8 +1531,20 @@ async function loadDynamicApps() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Map all apps to HTML, including hardcoded ones
|
// Filter out hardcoded apps and map only custom apps to HTML
|
||||||
const dynamicApps = apps.map(app => `
|
const customApps = apps.filter(app => !app.id || !app.id.startsWith('hardcoded-'));
|
||||||
|
|
||||||
|
if (customApps.length === 0) {
|
||||||
|
dynamicAppsList.innerHTML = `
|
||||||
|
<div class="text-center py-8">
|
||||||
|
<i class="fas fa-inbox text-4xl text-gray-300 mb-2"></i>
|
||||||
|
<p class="text-gray-500">Žádné vlastní aplikace nebyly nalezeny</p>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const dynamicApps = customApps.map(app => `
|
||||||
<div class="bg-white rounded-lg shadow p-4 flex items-center justify-between ${app.id && app.id.startsWith('hardcoded-') ? 'opacity-75' : ''}" data-app-id="${app.id}">
|
<div class="bg-white rounded-lg shadow p-4 flex items-center justify-between ${app.id && app.id.startsWith('hardcoded-') ? 'opacity-75' : ''}" data-app-id="${app.id}">
|
||||||
<div class="flex items-center space-x-4">
|
<div class="flex items-center space-x-4">
|
||||||
${app.icon ?
|
${app.icon ?
|
||||||
@@ -1556,8 +1601,13 @@ async function loadDynamicApps() {
|
|||||||
|
|
||||||
// Load all apps (both hardcoded and dynamic)
|
// Load all apps (both hardcoded and dynamic)
|
||||||
async function loadApps() {
|
async function loadApps() {
|
||||||
loadHardcodedApps();
|
try {
|
||||||
|
// Load hardcoded apps first, then dynamic apps
|
||||||
|
await loadHardcodedApps();
|
||||||
await loadDynamicApps();
|
await loadDynamicApps();
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error loading apps:', error);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function saveApp(event) {
|
async function saveApp(event) {
|
||||||
|
|||||||
Reference in New Issue
Block a user