ngx-thin-admin 0.0.0-alpha.0 → 0.0.0-alpha.10

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.
@@ -1,14 +1,16 @@
1
+ import * as rxjs from 'rxjs';
1
2
  import * as i0 from '@angular/core';
2
- import { OnChanges, OnInit, TemplateRef, SimpleChanges } from '@angular/core';
3
+ import { InjectionToken, Provider, EventEmitter, SimpleChanges, OnChanges, OnInit, TemplateRef } from '@angular/core';
3
4
  import { MtxGridColumn } from '@ng-matero/extensions/grid';
4
- import { FormlyFieldConfig, FormlyFieldProps } from '@ngx-formly/core';
5
+ import { UrlTree } from '@angular/router';
6
+ import { FormlyFieldConfig, FormlyFieldProps, ConfigOption } from '@ngx-formly/core';
5
7
  import { PageEvent } from '@angular/material/paginator';
6
8
  import { FormGroup } from '@angular/forms';
7
9
 
8
10
  /**
9
11
  * Config for editor
10
12
  */
11
- interface NgxThinAdminEditorConfig {
13
+ interface NgxThinAdminEditorConfig<T = any> {
12
14
  /**
13
15
  * Label for the item
14
16
  * @example "User Account", "Article", etc. (used for singular form in UI)
@@ -31,15 +33,44 @@ interface NgxThinAdminEditorConfig {
31
33
  * @param id
32
34
  * @returns The item data
33
35
  */
34
- fetcher: (id: string) => Promise<any> | any;
36
+ fetcher: (id: string) => Promise<T> | T;
35
37
  /**
36
38
  * Function to create item / save item
37
39
  * @param data
38
40
  * @param id (only for update)
39
41
  * @returns The created/updated item data
40
42
  */
41
- saver?: (data: any, id?: string) => Promise<any> | any;
43
+ saver?: (data: T, id?: string) => Promise<T> | T;
44
+ /**
45
+ * Optional config for back button
46
+ */
47
+ backButton?: NgxThinAdminEditorBackButtonConfig;
48
+ /**
49
+ * Optional config for custom footer buttons
50
+ */
51
+ footerButtons?: {
52
+ label: string;
53
+ click: (data: T, itemId: string | undefined) => void;
54
+ show?: (data: T, itemId: string | undefined) => boolean;
55
+ className?: string;
56
+ }[];
42
57
  }
58
+ type NgxThinAdminEditorBackButtonConfig = {
59
+ label?: string;
60
+ historyBack: true;
61
+ } | {
62
+ label?: string;
63
+ click: () => void;
64
+ historyBack?: boolean;
65
+ } | {
66
+ label?: string;
67
+ link: string;
68
+ historyBack?: boolean;
69
+ } | {
70
+ label?: string;
71
+ routerLink: string;
72
+ historyBack?: boolean;
73
+ };
43
74
  /**
44
75
  * Columns for editor (extended type of FormlyFieldConfig)
45
76
  */
@@ -58,14 +89,14 @@ interface NgxThinAdminEditorField extends Omit<NgxThinAdminFieldConfig, 'props'>
58
89
  * Columns for list (extended type of MtxGridColumn)
59
90
  * @see https://ng-matero.github.io/extensions/components/grid/api
60
91
  */
61
- interface NgxThinAdminListColumn extends MtxGridColumn {
62
- link?: (item: any) => string | undefined;
63
- routerLink?: (item: any) => string | undefined;
92
+ interface NgxThinAdminListColumn<T = any> extends MtxGridColumn<T> {
93
+ link?: (item: T) => string | undefined;
94
+ routerLink?: (item: T) => string | UrlTree | undefined;
64
95
  }
65
96
  /**
66
97
  * Config for list
67
98
  */
68
- interface NgxThinAdminListConfig {
99
+ interface NgxThinAdminListConfig<T = any> {
69
100
  /**
70
101
  * Title of the list
71
102
  * @example "User Accounts", "Articles", etc.
@@ -81,12 +112,16 @@ interface NgxThinAdminListConfig {
81
112
  * @default [10, 25, 50, 100]
82
113
  */
83
114
  pageSizes?: number[];
115
+ /**
116
+ * Default page size
117
+ */
118
+ pageSize?: number;
84
119
  /**
85
120
  * Function to fetch list data. It will be called with a query object when the component initializes and when the fetch() method is called.
86
121
  * @param query - The query object containing parameters for fetching the list (e.g., keyword, pagination info).
87
122
  * @returns An array of data to be displayed in the grid.
88
123
  */
89
- fetcher: ListFetcher;
124
+ fetcher: ListFetcher<T>;
90
125
  /**
91
126
  * Optional config for create button. If provided, a create button will be displayed in the UI.
92
127
  */
@@ -95,11 +130,36 @@ interface NgxThinAdminListConfig {
95
130
  * Optional config for CSV export
96
131
  */
97
132
  csvExportButton?: NgxThinAdminListCsvExportButtonConfig | 'default';
133
+ /**
134
+ * Field key for the item ID
135
+ * (used by itemDeleterConfig to identify the item being deleted)
136
+ * @example "id", "loginId", "articleId", etc.
137
+ */
138
+ idFieldKey?: string;
139
+ /**
140
+ * Field key for the item label
141
+ * (used by itemDeleterConfig to display the item label in the confirmation dialog)
142
+ * @example "userName", "accountName", "articleTitle", etc.
143
+ */
144
+ labelFieldKey?: string;
145
+ /**
146
+ * Function to change the category of an item.
147
+ * If provided, a category change button will be automatically added to the item's action column.
148
+ * @param id ID of the item
149
+ * @param categoryId Destination category ID (undefined if moving to "no category")
150
+ */
151
+ categoryChanger?: (id: string, categoryId: string | undefined) => Promise<void> | Promise<any> | void;
152
+ /**
153
+ * Field key or function to get the current category ID of an item.
154
+ * (used to set the initial selected category in the category change dialog)
155
+ * @example "categoryId", "role", or (item) => item.category?.id
156
+ */
157
+ categoryFieldKey?: string | ((item: T) => string | undefined);
98
158
  }
99
159
  /**
100
160
  * Fetcher function to retrieve list data.
101
161
  */
102
- type ListFetcher = (query: NgxThinAdminListQuery) => Promise<NgxThinAdminListResponse> | NgxThinAdminListResponse;
162
+ type ListFetcher<T = any> = (query: NgxThinAdminListQuery) => Promise<NgxThinAdminListResponse<T>> | NgxThinAdminListResponse<T>;
103
163
  /**
104
164
  * Config for category selector
105
165
  */
@@ -136,22 +196,22 @@ interface NgxThinAdminCategorySelectorConfig {
136
196
  * @param category The category object to be updated.
137
197
  * @returns A promise that resolves with the updated category object.
138
198
  */
139
- updater?: (category: NgxThinAdminCategory) => Promise<NgxThinAdminCategory> | NgxThinAdminCategory;
199
+ updater?: (category: NgxThinAdminCategory) => Promise<void> | Promise<any> | void;
140
200
  /**
141
201
  * Optional function to delete a category. If provided, a category deletion option will be displayed in the category selector.
142
202
  * @param category The category object to be deleted.
143
203
  * @returns A promise that resolves when the category has been deleted.
144
204
  */
145
- deleter?: (category: NgxThinAdminCategory) => Promise<void> | void;
205
+ deleter?: (category: NgxThinAdminCategory) => Promise<void> | Promise<any> | void;
146
206
  }
147
207
  type NgxThinAdminListCreateButtonConfig = {
148
- label: string;
208
+ label?: string;
149
209
  click: () => void;
150
210
  } | {
151
- label: string;
211
+ label?: string;
152
212
  link: string;
153
213
  } | {
154
- label: string;
214
+ label?: string;
155
215
  routerLink: string;
156
216
  };
157
217
  interface NgxThinAdminListCsvExportButtonConfig {
@@ -166,9 +226,12 @@ interface NgxThinAdminListQuery {
166
226
  categoryId?: string;
167
227
  page: number;
168
228
  perPage: number;
229
+ filterColumn?: string;
230
+ filterValue?: string;
231
+ filterLabel?: string;
169
232
  }
170
- interface NgxThinAdminListResponse {
171
- items: any[];
233
+ interface NgxThinAdminListResponse<T = any> {
234
+ items: T[];
172
235
  totalCount: number;
173
236
  }
174
237
  interface NgxThinAdminCategory {
@@ -179,9 +242,74 @@ interface NgxThinAdminCategory {
179
242
  interface NgxThinAdminCategoryListResponse {
180
243
  categories: NgxThinAdminCategory[];
181
244
  }
245
+ /**
246
+ * Config for item deleter
247
+ * (Can be used in both list and editor components)
248
+ */
249
+ interface NgxThinAdminItemDeleterConfig {
250
+ /**
251
+ * Function to delete an item
252
+ * @param id ID to be deleted (Value of the field specified by listConfig.idFieldKey or editorConfig.idFieldKey)
253
+ */
254
+ deleter: (id: string) => Promise<void> | Promise<any> | void;
255
+ /**
256
+ * Navigate to after deletion (used after deletion in editor screen)
257
+ * @example "/accounts"
258
+ */
259
+ afterDeleteNavigateTo?: string;
260
+ }
261
+
262
+ type NgxThinAdminLocale = 'en' | 'ja';
263
+ type NgxThinAdminI18nKey = 'common.cancel' | 'common.ok' | 'common.save' | 'common.create' | 'common.edit' | 'common.delete' | 'common.back' | 'list.defaultTitle' | 'list.clearFilters' | 'list.searchDefaultPlaceholder' | 'list.searchInCategoryPlaceholder' | 'list.clearSearchKeyword' | 'list.refresh' | 'list.exportAsCsv' | 'list.exportedFileName' | 'list.exportItems' | 'editor.titleForCreate' | 'editor.titleForEdit' | 'editor.idLabel' | 'editor.saveForCreate' | 'editor.saveForEdit' | 'editor.errorInvalidInput' | 'editor.errorNoSaver' | 'editor.successSaved' | 'editor.backToList' | 'category.defaultSingular' | 'category.defaultPlural' | 'category.all' | 'category.editorDialogTitleForCreate' | 'category.editorDialogTitleForEdit' | 'category.deletionDialogTitle' | 'category.deletionDialogMessage' | 'category.errorCouldNotCreate' | 'category.errorFailedUpdate' | 'category.errorFailedDelete' | 'category.errorCouldNotSave' | 'category.successCreated' | 'category.successUpdated' | 'category.successDeleted' | 'item.defaultSingular' | 'item.deletionDialogTitle' | 'item.deletionDialogMessage' | 'item.errorFailedDelete' | 'item.successDeleted' | 'item.changeCategory' | 'item.changeCategoryDialogTitle' | 'item.changeCategoryDialogMessage' | 'item.successCategoryChanged' | 'item.errorFailedCategoryChange' | 'category.unselected' | 'csv.exporting' | 'csv.exportCompleted' | 'csv.exportCompletedWithErrors' | 'csv.errorGenerateFailed';
264
+ type NgxThinAdminI18nParams = Record<string, string | number | undefined>;
265
+ type NgxThinAdminTranslate = (key: NgxThinAdminI18nKey, params?: NgxThinAdminI18nParams) => string;
266
+ interface NgxThinAdminI18nConfig {
267
+ locale?: NgxThinAdminLocale;
268
+ messages?: Partial<Record<NgxThinAdminI18nKey, string>>;
269
+ translate?: NgxThinAdminTranslate;
270
+ }
271
+ declare const NGX_THIN_ADMIN_TRANSLATE: InjectionToken<NgxThinAdminTranslate>;
272
+ declare function provideNgxThinAdminI18n(config?: NgxThinAdminI18nConfig): Provider;
273
+
274
+ declare class ListCategorySelector {
275
+ /**
276
+ * Config for the category selector
277
+ */
278
+ config?: NgxThinAdminCategorySelectorConfig;
279
+ /**
280
+ * Selected category. This will be updated when the user selects a category from the list.
281
+ */
282
+ selectedCategory?: (NgxThinAdminCategory | undefined)[];
283
+ /**
284
+ * Event emitted when the selected category changes.
285
+ */
286
+ selectedCategoryChange: EventEmitter<(NgxThinAdminCategory | undefined)[]>;
287
+ /**
288
+ * Categories to be displayed in the category selector.
289
+ */
290
+ categories: NgxThinAdminCategory[];
291
+ /**
292
+ * Services
293
+ */
294
+ private snackbar;
295
+ private dialog;
296
+ private cdr;
297
+ private translate;
298
+ t(key: NgxThinAdminI18nKey, params?: Record<string, string | number | undefined>): string;
299
+ ngOnChanges(changes: SimpleChanges<ListCategorySelector>): void;
300
+ fetchCategories(): Promise<void>;
301
+ createCategory(categoryLabel: string): Promise<void>;
302
+ updateCategory(category: NgxThinAdminCategory): Promise<void>;
303
+ deleteCategory(category: NgxThinAdminCategory): Promise<void>;
304
+ openCategoryEditorDialog(editCategory: NgxThinAdminCategory | undefined): Promise<void>;
305
+ openCategoryDeletionDialog(category: NgxThinAdminCategory): Promise<void>;
306
+ static ɵfac: i0.ɵɵFactoryDeclaration<ListCategorySelector, never>;
307
+ static ɵcmp: i0.ɵɵComponentDeclaration<ListCategorySelector, "lib-list-category-selector", never, { "config": { "alias": "config"; "required": false; }; "selectedCategory": { "alias": "selectedCategory"; "required": false; }; }, { "selectedCategoryChange": "selectedCategoryChange"; }, never, never, true, never>;
308
+ }
182
309
 
183
310
  declare class CsvExportService {
184
311
  private snackbar;
312
+ private translate;
185
313
  private encoders;
186
314
  constructor();
187
315
  private loadOptionalEncoders;
@@ -194,24 +322,33 @@ declare class CsvExportService {
194
322
  static ɵprov: i0.ɵɵInjectableDeclaration<CsvExportService>;
195
323
  }
196
324
 
197
- declare class NgxThinAdminList implements OnChanges, OnInit {
325
+ declare class NgxThinAdminList<T = any> implements OnChanges, OnInit {
198
326
  /**
199
327
  * Config for list
200
328
  */
201
- listConfig?: NgxThinAdminListConfig;
329
+ listConfig?: NgxThinAdminListConfig<T>;
202
330
  /**
203
331
  * Config for category selector. If provided, a category selector will be displayed in the UI.
204
332
  */
205
333
  categorySelectorConfig?: NgxThinAdminCategorySelectorConfig;
334
+ /**
335
+ * Config for item deleter (If provided, item deletion feature is enabled)
336
+ * It works by calling openItemDeletionDialog(row) from the click handler of the column definition.
337
+ */
338
+ itemDeleterConfig?: NgxThinAdminItemDeleterConfig;
206
339
  /**
207
340
  * Column schema (extended type of MtxGridColumn)
208
341
  * @see https://ng-matero.github.io/extensions/components/grid/api
209
342
  */
210
- listColumns?: MtxGridColumn[];
343
+ listColumns?: (NgxThinAdminListColumn<T> | MtxGridColumn)[];
211
344
  /**
212
345
  * Query (Optional)
213
346
  */
214
347
  query: NgxThinAdminListQuery;
348
+ /**
349
+ * Output query
350
+ */
351
+ queryChange: EventEmitter<NgxThinAdminListQuery>;
215
352
  /**
216
353
  * Fetcher function to retrieve list data.
217
354
  * This should be provided as part of listConfig.
@@ -222,7 +359,7 @@ declare class NgxThinAdminList implements OnChanges, OnInit {
222
359
  */
223
360
  isLoading: boolean;
224
361
  gridColumns: MtxGridColumn[];
225
- gridData: any[];
362
+ gridData: T[];
226
363
  totalCount: number;
227
364
  /**
228
365
  * Internal state for category list
@@ -238,27 +375,41 @@ declare class NgxThinAdminList implements OnChanges, OnInit {
238
375
  * Template for cells
239
376
  */
240
377
  cellTplWithLink: TemplateRef<any>;
378
+ /**
379
+ * Category Selector
380
+ */
381
+ categorySelector?: ListCategorySelector;
241
382
  /**
242
383
  * Services
243
384
  */
244
385
  private cdr;
386
+ private translate;
387
+ private snackbar;
245
388
  csvExportService: CsvExportService;
246
- ngOnChanges(changes: SimpleChanges<NgxThinAdminList>): void;
389
+ private dialog;
390
+ t(key: NgxThinAdminI18nKey, params?: Record<string, string | number | undefined>): string;
391
+ ngOnChanges(changes: SimpleChanges<NgxThinAdminList<T>>): void;
392
+ private buildGridColumns;
247
393
  fetchList(): Promise<void>;
248
394
  clearFilters(): void;
249
395
  onKeywordInput(): void;
250
396
  exportAsCsv(encoderKey: 'utf8' | string): Promise<void>;
397
+ getColumnLabel(columnName: string): string | rxjs.Observable<string>;
398
+ getColumnValueLabel(columnName: string, value: string): any;
251
399
  onPageChange(event: PageEvent): void;
252
400
  onSelectedCategoryChange($event: (NgxThinAdminCategory | undefined)[]): void;
253
- static ɵfac: i0.ɵɵFactoryDeclaration<NgxThinAdminList, never>;
254
- static ɵcmp: i0.ɵɵComponentDeclaration<NgxThinAdminList, "ngx-thin-admin-list", never, { "listConfig": { "alias": "listConfig"; "required": false; }; "categorySelectorConfig": { "alias": "categorySelectorConfig"; "required": false; }; "listColumns": { "alias": "listColumns"; "required": false; }; "query": { "alias": "query"; "required": false; }; }, {}, never, never, true, never>;
401
+ openItemDeletionDialog(item: any): Promise<void>;
402
+ deleteItem(id: string, label: string): Promise<void>;
403
+ openItemCategoryChangeDialog(item: any): Promise<void>;
404
+ static ɵfac: i0.ɵɵFactoryDeclaration<NgxThinAdminList<any>, never>;
405
+ static ɵcmp: i0.ɵɵComponentDeclaration<NgxThinAdminList<any>, "ngx-thin-admin-list", never, { "listConfig": { "alias": "listConfig"; "required": false; }; "categorySelectorConfig": { "alias": "categorySelectorConfig"; "required": false; }; "itemDeleterConfig": { "alias": "itemDeleterConfig"; "required": false; }; "listColumns": { "alias": "listColumns"; "required": false; }; "query": { "alias": "query"; "required": false; }; }, { "queryChange": "queryChange"; }, never, never, true, never>;
255
406
  }
256
407
 
257
- declare class NgxThinAdminEditor implements OnChanges {
408
+ declare class NgxThinAdminEditor<T = any> implements OnChanges {
258
409
  /**
259
410
  * Config for editor
260
411
  */
261
- editorConfig?: NgxThinAdminEditorConfig;
412
+ editorConfig?: NgxThinAdminEditorConfig<T>;
262
413
  /**
263
414
  * Fields for formly form
264
415
  */
@@ -267,26 +418,56 @@ declare class NgxThinAdminEditor implements OnChanges {
267
418
  * Id of the item being edited.
268
419
  */
269
420
  itemId?: string;
421
+ /**
422
+ * Config for item deleter
423
+ */
424
+ itemDeleterConfig?: NgxThinAdminItemDeleterConfig;
270
425
  /**
271
426
  * Internal state for form
272
427
  */
273
428
  isSaving: boolean;
274
429
  isLoading: boolean;
275
430
  form: FormGroup<{}>;
276
- data: any;
277
- formData: any;
431
+ data: Partial<T>;
432
+ formData: Partial<T>;
433
+ /**
434
+ * For history back
435
+ */
436
+ windowHistory: History;
278
437
  /**
279
438
  * Services
280
439
  */
281
440
  private snackbar;
282
441
  private cdr;
283
- ngOnChanges(changes: SimpleChanges<NgxThinAdminEditor>): void;
442
+ private translate;
443
+ private dialog;
444
+ private router;
445
+ t(key: NgxThinAdminI18nKey, params?: Record<string, string | number | undefined>): string;
446
+ get editorItemType(): string;
447
+ ngOnChanges(changes: SimpleChanges<NgxThinAdminEditor<T>>): void;
284
448
  overwriteFieldProps(field: NgxThinAdminEditorField): NgxThinAdminEditorField;
285
449
  fetchItem(): Promise<void>;
286
450
  save(): Promise<void>;
287
- static ɵfac: i0.ɵɵFactoryDeclaration<NgxThinAdminEditor, never>;
288
- static ɵcmp: i0.ɵɵComponentDeclaration<NgxThinAdminEditor, "ngx-thin-admin-editor", never, { "editorConfig": { "alias": "editorConfig"; "required": false; }; "editorFields": { "alias": "editorFields"; "required": false; }; "itemId": { "alias": "itemId"; "required": false; }; }, {}, never, never, true, never>;
451
+ openDeletionDialog(): Promise<void>;
452
+ deleteItem(id: string, label: string): Promise<void>;
453
+ static ɵfac: i0.ɵɵFactoryDeclaration<NgxThinAdminEditor<any>, never>;
454
+ static ɵcmp: i0.ɵɵComponentDeclaration<NgxThinAdminEditor<any>, "ngx-thin-admin-editor", never, { "editorConfig": { "alias": "editorConfig"; "required": false; }; "editorFields": { "alias": "editorFields"; "required": false; }; "itemId": { "alias": "itemId"; "required": false; }; "itemDeleterConfig": { "alias": "itemDeleterConfig"; "required": false; }; }, {}, never, never, true, never>;
289
455
  }
290
456
 
291
- export { NgxThinAdminEditor, NgxThinAdminList };
292
- export type { ListFetcher, NgxThinAdminCategory, NgxThinAdminCategoryListResponse, NgxThinAdminCategorySelectorConfig, NgxThinAdminEditorConfig, NgxThinAdminEditorField, NgxThinAdminFieldConfig, NgxThinAdminFieldProps, NgxThinAdminListColumn, NgxThinAdminListConfig, NgxThinAdminListCreateButtonConfig, NgxThinAdminListCsvExportButtonConfig, NgxThinAdminListQuery, NgxThinAdminListResponse };
457
+ /**
458
+ * Injection token for providing extra formly config to NgxThinAdminEditor.
459
+ * Use provideNgxThinAdminFormlyConfig() to register from the consumer app.
460
+ */
461
+ declare const NGX_THIN_ADMIN_EXTRA_FORMLY_CONFIG: InjectionToken<ConfigOption>;
462
+ /**
463
+ * Returns a provider that adds custom formly types, wrappers, etc. to NgxThinAdminEditor.
464
+ *
465
+ * @example
466
+ * provideNgxThinAdminFormlyConfig({
467
+ * types: [{ name: 'qrcode', component: QrcodeFieldComponent }],
468
+ * })
469
+ */
470
+ declare function provideNgxThinAdminFormlyConfig(config: ConfigOption): Provider;
471
+
472
+ export { NGX_THIN_ADMIN_EXTRA_FORMLY_CONFIG, NGX_THIN_ADMIN_TRANSLATE, NgxThinAdminEditor, NgxThinAdminList, provideNgxThinAdminFormlyConfig, provideNgxThinAdminI18n };
473
+ export type { ListFetcher, NgxThinAdminCategory, NgxThinAdminCategoryListResponse, NgxThinAdminCategorySelectorConfig, NgxThinAdminEditorBackButtonConfig, NgxThinAdminEditorConfig, NgxThinAdminEditorField, NgxThinAdminFieldConfig, NgxThinAdminFieldProps, NgxThinAdminI18nConfig, NgxThinAdminI18nKey, NgxThinAdminI18nParams, NgxThinAdminItemDeleterConfig, NgxThinAdminListColumn, NgxThinAdminListConfig, NgxThinAdminListCreateButtonConfig, NgxThinAdminListCsvExportButtonConfig, NgxThinAdminListQuery, NgxThinAdminListResponse, NgxThinAdminLocale, NgxThinAdminTranslate };