@memberjunction/ng-shared 2.0.0 → 2.1.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.
@@ -8,6 +8,7 @@ export declare class SharedService {
8
8
  private static _instance;
9
9
  private static _loaded;
10
10
  private static _resourceTypes;
11
+ private static isLoading$;
11
12
  private tabChange;
12
13
  tabChange$: Observable<unknown>;
13
14
  constructor(notificationService: NotificationService);
@@ -24,7 +25,11 @@ export declare class SharedService {
24
25
  get SearchResultsResourceType(): ResourceTypeEntity;
25
26
  ResourceTypeByID(id: string): ResourceTypeEntity | undefined;
26
27
  ResourceTypeByName(name: string): ResourceTypeEntity | undefined;
27
- static RefreshData(): Promise<void>;
28
+ /**
29
+ * Refreshes the data for the service. If OnlyIfNeeded is true, then the data is only refreshed if it hasn't been loaded yet.
30
+ */
31
+ static RefreshData(OnlyIfNeeded?: boolean): Promise<void>;
32
+ private static handleDataLoading;
28
33
  FormatColumnValue(col: ViewColumnInfo, value: any, maxLength?: number, trailingChars?: string): any;
29
34
  ConvertMarkdownStringToHtmlList(listType: HtmlListType, text: string): string;
30
35
  InvokeManualResize(delay?: number): void;
@@ -49,7 +54,7 @@ export declare class SharedService {
49
54
  * @param resourceConfiguration Any object, it is converted to a string by JSON.stringify and stored in the database
50
55
  * @returns
51
56
  */
52
- CreateNotification(title: string, message: string, resourceTypeId: string | null, resourceRecordId: number | null, resourceConfiguration: any | null): Promise<UserNotificationEntity>;
57
+ CreateNotification(title: string, message: string, resourceTypeId: string | null, resourceRecordId: string | null, resourceConfiguration: any | null): Promise<UserNotificationEntity>;
53
58
  static RefreshUserNotifications(): Promise<void>;
54
59
  /**
55
60
  * Creates a message that is not saved to the User Notifications table, but is displayed to the user.
@@ -1 +1 @@
1
- {"version":3,"file":"shared.service.d.ts","sourceRoot":"","sources":["../../src/lib/shared.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAc,MAAM,eAAe,CAAC;AAEvD,OA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AAC,MAAM,OAAO,YAAY,CAAC,CAAC;AAG1E,eAAO,MAAM,UAAU;;;;;;;;;;;;;CAab,CAAC;AAEX,MAAM,MAAM,UAAU,GAAG,OAAO,UAAU,CAAC,MAAM,OAAO,UAAU,CAAC,CAAC"}
@@ -10,7 +10,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  import { Injectable } from '@angular/core';
11
11
  import { LogError, Metadata, RunView } from '@memberjunction/core';
12
12
  import { MJEventType, MJGlobal } from '@memberjunction/global';
13
- import { Subject } from 'rxjs';
13
+ import { Subject, BehaviorSubject, firstValueFrom } from 'rxjs';
14
+ import { first, tap } from 'rxjs/operators';
14
15
  import * as i0 from "@angular/core";
15
16
  import * as i1 from "@progress/kendo-angular-notification";
16
17
  export class SharedService {
@@ -48,7 +49,7 @@ export class SharedService {
48
49
  break;
49
50
  case MJEventType.LoggedIn:
50
51
  if (SharedService._loaded === false)
51
- SharedService.RefreshData();
52
+ SharedService.RefreshData(true);
52
53
  // got the login, now subscribe to push status updates here so we can then raise them as events in MJ Global locally
53
54
  this.PushStatusUpdates().subscribe((status) => {
54
55
  var _a, _b, _c;
@@ -111,43 +112,45 @@ export class SharedService {
111
112
  ResourceTypeByName(name) {
112
113
  return SharedService._resourceTypes.find(rt => rt.Name.trim().toLowerCase() === name.trim().toLowerCase());
113
114
  }
115
+ /**
116
+ * Refreshes the data for the service. If OnlyIfNeeded is true, then the data is only refreshed if it hasn't been loaded yet.
117
+ */
114
118
  static RefreshData() {
119
+ return __awaiter(this, arguments, void 0, function* (OnlyIfNeeded = false) {
120
+ if (OnlyIfNeeded && SharedService._loaded) {
121
+ return;
122
+ }
123
+ const canProceed$ = SharedService.isLoading$.pipe(first(isLoading => !isLoading), tap(() => SharedService.isLoading$.next(true)));
124
+ yield firstValueFrom(canProceed$);
125
+ try {
126
+ // After waiting for the current loading operation to complete, check again
127
+ // if _loaded is true and OnlyIfNeeded is true, return early
128
+ if (OnlyIfNeeded && SharedService._loaded) {
129
+ return;
130
+ }
131
+ yield SharedService.handleDataLoading();
132
+ // Mark as loaded
133
+ SharedService._loaded = true;
134
+ }
135
+ finally {
136
+ // Ensure we always reset the loading flag
137
+ SharedService.isLoading$.next(false);
138
+ }
139
+ });
140
+ }
141
+ static handleDataLoading() {
115
142
  return __awaiter(this, void 0, void 0, function* () {
116
- // if we have a provider, then we can load the data, otherwise load isn't done yet
117
143
  const md = new Metadata();
118
144
  const rtResult = yield md.GetAndCacheDatasetByName('ResourceTypes');
119
145
  if (rtResult && rtResult.Success) {
120
146
  const data = rtResult.Results.find(r => r.EntityName === 'Resource Types');
121
147
  if (data) {
122
148
  SharedService._resourceTypes = data.Results;
123
- SharedService._loaded = true;
124
149
  }
125
150
  }
126
- SharedService.RefreshUserNotifications(); // also call this initially when refreshing the dataset...
151
+ yield SharedService.RefreshUserNotifications();
127
152
  });
128
153
  }
129
- /*
130
- public static GenerateKeyValuePairString(pkVals: KeyValuePair[]): string {
131
- return pkVals.map(pk => pk.FieldName + '|' + pk.Value).join('||');
132
- }
133
- */
134
- /*
135
- public static ParsePrimaryKeys(entity: EntityInfo, routeSegment: string): KeyValuePair[] {
136
- if (!routeSegment.includes('|')) {
137
- // If not, return a single element array with a default field name
138
- return [{ FieldName: entity.PrimaryKey.Name, Value: routeSegment }];
139
- }
140
- else {
141
- const parts = routeSegment.split('||');
142
- const pkVals: KeyValuePair[] = [];
143
- for (let p of parts) {
144
- const kv = p.split('|');
145
- pkVals.push({ FieldName: kv[0], Value: kv[1] });
146
- }
147
- return pkVals;
148
- }
149
- }
150
- */
151
154
  FormatColumnValue(col, value, maxLength = 0, trailingChars = "...") {
152
155
  if (value === null || value === undefined)
153
156
  return value;
@@ -314,6 +317,7 @@ export class SharedService {
314
317
  }
315
318
  SharedService._loaded = false;
316
319
  SharedService._resourceTypes = [];
320
+ SharedService.isLoading$ = new BehaviorSubject(false);
317
321
  SharedService._userNotifications = [];
318
322
  SharedService.ɵfac = function SharedService_Factory(t) { return new (t || SharedService)(i0.ɵɵinject(i1.NotificationService)); };
319
323
  SharedService.ɵprov = /*@__PURE__*/ i0.ɵɵdefineInjectable({ token: SharedService, factory: SharedService.ɵfac, providedIn: 'root' });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@memberjunction/ng-shared",
3
- "version": "2.0.0",
3
+ "version": "2.1.1",
4
4
  "description": "MemberJunction: Angular Shared Package - utility functions and other reusable elements used across other MJ Angular packages",
5
5
  "main": "./dist/public-api.js",
6
6
  "typings": "./dist/public-api.d.ts",
@@ -26,8 +26,8 @@
26
26
  "@angular/core": "18.0.2"
27
27
  },
28
28
  "dependencies": {
29
- "@memberjunction/core": "2.0.0",
30
- "@memberjunction/graphql-dataprovider": "2.0.0",
29
+ "@memberjunction/core": "2.1.1",
30
+ "@memberjunction/graphql-dataprovider": "2.1.1",
31
31
  "@progress/kendo-angular-notification": "16.2.0",
32
32
  "tslib": "^2.3.0"
33
33
  },