underpost 2.8.86 → 2.8.88
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/.env.development +39 -2
- package/.env.production +42 -2
- package/.env.test +39 -2
- package/.github/workflows/ghpkg.ci.yml +1 -1
- package/.github/workflows/npmpkg.ci.yml +1 -1
- package/.github/workflows/pwa-microservices-template-page.cd.yml +6 -5
- package/.github/workflows/pwa-microservices-template-test.ci.yml +1 -1
- package/.github/workflows/release.cd.yml +3 -3
- package/README.md +76 -2
- package/bin/build.js +5 -0
- package/bin/deploy.js +93 -27
- package/bin/file.js +8 -4
- package/bin/util.js +1 -56
- package/cli.md +16 -5
- package/conf.js +33 -7
- package/manifests/deployment/dd-default-development/deployment.yaml +2 -2
- package/manifests/deployment/dd-test-development/deployment.yaml +174 -0
- package/manifests/deployment/dd-test-development/proxy.yaml +51 -0
- package/manifests/deployment/mongo-express/deployment.yaml +12 -12
- package/manifests/maas/nvim.sh +91 -0
- package/package.json +8 -15
- package/src/api/core/core.router.js +2 -1
- package/src/api/default/default.controller.js +6 -1
- package/src/api/default/default.router.js +6 -2
- package/src/api/default/default.service.js +10 -1
- package/src/api/document/document.controller.js +66 -0
- package/src/api/document/document.model.js +51 -0
- package/src/api/document/document.router.js +24 -0
- package/src/api/document/document.service.js +125 -0
- package/src/api/file/file.controller.js +15 -1
- package/src/api/file/file.router.js +2 -1
- package/src/api/file/file.service.js +28 -8
- package/src/api/test/test.router.js +1 -1
- package/src/api/user/postman_collection.json +216 -0
- package/src/api/user/user.controller.js +25 -60
- package/src/api/user/user.model.js +29 -7
- package/src/api/user/user.router.js +40 -8
- package/src/api/user/user.service.js +86 -35
- package/src/cli/baremetal.js +33 -3
- package/src/cli/cloud-init.js +11 -0
- package/src/cli/cluster.js +4 -23
- package/src/cli/cron.js +0 -1
- package/src/cli/db.js +0 -19
- package/src/cli/deploy.js +67 -52
- package/src/cli/fs.js +1 -0
- package/src/cli/index.js +9 -1
- package/src/cli/lxd.js +7 -0
- package/src/cli/repository.js +44 -6
- package/src/cli/run.js +56 -9
- package/src/cli/ssh.js +20 -6
- package/src/client/Default.index.js +42 -1
- package/src/client/components/core/Account.js +10 -2
- package/src/client/components/core/AgGrid.js +30 -8
- package/src/client/components/core/Auth.js +99 -56
- package/src/client/components/core/BtnIcon.js +3 -2
- package/src/client/components/core/CalendarCore.js +2 -3
- package/src/client/components/core/CommonJs.js +1 -2
- package/src/client/components/core/Content.js +15 -12
- package/src/client/components/core/Css.js +2 -1
- package/src/client/components/core/CssCore.js +18 -1
- package/src/client/components/core/Docs.js +5 -5
- package/src/client/components/core/FileExplorer.js +3 -3
- package/src/client/components/core/FullScreen.js +19 -28
- package/src/client/components/core/Input.js +22 -16
- package/src/client/components/core/JoyStick.js +2 -2
- package/src/client/components/core/LoadingAnimation.js +2 -2
- package/src/client/components/core/LogIn.js +16 -23
- package/src/client/components/core/LogOut.js +5 -1
- package/src/client/components/core/Logger.js +4 -1
- package/src/client/components/core/Modal.js +102 -87
- package/src/client/components/core/ObjectLayerEngine.js +229 -4
- package/src/client/components/core/ObjectLayerEngineModal.js +442 -0
- package/src/client/components/core/Pagination.js +207 -0
- package/src/client/components/core/Panel.js +10 -10
- package/src/client/components/core/PanelForm.js +130 -33
- package/src/client/components/core/Recover.js +2 -2
- package/src/client/components/core/Router.js +210 -34
- package/src/client/components/core/SignUp.js +1 -2
- package/src/client/components/core/Stream.js +1 -1
- package/src/client/components/core/ToggleSwitch.js +15 -1
- package/src/client/components/core/VanillaJs.js +3 -84
- package/src/client/components/core/Worker.js +2 -2
- package/src/client/components/default/LogInDefault.js +0 -6
- package/src/client/components/default/LogOutDefault.js +0 -16
- package/src/client/components/default/MenuDefault.js +97 -44
- package/src/client/components/default/RoutesDefault.js +5 -2
- package/src/client/public/default/assets/mailer/api-user-default-avatar.png +0 -0
- package/src/client/services/core/core.service.js +8 -20
- package/src/client/services/default/default.management.js +115 -18
- package/src/client/services/default/default.service.js +13 -4
- package/src/client/services/document/document.service.js +97 -0
- package/src/client/services/file/file.service.js +2 -0
- package/src/client/services/test/test.service.js +3 -0
- package/src/client/services/user/user.management.js +6 -0
- package/src/client/services/user/user.service.js +15 -4
- package/src/client/ssr/Render.js +1 -1
- package/src/client/ssr/head/DefaultScripts.js +3 -0
- package/src/client/ssr/head/Seo.js +1 -0
- package/src/index.js +24 -2
- package/src/runtime/lampp/Lampp.js +89 -2
- package/src/runtime/xampp/Xampp.js +48 -1
- package/src/server/auth.js +519 -155
- package/src/server/backup.js +2 -2
- package/src/server/client-build-docs.js +1 -1
- package/src/server/client-build.js +4 -12
- package/src/server/client-icons.js +6 -78
- package/src/server/conf.js +144 -141
- package/src/server/process.js +2 -1
- package/src/server/proxy.js +1 -1
- package/src/server/runtime.js +136 -288
- package/src/server/ssl.js +1 -2
- package/src/server/ssr.js +85 -0
- package/src/server/start.js +4 -4
- package/src/server/valkey.js +2 -1
- package/test/api.test.js +3 -2
- package/bin/cyberia0.js +0 -78
|
@@ -2,17 +2,14 @@ import { getId, isValidDate, newInstance } from './CommonJs.js';
|
|
|
2
2
|
import { LoadingAnimation } from '../core/LoadingAnimation.js';
|
|
3
3
|
import { Validator } from '../core/Validator.js';
|
|
4
4
|
import { Input } from '../core/Input.js';
|
|
5
|
-
import { Responsive } from '../core/Responsive.js';
|
|
6
5
|
import { darkTheme, ThemeEvents } from './Css.js';
|
|
7
|
-
import { append, getDataFromInputFile,
|
|
6
|
+
import { append, getDataFromInputFile, htmls, s } from './VanillaJs.js';
|
|
8
7
|
import { BtnIcon } from './BtnIcon.js';
|
|
9
8
|
import { Translate } from './Translate.js';
|
|
10
9
|
import { DropDown } from './DropDown.js';
|
|
11
|
-
import { dynamicCol
|
|
10
|
+
import { dynamicCol } from './Css.js';
|
|
12
11
|
import { EventsUI } from './EventsUI.js';
|
|
13
12
|
import { ToggleSwitch } from './ToggleSwitch.js';
|
|
14
|
-
import { Modal } from './Modal.js';
|
|
15
|
-
import { RouterEvents } from './Router.js';
|
|
16
13
|
import { RichText } from './RichText.js';
|
|
17
14
|
import { loggerFactory } from './Logger.js';
|
|
18
15
|
import { Badge } from './Badge.js';
|
|
@@ -117,6 +114,7 @@ const Panel = {
|
|
|
117
114
|
options.originData().find((d) => d._id === obj._id || d.id === obj.id),
|
|
118
115
|
options.filesData().find((d) => d._id === obj._id || d.id === obj.id),
|
|
119
116
|
);
|
|
117
|
+
if (options.on.initEdit) await options.on.initEdit({ data: obj });
|
|
120
118
|
});
|
|
121
119
|
s(`.a-${payload._id}`).onclick = async (e) => {
|
|
122
120
|
e.preventDefault();
|
|
@@ -470,11 +468,9 @@ const Panel = {
|
|
|
470
468
|
s(`.${btnSelector}`).classList.remove('hide');
|
|
471
469
|
}
|
|
472
470
|
}
|
|
473
|
-
|
|
474
|
-
s(`.${idPanel}-form-body`).classList.add('hide');
|
|
475
|
-
});
|
|
471
|
+
s(`.${idPanel}-form-body`).classList.add('hide');
|
|
476
472
|
};
|
|
477
|
-
s(`.btn-${idPanel}-add`).onclick = (e) => {
|
|
473
|
+
s(`.btn-${idPanel}-add`).onclick = async (e) => {
|
|
478
474
|
e.preventDefault();
|
|
479
475
|
// s(`.btn-${idPanel}-clean`).click();
|
|
480
476
|
Panel.Tokens[idPanel].editId = undefined;
|
|
@@ -483,16 +479,20 @@ const Panel = {
|
|
|
483
479
|
s(`.${scrollClassContainer}`).scrollTop = 0;
|
|
484
480
|
|
|
485
481
|
openPanelForm();
|
|
482
|
+
if (options.on.initAdd) await options.on.initAdd();
|
|
486
483
|
};
|
|
487
484
|
if (s(`.${scrollClassContainer}`)) s(`.${scrollClassContainer}`).style.overflow = 'auto';
|
|
488
485
|
});
|
|
489
486
|
|
|
490
487
|
if (data.length > 0) for (const obj of data) render += await renderPanel(obj);
|
|
491
|
-
else
|
|
488
|
+
else {
|
|
492
489
|
render += html`<div class="in" style="min-height: 200px">
|
|
493
490
|
<div class="abs center"><i class="fas fa-exclamation-circle"></i> ${Translate.Render(`no-result-found`)}</div>
|
|
494
491
|
</div>`;
|
|
495
492
|
|
|
493
|
+
if (options.on.noResultFound) setTimeout(options.on.noResultFound);
|
|
494
|
+
}
|
|
495
|
+
|
|
496
496
|
this.Tokens[idPanel] = { idPanel, scrollClassContainer, formData, data, titleKey, subTitleKey, renderPanel };
|
|
497
497
|
|
|
498
498
|
let customButtonsRender = '';
|
|
@@ -1,12 +1,6 @@
|
|
|
1
|
-
import { getCapVariableName, newInstance, random, range, uniqueArray } from './CommonJs.js';
|
|
1
|
+
import { getCapVariableName, newInstance, random, range, timer, uniqueArray } from './CommonJs.js';
|
|
2
2
|
import { marked } from 'marked';
|
|
3
|
-
import {
|
|
4
|
-
getBlobFromUint8ArrayFile,
|
|
5
|
-
getDataFromInputFile,
|
|
6
|
-
getQueryParams,
|
|
7
|
-
getRawContentFile,
|
|
8
|
-
htmls,
|
|
9
|
-
} from './VanillaJs.js';
|
|
3
|
+
import { append, getBlobFromUint8ArrayFile, getDataFromInputFile, getRawContentFile, htmls, s } from './VanillaJs.js';
|
|
10
4
|
import { Panel } from './Panel.js';
|
|
11
5
|
import { NotificationManager } from './NotificationManager.js';
|
|
12
6
|
import { DocumentService } from '../../services/document/document.service.js';
|
|
@@ -15,7 +9,9 @@ import { getSrcFromFileData } from './Input.js';
|
|
|
15
9
|
import { imageShimmer, renderCssAttr } from './Css.js';
|
|
16
10
|
import { Translate } from './Translate.js';
|
|
17
11
|
import { Modal } from './Modal.js';
|
|
18
|
-
import { closeModalRouteChangeEvents, listenQueryPathInstance, setQueryPath } from './Router.js';
|
|
12
|
+
import { closeModalRouteChangeEvents, listenQueryPathInstance, setQueryPath, getQueryParams } from './Router.js';
|
|
13
|
+
import { Scroll } from './Scroll.js';
|
|
14
|
+
import { LoadingAnimation } from './LoadingAnimation.js';
|
|
19
15
|
|
|
20
16
|
const PanelForm = {
|
|
21
17
|
Data: {},
|
|
@@ -39,6 +35,10 @@ const PanelForm = {
|
|
|
39
35
|
originData: [],
|
|
40
36
|
data: [],
|
|
41
37
|
filesData: [],
|
|
38
|
+
skip: 0,
|
|
39
|
+
limit: 3, // Load 5 items per page
|
|
40
|
+
hasMore: true,
|
|
41
|
+
loading: false,
|
|
42
42
|
};
|
|
43
43
|
|
|
44
44
|
const formData = [
|
|
@@ -138,7 +138,7 @@ const PanelForm = {
|
|
|
138
138
|
`,
|
|
139
139
|
});
|
|
140
140
|
return await options.fileRender({
|
|
141
|
-
file: PanelForm.Data[idPanel].filesData.find((f) => f._id === options.data._id)
|
|
141
|
+
file: PanelForm.Data[idPanel].filesData.find((f) => f._id === options.data._id)?.fileId?.fileBlob,
|
|
142
142
|
style: {
|
|
143
143
|
overflow: 'auto',
|
|
144
144
|
width: '100%',
|
|
@@ -178,6 +178,15 @@ const PanelForm = {
|
|
|
178
178
|
}
|
|
179
179
|
return { status: 'error' };
|
|
180
180
|
},
|
|
181
|
+
initAdd: async function () {
|
|
182
|
+
s(`.modal-${options.route}`).scrollTo({ top: 0, behavior: 'smooth' });
|
|
183
|
+
},
|
|
184
|
+
initEdit: async function ({ data }) {
|
|
185
|
+
s(`.modal-${options.route}`).scrollTo({ top: 0, behavior: 'smooth' });
|
|
186
|
+
},
|
|
187
|
+
noResultFound: async function () {
|
|
188
|
+
LoadingAnimation.spinner.stop(`.panel-placeholder-bottom-${idPanel}`);
|
|
189
|
+
},
|
|
181
190
|
add: async function ({ data, editId }) {
|
|
182
191
|
let mdFileId;
|
|
183
192
|
const mdFileName = `${getCapVariableName(data.title)}.md`;
|
|
@@ -318,19 +327,36 @@ const PanelForm = {
|
|
|
318
327
|
},
|
|
319
328
|
});
|
|
320
329
|
|
|
321
|
-
const getPanelData = async () => {
|
|
330
|
+
const getPanelData = async (isLoadMore = false) => {
|
|
331
|
+
const panelData = PanelForm.Data[idPanel];
|
|
332
|
+
if (panelData.loading || !panelData.hasMore) return;
|
|
333
|
+
panelData.loading = true;
|
|
334
|
+
|
|
335
|
+
if (!isLoadMore) {
|
|
336
|
+
// Reset for a fresh load
|
|
337
|
+
panelData.skip = 0;
|
|
338
|
+
panelData.hasMore = true;
|
|
339
|
+
}
|
|
340
|
+
|
|
322
341
|
const result = await DocumentService.get({
|
|
323
|
-
|
|
342
|
+
params: {
|
|
343
|
+
tags: prefixTags.join(','),
|
|
344
|
+
...(getQueryParams().cid && { cid: getQueryParams().cid }),
|
|
345
|
+
skip: panelData.skip,
|
|
346
|
+
limit: panelData.limit,
|
|
347
|
+
},
|
|
348
|
+
id: 'public/',
|
|
324
349
|
});
|
|
325
350
|
|
|
326
|
-
NotificationManager.Push({
|
|
327
|
-
html: result.status === 'success' ? Translate.Render('success-get-posts') : result.message,
|
|
328
|
-
status: result.status,
|
|
329
|
-
});
|
|
330
351
|
if (result.status === 'success') {
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
352
|
+
if (!isLoadMore) {
|
|
353
|
+
panelData.originData = [];
|
|
354
|
+
panelData.filesData = [];
|
|
355
|
+
panelData.data = [];
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
panelData.originData.push(...newInstance(result.data));
|
|
359
|
+
|
|
334
360
|
for (const documentObject of result.data) {
|
|
335
361
|
let mdFileId, fileId;
|
|
336
362
|
let mdBlob, fileBlob;
|
|
@@ -339,7 +365,6 @@ const PanelForm = {
|
|
|
339
365
|
{
|
|
340
366
|
const {
|
|
341
367
|
data: [file],
|
|
342
|
-
status,
|
|
343
368
|
} = await FileService.get({ id: documentObject.mdFileId });
|
|
344
369
|
|
|
345
370
|
// const ext = file.name.split('.')[file.name.split('.').length - 1];
|
|
@@ -350,7 +375,6 @@ const PanelForm = {
|
|
|
350
375
|
if (documentObject.fileId) {
|
|
351
376
|
const {
|
|
352
377
|
data: [file],
|
|
353
|
-
status,
|
|
354
378
|
} = await FileService.get({ id: documentObject.fileId._id });
|
|
355
379
|
|
|
356
380
|
// const ext = file.name.split('.')[file.name.split('.').length - 1];
|
|
@@ -359,14 +383,14 @@ const PanelForm = {
|
|
|
359
383
|
fileId = getSrcFromFileData(file);
|
|
360
384
|
}
|
|
361
385
|
|
|
362
|
-
|
|
386
|
+
panelData.filesData.push({
|
|
363
387
|
id: documentObject._id,
|
|
364
388
|
_id: documentObject._id,
|
|
365
389
|
mdFileId: { mdBlob, mdPlain },
|
|
366
390
|
fileId: { fileBlob, filePlain },
|
|
367
391
|
});
|
|
368
392
|
|
|
369
|
-
|
|
393
|
+
panelData.data.push({
|
|
370
394
|
id: documentObject._id,
|
|
371
395
|
title: documentObject.title,
|
|
372
396
|
createdAt: documentObject.createdAt,
|
|
@@ -378,7 +402,23 @@ const PanelForm = {
|
|
|
378
402
|
_id: documentObject._id,
|
|
379
403
|
});
|
|
380
404
|
}
|
|
405
|
+
|
|
406
|
+
panelData.skip += result.data.length;
|
|
407
|
+
panelData.hasMore = result.data.length === panelData.limit;
|
|
408
|
+
if (result.data.length < panelData.limit) {
|
|
409
|
+
LoadingAnimation.spinner.stop(`.panel-placeholder-bottom-${idPanel}`);
|
|
410
|
+
}
|
|
411
|
+
} else {
|
|
412
|
+
NotificationManager.Push({
|
|
413
|
+
html: result.message,
|
|
414
|
+
status: result.status,
|
|
415
|
+
});
|
|
416
|
+
panelData.hasMore = false;
|
|
381
417
|
}
|
|
418
|
+
|
|
419
|
+
await timer(250);
|
|
420
|
+
|
|
421
|
+
panelData.loading = false;
|
|
382
422
|
};
|
|
383
423
|
const renderSrrPanelData = async () =>
|
|
384
424
|
await panelRender({
|
|
@@ -426,10 +466,10 @@ const PanelForm = {
|
|
|
426
466
|
let firsUpdateEvent = false;
|
|
427
467
|
let lastCid;
|
|
428
468
|
let lastUserId;
|
|
429
|
-
closeModalRouteChangeEvents[idPanel] = (
|
|
430
|
-
|
|
469
|
+
closeModalRouteChangeEvents[idPanel] = () => {
|
|
470
|
+
setTimeout(() => {
|
|
431
471
|
this.Data[idPanel].updatePanel();
|
|
432
|
-
}
|
|
472
|
+
});
|
|
433
473
|
};
|
|
434
474
|
this.Data[idPanel].updatePanel = async () => {
|
|
435
475
|
const cid = getQueryParams().cid ? getQueryParams().cid : '';
|
|
@@ -437,13 +477,60 @@ const PanelForm = {
|
|
|
437
477
|
if (lastCid === cid && !forceUpdate) return;
|
|
438
478
|
lastUserId = newInstance(Elements.Data.user.main.model.user._id);
|
|
439
479
|
lastCid = cid;
|
|
440
|
-
|
|
441
|
-
|
|
480
|
+
|
|
481
|
+
if (cid) {
|
|
482
|
+
this.Data[idPanel] = {
|
|
483
|
+
...this.Data[idPanel],
|
|
484
|
+
originData: [],
|
|
485
|
+
data: [],
|
|
486
|
+
filesData: [],
|
|
487
|
+
skip: 0,
|
|
488
|
+
limit: 3, // Load 5 items per page
|
|
489
|
+
hasMore: true,
|
|
490
|
+
loading: false,
|
|
491
|
+
};
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
const containerSelector = `.${options.parentIdModal ? 'html-' + options.parentIdModal : 'main-body'}`;
|
|
495
|
+
htmls(containerSelector, await renderSrrPanelData());
|
|
496
|
+
|
|
442
497
|
await getPanelData();
|
|
498
|
+
|
|
443
499
|
htmls(
|
|
444
|
-
|
|
445
|
-
|
|
500
|
+
containerSelector,
|
|
501
|
+
html`
|
|
502
|
+
<div class="in">${await panelRender({ data: this.Data[idPanel].data })}</div>
|
|
503
|
+
<div class="in panel-placeholder-bottom panel-placeholder-bottom-${idPanel}"></div>
|
|
504
|
+
`,
|
|
446
505
|
);
|
|
506
|
+
|
|
507
|
+
LoadingAnimation.spinner.play(`.panel-placeholder-bottom-${idPanel}`, 'dual-ring-mini');
|
|
508
|
+
|
|
509
|
+
const scrollContainerSelector = `.modal-${options.route}`;
|
|
510
|
+
|
|
511
|
+
if (cid) {
|
|
512
|
+
LoadingAnimation.spinner.stop(`.panel-placeholder-bottom-${idPanel}`);
|
|
513
|
+
return;
|
|
514
|
+
}
|
|
515
|
+
if (this.Data[idPanel].removeScrollEvent) {
|
|
516
|
+
this.Data[idPanel].removeScrollEvent();
|
|
517
|
+
}
|
|
518
|
+
const { removeEvent } = Scroll.setEvent(scrollContainerSelector, async (payload) => {
|
|
519
|
+
const panelData = PanelForm.Data[idPanel];
|
|
520
|
+
if (!panelData) return;
|
|
521
|
+
|
|
522
|
+
// Infinite scroll: load more items at bottom
|
|
523
|
+
if (payload.atBottom && panelData.hasMore && !panelData.loading) {
|
|
524
|
+
const oldDataCount = panelData.data.length;
|
|
525
|
+
await getPanelData(true); // isLoadMore = true
|
|
526
|
+
const newItems = panelData.data.slice(oldDataCount);
|
|
527
|
+
if (newItems.length > 0) {
|
|
528
|
+
for (const item of newItems) append(`.${idPanel}-render`, await Panel.Tokens[idPanel].renderPanel(item));
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
});
|
|
532
|
+
this.Data[idPanel].removeScrollEvent = removeEvent;
|
|
533
|
+
|
|
447
534
|
if (!firsUpdateEvent && options.firsUpdateEvent) {
|
|
448
535
|
firsUpdateEvent = true;
|
|
449
536
|
await options.firsUpdateEvent();
|
|
@@ -454,15 +541,25 @@ const PanelForm = {
|
|
|
454
541
|
id: options.parentIdModal ? 'html-' + options.parentIdModal : 'main-body',
|
|
455
542
|
routeId: options.route,
|
|
456
543
|
event: async (path) => {
|
|
457
|
-
|
|
544
|
+
PanelForm.Data[idPanel] = {
|
|
545
|
+
...PanelForm.Data[idPanel],
|
|
546
|
+
originData: [],
|
|
547
|
+
data: [],
|
|
548
|
+
filesData: [],
|
|
549
|
+
// skip: 0,
|
|
550
|
+
limit: 3, // Load 5 items per page
|
|
551
|
+
hasMore: true,
|
|
552
|
+
loading: false,
|
|
553
|
+
};
|
|
554
|
+
await PanelForm.Data[idPanel].updatePanel();
|
|
458
555
|
},
|
|
459
556
|
});
|
|
460
557
|
if (!options.parentIdModal)
|
|
461
558
|
Modal.Data['modal-menu'].onHome[idPanel] = async () => {
|
|
462
559
|
lastCid = undefined;
|
|
463
560
|
lastUserId = undefined;
|
|
464
|
-
setQueryPath({ path: options.route, queryPath: '' });
|
|
465
|
-
await
|
|
561
|
+
setQueryPath({ path: options.route, queryPath: options.route === 'home' ? '?' : '' });
|
|
562
|
+
await PanelForm.Data[idPanel].updatePanel();
|
|
466
563
|
};
|
|
467
564
|
}
|
|
468
565
|
|
|
@@ -3,11 +3,11 @@ import { Auth } from './Auth.js';
|
|
|
3
3
|
import { BtnIcon } from './BtnIcon.js';
|
|
4
4
|
import { EventsUI } from './EventsUI.js';
|
|
5
5
|
import { Input } from './Input.js';
|
|
6
|
-
import { LogIn } from './LogIn.js';
|
|
7
6
|
import { NotificationManager } from './NotificationManager.js';
|
|
8
7
|
import { Translate } from './Translate.js';
|
|
9
8
|
import { Validator } from './Validator.js';
|
|
10
|
-
import {
|
|
9
|
+
import { s } from './VanillaJs.js';
|
|
10
|
+
import { getProxyPath, getQueryParams } from './Router.js';
|
|
11
11
|
|
|
12
12
|
const Recover = {
|
|
13
13
|
Event: {},
|
|
@@ -1,21 +1,131 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Router module for handling routing in a PWA application.
|
|
3
|
+
* @module src/client/components/core/Router.js
|
|
4
|
+
* @namespace PwaRouter
|
|
5
|
+
*/
|
|
6
|
+
|
|
1
7
|
import { titleFormatted } from './CommonJs.js';
|
|
2
8
|
import { loggerFactory } from './Logger.js';
|
|
3
|
-
import {
|
|
9
|
+
import { htmls, s } from './VanillaJs.js';
|
|
4
10
|
import { Modal } from './Modal.js';
|
|
5
11
|
import { Worker } from './Worker.js';
|
|
6
12
|
|
|
7
|
-
|
|
13
|
+
const logger = loggerFactory(import.meta, { trace: true });
|
|
8
14
|
|
|
15
|
+
/**
|
|
16
|
+
* @type {Object.<string, function>}
|
|
17
|
+
* @description Holds event listeners for router changes.
|
|
18
|
+
* @memberof PwaRouter
|
|
19
|
+
*/
|
|
9
20
|
const RouterEvents = {};
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* @type {string[]}
|
|
24
|
+
* @description Array of core UI component IDs that should not trigger modal close route changes.
|
|
25
|
+
* @memberof PwaRouter
|
|
26
|
+
*/
|
|
27
|
+
const coreUI = ['modal-menu', 'main-body', 'main-body-top', 'bottom-bar', 'board-notification'];
|
|
28
|
+
/**
|
|
29
|
+
* @type {Object.<string, function>}
|
|
30
|
+
* @description Holds event listeners for route changes that should close a modal.
|
|
31
|
+
* @memberof PwaRouter
|
|
32
|
+
*/
|
|
10
33
|
const closeModalRouteChangeEvents = {};
|
|
11
34
|
|
|
12
|
-
|
|
35
|
+
/**
|
|
36
|
+
* Determines the base path for the application, often used for routing within a sub-directory.
|
|
37
|
+
* It checks the current URL's pathname and `window.Routes` to return the appropriate proxy path.
|
|
38
|
+
*
|
|
39
|
+
* @returns {string} The calculated proxy path. Returns `/<first-segment>/` if a segment exists,
|
|
40
|
+
* otherwise `/`. If `window.Routes` indicates the path is a root route, it returns `/`.
|
|
41
|
+
* @memberof PwaRouter
|
|
42
|
+
*/
|
|
43
|
+
const getProxyPath = () => {
|
|
44
|
+
let path = location.pathname.split('/')[1] ? `/${location.pathname.split('/')[1]}/` : '/';
|
|
45
|
+
if (window.Routes && path !== '/' && path.slice(0, -1) in window.Routes()) path = '/';
|
|
46
|
+
return path;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Sets the browser's path using the History API. It sanitizes the path, handles query strings and hashes,
|
|
51
|
+
* and prevents pushing the same state twice.
|
|
52
|
+
* @param {string} [path='/'] - The new path to set. Can include query strings and hashes.
|
|
53
|
+
* @param {object} [options={ removeSearch: false, removeHash: false }] - Options for path manipulation.
|
|
54
|
+
* @param {boolean} [options.removeSearch=false] - If true, removes the search part of the URL.
|
|
55
|
+
* @param {boolean} [options.removeHash=false] - If true, removes the hash part of the URL. Defaults to `false`.
|
|
56
|
+
* @param {object} [stateStorage={}] - State object to associate with the history entry.
|
|
57
|
+
* @param {string} [title=''] - The title for the new history entry.
|
|
58
|
+
* @memberof PwaRouter
|
|
59
|
+
* @returns {void | undefined} Returns `undefined` if the new path is the same as the current path, otherwise `void` (result of `history.pushState`).
|
|
60
|
+
*/
|
|
61
|
+
const setPath = (path = '/', options = { removeSearch: false, removeHash: false }, stateStorage = {}, title = '') => {
|
|
62
|
+
logger.warn(`Set path input`, `${path}`);
|
|
63
|
+
if (!path) path = '/';
|
|
64
|
+
|
|
65
|
+
let [inputPath, inputSearchHash] = `${path}`.split('?');
|
|
66
|
+
let [inputSearch, inputHash] = inputSearchHash ? inputSearchHash.split('#') : [];
|
|
13
67
|
|
|
68
|
+
let sanitizedPath = (inputPath[0] !== '/' ? `/${inputPath}` : inputPath)
|
|
69
|
+
.trim()
|
|
70
|
+
.replaceAll('//', '/')
|
|
71
|
+
.replaceAll(`\\`, '/');
|
|
72
|
+
|
|
73
|
+
if (sanitizedPath.length > 1 && sanitizedPath[sanitizedPath.length - 1] === '/')
|
|
74
|
+
sanitizedPath = sanitizedPath.slice(0, -1);
|
|
75
|
+
|
|
76
|
+
const newFullPath = `${sanitizedPath}${inputSearch && !options.removeSearch ? `?${inputSearch}` : ''}${
|
|
77
|
+
inputHash && !options.removeHash ? `#${inputHash}` : ''
|
|
78
|
+
}`;
|
|
79
|
+
const currentFullPath = `${window.location.pathname}${location.search}${location.hash}`;
|
|
80
|
+
logger.warn(`Set path output`, {
|
|
81
|
+
inputPath: inputPath,
|
|
82
|
+
inputSearch: inputSearch,
|
|
83
|
+
inputHash: inputHash,
|
|
84
|
+
sanitizedPath: sanitizedPath,
|
|
85
|
+
currentLocationSearch: location.search,
|
|
86
|
+
currentLocationHash: location.hash,
|
|
87
|
+
currentFullPath,
|
|
88
|
+
newFullPath,
|
|
89
|
+
});
|
|
90
|
+
if (currentFullPath === newFullPath) {
|
|
91
|
+
logger.warn('Prevent overwriting same path', { currentFullPath, newFullPath });
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
return history.pushState.call(history, stateStorage, title, newFullPath);
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Extracts query parameters from the current URL's search string and returns them as an object.
|
|
99
|
+
* @returns An object containing the query parameters from the current URL is being returned.
|
|
100
|
+
* @memberof PwaRouter
|
|
101
|
+
*/
|
|
102
|
+
const getQueryParams = () => {
|
|
103
|
+
const params = new URLSearchParams(window.location.search);
|
|
104
|
+
let queries = {};
|
|
105
|
+
for (const param of params) {
|
|
106
|
+
queries[param[0]] = param[1];
|
|
107
|
+
}
|
|
108
|
+
return queries;
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Sanitizes a route string for use in CSS classes or other identifiers.
|
|
113
|
+
* Defaults to 'home' for empty, '/', or '\' routes.
|
|
114
|
+
* @param {string} route - The route string to sanitize.
|
|
115
|
+
* @returns {string} The sanitized route string.
|
|
116
|
+
* @memberof PwaRouter
|
|
117
|
+
*/
|
|
14
118
|
const sanitizeRoute = (route) =>
|
|
15
119
|
!route || route === '/' || route === `\\`
|
|
16
120
|
? 'home'
|
|
17
121
|
: route.toLowerCase().replaceAll('/', '').replaceAll(`\\`, '').replaceAll(' ', '-');
|
|
18
122
|
|
|
123
|
+
/**
|
|
124
|
+
* Sets the document title and updates the active state of the main menu button corresponding to the route.
|
|
125
|
+
* The title is formatted and appended with the main application title from `Worker.title` if it's not already present.
|
|
126
|
+
* @param {string} route - The current route string.
|
|
127
|
+
* @memberof PwaRouter
|
|
128
|
+
*/
|
|
19
129
|
const setDocTitle = (route) => {
|
|
20
130
|
const _route = sanitizeRoute(route);
|
|
21
131
|
// logger.warn('setDocTitle', _route);
|
|
@@ -27,6 +137,14 @@ const setDocTitle = (route) => {
|
|
|
27
137
|
}
|
|
28
138
|
};
|
|
29
139
|
|
|
140
|
+
/**
|
|
141
|
+
* Main router function. It matches the current URL path against the provided routes configuration
|
|
142
|
+
* and renders the corresponding component. It also fires registered router events.
|
|
143
|
+
* @param {object} [options={ Routes: () => {}, e: new PopStateEvent() }] - The router options.
|
|
144
|
+
* @param {function} options.Routes - A function that returns the routes object.
|
|
145
|
+
* @param {PopStateEvent} options.e - The popstate event object.
|
|
146
|
+
* @memberof PwaRouter
|
|
147
|
+
*/
|
|
30
148
|
const Router = function (options = { Routes: () => {}, e: new PopStateEvent() }) {
|
|
31
149
|
const { e, Routes } = options;
|
|
32
150
|
const proxyPath = getProxyPath();
|
|
@@ -50,20 +168,43 @@ const Router = function (options = { Routes: () => {}, e: new PopStateEvent() })
|
|
|
50
168
|
}
|
|
51
169
|
};
|
|
52
170
|
|
|
171
|
+
/**
|
|
172
|
+
* Initializes the router and sets up the `onpopstate` event listener to handle browser
|
|
173
|
+
* back/forward navigation.
|
|
174
|
+
* @param {object} RouterInstance - The router instance configuration, including the `Routes` function.
|
|
175
|
+
* @memberof PwaRouter
|
|
176
|
+
*/
|
|
53
177
|
const LoadRouter = function (RouterInstance) {
|
|
54
178
|
Router(RouterInstance);
|
|
55
179
|
window.onpopstate = (e) => Router({ ...RouterInstance, e });
|
|
56
180
|
};
|
|
57
181
|
|
|
182
|
+
/**
|
|
183
|
+
* Sets the URL path with a specific query parameter, commonly used for content IDs.
|
|
184
|
+
* This function constructs a new URI based on the proxy path, a given path, and an optional query parameter.
|
|
185
|
+
* @param {object} [options={ path: '', queryPath: '' }] - The path options.
|
|
186
|
+
* @param {string} [options.path=''] - The base path segment.
|
|
187
|
+
* @memberof PwaRouter
|
|
188
|
+
*/
|
|
58
189
|
const setQueryPath = (options = { path: '', queryPath: '' }, queryKey = 'cid') => {
|
|
59
190
|
const { queryPath, path } = options;
|
|
60
191
|
const newUri = `${getProxyPath()}${path === 'home' ? '' : `${path}/`}${
|
|
61
|
-
typeof queryPath === 'string' ? `?${queryKey}=${queryPath}` : ''
|
|
192
|
+
typeof queryPath === 'string' && queryPath ? `?${queryKey}=${queryPath}` : ''
|
|
62
193
|
}`;
|
|
63
194
|
const currentUri = `${window.location.pathname}${location.search}`;
|
|
64
|
-
if (currentUri !== newUri && currentUri !== `${newUri}/`) setPath(newUri);
|
|
195
|
+
if (currentUri !== newUri && currentUri !== `${newUri}/`) setPath(newUri, {}, '');
|
|
65
196
|
};
|
|
66
197
|
|
|
198
|
+
/**
|
|
199
|
+
* Registers a listener for route changes that specifically watches for a `queryKey` parameter
|
|
200
|
+
* on a matching `routeId`. The provided event callback is triggered with the query parameter's value.
|
|
201
|
+
* @param {object} options - The listener options.
|
|
202
|
+
* @param {string} options.id - A unique ID for the listener.
|
|
203
|
+
* @param {string} options.routeId - The route ID to listen for.
|
|
204
|
+
* @param {function(string): void} options.event - The callback function to execute with the query path value (or an empty string if not found).
|
|
205
|
+
* @param {string} [queryKey='cid'] - The query parameter key to look for.
|
|
206
|
+
* @memberof PwaRouter
|
|
207
|
+
*/
|
|
67
208
|
const listenQueryPathInstance = ({ id, routeId, event }, queryKey = 'cid') => {
|
|
68
209
|
RouterEvents[id] = ({ path, pushPath, proxyPath, route }) => {
|
|
69
210
|
if ((route === '' && routeId === 'home') || (route && routeId && route === routeId)) {
|
|
@@ -80,38 +221,43 @@ const listenQueryPathInstance = ({ id, routeId, event }, queryKey = 'cid') => {
|
|
|
80
221
|
});
|
|
81
222
|
};
|
|
82
223
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
}
|
|
87
|
-
|
|
224
|
+
/**
|
|
225
|
+
* Handles the logic for changing the route when a modal is closed. It determines the next URL
|
|
226
|
+
* based on the remaining open modals or falls back to a home URL.
|
|
227
|
+
* @param {object} [options={}] - Options for the modal close event.
|
|
228
|
+
* @param {string} options.closedId - The ID of the modal that was just closed.
|
|
229
|
+
* @memberof PwaRouter
|
|
230
|
+
*/
|
|
88
231
|
const closeModalRouteChangeEvent = (options = {}) => {
|
|
89
|
-
|
|
90
|
-
|
|
232
|
+
logger.warn('closeModalRouteChangeEvent', options);
|
|
233
|
+
const { closedId } = options;
|
|
234
|
+
if (!closedId) return;
|
|
235
|
+
if (coreUI.find((id) => closedId.startsWith(id))) {
|
|
236
|
+
logger.warn('prevent core ui component close');
|
|
237
|
+
return;
|
|
238
|
+
}
|
|
91
239
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
240
|
+
const remainingModals = Object.keys(Modal.Data).filter(
|
|
241
|
+
(id) => id !== closedId && (Modal.Data[id]?.options?.route || Modal.Data[id]?.options?.query),
|
|
242
|
+
);
|
|
95
243
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
setDocTitle(newPath);
|
|
103
|
-
Modal.setTopModalCallback(subIdModal);
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
newPath = `${newPath}${homeCid ? `?cid=${homeCid}` : ''}`;
|
|
107
|
-
triggerCloseModalRouteChangeEvents(newPath);
|
|
108
|
-
setPath(newPath);
|
|
109
|
-
setDocTitle(newPath);
|
|
110
|
-
}
|
|
244
|
+
const topModalId = remainingModals.reverse().find((id) => Modal.Data[id]);
|
|
245
|
+
|
|
246
|
+
for (const event of Object.keys(closeModalRouteChangeEvents)) closeModalRouteChangeEvents[event]();
|
|
247
|
+
if (topModalId) Modal.setTopModalCallback(topModalId);
|
|
248
|
+
setPath(`${getProxyPath()}${Modal.Data[topModalId]?.options?.route ?? ''}`);
|
|
249
|
+
setDocTitle(Modal.Data[topModalId]?.options?.route ?? '');
|
|
111
250
|
};
|
|
112
251
|
|
|
113
|
-
|
|
114
|
-
|
|
252
|
+
/**
|
|
253
|
+
* Handles routing for modals that are meant to be displayed as a "view" (e.g., a full-page modal).
|
|
254
|
+
* It updates the URL to reflect the modal's route.
|
|
255
|
+
* @param {object} [options={ route: 'home' }] - The options for handling the modal view route.
|
|
256
|
+
* @param {string} options.route - The route associated with the modal view.
|
|
257
|
+
* @memberof PwaRouter
|
|
258
|
+
*/
|
|
259
|
+
const handleModalViewRoute = (options = { route: '' }) => {
|
|
260
|
+
const { route } = options;
|
|
115
261
|
if (!route) return;
|
|
116
262
|
|
|
117
263
|
let path = window.location.pathname;
|
|
@@ -125,14 +271,44 @@ const handleModalViewRoute = (options = {}) => {
|
|
|
125
271
|
}
|
|
126
272
|
};
|
|
127
273
|
|
|
274
|
+
/**
|
|
275
|
+
* Sets or updates query parameters in the URL.
|
|
276
|
+
* It preserves the existing path, hash, and other query parameters.
|
|
277
|
+
*
|
|
278
|
+
* @param {Object.<string, string|number>} newParams - An object of query parameters to set or update.
|
|
279
|
+
* If a value is `null` or `undefined`, the parameter will be removed.
|
|
280
|
+
* @param {object} [options={ replace: true }] - Options for history manipulation.
|
|
281
|
+
* @param {boolean} [options.replace=true] - If true, uses `history.replaceState` instead of `history.pushState`.
|
|
282
|
+
* @memberof PwaRouter
|
|
283
|
+
*/
|
|
284
|
+
const setQueryParams = (newParams, options = { replace: true }) => {
|
|
285
|
+
const url = new URL(window.location.href);
|
|
286
|
+
Object.entries(newParams).forEach(([key, value]) => {
|
|
287
|
+
if (value === null || value === undefined) {
|
|
288
|
+
url.searchParams.delete(key);
|
|
289
|
+
} else {
|
|
290
|
+
url.searchParams.set(key, value);
|
|
291
|
+
}
|
|
292
|
+
});
|
|
293
|
+
|
|
294
|
+
const newPath = url.pathname + url.search + url.hash;
|
|
295
|
+
|
|
296
|
+
history.pushState(history.state, '', newPath);
|
|
297
|
+
};
|
|
298
|
+
|
|
128
299
|
export {
|
|
300
|
+
RouterEvents,
|
|
301
|
+
closeModalRouteChangeEvents,
|
|
302
|
+
coreUI,
|
|
129
303
|
Router,
|
|
130
304
|
setDocTitle,
|
|
131
305
|
LoadRouter,
|
|
132
|
-
RouterEvents,
|
|
133
306
|
setQueryPath,
|
|
134
307
|
listenQueryPathInstance,
|
|
135
308
|
closeModalRouteChangeEvent,
|
|
136
309
|
handleModalViewRoute,
|
|
137
|
-
|
|
310
|
+
getQueryParams,
|
|
311
|
+
getProxyPath,
|
|
312
|
+
setPath,
|
|
313
|
+
setQueryParams,
|
|
138
314
|
};
|