diff --git a/frontend/js/api.js b/frontend/js/api.js index 379fc6a..7149d25 100644 --- a/frontend/js/api.js +++ b/frontend/js/api.js @@ -134,6 +134,7 @@ export const api = { // Widgets getWidgets: () => request('/widgets'), + getWidget: (id) => request('/widgets/' + id), // Device Groups getGroups: () => request('/groups'), diff --git a/frontend/js/app.js b/frontend/js/app.js index 96c106f..f155577 100644 --- a/frontend/js/app.js +++ b/frontend/js/app.js @@ -393,7 +393,7 @@ function route() { else if ((hash.startsWith('#/wall') || hash === '#/walls') && link.dataset.view === 'walls') link.classList.add('active'); else if (hash === '#/reports' && link.dataset.view === 'reports') link.classList.add('active'); else if (hash === '#/activity' && link.dataset.view === 'activity') link.classList.add('active'); - else if (hash === '#/designer' && link.dataset.view === 'designer') link.classList.add('active'); + else if ((hash === '#/designer' || hash.startsWith('#/designer/')) && link.dataset.view === 'designer') link.classList.add('active'); else if ((hash === '#/kiosk' || hash.startsWith('#/kiosk/')) && link.dataset.view === 'kiosk') link.classList.add('active'); else if (hash === '#/help' && link.dataset.view === 'help') link.classList.add('active'); else if (hash.startsWith('#/device/') && link.dataset.view === 'dashboard') link.classList.add('active'); @@ -431,9 +431,11 @@ function route() { } else if (hash === '#/kiosk' || hash.startsWith('#/kiosk/')) { currentView = kiosk; kiosk.render(app); - } else if (hash === '#/designer') { + } else if (hash === '#/designer' || hash.startsWith('#/designer/')) { currentView = designer; - designer.render(app); + // #/designer/ reopens a designer-made widget for editing; #/designer starts fresh. + const wid = hash.startsWith('#/designer/') ? hash.split('#/designer/')[1].split('/')[0] : null; + designer.render(app, wid || undefined); } else if (hash === '#/activity') { currentView = activity; activity.render(app); diff --git a/frontend/js/views/designer.js b/frontend/js/views/designer.js index 1dc44e5..a8ba70a 100644 --- a/frontend/js/views/designer.js +++ b/frontend/js/views/designer.js @@ -25,12 +25,18 @@ let bgValue = '#000000'; let bgImageDataUrl = null; let dragging = null; let dragStart = null; +// When editing an existing designer-made widget: its id + name, so Publish UPDATES it (PUT) instead of +// creating a new one. Null = a fresh design (create). +let editingWidgetId = null; +let editingWidgetName = null; -export function render(container) { +export function render(container, widgetId) { elements = []; selectedIdx = -1; bgValue = '#000000'; bgImageDataUrl = null; + editingWidgetId = null; + editingWidgetName = null; container.innerHTML = `