@stemy/ngx-utils 19.9.1 → 19.9.3

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.
@@ -831,6 +831,29 @@ class StateService {
831
831
  subscribe(osOrNext) {
832
832
  return this.$observable.subscribe(osOrNext);
833
833
  }
834
+ getConfig(route, path = []) {
835
+ return this.getConfigRecursive(route, this.routerConfig, path) || [];
836
+ }
837
+ getConfigRecursive(route, config, path) {
838
+ if (!config)
839
+ return null;
840
+ const match = config.findIndex(t => t == route);
841
+ if (match >= 0)
842
+ return config;
843
+ for (const subConfig of config) {
844
+ if (subConfig.path)
845
+ path.push(subConfig.path);
846
+ const loadedChildren = (subConfig["_loadedConfig"] || { routes: null }).routes || subConfig["_loadedRoutes"];
847
+ const match = this.getConfigRecursive(route, subConfig.children || loadedChildren, path);
848
+ if (!match) {
849
+ if (subConfig.path)
850
+ path.length -= 1;
851
+ continue;
852
+ }
853
+ return match;
854
+ }
855
+ return null;
856
+ }
834
857
  openInNewWindow(tree, target) {
835
858
  if (!this.universal.isBrowser)
836
859
  return false;
@@ -956,26 +979,6 @@ class AuthGuard {
956
979
  });
957
980
  });
958
981
  }
959
- getConfig(route, config, path) {
960
- if (!config)
961
- return null;
962
- const match = config.findIndex(t => t == route);
963
- if (match >= 0)
964
- return config;
965
- for (const subConfig of config) {
966
- if (subConfig.path)
967
- path.push(subConfig.path);
968
- const loadedChildren = (subConfig["_loadedConfig"] || { routes: null }).routes || subConfig["_loadedRoutes"];
969
- const match = this.getConfig(route, subConfig.children || loadedChildren, path);
970
- if (!match) {
971
- if (subConfig.path)
972
- path.length -= 1;
973
- continue;
974
- }
975
- return match;
976
- }
977
- return null;
978
- }
979
982
  getReturnState(route) {
980
983
  if (!route)
981
984
  return Promise.resolve(null);
@@ -983,7 +986,7 @@ class AuthGuard {
983
986
  return Promise.resolve(route.data.returnState);
984
987
  }
985
988
  const path = [];
986
- const config = this.getConfig(route, this.state.routerConfig, path);
989
+ const config = this.state.getConfig(route, path);
987
990
  return new Promise(resolve => {
988
991
  this.getReturnStateRecursive(config).then(rs => {
989
992
  if (!ObjectUtils.isArray(rs)) {
@@ -2727,7 +2730,7 @@ function diffEntities(current, incoming) {
2727
2730
  const incomingIds = new Set(incoming.map(item => item.id).filter(Boolean));
2728
2731
  return {
2729
2732
  // 1. Removed: Was in current, but ID is missing from incoming
2730
- removed: current.filter(item => !incomingIds.has(item.id)),
2733
+ removed: current.filter(item => !incomingIds.has(item.id) && item.id),
2731
2734
  // 2. Added: ID is missing entirely (new record)
2732
2735
  added: incoming.filter(item => !item.id),
2733
2736
  // 3. Updated: ID exists in both lists
@@ -3207,36 +3210,35 @@ class AclService {
3207
3210
  this.state = state;
3208
3211
  this.events = events;
3209
3212
  this.components = [];
3210
- this.events.userChanged.subscribe(() => {
3213
+ this.events.userChanged.subscribe(async () => {
3211
3214
  this.components.forEach(t => t.dirty = true);
3212
3215
  const info = this.getStateInfo();
3213
- const check = info && info.guard instanceof AuthGuard ? info.guard.checkRoute(info.route) : Promise.resolve(true);
3214
- check.then(result => {
3215
- if (result) {
3216
- if (!info || !info.dirty)
3217
- return;
3218
- info.dirty = false;
3219
- const component = info.component;
3220
- if (!info.component)
3221
- return;
3222
- if (info.first) {
3223
- if (ObjectUtils.isFunction(component.onUserInitialized)) {
3224
- component.onUserInitialized();
3225
- }
3226
- info.first = false;
3227
- return;
3228
- }
3229
- if (ObjectUtils.isFunction(component.onUserChanged)) {
3230
- component.onUserChanged();
3216
+ const result = info && info.guard instanceof AuthGuard
3217
+ ? await info.guard.checkRoute(info.route)
3218
+ : true;
3219
+ if (result) {
3220
+ if (!info || !info.dirty)
3221
+ return;
3222
+ info.dirty = false;
3223
+ const component = info.component;
3224
+ if (!info.component)
3225
+ return;
3226
+ if (info.first) {
3227
+ if (ObjectUtils.isFunction(component.onUserInitialized)) {
3228
+ component.onUserInitialized();
3231
3229
  }
3230
+ info.first = false;
3232
3231
  return;
3233
3232
  }
3234
- info.guard.getReturnState(info.route).then(returnState => {
3235
- if (!returnState)
3236
- return;
3237
- this.state.navigate(returnState);
3238
- });
3239
- });
3233
+ if (ObjectUtils.isFunction(component.onUserChanged)) {
3234
+ component.onUserChanged();
3235
+ }
3236
+ return;
3237
+ }
3238
+ const returnState = await info.guard.getReturnState(info.route);
3239
+ if (!returnState)
3240
+ return;
3241
+ await this.state.navigate(returnState);
3240
3242
  });
3241
3243
  this.state.subscribe(() => {
3242
3244
  const info = this.getStateInfo();
@@ -3249,6 +3251,25 @@ class AclService {
3249
3251
  info.first = false;
3250
3252
  });
3251
3253
  }
3254
+ async getCurrentMenu() {
3255
+ const path = [];
3256
+ const config = this.state.getConfig(this.state.route, path);
3257
+ const checks = await Promise.all(config.map(async (route) => {
3258
+ const guard = (route.canActivate || []).find(g => g instanceof AuthGuard);
3259
+ return guard ? await guard.checkRoute(route) : ObjectUtils.isStringWithValue(route.data?.name);
3260
+ }));
3261
+ const basePath = path.join("/").replace(/^([a-z]+)/gi, `/$1`);
3262
+ return config.map((route, index) => {
3263
+ return !checks[index] ? null : {
3264
+ path: `${basePath}/${route.path}`,
3265
+ page: route.data.page || route.data.id,
3266
+ label: route.data.name,
3267
+ side: route.data.side || `left`,
3268
+ external: false,
3269
+ data: route.data
3270
+ };
3271
+ }).filter(Boolean);
3272
+ }
3252
3273
  getStateInfo() {
3253
3274
  const route = this.state.route;
3254
3275
  if (!route)