@mmlogic/components 0.2.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/loader.cjs.js +1 -1
- package/dist/cjs/mosterdcomponents.cjs.js +1 -1
- package/dist/cjs/mrd-boolean-field_19.cjs.entry.js +323 -184
- package/dist/collection/components/mrd-layout-section/mrd-layout-section.js +61 -177
- package/dist/collection/components/mrd-table/mrd-table.js +325 -214
- package/dist/collection/dev/api.js +23 -6
- package/dist/collection/dev/app.js +358 -268
- package/dist/components/mrd-layout-section.js +1 -1
- package/dist/components/mrd-table2.js +1 -1
- package/dist/esm/loader.js +1 -1
- package/dist/esm/mosterdcomponents.js +1 -1
- package/dist/esm/mrd-boolean-field_19.entry.js +323 -184
- package/dist/mosterdcomponents/mosterdcomponents.esm.js +1 -1
- package/dist/mosterdcomponents/p-af4c247e.entry.js +1 -0
- package/dist/types/components/mrd-layout-section/mrd-layout-section.d.ts +18 -32
- package/dist/types/components/mrd-table/mrd-table.d.ts +54 -29
- package/dist/types/components.d.ts +42 -88
- package/dist/types/types/client-layout.d.ts +18 -17
- package/package.json +1 -1
- package/dist/mosterdcomponents/p-61ef0232.entry.js +0 -1
|
@@ -2,13 +2,17 @@
|
|
|
2
2
|
APP STATE
|
|
3
3
|
===================================================================== */
|
|
4
4
|
|
|
5
|
-
let _selectedTenant
|
|
6
|
-
let _selectedType
|
|
7
|
-
let _relationMeta
|
|
8
|
-
let
|
|
9
|
-
let _locale
|
|
10
|
-
let
|
|
11
|
-
let
|
|
5
|
+
let _selectedTenant = null;
|
|
6
|
+
let _selectedType = null; // { name, pluralName }
|
|
7
|
+
let _relationMeta = {}; // relatedClass / mostSignificantClass → { name, mostSignificantClass }
|
|
8
|
+
let _baseHref = null; // tenant base href: /data/{tenant}
|
|
9
|
+
let _locale = navigator.language || 'nl-NL';
|
|
10
|
+
let _dashboardData = null; // full dashboard response
|
|
11
|
+
let _dashboardRecord = null; // data-object voor object/form dashboards
|
|
12
|
+
let _activeLayoutIndex = 0;
|
|
13
|
+
let _dashboardType = 'class'; // 'class' | 'general' | 'navigation' | 'object' | 'form'
|
|
14
|
+
let _sectionGeneration = 0; // incremented on each renderSection(); prevents stale fetches
|
|
15
|
+
let _navHistory = []; // stack van { dashboardData, dashboardRecord, activeLayoutIndex }
|
|
12
16
|
|
|
13
17
|
/* =====================================================================
|
|
14
18
|
UTILITIES
|
|
@@ -21,6 +25,29 @@ function escHtml(str) {
|
|
|
21
25
|
.replace(/"/g, '"').replace(/'/g, ''');
|
|
22
26
|
}
|
|
23
27
|
|
|
28
|
+
function formatJson(value) {
|
|
29
|
+
try {
|
|
30
|
+
const parsed = typeof value === 'string' ? JSON.parse(value) : value;
|
|
31
|
+
const json = JSON.stringify(parsed, null, 2);
|
|
32
|
+
return json.replace(
|
|
33
|
+
/("(\\u[a-zA-Z0-9]{4}|\\[^u]|[^\\"])*"(\s*:)?|\b(true|false|null)\b|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?)/g,
|
|
34
|
+
match => {
|
|
35
|
+
let style = 'color:#2aa198';
|
|
36
|
+
if (/^"/.test(match)) {
|
|
37
|
+
style = /:$/.test(match) ? 'color:#81a1c1' : 'color:#a3be8c';
|
|
38
|
+
} else if (/true|false/.test(match)) {
|
|
39
|
+
style = 'color:#ebcb8b';
|
|
40
|
+
} else if (/null/.test(match)) {
|
|
41
|
+
style = 'color:#bf616a';
|
|
42
|
+
}
|
|
43
|
+
return `<span style="${style}">${match}</span>`;
|
|
44
|
+
},
|
|
45
|
+
);
|
|
46
|
+
} catch {
|
|
47
|
+
return escHtml(String(value));
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
24
51
|
function httpStatusText(code) {
|
|
25
52
|
const map = {
|
|
26
53
|
200: 'OK', 201: 'Created', 204: 'No Content',
|
|
@@ -31,9 +58,43 @@ function httpStatusText(code) {
|
|
|
31
58
|
return map[code] || '';
|
|
32
59
|
}
|
|
33
60
|
|
|
61
|
+
const EVENT_LOG_MAX = 200;
|
|
62
|
+
|
|
34
63
|
function logEvent(type, data) {
|
|
35
|
-
document.getElementById('event-log')
|
|
36
|
-
|
|
64
|
+
const log = document.getElementById('event-log');
|
|
65
|
+
|
|
66
|
+
const empty = log.querySelector('.event-log-empty');
|
|
67
|
+
if (empty) empty.remove();
|
|
68
|
+
|
|
69
|
+
// Trim oldest entries when the log grows too large
|
|
70
|
+
while (log.children.length >= EVENT_LOG_MAX) log.removeChild(log.firstChild);
|
|
71
|
+
|
|
72
|
+
const now = new Date();
|
|
73
|
+
const time = now.toTimeString().slice(0, 8) + '.' + String(now.getMilliseconds()).padStart(3, '0');
|
|
74
|
+
const json = data !== undefined ? JSON.stringify(data, null, 2) : null;
|
|
75
|
+
|
|
76
|
+
const entry = document.createElement('div');
|
|
77
|
+
entry.className = 'event-log-entry';
|
|
78
|
+
entry.dataset.type = type;
|
|
79
|
+
entry.innerHTML = `
|
|
80
|
+
<div class="event-log-entry-head">
|
|
81
|
+
<span class="event-log-time">${escHtml(time)}</span>
|
|
82
|
+
<span class="event-log-type">${escHtml(type)}</span>
|
|
83
|
+
${json ? '<span class="event-log-arrow">▶</span>' : ''}
|
|
84
|
+
</div>
|
|
85
|
+
${json ? `<pre class="event-log-detail">${escHtml(json)}</pre>` : ''}`;
|
|
86
|
+
|
|
87
|
+
entry.querySelector('.event-log-entry-head')?.addEventListener('click', () => {
|
|
88
|
+
if (json) entry.classList.toggle('open');
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
log.appendChild(entry);
|
|
92
|
+
log.scrollTop = log.scrollHeight;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function clearEventLog() {
|
|
96
|
+
const log = document.getElementById('event-log');
|
|
97
|
+
log.innerHTML = '<span class="event-log-empty">Wacht op events…</span>';
|
|
37
98
|
}
|
|
38
99
|
|
|
39
100
|
/* =====================================================================
|
|
@@ -139,293 +200,332 @@ function showCompanyList() {
|
|
|
139
200
|
===================================================================== */
|
|
140
201
|
|
|
141
202
|
async function loadTenants() {
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
grid.innerHTML = '<span class="spinner"></span>';
|
|
203
|
+
document.getElementById('panel-controls').classList.remove('hidden');
|
|
204
|
+
const sel = document.getElementById('tenant-select-compact');
|
|
205
|
+
sel.innerHTML = '<option value="">⏳ laden...</option>';
|
|
146
206
|
|
|
147
207
|
try {
|
|
148
208
|
const tenants = await apiFetchTenants(authGetToken());
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
const code = t.tenantCode || t.code || t.id || String(i);
|
|
164
|
-
const name = t.name || code;
|
|
165
|
-
const desc = t.description || '';
|
|
166
|
-
return `
|
|
167
|
-
<div class="tenant-card">
|
|
168
|
-
<input type="radio" name="tenant" id="tenant-${escHtml(code)}" value="${escHtml(code)}"
|
|
169
|
-
onchange="onTenantChange('${escHtml(code)}', '${escHtml(name)}')">
|
|
170
|
-
<label for="tenant-${escHtml(code)}">
|
|
171
|
-
${escHtml(name)}
|
|
172
|
-
${desc ? `<small>${escHtml(desc)}</small>` : ''}
|
|
173
|
-
</label>
|
|
174
|
-
</div>`;
|
|
175
|
-
}).join('');
|
|
176
|
-
|
|
177
|
-
const savedTenant = localStorage.getItem('last_tenant');
|
|
178
|
-
if (savedTenant) {
|
|
179
|
-
const radio = document.getElementById(`tenant-${savedTenant}`);
|
|
180
|
-
if (radio) {
|
|
181
|
-
radio.checked = true;
|
|
182
|
-
const label = document.querySelector(`label[for="tenant-${savedTenant}"]`);
|
|
183
|
-
const name = label ? (label.firstChild?.textContent?.trim() || savedTenant) : savedTenant;
|
|
184
|
-
onTenantChange(savedTenant, name);
|
|
209
|
+
if (!tenants || tenants.length === 0) {
|
|
210
|
+
sel.innerHTML = '<option value="">— geen tenants gevonden —</option>';
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
sel.innerHTML = '<option value="">— selecteer tenant —</option>' +
|
|
214
|
+
tenants.map(t => {
|
|
215
|
+
const code = t.tenantCode || t.code || t.id;
|
|
216
|
+
return `<option value="${escHtml(code)}">${escHtml(t.name || code)}</option>`;
|
|
217
|
+
}).join('');
|
|
218
|
+
|
|
219
|
+
const saved = localStorage.getItem('last_tenant');
|
|
220
|
+
if (saved) {
|
|
221
|
+
sel.value = saved;
|
|
222
|
+
onCompactTenantChange(saved);
|
|
185
223
|
}
|
|
224
|
+
} catch (err) {
|
|
225
|
+
sel.innerHTML = `<option value="">❌ ${escHtml(err.message)}</option>`;
|
|
186
226
|
}
|
|
187
227
|
}
|
|
188
228
|
|
|
189
|
-
|
|
229
|
+
function onCompactTenantChange(code) {
|
|
190
230
|
_selectedTenant = code;
|
|
231
|
+
_baseHref = `/data/${code}`;
|
|
191
232
|
localStorage.setItem('last_tenant', code);
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
document.getElementById('panel-form').classList.add('hidden');
|
|
195
|
-
document.getElementById('panel-response').innerHTML = '';
|
|
233
|
+
if (_dashboardType === 'class' && code) loadCompactTypes(code);
|
|
234
|
+
}
|
|
196
235
|
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
const sel = document.getElementById('type-select');
|
|
236
|
+
async function loadCompactTypes(tenantCode) {
|
|
237
|
+
const sel = document.getElementById('type-select-compact');
|
|
200
238
|
sel.innerHTML = '<option value="">⏳ laden...</option>';
|
|
201
239
|
sel.disabled = true;
|
|
202
|
-
|
|
203
240
|
try {
|
|
204
|
-
const types = await apiFetchTypes(authGetToken(),
|
|
205
|
-
|
|
241
|
+
const types = await apiFetchTypes(authGetToken(), tenantCode);
|
|
242
|
+
if (!types || types.length === 0) {
|
|
243
|
+
sel.innerHTML = '<option value="">— geen types —</option>';
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
246
|
+
sel.innerHTML = '<option value="">— selecteer type —</option>' +
|
|
247
|
+
types.map(t => {
|
|
248
|
+
const plural = t.pluralName || t.name;
|
|
249
|
+
return `<option value="${escHtml(plural)}">${escHtml(t.name)}</option>`;
|
|
250
|
+
}).join('');
|
|
251
|
+
sel.disabled = false;
|
|
252
|
+
|
|
253
|
+
const saved = localStorage.getItem('last_type');
|
|
254
|
+
if (saved && sel.querySelector(`option[value="${saved}"]`)) {
|
|
255
|
+
sel.value = saved;
|
|
256
|
+
}
|
|
206
257
|
} catch (err) {
|
|
207
|
-
sel.innerHTML =
|
|
258
|
+
sel.innerHTML = `<option value="">❌ ${escHtml(err.message)}</option>`;
|
|
208
259
|
sel.disabled = false;
|
|
209
|
-
typePanel.querySelector('h3').insertAdjacentHTML('afterend',
|
|
210
|
-
`<p style="color:var(--mrd-color-danger);font-size:.875rem;margin:0 0 .75rem">❌ ${escHtml(err.message)}</p>`);
|
|
211
260
|
}
|
|
212
261
|
}
|
|
213
262
|
|
|
214
|
-
function
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
return;
|
|
220
|
-
}
|
|
221
|
-
sel.innerHTML = '<option value="">— selecteer type —</option>' +
|
|
222
|
-
types.map(t => {
|
|
223
|
-
const plural = t.pluralName || t.name;
|
|
224
|
-
return `<option value="${escHtml(plural)}" data-name="${escHtml(t.name)}">${escHtml(t.name)}</option>`;
|
|
225
|
-
}).join('');
|
|
226
|
-
sel.disabled = false;
|
|
263
|
+
function onDashboardTypeChange(type) {
|
|
264
|
+
_dashboardType = type;
|
|
265
|
+
document.getElementById('controls-class-group').classList.toggle('hidden', type !== 'class');
|
|
266
|
+
document.getElementById('controls-object-group').classList.toggle('hidden', type !== 'object' && type !== 'form');
|
|
267
|
+
if (type === 'class' && _selectedTenant) loadCompactTypes(_selectedTenant);
|
|
227
268
|
}
|
|
228
269
|
|
|
229
270
|
/* =====================================================================
|
|
230
|
-
|
|
271
|
+
DASHBOARD — laad + render layout sections
|
|
231
272
|
===================================================================== */
|
|
232
273
|
|
|
233
|
-
async function
|
|
234
|
-
const
|
|
235
|
-
const
|
|
236
|
-
if (!pluralName) return;
|
|
237
|
-
|
|
238
|
-
const opt = sel.options[sel.selectedIndex];
|
|
239
|
-
_selectedType = { name: opt.dataset.name || pluralName, pluralName };
|
|
274
|
+
async function loadDashboard() {
|
|
275
|
+
const name = document.getElementById('dashboard-name-input').value.trim() || undefined;
|
|
276
|
+
const token = authGetToken();
|
|
240
277
|
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
document.getElementById('panel-form').classList.add('hidden');
|
|
278
|
+
document.getElementById('sections-container').innerHTML =
|
|
279
|
+
'<span class="spinner"></span> Dashboard laden...';
|
|
280
|
+
document.getElementById('panel-sections').classList.remove('hidden');
|
|
245
281
|
document.getElementById('panel-response').innerHTML = '';
|
|
246
|
-
_tableDataHref = null;
|
|
247
282
|
|
|
248
283
|
try {
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
284
|
+
let dashboard;
|
|
285
|
+
let recordData = null;
|
|
286
|
+
|
|
287
|
+
if (_dashboardType === 'class') {
|
|
288
|
+
const pluralName = document.getElementById('type-select-compact').value;
|
|
289
|
+
if (!pluralName) throw new Error('Selecteer een type');
|
|
290
|
+
const opt = document.getElementById('type-select-compact').selectedOptions[0];
|
|
291
|
+
_selectedType = { name: opt.text, pluralName };
|
|
292
|
+
localStorage.setItem('last_type', pluralName);
|
|
293
|
+
dashboard = await apiFetchClassDashboard(token, _selectedTenant, pluralName, name);
|
|
294
|
+
|
|
295
|
+
} else if (_dashboardType === 'general') {
|
|
296
|
+
dashboard = await apiFetchGeneralDashboard(token, _selectedTenant, name);
|
|
297
|
+
|
|
298
|
+
} else if (_dashboardType === 'navigation') {
|
|
299
|
+
dashboard = await apiFetchNavigationPane(token, _selectedTenant, name);
|
|
300
|
+
|
|
301
|
+
} else {
|
|
302
|
+
// 'object' of 'form': fetch record → gebruik _links.metadata.href of _links.form.href
|
|
303
|
+
const objectHref = document.getElementById('object-href-input').value.trim();
|
|
304
|
+
if (!objectHref) throw new Error('Vul een Object URL in');
|
|
305
|
+
const recResp = await apiRequest('GET', objectHref, token);
|
|
306
|
+
if (!recResp.ok) throw new Error(`${recResp.status}: kon object niet ophalen`);
|
|
307
|
+
recordData = recResp.body;
|
|
308
|
+
|
|
309
|
+
const linkKey = _dashboardType === 'form' ? 'form' : 'metadata';
|
|
310
|
+
const dashHref = recordData._links?.[linkKey]?.href;
|
|
311
|
+
if (!dashHref) throw new Error(`Geen _links.${linkKey} gevonden in object`);
|
|
312
|
+
|
|
313
|
+
const dashResp = await apiRequest('GET', dashHref, token);
|
|
314
|
+
if (!dashResp.ok) throw new Error(`${dashResp.status}: dashboard ophalen mislukt`);
|
|
315
|
+
dashboard = dashResp.body;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
_dashboardData = dashboard;
|
|
319
|
+
_dashboardRecord = recordData;
|
|
320
|
+
_activeLayoutIndex = 0;
|
|
321
|
+
_navHistory = [];
|
|
322
|
+
|
|
323
|
+
renderSectionTabs(dashboard.layouts ?? []);
|
|
324
|
+
renderSection(0);
|
|
325
|
+
updateBackButton();
|
|
278
326
|
} catch (err) {
|
|
279
|
-
|
|
327
|
+
document.getElementById('sections-container').innerHTML =
|
|
328
|
+
`<span style="color:var(--mrd-color-danger)">❌ ${escHtml(err.message)}</span>`;
|
|
280
329
|
}
|
|
281
330
|
}
|
|
282
331
|
|
|
283
|
-
function
|
|
284
|
-
const
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
332
|
+
function renderSectionTabs(layouts) {
|
|
333
|
+
const bar = document.getElementById('sections-tab-bar');
|
|
334
|
+
bar.innerHTML = '';
|
|
335
|
+
if (layouts.length <= 1) return;
|
|
336
|
+
|
|
337
|
+
layouts.forEach((layout, i) => {
|
|
338
|
+
const label = layout.label ?? layout.type ?? `Sectie ${i + 1}`;
|
|
339
|
+
const btn = document.createElement('button');
|
|
340
|
+
btn.className = 'section-tab-btn' + (i === 0 ? ' active' : '');
|
|
341
|
+
btn.textContent = label;
|
|
342
|
+
btn.onclick = () => renderSection(i);
|
|
343
|
+
bar.appendChild(btn);
|
|
344
|
+
});
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
function renderSection(index) {
|
|
348
|
+
_activeLayoutIndex = index;
|
|
349
|
+
const generation = ++_sectionGeneration; // snapshot for stale-fetch detection
|
|
350
|
+
|
|
351
|
+
document.querySelectorAll('.section-tab-btn').forEach((btn, i) =>
|
|
352
|
+
btn.classList.toggle('active', i === index));
|
|
353
|
+
|
|
354
|
+
const layout = _dashboardData.layouts[index];
|
|
355
|
+
document.getElementById('json-viewer').innerHTML = formatJson(layout);
|
|
356
|
+
|
|
357
|
+
const container = document.getElementById('sections-container');
|
|
358
|
+
container.innerHTML = '';
|
|
359
|
+
|
|
360
|
+
const section = document.createElement('mrd-layout-section');
|
|
361
|
+
section.items = layout.items;
|
|
362
|
+
section.data = _dashboardRecord ?? { _links: _dashboardData._links ?? {} };
|
|
363
|
+
section.locale = _locale;
|
|
364
|
+
|
|
365
|
+
section.addEventListener('mrdLoadViewPage', async (e) => {
|
|
366
|
+
if (generation !== _sectionGeneration) return;
|
|
367
|
+
const { name, page, path, qs } = e.detail;
|
|
368
|
+
logEvent('mrdLoadViewPage', e.detail);
|
|
369
|
+
try {
|
|
370
|
+
const url = `${_baseHref}${path}${qs ? '?' + qs : ''}`;
|
|
371
|
+
const result = await apiFetchPage(authGetToken(), url, page);
|
|
372
|
+
const rows = Object.values(result._embedded ?? {})[0] ?? [];
|
|
373
|
+
const total = result.page?.totalElements;
|
|
374
|
+
await section.setViewPage(name, page, rows, total);
|
|
375
|
+
} catch (err) {
|
|
376
|
+
console.error('[mrdLoadViewPage] mislukt', name, err);
|
|
327
377
|
}
|
|
378
|
+
});
|
|
328
379
|
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
380
|
+
section.addEventListener('mrdLoadViewAggregations', async (e) => {
|
|
381
|
+
if (generation !== _sectionGeneration) return;
|
|
382
|
+
const { name, path, aggQs } = e.detail;
|
|
383
|
+
logEvent('mrdLoadViewAggregations', e.detail);
|
|
384
|
+
try {
|
|
385
|
+
const aggUrl = `${_baseHref}${path}/aggregations`;
|
|
386
|
+
const result = await apiRequest('GET', aggQs ? `${aggUrl}?${aggQs}` : aggUrl, authGetToken());
|
|
387
|
+
if (result.ok) await section.setViewAggregations(name, result.body);
|
|
388
|
+
} catch (err) {
|
|
389
|
+
console.error('[mrdLoadViewAggregations] mislukt', name, err);
|
|
390
|
+
}
|
|
391
|
+
});
|
|
336
392
|
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
await table.setPage(page, rows);
|
|
341
|
-
} catch (err) {
|
|
342
|
-
console.error('[mrd-table] pagina laden mislukt', page, err);
|
|
343
|
-
}
|
|
344
|
-
});
|
|
393
|
+
section.addEventListener('mrdViewAction', async (e) => {
|
|
394
|
+
logEvent('mrdViewAction', e.detail);
|
|
395
|
+
});
|
|
345
396
|
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
397
|
+
section.addEventListener('mrdNavigate', async (e) => {
|
|
398
|
+
if (generation !== _sectionGeneration) return;
|
|
399
|
+
await handleNavigate(e.detail);
|
|
400
|
+
});
|
|
401
|
+
section.addEventListener('mrdDownload', (e) => logEvent('mrdDownload', e.detail));
|
|
402
|
+
section.addEventListener('mrdSearch', (e) => logEvent('mrdSearch', e.detail));
|
|
350
403
|
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
logEvent('mrdAction', e.detail);
|
|
354
|
-
if (e.detail.action === 'create') loadForm();
|
|
355
|
-
});
|
|
404
|
+
container.appendChild(section);
|
|
405
|
+
}
|
|
356
406
|
|
|
357
|
-
// Store filters; mrdLoadPage will pick them up automatically
|
|
358
|
-
table.addEventListener('mrdFilter', (e) => {
|
|
359
|
-
logEvent('mrdFilter', e.detail);
|
|
360
|
-
_activeFilters = e.detail.filters;
|
|
361
|
-
});
|
|
362
407
|
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
if (sum?.length) params.set('sum', sum.join(','));
|
|
370
|
-
if (avg?.length) params.set('avg', avg.join(','));
|
|
371
|
-
if (count?.length) params.set('count', count.join(','));
|
|
372
|
-
const qs = params.toString();
|
|
373
|
-
const result = await apiRequest('GET', qs ? `${aggUrl}?${qs}` : aggUrl, authGetToken());
|
|
374
|
-
if (result.ok) await table.setAggregations(result.body);
|
|
375
|
-
} catch (err) {
|
|
376
|
-
console.error('[mrdLoadAggregations] mislukt', err);
|
|
377
|
-
}
|
|
378
|
-
});
|
|
408
|
+
function toggleJsonViewer() {
|
|
409
|
+
const viewer = document.getElementById('json-viewer');
|
|
410
|
+
const btn = document.getElementById('btn-json-toggle');
|
|
411
|
+
const open = !viewer.classList.toggle('hidden');
|
|
412
|
+
btn.classList.toggle('active', open);
|
|
413
|
+
}
|
|
379
414
|
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
const newHref = _dashboard?._links?.[newKey]?.href;
|
|
385
|
-
if (!newView || !newHref) { console.error('[mrdSwitchView] view niet gevonden:', newKey); return; }
|
|
386
|
-
|
|
387
|
-
const clickedAlt = alternativeViews.find(av => av.name === newKey);
|
|
388
|
-
const newViewLabel = clickedAlt?.label ?? newKey;
|
|
389
|
-
const layoutItem = _dashboard.layouts?.[0]?.items?.[0];
|
|
390
|
-
|
|
391
|
-
// Old current becomes an alternative; clicked alternative becomes current
|
|
392
|
-
const newAlts = [
|
|
393
|
-
{ name: _currentViewKey, label: viewLabel, class: layoutItem?.class ?? '' },
|
|
394
|
-
...alternativeViews.filter(av => av.name !== newKey),
|
|
395
|
-
];
|
|
396
|
-
|
|
397
|
-
_currentViewKey = newKey;
|
|
398
|
-
_tableDataHref = newHref.replace(/([?&])page=\d+/, '').replace(/\?$/, '');
|
|
399
|
-
viewLabel = newViewLabel;
|
|
400
|
-
alternativeViews = newAlts;
|
|
401
|
-
viewFilter = newView.filter ?? [];
|
|
402
|
-
_activeFilters = [];
|
|
415
|
+
function updateBackButton() {
|
|
416
|
+
const btn = document.getElementById('btn-nav-back');
|
|
417
|
+
if (btn) btn.classList.toggle('hidden', _navHistory.length === 0);
|
|
418
|
+
}
|
|
403
419
|
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
table.viewLabel = viewLabel;
|
|
415
|
-
table.alternativeViews = alternativeViews;
|
|
416
|
-
|
|
417
|
-
await table.init();
|
|
418
|
-
await table.setPage(0, rows0);
|
|
419
|
-
} catch (err) {
|
|
420
|
-
console.error('[mrdSwitchView] laden mislukt', err);
|
|
421
|
-
}
|
|
422
|
-
});
|
|
420
|
+
function syncDashboardTypeUI(type, objectHref) {
|
|
421
|
+
_dashboardType = type;
|
|
422
|
+
document.getElementById('dashboard-type-select').value = type;
|
|
423
|
+
const isObject = type === 'object' || type === 'form';
|
|
424
|
+
document.getElementById('controls-class-group').classList.toggle('hidden', type !== 'class');
|
|
425
|
+
document.getElementById('controls-object-group').classList.toggle('hidden', !isObject);
|
|
426
|
+
if (isObject && objectHref) {
|
|
427
|
+
document.getElementById('object-href-input').value = objectHref;
|
|
428
|
+
}
|
|
429
|
+
}
|
|
423
430
|
|
|
424
|
-
|
|
425
|
-
|
|
431
|
+
function navigateBack() {
|
|
432
|
+
if (_navHistory.length === 0) return;
|
|
433
|
+
const prev = _navHistory.pop();
|
|
434
|
+
_dashboardData = prev.dashboardData;
|
|
435
|
+
_dashboardRecord = prev.dashboardRecord;
|
|
436
|
+
_activeLayoutIndex = prev.activeLayoutIndex;
|
|
437
|
+
syncDashboardTypeUI(prev.dashboardType ?? _dashboardType, prev.objectHref ?? '');
|
|
438
|
+
renderSectionTabs(_dashboardData.layouts ?? []);
|
|
439
|
+
renderSection(_activeLayoutIndex);
|
|
440
|
+
updateBackButton();
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
function pushHistory() {
|
|
444
|
+
_navHistory.push({
|
|
445
|
+
dashboardData: _dashboardData,
|
|
446
|
+
dashboardRecord: _dashboardRecord,
|
|
447
|
+
activeLayoutIndex: _activeLayoutIndex,
|
|
448
|
+
dashboardType: _dashboardType,
|
|
449
|
+
objectHref: document.getElementById('object-href-input').value,
|
|
426
450
|
});
|
|
427
451
|
}
|
|
428
452
|
|
|
453
|
+
async function navigateToObjectDashboard(selfHref) {
|
|
454
|
+
if (!selfHref) return;
|
|
455
|
+
|
|
456
|
+
document.getElementById('sections-container').innerHTML =
|
|
457
|
+
'<span class="spinner"></span> Object laden...';
|
|
458
|
+
document.getElementById('panel-sections').classList.remove('hidden');
|
|
459
|
+
|
|
460
|
+
try {
|
|
461
|
+
const recResp = await apiRequest('GET', selfHref, authGetToken());
|
|
462
|
+
if (!recResp.ok) throw new Error(`${recResp.status}: object ophalen mislukt`);
|
|
463
|
+
const record = recResp.body;
|
|
464
|
+
|
|
465
|
+
const dashHref = record._links?.metadata?.href;
|
|
466
|
+
if (!dashHref) throw new Error('Geen _links.metadata gevonden in object');
|
|
467
|
+
|
|
468
|
+
const dashResp = await apiRequest('GET', dashHref, authGetToken());
|
|
469
|
+
if (!dashResp.ok) throw new Error(`${dashResp.status}: dashboard ophalen mislukt`);
|
|
470
|
+
const dashboard = dashResp.body;
|
|
471
|
+
|
|
472
|
+
pushHistory();
|
|
473
|
+
_dashboardData = dashboard;
|
|
474
|
+
_dashboardRecord = record;
|
|
475
|
+
_activeLayoutIndex = 0;
|
|
476
|
+
|
|
477
|
+
const displayHref = selfHref.startsWith('http') ? selfHref : API_BASE + selfHref;
|
|
478
|
+
syncDashboardTypeUI('object', displayHref);
|
|
479
|
+
renderSectionTabs(dashboard.layouts ?? []);
|
|
480
|
+
renderSection(0);
|
|
481
|
+
updateBackButton();
|
|
482
|
+
} catch (err) {
|
|
483
|
+
document.getElementById('sections-container').innerHTML =
|
|
484
|
+
`<span style="color:var(--mrd-color-danger)">❌ ${escHtml(err.message)}</span>`;
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
async function navigateToClassDashboard(pluralName) {
|
|
489
|
+
if (!_selectedTenant || !pluralName) return;
|
|
490
|
+
|
|
491
|
+
document.getElementById('sections-container').innerHTML =
|
|
492
|
+
'<span class="spinner"></span> Dashboard laden...';
|
|
493
|
+
document.getElementById('panel-sections').classList.remove('hidden');
|
|
494
|
+
|
|
495
|
+
try {
|
|
496
|
+
const dashboard = await apiFetchClassDashboard(authGetToken(), _selectedTenant, pluralName);
|
|
497
|
+
|
|
498
|
+
pushHistory();
|
|
499
|
+
_dashboardData = dashboard;
|
|
500
|
+
_dashboardRecord = null;
|
|
501
|
+
_activeLayoutIndex = 0;
|
|
502
|
+
|
|
503
|
+
syncDashboardTypeUI('class', '');
|
|
504
|
+
const sel = document.getElementById('type-select-compact');
|
|
505
|
+
if (sel.querySelector(`option[value="${pluralName}"]`)) sel.value = pluralName;
|
|
506
|
+
|
|
507
|
+
renderSectionTabs(dashboard.layouts ?? []);
|
|
508
|
+
renderSection(0);
|
|
509
|
+
updateBackButton();
|
|
510
|
+
} catch (err) {
|
|
511
|
+
document.getElementById('sections-container').innerHTML =
|
|
512
|
+
`<span style="color:var(--mrd-color-danger)">❌ ${escHtml(err.message)}</span>`;
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
async function handleNavigate(detail) {
|
|
517
|
+
const { href, label, navigate } = detail;
|
|
518
|
+
if (href) {
|
|
519
|
+
logEvent('mrdNavigate', { href, label });
|
|
520
|
+
await navigateToObjectDashboard(href);
|
|
521
|
+
} else if (navigate?.dataClass) {
|
|
522
|
+
logEvent('mrdNavigate', { dataClass: navigate.dataClass, navigationType: navigate.navigationType, label });
|
|
523
|
+
await navigateToClassDashboard(navigate.dataClass);
|
|
524
|
+
} else {
|
|
525
|
+
logEvent('mrdNavigate', detail);
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
|
|
429
529
|
/* =====================================================================
|
|
430
530
|
FORM — LOAD & RENDER
|
|
431
531
|
===================================================================== */
|
|
@@ -438,18 +538,14 @@ function renderTable(columns, totalElements, pageSize, page0Rows, dataHref, defa
|
|
|
438
538
|
async function loadRecord(row) {
|
|
439
539
|
const selfHref = row?._links?.self?.href;
|
|
440
540
|
if (!selfHref) { console.warn('[loadRecord] geen _links.self.href in rij', row); return; }
|
|
441
|
-
|
|
442
|
-
const sel = document.getElementById('type-select');
|
|
443
|
-
if (!sel.value) return;
|
|
541
|
+
if (!_selectedType) return;
|
|
444
542
|
|
|
445
543
|
const formPanel = document.getElementById('panel-form');
|
|
446
544
|
formPanel.classList.remove('hidden');
|
|
447
545
|
formPanel.innerHTML = '<span class="spinner"></span> Record laden...';
|
|
448
|
-
document.getElementById('panel-table').classList.add('hidden');
|
|
449
546
|
document.getElementById('panel-response').innerHTML = '';
|
|
450
547
|
|
|
451
548
|
try {
|
|
452
|
-
// Fetch the record first so we can read _links.form.href for the exact layout URL
|
|
453
549
|
const recordResp = await apiRequest('GET', selfHref, authGetToken());
|
|
454
550
|
if (!recordResp.ok) throw new Error(`${recordResp.status}: kon record niet ophalen`);
|
|
455
551
|
|
|
@@ -462,13 +558,9 @@ async function loadRecord(row) {
|
|
|
462
558
|
}
|
|
463
559
|
|
|
464
560
|
async function loadForm() {
|
|
465
|
-
const
|
|
466
|
-
const pluralName = sel.value;
|
|
561
|
+
const pluralName = _selectedType?.pluralName;
|
|
467
562
|
if (!pluralName) return;
|
|
468
563
|
|
|
469
|
-
const opt = sel.options[sel.selectedIndex];
|
|
470
|
-
_selectedType = { name: opt.dataset.name || pluralName, pluralName };
|
|
471
|
-
|
|
472
564
|
const formPanel = document.getElementById('panel-form');
|
|
473
565
|
formPanel.classList.remove('hidden');
|
|
474
566
|
formPanel.innerHTML = '<span class="spinner"></span> Formulier laden...';
|
|
@@ -532,7 +624,7 @@ async function renderForm(layout, record = null, selfHref = null) {
|
|
|
532
624
|
}
|
|
533
625
|
|
|
534
626
|
const formPanel = document.getElementById('panel-form');
|
|
535
|
-
formPanel.innerHTML = `<mrd-form id="live-form" locale="${_locale}"></mrd-form>`;
|
|
627
|
+
formPanel.innerHTML = `<mrd-form id="live-form" locale="${escHtml(_locale)}"></mrd-form>`;
|
|
536
628
|
|
|
537
629
|
const form = document.getElementById('live-form');
|
|
538
630
|
// Wait for Stencil to fully initialize this specific instance before setting props.
|
|
@@ -701,15 +793,13 @@ customElements.whenDefined('mrd-form').then(() => {
|
|
|
701
793
|
|
|
702
794
|
document.getElementById('locale-select').addEventListener('change', (e) => {
|
|
703
795
|
_locale = e.target.value;
|
|
704
|
-
// Update embedded demo form
|
|
705
796
|
const demoForm = document.getElementById('demo-form');
|
|
706
797
|
if (demoForm) demoForm.locale = _locale;
|
|
707
|
-
// Update live table if present
|
|
708
|
-
const liveTable = document.getElementById('live-table');
|
|
709
|
-
if (liveTable) liveTable.locale = _locale;
|
|
710
|
-
// Update live form if present
|
|
711
798
|
const liveForm = document.getElementById('live-form');
|
|
712
799
|
if (liveForm) liveForm.locale = _locale;
|
|
800
|
+
// Update actieve section als aanwezig
|
|
801
|
+
const section = document.querySelector('#sections-container mrd-layout-section');
|
|
802
|
+
if (section) section.locale = _locale;
|
|
713
803
|
});
|
|
714
804
|
|
|
715
805
|
document.getElementById('btn-inject-results').addEventListener('click', () => {
|