@mediusinc/mng-commons 0.19.0 → 0.19.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.
@@ -7550,6 +7550,56 @@ class MngCommonsService {
7550
7550
  this._menuResetSubject.next(null);
7551
7551
  }
7552
7552
  // BREADCRUMB actions
7553
+ findBreadcrumbItem(item) {
7554
+ const items = this.breadcrumbsSubject.value;
7555
+ if (item.id) {
7556
+ return items.find(i => i.id && i.id === item.id) ?? null;
7557
+ }
7558
+ else if (item.routerLink) {
7559
+ const routerLinkStr = Array.isArray(item.routerLink) ? item.routerLink.join('/') : item.routerLink;
7560
+ return items.find(i => i.routerLink && (Array.isArray(i.routerLink) ? i.routerLink.join('/') : i.routerLink) === routerLinkStr) ?? null;
7561
+ }
7562
+ else if (item.positionIndex) {
7563
+ return items.find(i => i.positionIndex && i.positionIndex === i.positionIndex) ?? null;
7564
+ }
7565
+ else if (item.label) {
7566
+ return items.find(i => i.label && i.label === i.label) ?? null;
7567
+ }
7568
+ else if (item.icon) {
7569
+ return items.find(i => i.icon && i.icon === i.icon) ?? null;
7570
+ }
7571
+ return null;
7572
+ }
7573
+ updateBreadcrumbItem(item) {
7574
+ const items = [...this.breadcrumbsSubject.value];
7575
+ let posIdx = -1;
7576
+ if (item.id) {
7577
+ posIdx = items.findIndex(i => i.id && i.id === item.id);
7578
+ }
7579
+ else if (item.routerLink) {
7580
+ const routerLinkStr = Array.isArray(item.routerLink) ? item.routerLink.join('/') : item.routerLink;
7581
+ posIdx = items.findIndex(i => i.routerLink && (Array.isArray(i.routerLink) ? i.routerLink.join('/') : i.routerLink) === routerLinkStr);
7582
+ }
7583
+ else if (item.positionIndex) {
7584
+ posIdx = items.findIndex(i => i.positionIndex && i.positionIndex === i.positionIndex);
7585
+ }
7586
+ else if (item.label) {
7587
+ posIdx = items.findIndex(i => i.label && i.label === i.label);
7588
+ }
7589
+ else if (item.icon) {
7590
+ posIdx = items.findIndex(i => i.icon && i.icon === i.icon);
7591
+ }
7592
+ if (posIdx < 0) {
7593
+ return false;
7594
+ }
7595
+ items[posIdx] = {
7596
+ ...items[posIdx],
7597
+ ...item,
7598
+ updated: true
7599
+ };
7600
+ this.breadcrumbsSubject.next(items);
7601
+ return true;
7602
+ }
7553
7603
  updateBreadcrumbs() {
7554
7604
  if (this.breadcrumbsTranslateSubscription) {
7555
7605
  this.breadcrumbsTranslateSubscription.unsubscribe();
@@ -7574,11 +7624,14 @@ class MngCommonsService {
7574
7624
  }
7575
7625
  const breadcrumbs = [];
7576
7626
  this.generateBreadcrumbs(rootRoute, [], breadcrumbs);
7627
+ breadcrumbs.forEach((b, idx) => {
7628
+ b.positionIndex = idx;
7629
+ });
7577
7630
  const i18nKeys = breadcrumbs.filter(b => typeof b.label === 'string').map(b => b.label);
7578
7631
  if (i18nKeys.length > 0) {
7579
7632
  this.breadcrumbsTranslateSubscription = this.translate.get(i18nKeys).subscribe(i18n => {
7580
7633
  // Construct the breadcrumb hierarchy
7581
- breadcrumbs.forEach(b => {
7634
+ breadcrumbs.forEach((b, idx) => {
7582
7635
  if (b.label && i18n[b.label]) {
7583
7636
  b.label = i18n[b.label];
7584
7637
  }
@@ -7644,8 +7697,14 @@ class MngCommonsService {
7644
7697
  this.generateBreadcrumbs(route.firstChild, routeUrlSegments, breadcrumbs);
7645
7698
  }
7646
7699
  createBreadcrumb(routeUrl, routeBreadcrumb, includeHome = false) {
7700
+ const existingBreadcrumb = this.findBreadcrumbItem({ routerLink: routeUrl });
7701
+ if (existingBreadcrumb?.updated) {
7702
+ return existingBreadcrumb;
7703
+ }
7647
7704
  if (typeof routeBreadcrumb === 'string') {
7705
+ // check for updated existing breadcrumb
7648
7706
  return {
7707
+ id: routeUrl,
7649
7708
  label: routeBreadcrumb,
7650
7709
  routerLink: routeUrl
7651
7710
  };
@@ -7658,6 +7717,7 @@ class MngCommonsService {
7658
7717
  if (typeof routeBreadcrumb.routerLink === 'undefined') {
7659
7718
  routeBreadcrumb.routerLink = routeUrl;
7660
7719
  }
7720
+ routeBreadcrumb.id = routeUrl;
7661
7721
  return routeBreadcrumb;
7662
7722
  }
7663
7723
  }