@memberjunction/ng-notifications 5.14.0 → 5.16.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.
|
@@ -8,7 +8,7 @@ import * as i0 from "@angular/core";
|
|
|
8
8
|
*/
|
|
9
9
|
export declare class MJNotificationService {
|
|
10
10
|
private notificationService;
|
|
11
|
-
private static
|
|
11
|
+
private static readonly _globalStoreKey;
|
|
12
12
|
private static _loaded;
|
|
13
13
|
private static isLoading$;
|
|
14
14
|
private tabChange;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"notifications.service.d.ts","sourceRoot":"","sources":["../../src/lib/notifications.service.ts"],"names":[],"mappings":"AAEA,OAAO,EAAkB,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AAGzF,OAAO,EAAE,mBAAmB,EAAwB,MAAM,sCAAsC,CAAC;AACjG,OAAO,EAAmB,UAAU,EAAW,MAAM,MAAM,CAAC;;AAE5D;;;GAGG;AACH,qBAGa,qBAAqB;IAYpB,OAAO,CAAC,mBAAmB;IAXvC,OAAO,CAAC,MAAM,CAAC,
|
|
1
|
+
{"version":3,"file":"notifications.service.d.ts","sourceRoot":"","sources":["../../src/lib/notifications.service.ts"],"names":[],"mappings":"AAEA,OAAO,EAAkB,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AAGzF,OAAO,EAAE,mBAAmB,EAAwB,MAAM,sCAAsC,CAAC;AACjG,OAAO,EAAmB,UAAU,EAAW,MAAM,MAAM,CAAC;;AAE5D;;;GAGG;AACH,qBAGa,qBAAqB;IAYpB,OAAO,CAAC,mBAAmB;IAXvC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,eAAe,CAAyC;IAChF,OAAO,CAAC,MAAM,CAAC,OAAO,CAAkB;IAExC,OAAO,CAAC,MAAM,CAAC,UAAU,CAAuC;IAChE,OAAO,CAAC,SAAS,CAAiB;IAClC,UAAU,sBAAiC;IAG3C,OAAO,CAAC,MAAM,CA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|
-
import { LogError, Metadata } from '@memberjunction/core';
|
|
2
|
+
import { LogError, Metadata, StartupManager } from '@memberjunction/core';
|
|
3
3
|
import { UserInfoEngine } from '@memberjunction/core-entities';
|
|
4
|
-
import { MJEventType, MJGlobal } from '@memberjunction/global';
|
|
4
|
+
import { MJEventType, MJGlobal, GetGlobalObjectStore } from '@memberjunction/global';
|
|
5
5
|
import { BehaviorSubject, Subject } from 'rxjs';
|
|
6
6
|
import * as i0 from "@angular/core";
|
|
7
7
|
import * as i1 from "@progress/kendo-angular-notification";
|
|
@@ -11,7 +11,7 @@ import * as i1 from "@progress/kendo-angular-notification";
|
|
|
11
11
|
*/
|
|
12
12
|
export class MJNotificationService {
|
|
13
13
|
notificationService;
|
|
14
|
-
static
|
|
14
|
+
static _globalStoreKey = '___SINGLETON__MJNotificationService';
|
|
15
15
|
static _loaded = false;
|
|
16
16
|
static isLoading$ = new BehaviorSubject(false);
|
|
17
17
|
tabChange = new Subject();
|
|
@@ -21,12 +21,11 @@ export class MJNotificationService {
|
|
|
21
21
|
static _unreadCount$ = new BehaviorSubject(0);
|
|
22
22
|
constructor(notificationService) {
|
|
23
23
|
this.notificationService = notificationService;
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
return MJNotificationService.
|
|
24
|
+
const g = GetGlobalObjectStore();
|
|
25
|
+
if (g[MJNotificationService._globalStoreKey]) {
|
|
26
|
+
return g[MJNotificationService._globalStoreKey];
|
|
27
27
|
}
|
|
28
|
-
|
|
29
|
-
MJNotificationService._instance = this;
|
|
28
|
+
g[MJNotificationService._globalStoreKey] = this;
|
|
30
29
|
MJGlobal.Instance.GetEventListener(true).subscribe((event) => {
|
|
31
30
|
switch (event.event) {
|
|
32
31
|
case MJEventType.DisplaySimpleNotificationRequest:
|
|
@@ -41,8 +40,16 @@ export class MJNotificationService {
|
|
|
41
40
|
}
|
|
42
41
|
break;
|
|
43
42
|
case MJEventType.LoggedIn:
|
|
44
|
-
if (MJNotificationService._loaded === false)
|
|
45
|
-
|
|
43
|
+
if (MJNotificationService._loaded === false) {
|
|
44
|
+
// Wait for StartupManager to complete before refreshing notifications.
|
|
45
|
+
// UserInfoEngine (which backs RefreshUserNotifications) is @RegisterForStartup
|
|
46
|
+
// and its _metadataConfigs are only populated during Config() which runs
|
|
47
|
+
// as part of StartupManager.Startup(). Calling RefreshItem() before that
|
|
48
|
+
// completes would silently find no config and return nothing.
|
|
49
|
+
StartupManager.Instance.Startup().then(() => {
|
|
50
|
+
MJNotificationService.RefreshUserNotifications();
|
|
51
|
+
});
|
|
52
|
+
}
|
|
46
53
|
// Subscribe to UserInfoEngine's DataChange$ so that when CACHE_INVALIDATION
|
|
47
54
|
// updates the _UserNotifications array, we immediately sync our BehaviorSubjects.
|
|
48
55
|
// This is the primary mechanism for real-time notification updates — it fires
|
|
@@ -93,7 +100,7 @@ export class MJNotificationService {
|
|
|
93
100
|
return gp.PushStatusUpdates();
|
|
94
101
|
}
|
|
95
102
|
static get Instance() {
|
|
96
|
-
return MJNotificationService.
|
|
103
|
+
return GetGlobalObjectStore()[MJNotificationService._globalStoreKey];
|
|
97
104
|
}
|
|
98
105
|
static _userNotifications = [];
|
|
99
106
|
static get UserNotifications() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"notifications.service.js","sourceRoot":"","sources":["../../src/lib/notifications.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,UAAU,EAAE,MAAM,eAAe,CAAC;AACvD,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,cAAc,EAA4B,MAAM,+BAA+B,CAAC;AACzF,OAAO,EAAwC,WAAW,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAGrG,OAAO,EAAE,eAAe,EAAc,OAAO,EAAE,MAAM,MAAM,CAAC;;;AAE5D;;;GAGG;AAIH,MAAM,OAAO,qBAAqB;IAYZ;IAXZ,MAAM,CAAC,SAAS,CAAwB;IACxC,MAAM,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AqB;gEAArB,qBAAqB,WAArB,qBAAqB,mBAFpB,MAAM;;iFAEP,qBAAqB;cAHjC,UAAU;eAAC;gBACV,UAAU,EAAE,MAAM;aACnB","sourcesContent":["import { ElementRef, Injectable } from '@angular/core';\nimport { LogError, Metadata } from '@memberjunction/core';\nimport { UserInfoEngine, MJUserNotificationEntity } from '@memberjunction/core-entities';\nimport { DisplaySimpleNotificationRequestData, MJEventType, MJGlobal } from '@memberjunction/global';\nimport { GraphQLDataProvider } from '@memberjunction/graphql-dataprovider';\nimport { NotificationService, NotificationSettings } from \"@progress/kendo-angular-notification\";\nimport { BehaviorSubject, Observable, Subject } from 'rxjs';\n\n/**\n * This injectable service is also available as a singleton MJNotificationService.Instance globally within an Angular application/library process space. It is responsible for displaying notifications to the user and also is able to manage the User Notifications entity\n * in the database.\n */\n@Injectable({\n providedIn: 'root'\n})\nexport class MJNotificationService {\n private static _instance: MJNotificationService;\n private static _loaded: boolean = false;\n\n private static isLoading$ = new BehaviorSubject<boolean>(false);\n private tabChange = new Subject();\n tabChange$ = this.tabChange.asObservable();\n\n // Observable for notification changes\n private static _notifications$ = new BehaviorSubject<MJUserNotificationEntity[]>([]);\n private static _unreadCount$ = new BehaviorSubject<number>(0);\n\n constructor(private notificationService: NotificationService) {\n if (MJNotificationService._instance) {\n // return existing instance which will short circuit the creation of a new instance\n return MJNotificationService._instance;\n }\n // first time this has been called, so return ourselves since we're in the constructor\n MJNotificationService._instance = this;\n\n MJGlobal.Instance.GetEventListener(true).subscribe( (event) => {\n switch (event.event) {\n case MJEventType.DisplaySimpleNotificationRequest: \n // received the message to display a notification to the user, so do that...\n const messageData: DisplaySimpleNotificationRequestData = <DisplaySimpleNotificationRequestData>event.args;\n this.CreateSimpleNotification(messageData.message,messageData.style, messageData.DisplayDuration);\n break;\n case MJEventType.ComponentEvent:\n if (event.eventCode === \"UserNotificationsUpdated\") {\n // refresh the user notifications\n MJNotificationService.RefreshUserNotifications();\n }\n break;\n case MJEventType.LoggedIn:\n if (MJNotificationService._loaded === false) \n MJNotificationService.RefreshUserNotifications();\n\n // Subscribe to UserInfoEngine's DataChange$ so that when CACHE_INVALIDATION\n // updates the _UserNotifications array, we immediately sync our BehaviorSubjects.\n // This is the primary mechanism for real-time notification updates — it fires\n // whenever BaseEngine processes a remote-invalidate event for User Notifications.\n UserInfoEngine.Instance.DataChange$.subscribe(event => {\n if (event.config.PropertyName === '_UserNotifications') {\n MJNotificationService._userNotifications = UserInfoEngine.Instance.UserNotifications;\n MJNotificationService.UpdateNotificationObservables();\n }\n });\n\n // got the login, now subscribe to push status updates here so we can then raise them as events in MJ Global locally\n this.PushStatusUpdates().subscribe( (message: string) => {\n // Handle undefined/null messages gracefully\n if (!message) {\n return;\n }\n\n const statusObj = JSON.parse(message);\n\n // pass along as an event so anyone else who wants to know about the push status update can do stuff\n MJGlobal.Instance.RaiseEvent({\n event: MJEventType.ComponentEvent,\n eventCode: \"PushStatusUpdates\",\n args: statusObj,\n component: this\n })\n\n const type = statusObj.type?.trim().toLowerCase();\n if (type === 'notification' || type === 'usernotifications') {\n // Server sends type:'notification', legacy used 'usernotifications' — support both\n const action = statusObj.action?.trim().toLowerCase()\n || statusObj.details?.action?.trim().toLowerCase();\n if (action === 'create') {\n this.CreateSimpleNotification(statusObj.title || 'New Notification Available', \"success\", 3000);\n MJNotificationService.RefreshUserNotifications();\n }\n }\n else {\n // otherwise just post it as a simple notification, except Skip messages, we will let Skip handle those\n if (type !== 'askskip' && type !== 'entityobjectstatusmessage' && typeof statusObj.message === 'string') {\n this.CreateSimpleNotification(statusObj.message, \"success\", 2500);\n }\n }\n });\n break;\n } \n });\n }\n\n public PushStatusUpdates(): Observable<string> {\n const gp: GraphQLDataProvider = <GraphQLDataProvider>Metadata.Provider;\n return gp.PushStatusUpdates();\n }\n\n public static get Instance(): MJNotificationService {\n return MJNotificationService._instance;\n }\n \n private static _userNotifications: MJUserNotificationEntity[] = [];\n public static get UserNotifications(): MJUserNotificationEntity[] {\n return MJNotificationService._userNotifications;\n }\n public static get UnreadUserNotifications(): MJUserNotificationEntity[] {\n return MJNotificationService._userNotifications.filter(n => n.Unread);\n }\n public static get UnreadUserNotificationCount(): number {\n return MJNotificationService.UnreadUserNotifications.length;\n }\n\n /**\n * Observable that emits the full list of user notifications whenever they change\n */\n public static get Notifications$(): Observable<MJUserNotificationEntity[]> {\n return MJNotificationService._notifications$.asObservable();\n }\n\n /**\n * Observable that emits the unread notification count whenever it changes\n */\n public static get UnreadCount$(): Observable<number> {\n return MJNotificationService._unreadCount$.asObservable();\n }\n\n /**\n * Instance method to access Notifications$ observable\n */\n public get notifications$(): Observable<MJUserNotificationEntity[]> {\n return MJNotificationService.Notifications$;\n }\n\n /**\n * Instance method to access UnreadCount$ observable\n */\n public get unreadCount$(): Observable<number> {\n return MJNotificationService.UnreadCount$;\n }\n\n\n /**\n * Creates a user notification in the database and refreshes the UI. Returns the notification object.\n * @param title \n * @param message \n * @param resourceTypeId \n * @param resourceRecordId \n * @param resourceConfiguration Any object, it is converted to a string by JSON.stringify and stored in the database\n * @returns \n */\n public async CreateNotification(title: string, message: string, resourceTypeId: string | null, resourceRecordId: string | null, resourceConfiguration: any | null, displayToUser: boolean = true): Promise<MJUserNotificationEntity> {\n const md = new Metadata();\n const notification = <MJUserNotificationEntity>await md.GetEntityObject('MJ: User Notifications');\n notification.Title = title;\n notification.Message = message;\n if (resourceTypeId)\n notification.ResourceTypeID = resourceTypeId;\n if (resourceRecordId)\n notification.ResourceRecordID = resourceRecordId;\n if (resourceConfiguration)\n notification.ResourceConfiguration = JSON.stringify(resourceConfiguration);\n \n notification.UserID = md.CurrentUser.ID;\n notification.Unread = true;\n const result = await notification.Save();\n if (result) {\n MJNotificationService.RefreshUserNotifications();\n }\n\n if (displayToUser)\n this.CreateSimpleNotification(notification.Message, \"success\", 2500);\n\n return notification;\n }\n\n /**\n * Refresh user notifications and re-emit to observables.\n *\n * Uses RefreshItem() to guarantee fresh data from the server. The global\n * CACHE_INVALIDATION listener keeps the engine cache updated for background\n * changes, but when this method is called in response to a PushStatusUpdates\n * message, the cache invalidation event may not have arrived yet (separate\n * WebSocket message, potential race). RefreshItem() eliminates that race by\n * doing a targeted RunView for just notifications.\n */\n public static async RefreshUserNotifications() {\n try {\n const engine = UserInfoEngine.Instance;\n await engine.RefreshItem('_UserNotifications');\n MJNotificationService._userNotifications = engine.UserNotifications;\n MJNotificationService._notifications$.next(engine.UserNotifications);\n MJNotificationService._unreadCount$.next(MJNotificationService.UnreadUserNotificationCount);\n MJNotificationService._loaded = true;\n }\n catch (e) {\n LogError(e);\n }\n }\n\n /**\n * Update notification observables from existing in-memory data without doing a database query.\n * This is efficient for cases where notifications have been modified locally (e.g., marking as read)\n * and we just need to notify subscribers of the change.\n */\n public static UpdateNotificationObservables() {\n MJNotificationService._notifications$.next(MJNotificationService._userNotifications);\n MJNotificationService._unreadCount$.next(MJNotificationService.UnreadUserNotificationCount);\n }\n\n /**\n * Creates a message that is not saved to the User Notifications table, but is displayed to the user.\n * @param message - text to display\n * @param style - display styling\n * @param hideAfter - option to auto hide after the specified delay in milliseconds\n */\n public CreateSimpleNotification(message: string, style: \"none\" | \"success\" | \"error\" | \"warning\" | \"info\" = \"success\", hideAfter?: number) {\n const props: NotificationSettings = {\n content: message,\n cssClass: \"button-notification\",\n animation: { type: \"slide\", duration: 400 },\n position: { horizontal: \"center\", vertical: \"top\" },\n type: { style: style, icon: true }\n }\n if (hideAfter)\n props.hideAfter = hideAfter;\n else\n props.closable = true;\n\n this.notificationService.show(props);\n }\n}"]}
|
|
1
|
+
{"version":3,"file":"notifications.service.js","sourceRoot":"","sources":["../../src/lib/notifications.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,UAAU,EAAE,MAAM,eAAe,CAAC;AACvD,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAC1E,OAAO,EAAE,cAAc,EAA4B,MAAM,+BAA+B,CAAC;AACzF,OAAO,EAAwC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e,EAAE,QAA2D,SAAS,EAAE,SAAkB;QACvI,MAAM,KAAK,GAAyB;YAClC,OAAO,EAAE,OAAO;YAChB,QAAQ,EAAE,qBAAqB;YAC/B,SAAS,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,QAAQ,EAAE,GAAG,EAAE;YAC3C,QAAQ,EAAE,EAAE,UAAU,EAAE,QAAQ,EAAE,QAAQ,EAAE,KAAK,EAAE;YACnD,IAAI,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE;SACnC,CAAA;QACD,IAAI,SAAS;YACX,KAAK,CAAC,SAAS,GAAG,SAAS,CAAC;;YAE5B,KAAK,CAAC,QAAQ,GAAG,IAAI,CAAC;QAExB,IAAI,CAAC,mBAAmB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACvC,CAAC;+GAvOU,qBAAqB;gEAArB,qBAAqB,WAArB,qBAAqB,mBAFpB,MAAM;;iFAEP,qBAAqB;cAHjC,UAAU;eAAC;gBACV,UAAU,EAAE,MAAM;aACnB","sourcesContent":["import { ElementRef, Injectable } from '@angular/core';\nimport { LogError, Metadata, StartupManager } from '@memberjunction/core';\nimport { UserInfoEngine, MJUserNotificationEntity } from '@memberjunction/core-entities';\nimport { DisplaySimpleNotificationRequestData, MJEventType, MJGlobal, GetGlobalObjectStore } from '@memberjunction/global';\nimport { GraphQLDataProvider } from '@memberjunction/graphql-dataprovider';\nimport { NotificationService, NotificationSettings } from \"@progress/kendo-angular-notification\";\nimport { BehaviorSubject, Observable, Subject } from 'rxjs';\n\n/**\n * This injectable service is also available as a singleton MJNotificationService.Instance globally within an Angular application/library process space. It is responsible for displaying notifications to the user and also is able to manage the User Notifications entity\n * in the database.\n */\n@Injectable({\n providedIn: 'root'\n})\nexport class MJNotificationService {\n private static readonly _globalStoreKey = '___SINGLETON__MJNotificationService';\n private static _loaded: boolean = false;\n\n private static isLoading$ = new BehaviorSubject<boolean>(false);\n private tabChange = new Subject();\n tabChange$ = this.tabChange.asObservable();\n\n // Observable for notification changes\n private static _notifications$ = new BehaviorSubject<MJUserNotificationEntity[]>([]);\n private static _unreadCount$ = new BehaviorSubject<number>(0);\n\n constructor(private notificationService: NotificationService) {\n const g = GetGlobalObjectStore()!;\n if (g[MJNotificationService._globalStoreKey]) {\n return g[MJNotificationService._globalStoreKey] as MJNotificationService;\n }\n g[MJNotificationService._globalStoreKey] = this;\n\n MJGlobal.Instance.GetEventListener(true).subscribe( (event) => {\n switch (event.event) {\n case MJEventType.DisplaySimpleNotificationRequest: \n // received the message to display a notification to the user, so do that...\n const messageData: DisplaySimpleNotificationRequestData = <DisplaySimpleNotificationRequestData>event.args;\n this.CreateSimpleNotification(messageData.message,messageData.style, messageData.DisplayDuration);\n break;\n case MJEventType.ComponentEvent:\n if (event.eventCode === \"UserNotificationsUpdated\") {\n // refresh the user notifications\n MJNotificationService.RefreshUserNotifications();\n }\n break;\n case MJEventType.LoggedIn:\n if (MJNotificationService._loaded === false) {\n // Wait for StartupManager to complete before refreshing notifications.\n // UserInfoEngine (which backs RefreshUserNotifications) is @RegisterForStartup\n // and its _metadataConfigs are only populated during Config() which runs\n // as part of StartupManager.Startup(). Calling RefreshItem() before that\n // completes would silently find no config and return nothing.\n StartupManager.Instance.Startup().then(() => {\n MJNotificationService.RefreshUserNotifications();\n });\n }\n\n // Subscribe to UserInfoEngine's DataChange$ so that when CACHE_INVALIDATION\n // updates the _UserNotifications array, we immediately sync our BehaviorSubjects.\n // This is the primary mechanism for real-time notification updates — it fires\n // whenever BaseEngine processes a remote-invalidate event for User Notifications.\n UserInfoEngine.Instance.DataChange$.subscribe(event => {\n if (event.config.PropertyName === '_UserNotifications') {\n MJNotificationService._userNotifications = UserInfoEngine.Instance.UserNotifications;\n MJNotificationService.UpdateNotificationObservables();\n }\n });\n\n // got the login, now subscribe to push status updates here so we can then raise them as events in MJ Global locally\n this.PushStatusUpdates().subscribe( (message: string) => {\n // Handle undefined/null messages gracefully\n if (!message) {\n return;\n }\n\n const statusObj = JSON.parse(message);\n\n // pass along as an event so anyone else who wants to know about the push status update can do stuff\n MJGlobal.Instance.RaiseEvent({\n event: MJEventType.ComponentEvent,\n eventCode: \"PushStatusUpdates\",\n args: statusObj,\n component: this\n })\n\n const type = statusObj.type?.trim().toLowerCase();\n if (type === 'notification' || type === 'usernotifications') {\n // Server sends type:'notification', legacy used 'usernotifications' — support both\n const action = statusObj.action?.trim().toLowerCase()\n || statusObj.details?.action?.trim().toLowerCase();\n if (action === 'create') {\n this.CreateSimpleNotification(statusObj.title || 'New Notification Available', \"success\", 3000);\n MJNotificationService.RefreshUserNotifications();\n }\n }\n else {\n // otherwise just post it as a simple notification, except Skip messages, we will let Skip handle those\n if (type !== 'askskip' && type !== 'entityobjectstatusmessage' && typeof statusObj.message === 'string') {\n this.CreateSimpleNotification(statusObj.message, \"success\", 2500);\n }\n }\n });\n break;\n } \n });\n }\n\n public PushStatusUpdates(): Observable<string> {\n const gp: GraphQLDataProvider = <GraphQLDataProvider>Metadata.Provider;\n return gp.PushStatusUpdates();\n }\n\n public static get Instance(): MJNotificationService {\n return GetGlobalObjectStore()![MJNotificationService._globalStoreKey] as MJNotificationService;\n }\n \n private static _userNotifications: MJUserNotificationEntity[] = [];\n public static get UserNotifications(): MJUserNotificationEntity[] {\n return MJNotificationService._userNotifications;\n }\n public static get UnreadUserNotifications(): MJUserNotificationEntity[] {\n return MJNotificationService._userNotifications.filter(n => n.Unread);\n }\n public static get UnreadUserNotificationCount(): number {\n return MJNotificationService.UnreadUserNotifications.length;\n }\n\n /**\n * Observable that emits the full list of user notifications whenever they change\n */\n public static get Notifications$(): Observable<MJUserNotificationEntity[]> {\n return MJNotificationService._notifications$.asObservable();\n }\n\n /**\n * Observable that emits the unread notification count whenever it changes\n */\n public static get UnreadCount$(): Observable<number> {\n return MJNotificationService._unreadCount$.asObservable();\n }\n\n /**\n * Instance method to access Notifications$ observable\n */\n public get notifications$(): Observable<MJUserNotificationEntity[]> {\n return MJNotificationService.Notifications$;\n }\n\n /**\n * Instance method to access UnreadCount$ observable\n */\n public get unreadCount$(): Observable<number> {\n return MJNotificationService.UnreadCount$;\n }\n\n\n /**\n * Creates a user notification in the database and refreshes the UI. Returns the notification object.\n * @param title \n * @param message \n * @param resourceTypeId \n * @param resourceRecordId \n * @param resourceConfiguration Any object, it is converted to a string by JSON.stringify and stored in the database\n * @returns \n */\n public async CreateNotification(title: string, message: string, resourceTypeId: string | null, resourceRecordId: string | null, resourceConfiguration: any | null, displayToUser: boolean = true): Promise<MJUserNotificationEntity> {\n const md = new Metadata();\n const notification = <MJUserNotificationEntity>await md.GetEntityObject('MJ: User Notifications');\n notification.Title = title;\n notification.Message = message;\n if (resourceTypeId)\n notification.ResourceTypeID = resourceTypeId;\n if (resourceRecordId)\n notification.ResourceRecordID = resourceRecordId;\n if (resourceConfiguration)\n notification.ResourceConfiguration = JSON.stringify(resourceConfiguration);\n \n notification.UserID = md.CurrentUser.ID;\n notification.Unread = true;\n const result = await notification.Save();\n if (result) {\n MJNotificationService.RefreshUserNotifications();\n }\n\n if (displayToUser)\n this.CreateSimpleNotification(notification.Message, \"success\", 2500);\n\n return notification;\n }\n\n /**\n * Refresh user notifications and re-emit to observables.\n *\n * Uses RefreshItem() to guarantee fresh data from the server. The global\n * CACHE_INVALIDATION listener keeps the engine cache updated for background\n * changes, but when this method is called in response to a PushStatusUpdates\n * message, the cache invalidation event may not have arrived yet (separate\n * WebSocket message, potential race). RefreshItem() eliminates that race by\n * doing a targeted RunView for just notifications.\n */\n public static async RefreshUserNotifications() {\n try {\n const engine = UserInfoEngine.Instance;\n await engine.RefreshItem('_UserNotifications');\n MJNotificationService._userNotifications = engine.UserNotifications;\n MJNotificationService._notifications$.next(engine.UserNotifications);\n MJNotificationService._unreadCount$.next(MJNotificationService.UnreadUserNotificationCount);\n MJNotificationService._loaded = true;\n }\n catch (e) {\n LogError(e);\n }\n }\n\n /**\n * Update notification observables from existing in-memory data without doing a database query.\n * This is efficient for cases where notifications have been modified locally (e.g., marking as read)\n * and we just need to notify subscribers of the change.\n */\n public static UpdateNotificationObservables() {\n MJNotificationService._notifications$.next(MJNotificationService._userNotifications);\n MJNotificationService._unreadCount$.next(MJNotificationService.UnreadUserNotificationCount);\n }\n\n /**\n * Creates a message that is not saved to the User Notifications table, but is displayed to the user.\n * @param message - text to display\n * @param style - display styling\n * @param hideAfter - option to auto hide after the specified delay in milliseconds\n */\n public CreateSimpleNotification(message: string, style: \"none\" | \"success\" | \"error\" | \"warning\" | \"info\" = \"success\", hideAfter?: number) {\n const props: NotificationSettings = {\n content: message,\n cssClass: \"button-notification\",\n animation: { type: \"slide\", duration: 400 },\n position: { horizontal: \"center\", vertical: \"top\" },\n type: { style: style, icon: true }\n }\n if (hideAfter)\n props.hideAfter = hideAfter;\n else\n props.closable = true;\n\n this.notificationService.show(props);\n }\n}"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@memberjunction/ng-notifications",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.16.0",
|
|
4
4
|
"description": "MemberJunction: Simple Angular library for displaying user notifications",
|
|
5
5
|
"main": "./dist/public-api.js",
|
|
6
6
|
"typings": "./dist/public-api.d.ts",
|
|
@@ -26,10 +26,10 @@
|
|
|
26
26
|
"@progress/kendo-angular-notification": "22.0.1"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@memberjunction/core": "5.
|
|
30
|
-
"@memberjunction/core-entities": "5.
|
|
31
|
-
"@memberjunction/global": "5.
|
|
32
|
-
"@memberjunction/graphql-dataprovider": "5.
|
|
29
|
+
"@memberjunction/core": "5.16.0",
|
|
30
|
+
"@memberjunction/core-entities": "5.16.0",
|
|
31
|
+
"@memberjunction/global": "5.16.0",
|
|
32
|
+
"@memberjunction/graphql-dataprovider": "5.16.0",
|
|
33
33
|
"tslib": "^2.8.1",
|
|
34
34
|
"rxjs": "^7.8.2"
|
|
35
35
|
},
|