@sumaris-net/ngx-components 2.4.131 → 2.4.132
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/esm2020/src/app/core/menu/menu.service.mjs +50 -21
- package/esm2020/src/app/core/menu/sub-menu-tab.directive.mjs +6 -6
- package/esm2020/src/app/core/menu/testing/menu.testing.mjs +4 -10
- package/esm2020/src/app/core/menu/testing/menu.testing.module.mjs +15 -20
- package/fesm2015/sumaris-net.ngx-components.mjs +67 -50
- package/fesm2015/sumaris-net.ngx-components.mjs.map +1 -1
- package/fesm2020/sumaris-net.ngx-components.mjs +67 -50
- package/fesm2020/sumaris-net.ngx-components.mjs.map +1 -1
- package/package.json +1 -1
- package/src/app/core/menu/menu.service.d.ts +2 -1
- package/src/app/core/menu/testing/menu.testing.d.ts +3 -5
|
@@ -23154,7 +23154,7 @@ class MenuService extends StartableObservableService {
|
|
|
23154
23154
|
this.router = router;
|
|
23155
23155
|
this.environment = environment;
|
|
23156
23156
|
this.accountChanges = new BehaviorSubject(undefined);
|
|
23157
|
-
this.
|
|
23157
|
+
this._detachedSubItems = [];
|
|
23158
23158
|
this._itemCounter = 0;
|
|
23159
23159
|
this._logPrefix = '[menu-service] ';
|
|
23160
23160
|
this._$opened = new Subject();
|
|
@@ -23164,10 +23164,10 @@ class MenuService extends StartableObservableService {
|
|
|
23164
23164
|
this._debug = !environment.production;
|
|
23165
23165
|
this._staticItems = (staticItems || []).map(i => {
|
|
23166
23166
|
const item = MenuItems.prepareItem(i);
|
|
23167
|
-
item.id = this.
|
|
23167
|
+
item.id = this.computeNewId();
|
|
23168
23168
|
return item;
|
|
23169
23169
|
});
|
|
23170
|
-
this.
|
|
23170
|
+
this._detachedSubItems = []; // TODO restore from settings ?
|
|
23171
23171
|
}
|
|
23172
23172
|
get opened() {
|
|
23173
23173
|
return this._$opened.asObservable();
|
|
@@ -23251,16 +23251,22 @@ class MenuService extends StartableObservableService {
|
|
|
23251
23251
|
console.debug(`${this._logPrefix}Received config or account event. Refreshing items...`, account);
|
|
23252
23252
|
// Load all items
|
|
23253
23253
|
const items = yield this._loadMenuItems(config, account);
|
|
23254
|
+
const pathParam = MenuItems.parsePathWithQuery(this.router.routerState.snapshot.url);
|
|
23255
|
+
this.detachSubMenuItem(pathParam);
|
|
23254
23256
|
this.dataSubject.next(items);
|
|
23255
23257
|
// Emit account changes event
|
|
23256
23258
|
this.accountChanges.next(account);
|
|
23257
23259
|
})));
|
|
23258
|
-
this.registerSubscription(this._$listenRoute.pipe(filter(listen => listen === true), mergeMap$1(_ => this.router.events), filter(event => event instanceof NavigationEnd), map((event) => MenuItems.parsePathWithQuery(event.url))).
|
|
23260
|
+
this.registerSubscription(merge(this.accountChanges.pipe(map(() => MenuItems.parsePathWithQuery(this.router.routerState.snapshot.url))), this._$listenRoute.pipe(filter(listen => listen === true), mergeMap$1(_ => this.router.events), filter(event => event instanceof NavigationEnd), map((event) => MenuItems.parsePathWithQuery(event.url)))).pipe(throttleTime(250), filter(() => isNotEmptyArray(this.data)))
|
|
23261
|
+
.subscribe(pathParam => {
|
|
23259
23262
|
this.detachSubMenuItem(pathParam);
|
|
23260
23263
|
}));
|
|
23261
23264
|
return items;
|
|
23262
23265
|
});
|
|
23263
23266
|
}
|
|
23267
|
+
computeNewId() {
|
|
23268
|
+
return this._itemCounter++;
|
|
23269
|
+
}
|
|
23264
23270
|
_addSubMenuItem(newItem, opts) {
|
|
23265
23271
|
opts = Object.assign({ skipIfExists: true }, opts);
|
|
23266
23272
|
// Make sure path (and pathParams) are filled in the same way
|
|
@@ -23268,7 +23274,7 @@ class MenuService extends StartableObservableService {
|
|
|
23268
23274
|
// Find if item already exists
|
|
23269
23275
|
const existingItem = this._findExistingItem(newItem);
|
|
23270
23276
|
if (existingItem) {
|
|
23271
|
-
if (opts.skipIfExists) {
|
|
23277
|
+
if (opts.skipIfExists && !!existingItem.parentPath) {
|
|
23272
23278
|
// DEBUG
|
|
23273
23279
|
if (this._debug)
|
|
23274
23280
|
console.debug(`${this._logPrefix}Skipping sub item (already exist)`, newItem);
|
|
@@ -23280,17 +23286,32 @@ class MenuService extends StartableObservableService {
|
|
|
23280
23286
|
newItem.id = existingItem.id;
|
|
23281
23287
|
newItem.$children = existingItem.$children;
|
|
23282
23288
|
newItem.pinned = existingItem.pinned;
|
|
23289
|
+
newItem.title = newItem.title || existingItem.title; // Keep existing title
|
|
23290
|
+
}
|
|
23291
|
+
else {
|
|
23292
|
+
// Generate item's id (if need)
|
|
23293
|
+
if (isNil(newItem.id))
|
|
23294
|
+
newItem.id = this.computeNewId();
|
|
23283
23295
|
}
|
|
23284
|
-
// Generate item's id (if need)
|
|
23285
|
-
if (isNil(newItem.id))
|
|
23286
|
-
newItem.id = this._itemCounter++;
|
|
23287
23296
|
const parent = this._findParent(newItem, opts === null || opts === void 0 ? void 0 : opts.availableParents);
|
|
23288
23297
|
if (parent) {
|
|
23289
23298
|
this._addMenuToParent(parent, newItem);
|
|
23299
|
+
// Removed from detached items
|
|
23300
|
+
const detachedIndex = existingItem ? this._detachedSubItems.indexOf(existingItem) : -1;
|
|
23301
|
+
if (detachedIndex !== -1) {
|
|
23302
|
+
this._detachedSubItems.splice(detachedIndex, 1);
|
|
23303
|
+
}
|
|
23290
23304
|
}
|
|
23291
23305
|
else {
|
|
23292
|
-
|
|
23293
|
-
|
|
23306
|
+
const detachedIndex = existingItem ? this._detachedSubItems.indexOf(existingItem) : -1;
|
|
23307
|
+
if (detachedIndex !== -1) {
|
|
23308
|
+
// Update existing detached item
|
|
23309
|
+
this._detachedSubItems[detachedIndex] = newItem;
|
|
23310
|
+
}
|
|
23311
|
+
else {
|
|
23312
|
+
// Add to detached item
|
|
23313
|
+
this._detachedSubItems.push(newItem);
|
|
23314
|
+
}
|
|
23294
23315
|
}
|
|
23295
23316
|
// Start listening route
|
|
23296
23317
|
if (!this._$listenRoute.value)
|
|
@@ -23302,12 +23323,15 @@ class MenuService extends StartableObservableService {
|
|
|
23302
23323
|
if (this._debug)
|
|
23303
23324
|
console.debug(`${this._logPrefix}Loading menu items...`);
|
|
23304
23325
|
// Save previous children of root items
|
|
23305
|
-
const
|
|
23326
|
+
const detachedSubItems = (this.data || [])
|
|
23306
23327
|
.reduce((res, rootItem) => {
|
|
23307
23328
|
var _a;
|
|
23329
|
+
const subItems = (_a = rootItem.$children) === null || _a === void 0 ? void 0 : _a.value;
|
|
23330
|
+
if (isEmptyArray(subItems))
|
|
23331
|
+
return res;
|
|
23308
23332
|
rootItem.$children.next([]);
|
|
23309
|
-
return res.concat(
|
|
23310
|
-
}, []);
|
|
23333
|
+
return res.concat(subItems);
|
|
23334
|
+
}, this._detachedSubItems || []);
|
|
23311
23335
|
// Reset base root items (clean items added by config)
|
|
23312
23336
|
let items = this._staticItems.slice();
|
|
23313
23337
|
// Concat config's items
|
|
@@ -23357,7 +23381,7 @@ class MenuService extends StartableObservableService {
|
|
|
23357
23381
|
.map(item => {
|
|
23358
23382
|
// Generate item's id (if need)
|
|
23359
23383
|
if (isNil(item.id))
|
|
23360
|
-
item.id = this.
|
|
23384
|
+
item.id = this.computeNewId();
|
|
23361
23385
|
// Replace title using properties
|
|
23362
23386
|
if (isNotNilOrBlank(item.titleProperty) && config) {
|
|
23363
23387
|
const title = config.properties[item.titleProperty];
|
|
@@ -23367,8 +23391,13 @@ class MenuService extends StartableObservableService {
|
|
|
23367
23391
|
return item;
|
|
23368
23392
|
});
|
|
23369
23393
|
// Re-attach sub menu items
|
|
23370
|
-
if (
|
|
23371
|
-
|
|
23394
|
+
if (detachedSubItems.length) {
|
|
23395
|
+
if (account) {
|
|
23396
|
+
yield this.addSubMenuItems(detachedSubItems, { skipIfExists: false, availableParents: detachedSubItems.concat(items) });
|
|
23397
|
+
}
|
|
23398
|
+
else {
|
|
23399
|
+
this._detachedSubItems = detachedSubItems;
|
|
23400
|
+
}
|
|
23372
23401
|
}
|
|
23373
23402
|
if (this._debug)
|
|
23374
23403
|
console.debug(`${this._logPrefix}Found ${items.length} visible items...`);
|
|
@@ -23376,7 +23405,7 @@ class MenuService extends StartableObservableService {
|
|
|
23376
23405
|
});
|
|
23377
23406
|
}
|
|
23378
23407
|
_findExistingItem(item, items) {
|
|
23379
|
-
items = items || this.
|
|
23408
|
+
items = items || this._detachedSubItems.concat(this.data);
|
|
23380
23409
|
if (!items.length)
|
|
23381
23410
|
return undefined; // Not found
|
|
23382
23411
|
for (const i of items) {
|
|
@@ -23390,7 +23419,7 @@ class MenuService extends StartableObservableService {
|
|
|
23390
23419
|
_findParent(childItem, availableParents) {
|
|
23391
23420
|
if (!(childItem === null || childItem === void 0 ? void 0 : childItem.path))
|
|
23392
23421
|
return undefined;
|
|
23393
|
-
availableParents = availableParents || this.
|
|
23422
|
+
availableParents = availableParents || this._detachedSubItems.concat(this.data);
|
|
23394
23423
|
return availableParents.reduce((res, item) => {
|
|
23395
23424
|
var _a, _b;
|
|
23396
23425
|
if (!(item === null || item === void 0 ? void 0 : item.path))
|
|
@@ -23790,7 +23819,6 @@ class SubMenuTabDirective {
|
|
|
23790
23819
|
}
|
|
23791
23820
|
ngOnChanges(changes) {
|
|
23792
23821
|
if (changes.disabled || changes.label || changes.subMenuTitle || changes.parentPath || changes.path) {
|
|
23793
|
-
console.log('TODO received tab=' + (this.subMenuTitle || this.label), this.path);
|
|
23794
23822
|
if (this.disabled) {
|
|
23795
23823
|
if (this._menuItem)
|
|
23796
23824
|
this.menuService.removeSubMenuItem(this._menuItem);
|
|
@@ -23820,10 +23848,11 @@ class SubMenuTabDirective {
|
|
|
23820
23848
|
return; // Skip if no changes
|
|
23821
23849
|
menuItem.id = this._menuItem.id;
|
|
23822
23850
|
}
|
|
23823
|
-
|
|
23824
|
-
|
|
23825
|
-
|
|
23826
|
-
|
|
23851
|
+
else {
|
|
23852
|
+
menuItem.id = this.menuService.computeNewId();
|
|
23853
|
+
this._menuItem = menuItem;
|
|
23854
|
+
}
|
|
23855
|
+
this._menuItem = yield this.menuService.addSubMenuItem(menuItem, { skipIfExists: false });
|
|
23827
23856
|
});
|
|
23828
23857
|
}
|
|
23829
23858
|
}
|
|
@@ -37190,21 +37219,15 @@ class MenuTestingPage extends AppTabEditor {
|
|
|
37190
37219
|
this.thirdTabTitle = '';
|
|
37191
37220
|
this.parentPath = null;
|
|
37192
37221
|
this.showOtherLinks = true;
|
|
37193
|
-
this.$title = new
|
|
37194
|
-
this.$secondTabTitle = new
|
|
37222
|
+
this.$title = new Subject();
|
|
37223
|
+
this.$secondTabTitle = new Subject();
|
|
37195
37224
|
}
|
|
37196
37225
|
set title(value) {
|
|
37197
37226
|
this.$title.next(value);
|
|
37198
37227
|
}
|
|
37199
|
-
get title() {
|
|
37200
|
-
return this.$title.value;
|
|
37201
|
-
}
|
|
37202
37228
|
set secondTabTitle(value) {
|
|
37203
37229
|
this.$secondTabTitle.next(value);
|
|
37204
37230
|
}
|
|
37205
|
-
get secondTabTitle() {
|
|
37206
|
-
return this.$secondTabTitle.value;
|
|
37207
|
-
}
|
|
37208
37231
|
ngOnInit() {
|
|
37209
37232
|
console.debug(`${this.logPrefix} Init page...`);
|
|
37210
37233
|
super.ngOnInit();
|
|
@@ -37328,34 +37351,28 @@ const routes$4 = [
|
|
|
37328
37351
|
pathMatch: 'full',
|
|
37329
37352
|
component: MenuTestingPage,
|
|
37330
37353
|
data: {
|
|
37331
|
-
test: 'empty'
|
|
37332
|
-
}
|
|
37354
|
+
test: 'empty',
|
|
37355
|
+
},
|
|
37333
37356
|
},
|
|
37334
37357
|
{
|
|
37335
37358
|
path: 'others',
|
|
37336
|
-
|
|
37359
|
+
canActivate: [AuthGuardService],
|
|
37360
|
+
data: {
|
|
37361
|
+
profile: 'USER',
|
|
37362
|
+
},
|
|
37337
37363
|
children: [
|
|
37338
37364
|
{
|
|
37339
37365
|
path: ':otherId',
|
|
37366
|
+
pathMatch: 'full',
|
|
37340
37367
|
component: OtherMenuTestingPage,
|
|
37368
|
+
canActivate: [AuthGuardService],
|
|
37369
|
+
data: {
|
|
37370
|
+
profile: 'ADMIN',
|
|
37371
|
+
},
|
|
37341
37372
|
},
|
|
37342
|
-
]
|
|
37343
|
-
// canActivate: [
|
|
37344
|
-
// <CanActivateFn>(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) => {
|
|
37345
|
-
// console.log('TODO canActivate', route.data?.tabs);
|
|
37346
|
-
//
|
|
37347
|
-
// if (route.component?.['tabsChanges']) {
|
|
37348
|
-
// (route.component as any).tabsChanges
|
|
37349
|
-
// .subscribe(tabs => {
|
|
37350
|
-
// console.log('TODO tabs', tabs);
|
|
37351
|
-
// });
|
|
37352
|
-
// }
|
|
37353
|
-
//
|
|
37354
|
-
// return true;
|
|
37355
|
-
// }
|
|
37356
|
-
// ]
|
|
37373
|
+
],
|
|
37357
37374
|
},
|
|
37358
|
-
]
|
|
37375
|
+
],
|
|
37359
37376
|
},
|
|
37360
37377
|
];
|
|
37361
37378
|
class MenuTestingModule {
|