@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.
@@ -22791,7 +22791,7 @@ class MenuService extends StartableObservableService {
22791
22791
  this.router = router;
22792
22792
  this.environment = environment;
22793
22793
  this.accountChanges = new BehaviorSubject(undefined);
22794
- this._detachedItems = [];
22794
+ this._detachedSubItems = [];
22795
22795
  this._itemCounter = 0;
22796
22796
  this._logPrefix = '[menu-service] ';
22797
22797
  this._$opened = new Subject();
@@ -22801,10 +22801,10 @@ class MenuService extends StartableObservableService {
22801
22801
  this._debug = !environment.production;
22802
22802
  this._staticItems = (staticItems || []).map(i => {
22803
22803
  const item = MenuItems.prepareItem(i);
22804
- item.id = this._itemCounter++;
22804
+ item.id = this.computeNewId();
22805
22805
  return item;
22806
22806
  });
22807
- this._detachedItems = []; // TODO restore from settings ?
22807
+ this._detachedSubItems = []; // TODO restore from settings ?
22808
22808
  }
22809
22809
  get opened() {
22810
22810
  return this._$opened.asObservable();
@@ -22883,15 +22883,21 @@ class MenuService extends StartableObservableService {
22883
22883
  console.debug(`${this._logPrefix}Received config or account event. Refreshing items...`, account);
22884
22884
  // Load all items
22885
22885
  const items = await this._loadMenuItems(config, account);
22886
+ const pathParam = MenuItems.parsePathWithQuery(this.router.routerState.snapshot.url);
22887
+ this.detachSubMenuItem(pathParam);
22886
22888
  this.dataSubject.next(items);
22887
22889
  // Emit account changes event
22888
22890
  this.accountChanges.next(account);
22889
22891
  }));
22890
- 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))).subscribe(pathParam => {
22892
+ 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)))
22893
+ .subscribe(pathParam => {
22891
22894
  this.detachSubMenuItem(pathParam);
22892
22895
  }));
22893
22896
  return items;
22894
22897
  }
22898
+ computeNewId() {
22899
+ return this._itemCounter++;
22900
+ }
22895
22901
  _addSubMenuItem(newItem, opts) {
22896
22902
  opts = {
22897
22903
  skipIfExists: true,
@@ -22902,7 +22908,7 @@ class MenuService extends StartableObservableService {
22902
22908
  // Find if item already exists
22903
22909
  const existingItem = this._findExistingItem(newItem);
22904
22910
  if (existingItem) {
22905
- if (opts.skipIfExists) {
22911
+ if (opts.skipIfExists && !!existingItem.parentPath) {
22906
22912
  // DEBUG
22907
22913
  if (this._debug)
22908
22914
  console.debug(`${this._logPrefix}Skipping sub item (already exist)`, newItem);
@@ -22914,17 +22920,32 @@ class MenuService extends StartableObservableService {
22914
22920
  newItem.id = existingItem.id;
22915
22921
  newItem.$children = existingItem.$children;
22916
22922
  newItem.pinned = existingItem.pinned;
22923
+ newItem.title = newItem.title || existingItem.title; // Keep existing title
22924
+ }
22925
+ else {
22926
+ // Generate item's id (if need)
22927
+ if (isNil(newItem.id))
22928
+ newItem.id = this.computeNewId();
22917
22929
  }
22918
- // Generate item's id (if need)
22919
- if (isNil(newItem.id))
22920
- newItem.id = this._itemCounter++;
22921
22930
  const parent = this._findParent(newItem, opts?.availableParents);
22922
22931
  if (parent) {
22923
22932
  this._addMenuToParent(parent, newItem);
22933
+ // Removed from detached items
22934
+ const detachedIndex = existingItem ? this._detachedSubItems.indexOf(existingItem) : -1;
22935
+ if (detachedIndex !== -1) {
22936
+ this._detachedSubItems.splice(detachedIndex, 1);
22937
+ }
22924
22938
  }
22925
22939
  else {
22926
- console.debug(`${this._logPrefix}Add detached sub item (no parent found)`);
22927
- this._detachedItems.push(newItem);
22940
+ const detachedIndex = existingItem ? this._detachedSubItems.indexOf(existingItem) : -1;
22941
+ if (detachedIndex !== -1) {
22942
+ // Update existing detached item
22943
+ this._detachedSubItems[detachedIndex] = newItem;
22944
+ }
22945
+ else {
22946
+ // Add to detached item
22947
+ this._detachedSubItems.push(newItem);
22948
+ }
22928
22949
  }
22929
22950
  // Start listening route
22930
22951
  if (!this._$listenRoute.value)
@@ -22935,11 +22956,14 @@ class MenuService extends StartableObservableService {
22935
22956
  if (this._debug)
22936
22957
  console.debug(`${this._logPrefix}Loading menu items...`);
22937
22958
  // Save previous children of root items
22938
- const detachedItems = (this.data || [])
22959
+ const detachedSubItems = (this.data || [])
22939
22960
  .reduce((res, rootItem) => {
22961
+ const subItems = rootItem.$children?.value;
22962
+ if (isEmptyArray(subItems))
22963
+ return res;
22940
22964
  rootItem.$children.next([]);
22941
- return res.concat(rootItem.$children?.value || []);
22942
- }, []);
22965
+ return res.concat(subItems);
22966
+ }, this._detachedSubItems || []);
22943
22967
  // Reset base root items (clean items added by config)
22944
22968
  let items = this._staticItems.slice();
22945
22969
  // Concat config's items
@@ -22988,7 +23012,7 @@ class MenuService extends StartableObservableService {
22988
23012
  .map(item => {
22989
23013
  // Generate item's id (if need)
22990
23014
  if (isNil(item.id))
22991
- item.id = this._itemCounter++;
23015
+ item.id = this.computeNewId();
22992
23016
  // Replace title using properties
22993
23017
  if (isNotNilOrBlank(item.titleProperty) && config) {
22994
23018
  const title = config.properties[item.titleProperty];
@@ -22998,15 +23022,20 @@ class MenuService extends StartableObservableService {
22998
23022
  return item;
22999
23023
  });
23000
23024
  // Re-attach sub menu items
23001
- if (detachedItems.length) {
23002
- await this.addSubMenuItems(detachedItems, { skipIfExists: false, availableParents: detachedItems.concat(items) });
23025
+ if (detachedSubItems.length) {
23026
+ if (account) {
23027
+ await this.addSubMenuItems(detachedSubItems, { skipIfExists: false, availableParents: detachedSubItems.concat(items) });
23028
+ }
23029
+ else {
23030
+ this._detachedSubItems = detachedSubItems;
23031
+ }
23003
23032
  }
23004
23033
  if (this._debug)
23005
23034
  console.debug(`${this._logPrefix}Found ${items.length} visible items...`);
23006
23035
  return items;
23007
23036
  }
23008
23037
  _findExistingItem(item, items) {
23009
- items = items || this._detachedItems.concat(this.data);
23038
+ items = items || this._detachedSubItems.concat(this.data);
23010
23039
  if (!items.length)
23011
23040
  return undefined; // Not found
23012
23041
  for (const i of items) {
@@ -23020,7 +23049,7 @@ class MenuService extends StartableObservableService {
23020
23049
  _findParent(childItem, availableParents) {
23021
23050
  if (!childItem?.path)
23022
23051
  return undefined;
23023
- availableParents = availableParents || this._detachedItems.concat(this.data);
23052
+ availableParents = availableParents || this._detachedSubItems.concat(this.data);
23024
23053
  return availableParents.reduce((res, item) => {
23025
23054
  if (!item?.path)
23026
23055
  return res;
@@ -23395,7 +23424,6 @@ class SubMenuTabDirective {
23395
23424
  }
23396
23425
  ngOnChanges(changes) {
23397
23426
  if (changes.disabled || changes.label || changes.subMenuTitle || changes.parentPath || changes.path) {
23398
- console.log('TODO received tab=' + (this.subMenuTitle || this.label), this.path);
23399
23427
  if (this.disabled) {
23400
23428
  if (this._menuItem)
23401
23429
  this.menuService.removeSubMenuItem(this._menuItem);
@@ -23424,10 +23452,11 @@ class SubMenuTabDirective {
23424
23452
  return; // Skip if no changes
23425
23453
  menuItem.id = this._menuItem.id;
23426
23454
  }
23427
- //if (!menuItem.parentPath) return; // Skip if no parent
23428
- //if (isNil(menuItem.title)) return; // Skip if no title
23429
- menuItem = await this.menuService.addSubMenuItem(menuItem, { skipIfExists: false });
23430
- this._menuItem = menuItem;
23455
+ else {
23456
+ menuItem.id = this.menuService.computeNewId();
23457
+ this._menuItem = menuItem;
23458
+ }
23459
+ this._menuItem = await this.menuService.addSubMenuItem(menuItem, { skipIfExists: false });
23431
23460
  }
23432
23461
  }
23433
23462
  SubMenuTabDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.3.0", ngImport: i0, type: SubMenuTabDirective, deps: [{ token: MenuService }, { token: i7$3.MatTabGroup }, { token: i7$3.MatTab }, { token: i1$5.Router }], target: i0.ɵɵFactoryTarget.Directive });
@@ -36336,21 +36365,15 @@ class MenuTestingPage extends AppTabEditor {
36336
36365
  this.thirdTabTitle = '';
36337
36366
  this.parentPath = null;
36338
36367
  this.showOtherLinks = true;
36339
- this.$title = new BehaviorSubject('');
36340
- this.$secondTabTitle = new BehaviorSubject('Second');
36368
+ this.$title = new Subject();
36369
+ this.$secondTabTitle = new Subject();
36341
36370
  }
36342
36371
  set title(value) {
36343
36372
  this.$title.next(value);
36344
36373
  }
36345
- get title() {
36346
- return this.$title.value;
36347
- }
36348
36374
  set secondTabTitle(value) {
36349
36375
  this.$secondTabTitle.next(value);
36350
36376
  }
36351
- get secondTabTitle() {
36352
- return this.$secondTabTitle.value;
36353
- }
36354
36377
  ngOnInit() {
36355
36378
  console.debug(`${this.logPrefix} Init page...`);
36356
36379
  super.ngOnInit();
@@ -36466,34 +36489,28 @@ const routes$4 = [
36466
36489
  pathMatch: 'full',
36467
36490
  component: MenuTestingPage,
36468
36491
  data: {
36469
- test: 'empty'
36470
- }
36492
+ test: 'empty',
36493
+ },
36471
36494
  },
36472
36495
  {
36473
36496
  path: 'others',
36474
- // component: OtherMenuTestingPage,
36497
+ canActivate: [AuthGuardService],
36498
+ data: {
36499
+ profile: 'USER',
36500
+ },
36475
36501
  children: [
36476
36502
  {
36477
36503
  path: ':otherId',
36504
+ pathMatch: 'full',
36478
36505
  component: OtherMenuTestingPage,
36506
+ canActivate: [AuthGuardService],
36507
+ data: {
36508
+ profile: 'ADMIN',
36509
+ },
36479
36510
  },
36480
- ]
36481
- // canActivate: [
36482
- // <CanActivateFn>(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) => {
36483
- // console.log('TODO canActivate', route.data?.tabs);
36484
- //
36485
- // if (route.component?.['tabsChanges']) {
36486
- // (route.component as any).tabsChanges
36487
- // .subscribe(tabs => {
36488
- // console.log('TODO tabs', tabs);
36489
- // });
36490
- // }
36491
- //
36492
- // return true;
36493
- // }
36494
- // ]
36511
+ ],
36495
36512
  },
36496
- ]
36513
+ ],
36497
36514
  },
36498
36515
  ];
36499
36516
  class MenuTestingModule {