@memberjunction/ng-timeline 2.122.0 → 2.122.2

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.
@@ -0,0 +1,387 @@
1
+ /**
2
+ * @fileoverview TimelineGroup class for configuring timeline data sources.
3
+ *
4
+ * The TimelineGroup class defines how data is loaded and displayed in the timeline.
5
+ * It supports both MemberJunction BaseEntity objects and plain JavaScript objects,
6
+ * making it usable in any Angular application.
7
+ *
8
+ * @module @memberjunction/ng-timeline/timeline-group
9
+ */
10
+ import { TimelineCardConfig, TimelineEventConfig } from './types';
11
+ /**
12
+ * Extracts a field value from a record, supporting both BaseEntity and plain objects.
13
+ *
14
+ * For BaseEntity objects (detected by presence of `.Get()` method), uses the `.Get()` method.
15
+ * For plain JavaScript objects, uses standard bracket notation.
16
+ *
17
+ * @param record - The source record (BaseEntity or plain object)
18
+ * @param fieldName - The name of the field to extract
19
+ * @returns The field value, or undefined if not found
20
+ *
21
+ * @example
22
+ * ```typescript
23
+ * // Works with BaseEntity
24
+ * const entity = await md.GetEntityObject<TaskEntity>('Tasks');
25
+ * const name = getFieldValue(entity, 'Name'); // Uses entity.Get('Name')
26
+ *
27
+ * // Works with plain objects
28
+ * const obj = { name: 'My Task', status: 'Open' };
29
+ * const name = getFieldValue(obj, 'name'); // Uses obj['name']
30
+ * ```
31
+ */
32
+ export declare function getFieldValue(record: any, fieldName: string): unknown;
33
+ /**
34
+ * Extracts an ID from a record, trying common ID field names.
35
+ *
36
+ * @param record - The source record
37
+ * @param idFieldName - Optional explicit ID field name
38
+ * @returns The record ID as a string, or a generated fallback ID
39
+ */
40
+ export declare function getRecordId(record: any, idFieldName?: string): string;
41
+ /**
42
+ * Configures a data source for the timeline component.
43
+ *
44
+ * TimelineGroup defines how records are loaded, which fields to display,
45
+ * and how they should be styled. Multiple groups can be used to display
46
+ * different types of events on the same timeline.
47
+ *
48
+ * @typeParam T - The type of the source records. Defaults to `any` for maximum
49
+ * flexibility. MemberJunction users can specify BaseEntity subclasses
50
+ * for full type safety.
51
+ *
52
+ * @example Basic usage with plain objects
53
+ * ```typescript
54
+ * interface MyEvent {
55
+ * id: string;
56
+ * title: string;
57
+ * eventDate: Date;
58
+ * description: string;
59
+ * }
60
+ *
61
+ * const group = new TimelineGroup<MyEvent>();
62
+ * group.DataSourceType = 'array';
63
+ * group.EntityObjects = myEventsArray;
64
+ * group.TitleFieldName = 'title';
65
+ * group.DateFieldName = 'eventDate';
66
+ * group.DescriptionFieldName = 'description';
67
+ * ```
68
+ *
69
+ * @example MemberJunction usage with BaseEntity
70
+ * ```typescript
71
+ * import { TaskEntity } from '@memberjunction/core-entities';
72
+ *
73
+ * const group = new TimelineGroup<TaskEntity>();
74
+ * group.EntityName = 'Tasks';
75
+ * group.DataSourceType = 'entity';
76
+ * group.Filter = "Status = 'Open'";
77
+ * group.TitleFieldName = 'Name';
78
+ * group.DateFieldName = 'DueDate';
79
+ * ```
80
+ *
81
+ * @example With full configuration
82
+ * ```typescript
83
+ * const group = new TimelineGroup<TaskEntity>();
84
+ * group.EntityName = 'Tasks';
85
+ * group.TitleFieldName = 'Name';
86
+ * group.DateFieldName = 'CompletedAt';
87
+ * group.SubtitleFieldName = 'Category';
88
+ * group.DescriptionFieldName = 'Description';
89
+ * group.DisplayIcon = 'fa-solid fa-check-circle';
90
+ * group.DisplayColor = '#4caf50';
91
+ * group.GroupLabel = 'Completed Tasks';
92
+ *
93
+ * group.CardConfig = {
94
+ * collapsible: true,
95
+ * defaultExpanded: false,
96
+ * summaryFields: [
97
+ * { fieldName: 'AssignedTo', label: 'Assignee', icon: 'fa-solid fa-user' },
98
+ * { fieldName: 'Priority', icon: 'fa-solid fa-flag' }
99
+ * ],
100
+ * actions: [
101
+ * { id: 'view', label: 'View', variant: 'primary' },
102
+ * { id: 'edit', label: 'Edit', variant: 'secondary' }
103
+ * ]
104
+ * };
105
+ *
106
+ * group.EventConfigFunction = (task) => ({
107
+ * icon: task.Priority === 'High' ? 'fa-solid fa-exclamation' : undefined,
108
+ * color: task.Status === 'Overdue' ? '#f44336' : undefined
109
+ * });
110
+ * ```
111
+ */
112
+ export declare class TimelineGroup<T = any> {
113
+ /**
114
+ * The MemberJunction entity name for this group.
115
+ * Required when `DataSourceType` is `'entity'`.
116
+ *
117
+ * @example 'Tasks', 'AI Agents', 'Users'
118
+ */
119
+ EntityName?: string;
120
+ /**
121
+ * How data is provided to the timeline.
122
+ * - `'array'`: Data is provided via the `EntityObjects` array (works with any object type)
123
+ * - `'entity'`: Data is loaded using MemberJunction's RunView (requires MJ core)
124
+ *
125
+ * @default 'entity'
126
+ */
127
+ DataSourceType: 'array' | 'entity';
128
+ /**
129
+ * SQL WHERE clause filter for entity queries.
130
+ * Only used when `DataSourceType` is `'entity'`.
131
+ *
132
+ * @example "Status = 'Open' AND Priority = 'High'"
133
+ */
134
+ Filter?: string;
135
+ /**
136
+ * Pre-loaded data array.
137
+ * Used when `DataSourceType` is `'array'`, or populated after loading when using `'entity'`.
138
+ */
139
+ EntityObjects: T[];
140
+ /**
141
+ * SQL ORDER BY clause for entity queries.
142
+ * Only used when `DataSourceType` is `'entity'`.
143
+ *
144
+ * @example 'CreatedAt DESC', 'Priority ASC, DueDate DESC'
145
+ */
146
+ OrderBy?: string;
147
+ /**
148
+ * Maximum number of records to load per batch.
149
+ * Used for virtual scrolling.
150
+ *
151
+ * @default undefined (uses component's virtualScroll.batchSize)
152
+ */
153
+ MaxRecords?: number;
154
+ /**
155
+ * Field name for the event title.
156
+ * This is the primary text displayed on each timeline card.
157
+ *
158
+ * @required
159
+ */
160
+ TitleFieldName: string;
161
+ /**
162
+ * Field name for the event date.
163
+ * Used for chronological ordering and date display.
164
+ *
165
+ * @required
166
+ */
167
+ DateFieldName: string;
168
+ /**
169
+ * Field name for the subtitle.
170
+ * Displayed below the title in smaller text.
171
+ */
172
+ SubtitleFieldName?: string;
173
+ /**
174
+ * Field name for the description/body text.
175
+ * Displayed in the card body when expanded.
176
+ */
177
+ DescriptionFieldName?: string;
178
+ /**
179
+ * Field name containing an image URL.
180
+ * When set, displays an image in the card.
181
+ */
182
+ ImageFieldName?: string;
183
+ /**
184
+ * Field name for the unique record ID.
185
+ * Defaults to 'ID' or 'id' if not specified.
186
+ */
187
+ IdFieldName?: string;
188
+ /**
189
+ * Icon display mode.
190
+ * - `'standard'`: Uses a default icon based on the group index
191
+ * - `'custom'`: Uses the icon specified in `DisplayIcon`
192
+ *
193
+ * @default 'standard'
194
+ */
195
+ DisplayIconMode: 'standard' | 'custom';
196
+ /**
197
+ * Custom icon class (Font Awesome).
198
+ * Only used when `DisplayIconMode` is `'custom'`.
199
+ *
200
+ * @example 'fa-solid fa-check', 'fa-regular fa-calendar'
201
+ */
202
+ DisplayIcon?: string;
203
+ /**
204
+ * Color assignment mode.
205
+ * - `'auto'`: System assigns colors based on group index
206
+ * - `'manual'`: Uses the color specified in `DisplayColor`
207
+ *
208
+ * @default 'auto'
209
+ */
210
+ DisplayColorMode: 'auto' | 'manual';
211
+ /**
212
+ * Custom color for this group's markers and accents.
213
+ * Only used when `DisplayColorMode` is `'manual'`.
214
+ * Any valid CSS color value.
215
+ *
216
+ * @example '#4caf50', 'rgb(66, 135, 245)', 'var(--primary-color)'
217
+ */
218
+ DisplayColor?: string;
219
+ /**
220
+ * Human-readable label for this group.
221
+ * Used in legends, headers, or when distinguishing multiple groups.
222
+ *
223
+ * @example 'Completed Tasks', 'System Events', 'User Activities'
224
+ */
225
+ GroupLabel?: string;
226
+ /**
227
+ * Card display configuration for this group.
228
+ * Defines how event cards are rendered.
229
+ * If not set, uses the component's `defaultCardConfig`.
230
+ */
231
+ CardConfig?: TimelineCardConfig;
232
+ /**
233
+ * Custom function to generate the event summary/description.
234
+ * Takes precedence over `DescriptionFieldName`.
235
+ *
236
+ * @param record - The source record
237
+ * @returns HTML string or plain text to display
238
+ *
239
+ * @example
240
+ * ```typescript
241
+ * group.SummaryFunction = (task) => {
242
+ * return `<strong>${task.Status}</strong>: ${task.Description}`;
243
+ * };
244
+ * ```
245
+ */
246
+ SummaryFunction?: (record: T) => string;
247
+ /**
248
+ * Custom function to configure individual events.
249
+ * Allows per-event customization of icons, colors, and actions.
250
+ *
251
+ * @param record - The source record
252
+ * @returns Configuration overrides for this event
253
+ *
254
+ * @example
255
+ * ```typescript
256
+ * group.EventConfigFunction = (task) => ({
257
+ * icon: task.Priority === 'High' ? 'fa-solid fa-exclamation' : undefined,
258
+ * color: task.IsOverdue ? '#f44336' : undefined,
259
+ * actions: task.CanEdit ? [{ id: 'edit', label: 'Edit' }] : []
260
+ * });
261
+ * ```
262
+ */
263
+ EventConfigFunction?: (record: T) => TimelineEventConfig;
264
+ /**
265
+ * Gets the effective card configuration, merging with defaults.
266
+ *
267
+ * @returns The merged card configuration
268
+ */
269
+ getEffectiveCardConfig(): TimelineCardConfig;
270
+ /**
271
+ * Extracts a field value from a record in this group.
272
+ *
273
+ * @param record - The source record
274
+ * @param fieldName - The field name to extract
275
+ * @returns The field value
276
+ */
277
+ getValue(record: T, fieldName: string): unknown;
278
+ /**
279
+ * Gets the ID of a record in this group.
280
+ *
281
+ * @param record - The source record
282
+ * @returns The record ID
283
+ */
284
+ getId(record: T): string;
285
+ /**
286
+ * Gets the title from a record.
287
+ *
288
+ * @param record - The source record
289
+ * @returns The title string
290
+ */
291
+ getTitle(record: T): string;
292
+ /**
293
+ * Gets the date from a record.
294
+ *
295
+ * @param record - The source record
296
+ * @returns The date object
297
+ */
298
+ getDate(record: T): Date;
299
+ /**
300
+ * Gets the subtitle from a record.
301
+ *
302
+ * @param record - The source record
303
+ * @returns The subtitle string, or undefined
304
+ */
305
+ getSubtitle(record: T): string | undefined;
306
+ /**
307
+ * Gets the description from a record.
308
+ *
309
+ * @param record - The source record
310
+ * @returns The description string, or undefined
311
+ */
312
+ getDescription(record: T): string | undefined;
313
+ /**
314
+ * Gets the image URL from a record.
315
+ *
316
+ * @param record - The source record
317
+ * @returns The image URL, or undefined
318
+ */
319
+ getImageUrl(record: T): string | undefined;
320
+ /**
321
+ * Gets the event configuration for a specific record.
322
+ *
323
+ * @param record - The source record
324
+ * @returns The event configuration (from EventConfigFunction or defaults)
325
+ */
326
+ getEventConfig(record: T): TimelineEventConfig;
327
+ /**
328
+ * Creates a TimelineGroup from MemberJunction RunViewParams.
329
+ *
330
+ * This is a convenience method for MemberJunction applications.
331
+ * It loads data immediately and returns a configured group.
332
+ *
333
+ * **Note**: This method requires `@memberjunction/core` to be available.
334
+ * It will throw an error if used in non-MJ applications.
335
+ *
336
+ * @param params - RunView parameters for loading data
337
+ * @returns A configured TimelineGroup with loaded data
338
+ *
339
+ * @example
340
+ * ```typescript
341
+ * const group = await TimelineGroup.FromView<TaskEntity>({
342
+ * EntityName: 'Tasks',
343
+ * ExtraFilter: "Status = 'Open'",
344
+ * OrderBy: 'DueDate DESC'
345
+ * });
346
+ * group.TitleFieldName = 'Name';
347
+ * group.DateFieldName = 'DueDate';
348
+ * ```
349
+ */
350
+ static FromView<T = any>(params: {
351
+ EntityName?: string;
352
+ ExtraFilter?: string;
353
+ OrderBy?: string;
354
+ MaxRows?: number;
355
+ [key: string]: unknown;
356
+ }): Promise<TimelineGroup<T>>;
357
+ /**
358
+ * Creates a TimelineGroup from a plain array of objects.
359
+ *
360
+ * This is a convenience method that sets up the group for array-based data.
361
+ *
362
+ * @param data - Array of objects to display
363
+ * @param config - Configuration for field mappings
364
+ * @returns A configured TimelineGroup
365
+ *
366
+ * @example
367
+ * ```typescript
368
+ * const group = TimelineGroup.FromArray(myEvents, {
369
+ * titleField: 'name',
370
+ * dateField: 'eventDate',
371
+ * descriptionField: 'details'
372
+ * });
373
+ * ```
374
+ */
375
+ static FromArray<T = any>(data: T[], config: {
376
+ titleField: string;
377
+ dateField: string;
378
+ subtitleField?: string;
379
+ descriptionField?: string;
380
+ imageField?: string;
381
+ idField?: string;
382
+ groupLabel?: string;
383
+ icon?: string;
384
+ color?: string;
385
+ }): TimelineGroup<T>;
386
+ }
387
+ //# sourceMappingURL=timeline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