turbogui-angular 20.1.0 → 20.3.0

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.
@@ -22,7 +22,7 @@ import { MatFormFieldModule } from '@angular/material/form-field';
22
22
  import * as i4 from '@angular/material/input';
23
23
  import { MatInputModule } from '@angular/material/input';
24
24
  import * as i5 from '@angular/forms';
25
- import { FormsModule, Validators } from '@angular/forms';
25
+ import { FormsModule, Validators, FormControl } from '@angular/forms';
26
26
 
27
27
  /**
28
28
  * TurboGUI is A library that helps with the most common and generic UI elements and functionalities
@@ -984,10 +984,6 @@ class DialogService extends SingletoneStrictClass {
984
984
  if (!this._isEnabled) {
985
985
  return;
986
986
  }
987
- // If there are dialogs that should close on navigation and a history state was pushed, pop it
988
- if (this._activeCloseableDialogs > 0 && window.history.state?.dialogOpen) {
989
- history.back();
990
- }
991
987
  for (const dialogRef of this._activeDialogInstances) {
992
988
  dialogRef.close({ index: -1 });
993
989
  }
@@ -1669,10 +1665,34 @@ class RouterBaseService {
1669
1665
  }
1670
1666
  /**
1671
1667
  * Gets the current value of the route URL synchronously.
1668
+ * For example, if the current route is `/user/123`, it will return `/user/123`.
1669
+ * Notice that the base URL is not included in the returned value.
1672
1670
  */
1673
1671
  getCurrentRoute() {
1674
1672
  return this._currentRoute.getValue();
1675
1673
  }
1674
+ /**
1675
+ * The current route title, translated using the LocalesService.
1676
+ * This is updated automatically after each navigation event if the title manager is initialized.
1677
+ */
1678
+ getCurrentRouteTitle() {
1679
+ return this._currentRouteTitle;
1680
+ }
1681
+ /**
1682
+ * The current browser title, which may include prefixes or suffixes.
1683
+ * This is updated automatically after each navigation event if the title manager is initialized.
1684
+ */
1685
+ getCurrentBrowserTitle() {
1686
+ return this._currentBrowserTitle;
1687
+ }
1688
+ /**
1689
+ * Gets the current value of the route absolute URL synchronously.
1690
+ *
1691
+ * For example, if the current route is `/user/123` and the base href is `http://example.com/app/`, it will return `http://example.com/app/user/123`.
1692
+ */
1693
+ getCurrentRouteAbsolute() {
1694
+ return window.location.origin + this.getCurrentRoute();
1695
+ }
1676
1696
  /**
1677
1697
  * Gets the value of a specific route parameter by its key from the current route.
1678
1698
  *
@@ -1709,6 +1729,7 @@ class RouterBaseService {
1709
1729
  * { path: '', component: HomePageComponent,
1710
1730
  * data: { titleKey: 'HOME', titleBundle: 'turbodepot/user-interface'} },
1711
1731
  *
1732
+ * @param localesService An instance of the LocalesService to be used for translations.
1712
1733
  * @param prefix A text to be added before the computed title.
1713
1734
  * @param sufix A text to be added after the computed title.
1714
1735
  */
@@ -1734,14 +1755,18 @@ class RouterBaseService {
1734
1755
  * @param sufix A text to be added after the computed title.
1735
1756
  */
1736
1757
  updateTitleFromCurrentRoute(prefix, sufix) {
1758
+ this._currentRouteTitle = '';
1759
+ this._currentBrowserTitle = '';
1737
1760
  let currentRoute = this.router.routerState.snapshot.root;
1738
1761
  while (currentRoute.firstChild) {
1739
1762
  currentRoute = currentRoute.firstChild;
1740
1763
  }
1741
1764
  const data = currentRoute.data;
1742
1765
  if (data['titleKey'] && data['titleBundle']) {
1743
- this.titleService.setTitle(prefix + this._localesService.t(data['titleKey'], data['titleBundle']) + sufix);
1766
+ this._currentRouteTitle = this._localesService.t(data['titleKey'], data['titleBundle']);
1744
1767
  }
1768
+ this._currentBrowserTitle = prefix + this._currentRouteTitle + sufix;
1769
+ this.titleService.setTitle(this._currentBrowserTitle);
1745
1770
  }
1746
1771
  /**
1747
1772
  * Navigates to the specified route.
@@ -1751,6 +1776,12 @@ class RouterBaseService {
1751
1776
  navigateTo(route) {
1752
1777
  this.router.navigate(['/' + route]);
1753
1778
  }
1779
+ /**
1780
+ * Automatically called when the service is destroyed.
1781
+ * We use it to clean up subscriptions and other resources.
1782
+ *
1783
+ * Usially not necessary to call this manually.
1784
+ */
1754
1785
  ngOnDestroy() {
1755
1786
  this._routerSubscription?.unsubscribe();
1756
1787
  // Clean up BehaviorSubject
@@ -3062,6 +3093,28 @@ class ValidatorsPlus extends Validators {
3062
3093
  return null;
3063
3094
  }
3064
3095
  }
3096
+ /**
3097
+ * Validator to check that at least one of the specified form controls has a non empty value.
3098
+ * Non empty criteria is the same as the nonEmpty validator on this same class, which verifies that the value is not semantically empty.
3099
+ *
3100
+ * To use this validator, you need to pass an array of control names that you want to check. And set it to the validators property
3101
+ * of the form builder group.
3102
+ *
3103
+ * @param controlNames An array of control names to check. For example, ['name', 'surname'].
3104
+ *
3105
+ * @returns A validator function.
3106
+ */
3107
+ static atLeastOneIsNotEmpty(controlNames) {
3108
+ return (control) => {
3109
+ const formGroup = control;
3110
+ const hasValue = controlNames.some(name => {
3111
+ const formControl = formGroup.get(name);
3112
+ // Check if it's a FormControl and if it's not empty
3113
+ return formControl instanceof FormControl && ValidatorsPlus.nonEmpty(formControl) === null;
3114
+ });
3115
+ return hasValue ? null : { atLeastOneRequired: true };
3116
+ };
3117
+ }
3065
3118
  }
3066
3119
 
3067
3120
  /*