Upload new version

This commit is contained in:
2026-01-20 01:12:22 +01:00
parent abd74a9a50
commit 3d559924a9
15 changed files with 1632 additions and 517 deletions

View File

@@ -18,6 +18,7 @@
const requestedMode = (qs.get('mode') || 'templates').toLowerCase();
B.EDITOR_MODE = (B.EDITOR_MODE || requestedMode.toUpperCase());
const EDITOR_MODE = (B.EDITOR_MODE || 'TEMPLATES').toLowerCase();
const SECTION_ID = Number(qs.get('section_id') || B.CURRENT_SECTION_ID || 0);
log(`START: SKRIPT-AUSFÜHRUNG GESTARTET. Editor Modus: ${EDITOR_MODE}.`, '#DC143C');
const TARGET_CAT_ID = 'custom';
@@ -479,7 +480,7 @@
jsonProjectDataRaw = '';
}
const resource = EDITOR_MODE;
const resource = 'content';
const action = `${resource}.update`;
const debugSave = (() => {
try {
@@ -501,6 +502,9 @@
// 🚨 KRITISCH: Server erwartet das Feld 'json'
json: jsonProjectDataRaw,
};
if (SECTION_ID) {
dataToSend.section_id = SECTION_ID;
}
if (debugSave) {
dataToSend.debug = 1;
console.log('[ET DEBUG] save-data payload', {

View File

@@ -61,28 +61,32 @@
    };
    const shouldLoad = (resource) => {
        if (Array.isArray(B.ALLOWED_SECTION_SLUGS) && B.ALLOWED_SECTION_SLUGS.length) {
            return B.ALLOWED_SECTION_SLUGS.includes(resource);
        }
        const mode = (B.EDITOR_MODE || 'TEMPLATES').toUpperCase();
        
// HINWEIS: Hier muss für neue Ressourcen (wie 'products') ggf. der mode angepasst werden,
// falls sie nicht in TEMPLATES geladen werden sollen.
        switch (mode) {
            case 'TEMPLATES':
                const templateResources = ['templates', 'sections', 'blocks', 'snippets', 'products']; // Beispiel: products hinzugefügt
                return templateResources.includes(resource);
            case 'SECTIONS':
                const sectionResources = ['blocks', 'snippets'];
                return sectionResources.includes(resource);
            case 'BLOCKS':
                return resource === 'snippets';
            
                return true;
            default:
                log('MODE WARN', `Unbekannter Editor Modus '${mode}' festgestellt.`, 'orange', 'warn');
                return resource === 'snippets';
                return true;
        }
    };
    const fetchSectionsConfig = async () => {
        const rows = await fetchData('sections_config', 'list');
        return Array.isArray(rows) ? rows : [];
    };
    const resolveAllowedSections = async () => {
        const sections = await fetchSectionsConfig();
        if (!sections.length) return [];
        const modeSlug = String(B.EDITOR_MODE || '').toLowerCase();
        const current = sections.find(s => String(s.slug || '').toLowerCase() === modeSlug);
        if (!current) return sections;
        return sections.filter(s => Number(s.position) > Number(current.position));
    };
    const fetchData = (resource, action='list', params = {}) => {
// ... (Rest der fetchData-Funktion bleibt unverändert, nutzt aber die korrigierte buildApiUrl)
@@ -151,13 +155,13 @@
// --- Exportierte Core-Funktionen (jetzt generisch) ---
// NEU: Generische Fetch-Funktion für jeden Ressourcentyp ('kind')
B.fetchResource = (kind) => {
    B.fetchResource = (kind) => {
        if (!shouldLoad(kind)) {
            log('BLOCKED', `Blockiert: ${kind} (Modus: ${B.EDITOR_MODE})`, '#708090', 'info');
            return Promise.resolve([]);
        }
        return fetchData(kind).then(items => Array.isArray(items) ? items : []);
};
    };
// Die alten hardcodierten Funktionen verwenden jetzt die neue generische Funktion
B.fetchTemplates = () => B.fetchResource('templates');
@@ -173,37 +177,40 @@
    };
    // 🚀 Zentrale Funktion zum Laden und Registrieren der Blöcke
B.loadAndRegisterApiBlocks = (editor) => {
    B.loadAndRegisterApiBlocks = (editor) => {
const bm = editor.BlockManager;
// NEU: Ressourcen-Kinds aus der Konfiguration sammeln
const resourceKindsToLoad = Object.keys(B.RESOURCE_API_BASES || {});
if (resourceKindsToLoad.length === 0) {
log('FEHLER', 'Keine Ressourcen-Kind-Konfiguration (B.RESOURCE_API_BASES) gefunden.', '#dc3545', 'error', true);
bm.remove(PLACEHOLDER_ID);
return;
}
// Map aller Fetch-Promises erstellen
const fetchPromises = resourceKindsToLoad.map(kind =>
B.fetchResource(kind).then(items => items.map(i => ({ ...i, kind: kind })))
);
const loadDynamic = async () => {
const sections = await resolveAllowedSections();
B.ALLOWED_SECTION_SLUGS = sections.map(s => String(s.slug || '').toLowerCase());
if (!sections.length) return [];
const promises = sections.map(section =>
fetchData('content', 'list', { section_id: section.id })
.then(items => (Array.isArray(items) ? items : []).map(i => ({
...i,
kind: String(section.slug || '').toLowerCase(),
section_name: section.name || '',
})))
);
const results = await Promise.all(promises);
return results.flat();
};
log('API START', `Starte Promise.all für API-Abruf der Blöcke/Sektionen (${resourceKindsToLoad.join(', ')})...`, '#1E90FF');
const startLoad = (B.USE_DYNAMIC_SECTIONS ? loadDynamic() : Promise.resolve([]));
Promise.all(fetchPromises)
.then(results => {
const apiItems = results.flat().filter(item => item && item.id);
log('API START', 'Starte API-Abruf für dynamische Sections...', '#1E90FF');
startLoad
.then(apiItems => {
const filtered = Array.isArray(apiItems) ? apiItems.filter(item => item && item.id) : [];
 
log(`API SUCCESS`, `${apiItems.length} Elemente gefunden.`, '#9400D3');
logApiData(apiItems); 
log(`API SUCCESS`, `${filtered.length} Elemente gefunden.`, '#9400D3');
logApiData(filtered); 
 
if (apiItems.length === 0) {
if (filtered.length === 0) {
log('NO DATA', 'Keine API-Daten gefunden.', 'orange', 'warn', true);
} else {
apiItems.forEach(item => {
filtered.forEach(item => {
const blockId = `lib-${item.kind}-${item.id}`;
const label = item.name || item.label || 'Unbenannter Block';
const itemKindUpper = item.kind.toUpperCase();