@memberjunction/ng-shared 2.42.1 → 2.44.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.
- package/README.md +196 -30
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -12,6 +12,7 @@ Utility functions and reusable components used across MemberJunction Explorer An
|
|
|
12
12
|
- Notification system integration
|
|
13
13
|
- Event management
|
|
14
14
|
- DOM utilities
|
|
15
|
+
- Angular pipes for text and URL formatting
|
|
15
16
|
|
|
16
17
|
## Installation
|
|
17
18
|
|
|
@@ -19,18 +20,40 @@ Utility functions and reusable components used across MemberJunction Explorer An
|
|
|
19
20
|
npm install @memberjunction/ng-shared
|
|
20
21
|
```
|
|
21
22
|
|
|
23
|
+
## Dependencies
|
|
24
|
+
|
|
25
|
+
### Peer Dependencies
|
|
26
|
+
- `@angular/common`: ^18.0.2
|
|
27
|
+
- `@angular/core`: ^18.0.2
|
|
28
|
+
- `rxjs`: ^7.8.1
|
|
29
|
+
|
|
30
|
+
### Core Dependencies
|
|
31
|
+
- `@memberjunction/core`: Provides core functionality and metadata management
|
|
32
|
+
- `@memberjunction/core-entities`: Entity definitions and resource management
|
|
33
|
+
- `@memberjunction/ng-notifications`: Notification system integration
|
|
34
|
+
- `@memberjunction/ng-base-types`: Base Angular component types
|
|
35
|
+
- `@memberjunction/graphql-dataprovider`: GraphQL data provider for API communication
|
|
36
|
+
- `@progress/kendo-angular-notification`: UI notification components
|
|
37
|
+
|
|
38
|
+
## Module Import
|
|
39
|
+
|
|
40
|
+
```typescript
|
|
41
|
+
import { MemberJunctionSharedModule } from '@memberjunction/ng-shared';
|
|
42
|
+
|
|
43
|
+
@NgModule({
|
|
44
|
+
imports: [
|
|
45
|
+
MemberJunctionSharedModule
|
|
46
|
+
// ... other imports
|
|
47
|
+
]
|
|
48
|
+
})
|
|
49
|
+
export class YourModule { }
|
|
50
|
+
```
|
|
51
|
+
|
|
22
52
|
## Key Components
|
|
23
53
|
|
|
24
54
|
### SharedService
|
|
25
55
|
|
|
26
|
-
A singleton service that provides:
|
|
27
|
-
|
|
28
|
-
- Application-wide state management
|
|
29
|
-
- Resource type handling
|
|
30
|
-
- User notifications
|
|
31
|
-
- Markdown to HTML conversion
|
|
32
|
-
- DOM utilities
|
|
33
|
-
- Notification creation and management
|
|
56
|
+
A singleton service that provides application-wide functionality:
|
|
34
57
|
|
|
35
58
|
```typescript
|
|
36
59
|
import { SharedService } from '@memberjunction/ng-shared';
|
|
@@ -38,8 +61,30 @@ import { SharedService } from '@memberjunction/ng-shared';
|
|
|
38
61
|
// Get singleton instance
|
|
39
62
|
const service = SharedService.Instance;
|
|
40
63
|
|
|
41
|
-
//
|
|
42
|
-
|
|
64
|
+
// Access session ID
|
|
65
|
+
const sessionId = service.SessionId;
|
|
66
|
+
|
|
67
|
+
// Access resource types
|
|
68
|
+
const viewResourceType = service.ViewResourceType;
|
|
69
|
+
const recordResourceType = service.RecordResourceType;
|
|
70
|
+
const dashboardResourceType = service.DashboardResourceType;
|
|
71
|
+
const reportResourceType = service.ReportResourceType;
|
|
72
|
+
const searchResultsResourceType = service.SearchResultsResourceType;
|
|
73
|
+
const listResourceType = service.ListResourceType;
|
|
74
|
+
|
|
75
|
+
// Get resource type by ID or name
|
|
76
|
+
const resourceTypeById = service.ResourceTypeByID('some-id');
|
|
77
|
+
const resourceTypeByName = service.ResourceTypeByName('reports');
|
|
78
|
+
|
|
79
|
+
// Format column values
|
|
80
|
+
const formattedValue = service.FormatColumnValue(column, value, maxLength, '...');
|
|
81
|
+
|
|
82
|
+
// Create notifications (Note: prefer MJNotificationService for new code)
|
|
83
|
+
service.CreateSimpleNotification('Operation completed', 'success', 3000);
|
|
84
|
+
|
|
85
|
+
// Convert between route segments and resource type names
|
|
86
|
+
const routeSegment = service.mapResourceTypeNameToRouteSegment('user views'); // returns 'view'
|
|
87
|
+
const resourceTypeName = service.mapResourceTypeRouteSegmentToName('view'); // returns 'user views'
|
|
43
88
|
```
|
|
44
89
|
|
|
45
90
|
### Base Components
|
|
@@ -49,10 +94,16 @@ service.CreateSimpleNotification('Operation completed successfully', 'success',
|
|
|
49
94
|
Base class for all MJ Explorer navigation components that can be displayed from a route:
|
|
50
95
|
|
|
51
96
|
```typescript
|
|
97
|
+
import { Component } from '@angular/core';
|
|
52
98
|
import { BaseNavigationComponent } from '@memberjunction/ng-shared';
|
|
53
99
|
|
|
100
|
+
@Component({
|
|
101
|
+
selector: 'app-your-navigation',
|
|
102
|
+
templateUrl: './your-navigation.component.html'
|
|
103
|
+
})
|
|
54
104
|
export class YourNavigationComponent extends BaseNavigationComponent {
|
|
55
|
-
//
|
|
105
|
+
// Inherits from BaseAngularComponent
|
|
106
|
+
// Provides foundation for routable components
|
|
56
107
|
}
|
|
57
108
|
```
|
|
58
109
|
|
|
@@ -61,29 +112,87 @@ export class YourNavigationComponent extends BaseNavigationComponent {
|
|
|
61
112
|
Extended base class for components that work with MemberJunction resources:
|
|
62
113
|
|
|
63
114
|
```typescript
|
|
115
|
+
import { Component } from '@angular/core';
|
|
64
116
|
import { BaseResourceComponent } from '@memberjunction/ng-shared';
|
|
117
|
+
import { ResourceData } from '@memberjunction/core-entities';
|
|
65
118
|
|
|
119
|
+
@Component({
|
|
120
|
+
selector: 'app-your-resource',
|
|
121
|
+
templateUrl: './your-resource.component.html'
|
|
122
|
+
})
|
|
66
123
|
export class YourResourceComponent extends BaseResourceComponent {
|
|
124
|
+
// Access resource data
|
|
125
|
+
ngOnInit() {
|
|
126
|
+
console.log(this.Data); // ResourceData object
|
|
127
|
+
}
|
|
128
|
+
|
|
67
129
|
// Required abstract methods
|
|
68
130
|
async GetResourceDisplayName(data: ResourceData): Promise<string> {
|
|
69
|
-
//
|
|
70
|
-
return
|
|
131
|
+
// Return display name based on resource data
|
|
132
|
+
return `Resource: ${data.ResourceRecordID}`;
|
|
71
133
|
}
|
|
72
134
|
|
|
73
135
|
async GetResourceIconClass(data: ResourceData): Promise<string> {
|
|
74
|
-
//
|
|
75
|
-
return 'fa-
|
|
136
|
+
// Return Font Awesome icon class
|
|
137
|
+
return 'fa-solid fa-file';
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// Lifecycle notifications
|
|
141
|
+
protected onLoad() {
|
|
142
|
+
this.NotifyLoadStarted();
|
|
143
|
+
// ... load resource data
|
|
144
|
+
this.NotifyLoadComplete();
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// Handle resource save
|
|
148
|
+
protected async saveResource() {
|
|
149
|
+
const entity = await this.getResourceEntity();
|
|
150
|
+
if (await entity.Save()) {
|
|
151
|
+
this.ResourceRecordSaved(entity);
|
|
152
|
+
}
|
|
76
153
|
}
|
|
77
154
|
}
|
|
78
155
|
```
|
|
79
156
|
|
|
157
|
+
## Angular Pipes
|
|
158
|
+
|
|
159
|
+
### URLPipe (formatUrl)
|
|
160
|
+
|
|
161
|
+
Ensures URLs have proper protocol prefix:
|
|
162
|
+
|
|
163
|
+
```typescript
|
|
164
|
+
// In template
|
|
165
|
+
<a [href]="website | formatUrl">Visit Site</a>
|
|
166
|
+
|
|
167
|
+
// Transforms:
|
|
168
|
+
// "example.com" → "https://example.com"
|
|
169
|
+
// "http://example.com" → "http://example.com" (unchanged)
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
### SimpleTextFormatPipe (formatText)
|
|
173
|
+
|
|
174
|
+
Converts plain text formatting to HTML:
|
|
175
|
+
|
|
176
|
+
```typescript
|
|
177
|
+
// In template
|
|
178
|
+
<div [innerHTML]="description | formatText"></div>
|
|
179
|
+
|
|
180
|
+
// Transforms:
|
|
181
|
+
// "Line 1\nLine 2" → "Line 1<br>Line 2"
|
|
182
|
+
// "Text\tIndented" → "Text Indented"
|
|
183
|
+
```
|
|
184
|
+
|
|
80
185
|
## Utilities
|
|
81
186
|
|
|
82
187
|
### Format Utilities
|
|
83
188
|
|
|
84
189
|
```typescript
|
|
85
|
-
// Convert Markdown to HTML
|
|
190
|
+
// Convert Markdown list to HTML
|
|
86
191
|
const htmlList = service.ConvertMarkdownStringToHtmlList('Unordered', '- Item 1\n- Item 2');
|
|
192
|
+
// Result: <ul><li>Item 1</li><li>Item 2</li></ul>
|
|
193
|
+
|
|
194
|
+
const orderedList = service.ConvertMarkdownStringToHtmlList('Ordered', '1. First\n2. Second');
|
|
195
|
+
// Result: <ol><li>First</li><li>Second</li></ol>
|
|
87
196
|
```
|
|
88
197
|
|
|
89
198
|
### DOM Utilities
|
|
@@ -92,28 +201,85 @@ const htmlList = service.ConvertMarkdownStringToHtmlList('Unordered', '- Item 1\
|
|
|
92
201
|
// Check if one element is a descendant of another
|
|
93
202
|
const isDescendant = SharedService.IsDescendant(parentRef, childRef);
|
|
94
203
|
|
|
95
|
-
// Trigger manual resize
|
|
96
|
-
service.InvokeManualResize(50);
|
|
204
|
+
// Trigger manual window resize event (useful for responsive components)
|
|
205
|
+
service.InvokeManualResize(50); // 50ms delay
|
|
97
206
|
```
|
|
98
207
|
|
|
99
|
-
###
|
|
208
|
+
### Push Status Updates
|
|
100
209
|
|
|
101
210
|
```typescript
|
|
102
|
-
//
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
const routeSegment = service.mapResourceTypeNameToRouteSegment('user views');
|
|
107
|
-
const resourceTypeName = service.mapResourceTypeRouteSegmentToName('view');
|
|
211
|
+
// Subscribe to server push updates
|
|
212
|
+
service.PushStatusUpdates().subscribe(status => {
|
|
213
|
+
console.log('Server status:', status);
|
|
214
|
+
});
|
|
108
215
|
```
|
|
109
216
|
|
|
110
|
-
##
|
|
217
|
+
## Event Codes
|
|
111
218
|
|
|
112
|
-
|
|
219
|
+
Predefined event codes for standardized application event handling:
|
|
113
220
|
|
|
114
221
|
```typescript
|
|
115
222
|
import { EventCodes } from '@memberjunction/ng-shared';
|
|
116
223
|
|
|
117
|
-
//
|
|
118
|
-
|
|
119
|
-
|
|
224
|
+
// Available event codes:
|
|
225
|
+
EventCodes.ViewClicked // User clicked on a view
|
|
226
|
+
EventCodes.EntityRecordClicked // User clicked on an entity record
|
|
227
|
+
EventCodes.AddDashboard // Request to add a dashboard
|
|
228
|
+
EventCodes.AddReport // Request to add a report
|
|
229
|
+
EventCodes.AddQuery // Request to add a query
|
|
230
|
+
EventCodes.ViewCreated // View was created
|
|
231
|
+
EventCodes.ViewUpdated // View was updated
|
|
232
|
+
EventCodes.RunSearch // Execute a search
|
|
233
|
+
EventCodes.ViewNotifications // View notifications panel
|
|
234
|
+
EventCodes.PushStatusUpdates // Server push status updates
|
|
235
|
+
EventCodes.UserNotificationsUpdated // User notifications changed
|
|
236
|
+
EventCodes.CloseCurrentTab // Close current tab
|
|
237
|
+
EventCodes.ListCreated // List was created
|
|
238
|
+
EventCodes.ListClicked // User clicked on a list
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
## Integration with Other MJ Packages
|
|
242
|
+
|
|
243
|
+
This package seamlessly integrates with:
|
|
244
|
+
|
|
245
|
+
- **@memberjunction/core**: Uses Metadata for entity access and logging
|
|
246
|
+
- **@memberjunction/core-entities**: Works with ResourceTypeEntity, UserNotificationEntity, and ResourceData
|
|
247
|
+
- **@memberjunction/ng-notifications**: Delegates notification functionality to the dedicated notification service
|
|
248
|
+
- **@memberjunction/global**: Uses global event system and utilities
|
|
249
|
+
|
|
250
|
+
## Migration Notes
|
|
251
|
+
|
|
252
|
+
### Deprecated Methods
|
|
253
|
+
|
|
254
|
+
Several notification-related methods in SharedService are deprecated in favor of MJNotificationService:
|
|
255
|
+
|
|
256
|
+
```typescript
|
|
257
|
+
// Deprecated
|
|
258
|
+
SharedService.UserNotifications
|
|
259
|
+
SharedService.UnreadUserNotifications
|
|
260
|
+
SharedService.UnreadUserNotificationCount
|
|
261
|
+
service.CreateNotification(...)
|
|
262
|
+
SharedService.RefreshUserNotifications()
|
|
263
|
+
service.CreateSimpleNotification(...)
|
|
264
|
+
|
|
265
|
+
// Use instead
|
|
266
|
+
import { MJNotificationService } from '@memberjunction/ng-notifications';
|
|
267
|
+
|
|
268
|
+
MJNotificationService.UserNotifications
|
|
269
|
+
MJNotificationService.UnreadUserNotifications
|
|
270
|
+
MJNotificationService.UnreadUserNotificationCount
|
|
271
|
+
mjNotificationService.CreateNotification(...)
|
|
272
|
+
MJNotificationService.RefreshUserNotifications()
|
|
273
|
+
mjNotificationService.CreateSimpleNotification(...)
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
## Build
|
|
277
|
+
|
|
278
|
+
To build this package:
|
|
279
|
+
|
|
280
|
+
```bash
|
|
281
|
+
cd packages/Angular/Explorer/shared
|
|
282
|
+
npm run build
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
The build uses Angular's `ngc` compiler and outputs to the `dist` directory.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@memberjunction/ng-shared",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.44.0",
|
|
4
4
|
"description": "MemberJunction: MJ Explorer Angular Shared Package - utility functions and other reusable elements used across other MJ Angular packages within the MJ Explorer App - do not use outside of MJ Explorer.",
|
|
5
5
|
"main": "./dist/public-api.js",
|
|
6
6
|
"typings": "./dist/public-api.d.ts",
|
|
@@ -27,11 +27,11 @@
|
|
|
27
27
|
"rxjs": "^7.8.1"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@memberjunction/core": "2.
|
|
31
|
-
"@memberjunction/core-entities": "2.
|
|
32
|
-
"@memberjunction/ng-notifications": "2.
|
|
33
|
-
"@memberjunction/ng-base-types": "2.
|
|
34
|
-
"@memberjunction/graphql-dataprovider": "2.
|
|
30
|
+
"@memberjunction/core": "2.44.0",
|
|
31
|
+
"@memberjunction/core-entities": "2.44.0",
|
|
32
|
+
"@memberjunction/ng-notifications": "2.44.0",
|
|
33
|
+
"@memberjunction/ng-base-types": "2.44.0",
|
|
34
|
+
"@memberjunction/graphql-dataprovider": "2.44.0",
|
|
35
35
|
"@progress/kendo-angular-notification": "16.2.0",
|
|
36
36
|
"tslib": "^2.3.0"
|
|
37
37
|
},
|