@smartsoft001/crud-shell-angular 2.76.0 → 2.80.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.
Files changed (75) hide show
  1. package/fesm2022/smartsoft001-crud-shell-angular.mjs +2840 -0
  2. package/fesm2022/smartsoft001-crud-shell-angular.mjs.map +1 -0
  3. package/index.d.ts +632 -0
  4. package/package.json +18 -3
  5. package/.storybook/addons.js +0 -1
  6. package/.storybook/config.js +0 -5
  7. package/.storybook/tsconfig.json +0 -8
  8. package/.storybook/webpack.config.js +0 -7
  9. package/jest.config.ts +0 -38
  10. package/ng-package.json +0 -7
  11. package/project.json +0 -49
  12. package/src/index.ts +0 -13
  13. package/src/lib/+state/crud.facade.ts +0 -82
  14. package/src/lib/+state/crud.methods.ts +0 -258
  15. package/src/lib/+state/crud.store.ts +0 -77
  16. package/src/lib/components/components.module.ts +0 -58
  17. package/src/lib/components/export/export.component.ts +0 -69
  18. package/src/lib/components/filter/base/base.component.ts +0 -175
  19. package/src/lib/components/filter/check/check.component.scss +0 -25
  20. package/src/lib/components/filter/check/check.component.ts +0 -72
  21. package/src/lib/components/filter/date/date.component.html +0 -30
  22. package/src/lib/components/filter/date/date.component.ts +0 -70
  23. package/src/lib/components/filter/date-time/date-time.component.html +0 -62
  24. package/src/lib/components/filter/date-time/date-time.component.ts +0 -56
  25. package/src/lib/components/filter/date-with-edit/date-with-edit.component.html +0 -109
  26. package/src/lib/components/filter/date-with-edit/date-with-edit.component.ts +0 -70
  27. package/src/lib/components/filter/filter.component.html +0 -52
  28. package/src/lib/components/filter/filter.component.ts +0 -34
  29. package/src/lib/components/filter/flag/flag.component.ts +0 -55
  30. package/src/lib/components/filter/index.ts +0 -9
  31. package/src/lib/components/filter/int/int.component.html +0 -74
  32. package/src/lib/components/filter/int/int.component.ts +0 -57
  33. package/src/lib/components/filter/radio/radio.component.ts +0 -74
  34. package/src/lib/components/filter/text/text.component.ts +0 -46
  35. package/src/lib/components/filters/filters.component.scss +0 -150
  36. package/src/lib/components/filters/filters.component.ts +0 -157
  37. package/src/lib/components/filters-config/filters-config.component.ts +0 -69
  38. package/src/lib/components/group/group.component.ts +0 -93
  39. package/src/lib/components/index.ts +0 -7
  40. package/src/lib/components/multiselect/multiselect.component.html +0 -41
  41. package/src/lib/components/multiselect/multiselect.component.scss +0 -125
  42. package/src/lib/components/multiselect/multiselect.component.ts +0 -104
  43. package/src/lib/crud-full.module.ts +0 -51
  44. package/src/lib/crud.config.ts +0 -79
  45. package/src/lib/crud.module.ts +0 -72
  46. package/src/lib/factories/list-pagination/list-pagination.factory.ts +0 -77
  47. package/src/lib/models/index.ts +0 -1
  48. package/src/lib/models/interfaces.ts +0 -34
  49. package/src/lib/pages/index.ts +0 -6
  50. package/src/lib/pages/item/base/base.component.ts +0 -54
  51. package/src/lib/pages/item/item.component.ts +0 -513
  52. package/src/lib/pages/item/standard/standard.component.scss +0 -0
  53. package/src/lib/pages/item/standard/standard.component.ts +0 -50
  54. package/src/lib/pages/list/base/base.component.ts +0 -29
  55. package/src/lib/pages/list/list.component.stories.ts +0 -77
  56. package/src/lib/pages/list/list.component.ts +0 -438
  57. package/src/lib/pages/list/standard/standard.component.ts +0 -42
  58. package/src/lib/pipes/form-options/form-options.pipe.ts +0 -61
  59. package/src/lib/pipes/index.ts +0 -2
  60. package/src/lib/pipes/pipes.module.ts +0 -9
  61. package/src/lib/providers/model-possibilities/model-possibilities.provider.ts +0 -19
  62. package/src/lib/services/crud/crud.service.spec.ts +0 -303
  63. package/src/lib/services/crud/crud.service.ts +0 -178
  64. package/src/lib/services/list-group/list-group.service.spec.ts +0 -87
  65. package/src/lib/services/list-group/list-group.service.ts +0 -65
  66. package/src/lib/services/page/page.service.spec.ts +0 -143
  67. package/src/lib/services/page/page.service.ts +0 -44
  68. package/src/lib/services/search/search.service.spec.ts +0 -134
  69. package/src/lib/services/search/search.service.ts +0 -42
  70. package/test-setup.ts +0 -0
  71. package/tsconfig.json +0 -13
  72. package/tsconfig.lib.json +0 -31
  73. package/tsconfig.lib.prod.json +0 -11
  74. package/tsconfig.spec.json +0 -10
  75. package/tslint.json +0 -10
@@ -1,7 +0,0 @@
1
- const rootWebpackConfig = require('../../../../../.storybook/webpack.config');
2
- // Export a function. Accept the base config as the only param.
3
- module.exports = async ({ config, mode }) => {
4
- config = await rootWebpackConfig({ config, mode });
5
-
6
- return config;
7
- };
package/jest.config.ts DELETED
@@ -1,38 +0,0 @@
1
- import type { Config } from 'jest';
2
-
3
- const config: Config = {
4
- globals: {},
5
- setupFilesAfterEnv: ['<rootDir>/test-setup.ts'],
6
- transform: {
7
- '^.+\\.(ts|js|mjs|html)$': [
8
- 'jest-preset-angular',
9
- {
10
- tsconfig: '<rootDir>/tsconfig.spec.json',
11
- stringifyContentPathRegex: '\\.(html|svg)$',
12
- },
13
- ],
14
- },
15
- snapshotSerializers: [
16
- 'jest-preset-angular/build/serializers/no-ng-attributes',
17
- 'jest-preset-angular/build/serializers/ng-snapshot',
18
- 'jest-preset-angular/build/serializers/html-comment',
19
- ],
20
- displayName: 'crud-shell-angular',
21
- coverageDirectory: '../../../../coverage/packages/crud/shell/angular',
22
- preset: 'jest-preset-angular',
23
- moduleFileExtensions: ['ts', 'html', 'js', 'json', 'mjs'],
24
- transformIgnorePatterns: ['node_modules/(?!(@angular|@ngrx)/)'],
25
- snapshotFormat: { escapeString: true, printBasicPrototype: true },
26
- moduleNameMapper: {
27
- '^@smartsoft001/angular$':
28
- '<rootDir>/../../../../packages/shared/angular/src/index.ts',
29
- '^@smartsoft001/angular/(.*)$':
30
- '<rootDir>/../../../../packages/shared/angular/src/$1',
31
- '^@smartsoft001/models$':
32
- '<rootDir>/../../../../packages/shared/models/src/index.ts',
33
- '^@smartsoft001/models/(.*)$':
34
- '<rootDir>/../../../../packages/shared/models/src/$1',
35
- },
36
- };
37
-
38
- export default config;
package/ng-package.json DELETED
@@ -1,7 +0,0 @@
1
- {
2
- "$schema": "../../../../node_modules/ng-packagr/ng-package.schema.json",
3
- "dest": "../../../../dist/packages/crud/shell/angular",
4
- "lib": {
5
- "entryFile": "src/index.ts"
6
- }
7
- }
package/project.json DELETED
@@ -1,49 +0,0 @@
1
- {
2
- "name": "crud-shell-angular",
3
- "$schema": "../../../../node_modules/nx/schemas/project-schema.json",
4
- "projectType": "library",
5
- "sourceRoot": "packages/crud/shell/angular/src",
6
- "prefix": "smart",
7
- "targets": {
8
- "lint": {
9
- "executor": "@nx/eslint:lint",
10
- "outputs": ["{options.outputFile}"],
11
- "options": {
12
- "lintFilePatterns": [
13
- "packages/crud/shell/angular/**/*.{ts,tsx,js,jsx}",
14
- "packages/crud/shell/angular/package.json"
15
- ],
16
- "tsConfig": [
17
- "packages/crud/shell/angular/tsconfig.lib.json",
18
- "packages/crud/shell/angular/tsconfig.spec.json"
19
- ]
20
- }
21
- },
22
- "test": {
23
- "executor": "@nx/jest:jest",
24
- "options": {
25
- "jestConfig": "packages/crud/shell/angular/jest.config.ts",
26
- "passWithNoTests": true
27
- },
28
- "outputs": ["{workspaceRoot}/coverage/packages/crud/shell/angular"]
29
- },
30
- "build": {
31
- "executor": "@nx/angular:package",
32
- "options": {
33
- "tsConfig": "packages/crud/shell/angular/tsconfig.lib.json",
34
- "project": "packages/crud/shell/angular/ng-package.json"
35
- },
36
- "configurations": {
37
- "production": {
38
- "tsConfig": "packages/crud/shell/angular/tsconfig.lib.prod.json"
39
- }
40
- }
41
- }
42
- },
43
- "generators": {
44
- "@schematics/angular:component": {
45
- "style": "scss"
46
- }
47
- },
48
- "tags": ["scope:crud", "type:shell"]
49
- }
package/src/index.ts DELETED
@@ -1,13 +0,0 @@
1
- export * from './lib/components';
2
- export * from './lib/crud.config';
3
- export * from './lib/crud.module';
4
- export * from './lib/crud-full.module';
5
- export * from './lib/factories/list-pagination/list-pagination.factory';
6
- export * from './lib/pipes';
7
- export * from './lib/services/crud/crud.service';
8
- export * from './lib/services/page/page.service';
9
- export * from './lib/services/search/search.service';
10
- export * from './lib/+state/crud.facade';
11
- export * from './lib/models';
12
- export * from './lib/pages';
13
- export * from './lib/providers/model-possibilities/model-possibilities.provider';
@@ -1,82 +0,0 @@
1
- import { computed, Injectable, Signal } from '@angular/core';
2
-
3
- import { IEntity } from '@smartsoft001/domain-core';
4
-
5
- import { CrudConfig } from '../crud.config';
6
- import { ICrudCreateManyOptions, ICrudFilter } from '../models';
7
- import { createCrudFeatureStore } from './crud.store';
8
-
9
- @Injectable()
10
- export class CrudFacade<T extends IEntity<string>> {
11
- private store = createCrudFeatureStore<T>();
12
-
13
- loaded: Signal<boolean> = this.store.getLoaded;
14
- loading: Signal<boolean> = computed(() => !this.store.getLoaded());
15
- selected: Signal<T> = this.store.getSelected;
16
- multiSelected: Signal<T[]> = this.store.getMultiSelected;
17
- list: Signal<T[]> = this.store.getList;
18
- filter: Signal<ICrudFilter> = this.store.getFilter;
19
- totalCount: Signal<number> = this.store.getTotalCount;
20
- links: Signal<any> = this.store.getLinks;
21
- error: Signal<any> = this.store.getError;
22
-
23
- constructor(private config: CrudConfig<T>) {}
24
-
25
- create(item: T): void {
26
- this.store.create(item);
27
- }
28
-
29
- createMany(items: Array<T>, options: ICrudCreateManyOptions): void {
30
- this.store.createMany({ items, options });
31
- }
32
-
33
- read(filter: ICrudFilter = null): void {
34
- let baseQuery = [];
35
- if (this.config.baseQuery) {
36
- baseQuery = this.config.baseQuery;
37
- }
38
-
39
- const fullFilter = {
40
- ...(filter ? filter : {}),
41
- query: filter && filter.query ? filter.query : baseQuery,
42
- };
43
-
44
- this.store.read(fullFilter);
45
- }
46
-
47
- clear(): void {
48
- this.store.clear();
49
- }
50
-
51
- select(id: string): void {
52
- this.store.select(id);
53
- }
54
-
55
- unselect(): void {
56
- this.store.unselect();
57
- }
58
-
59
- multiSelect(items: Array<T>): void {
60
- this.store.multiSelect(items);
61
- }
62
-
63
- update(item: T): void {
64
- this.store.update(item);
65
- }
66
-
67
- export(filter: ICrudFilter = null, format = null): void {
68
- this.store.export(filter, format);
69
- }
70
-
71
- updatePartial(item: Partial<T> & { id: string }): void {
72
- this.store.updatePartial(item);
73
- }
74
-
75
- updatePartialMany(items: (Partial<T> & { id: string })[]) {
76
- this.store.updatePartialMany(items);
77
- }
78
-
79
- delete(id: string): void {
80
- this.store.delete(id);
81
- }
82
- }
@@ -1,258 +0,0 @@
1
- import { inject } from '@angular/core';
2
- import { patchState } from '@ngrx/signals';
3
-
4
- import { PaginationMode } from '@smartsoft001/angular';
5
- import { IEntity } from '@smartsoft001/domain-core';
6
-
7
- import { ICrudCreateManyOptions, ICrudFilter } from '../models';
8
- import { initialState } from './crud.store';
9
- import { CrudService } from '../services/crud/crud.service';
10
-
11
- // "Actions, Reducers, Effects" in a normal store
12
- export function CrudMethodsFactory<T extends IEntity<string>>() {
13
- return (store: any, crudService = inject(CrudService<T>)) => {
14
- const methods = {
15
- async create(item: T) {
16
- patchState(store, {
17
- loaded: false,
18
- error: null,
19
- });
20
-
21
- try {
22
- await crudService.create(item);
23
- await this.createSuccess();
24
- } catch (error) {
25
- methods.defaultFailure(error);
26
- }
27
- },
28
-
29
- async createSuccess() {
30
- patchState(store, {
31
- loaded: true,
32
- error: null,
33
- });
34
-
35
- await methods.read(
36
- store.filter ? { ...store.filter, offset: 0 } : null,
37
- );
38
- },
39
-
40
- async createMany(data: { items: T[]; options: ICrudCreateManyOptions }) {
41
- patchState(store, {
42
- loaded: false,
43
- error: null,
44
- });
45
-
46
- try {
47
- await crudService.createMany(data.items, data.options);
48
- await methods.createManySuccess();
49
- } catch (e) {
50
- methods.defaultFailure(e);
51
- }
52
- },
53
-
54
- async createManySuccess() {
55
- patchState(store, {
56
- loaded: true,
57
- error: null,
58
- });
59
-
60
- await methods.read(
61
- store.filter ? { ...store.filter, offset: 0 } : null,
62
- );
63
- },
64
-
65
- async export(filter: ICrudFilter, format: any) {
66
- patchState(store, {
67
- loaded: false,
68
- });
69
-
70
- try {
71
- await crudService.exportList(filter, format);
72
- methods.exportSuccess();
73
- } catch (e) {
74
- methods.defaultFailure(e);
75
- }
76
- },
77
-
78
- exportSuccess() {
79
- patchState(store, {
80
- loaded: true,
81
- });
82
- },
83
-
84
- async read(filter: ICrudFilter) {
85
- patchState(store, {
86
- loaded: false,
87
- filter,
88
- error: null,
89
- totalCount: null,
90
- links: null,
91
- });
92
-
93
- try {
94
- const result = await crudService.getList<T>(filter);
95
- methods.readSuccess<T>({
96
- list: result.data,
97
- filter,
98
- totalCount: result.totalCount,
99
- links: result.links,
100
- });
101
- } catch (error) {
102
- methods.defaultFailure(error);
103
- }
104
- },
105
-
106
- readSuccess<T>(data: {
107
- list: T[];
108
- filter?: ICrudFilter;
109
- totalCount?: number;
110
- links?: any;
111
- }) {
112
- let list = [];
113
-
114
- if (
115
- data.filter?.offset &&
116
- store.list() &&
117
- data.filter.paginationMode !== PaginationMode.singlePage
118
- ) {
119
- list = [...store.list(), ...data.list];
120
- } else {
121
- list = data.list;
122
- }
123
-
124
- patchState(store, {
125
- loaded: true,
126
- list,
127
- totalCount: data.totalCount,
128
- links: data.links,
129
- error: null,
130
- });
131
- },
132
-
133
- clear() {
134
- store.set(() => ({ ...initialState }));
135
- },
136
-
137
- async select(id: string) {
138
- patchState(store, {
139
- loaded: false,
140
- selected: null,
141
- error: null,
142
- });
143
-
144
- try {
145
- const result = await crudService.getById(id);
146
- methods.selectSuccess(result);
147
- } catch (e) {
148
- methods.defaultFailure(e);
149
- }
150
- },
151
-
152
- selectSuccess(selected: T) {
153
- patchState(store, {
154
- loaded: true,
155
- selected,
156
- error: null,
157
- });
158
- },
159
-
160
- unselect() {
161
- patchState(store, {
162
- loaded: true,
163
- selected: null,
164
- error: null,
165
- });
166
- },
167
-
168
- multiSelect(items: Array<T>) {
169
- patchState(store, {
170
- multiSelected: [...items],
171
- });
172
- },
173
-
174
- async update(item: Partial<T> & { id: string }) {
175
- patchState(store, {
176
- loaded: false,
177
- error: null,
178
- });
179
-
180
- try {
181
- await crudService.updatePartial(item);
182
- await methods.updateSuccess(item.id);
183
- } catch (e) {
184
- methods.defaultFailure(e);
185
- }
186
- },
187
-
188
- async updateSuccess(id: string) {
189
- await methods.read({ ...store.filter, offset: 0 });
190
- await methods.select(id);
191
- },
192
-
193
- async updatePartial(item: Partial<T> & { id: string }) {
194
- patchState(store, {
195
- loaded: false,
196
- error: null,
197
- });
198
-
199
- try {
200
- await crudService.updatePartial(item);
201
- await methods.updatePartialSuccess(item.id);
202
- } catch (e) {
203
- methods.defaultFailure(e);
204
- }
205
- },
206
-
207
- async updatePartialSuccess(id: string) {
208
- await methods.read({ ...store.filter, offset: 0 });
209
- await methods.select(id);
210
- },
211
-
212
- async updatePartialMany(items: Array<Partial<T> & { id: string }>) {
213
- patchState(store, {
214
- loaded: false,
215
- error: null,
216
- });
217
-
218
- try {
219
- await crudService.updatePartialMany(items);
220
- await methods.updatePartialManySuccess();
221
- } catch (e) {
222
- methods.defaultFailure(e);
223
- }
224
- },
225
-
226
- async updatePartialManySuccess() {
227
- await methods.read({ ...store.filter, offset: 0 });
228
- },
229
-
230
- async delete(id: string) {
231
- patchState(store, {
232
- loaded: false,
233
- error: null,
234
- });
235
-
236
- try {
237
- await crudService.delete(id);
238
- await methods.deleteSuccess();
239
- } catch (e) {
240
- methods.defaultFailure(e);
241
- }
242
- },
243
-
244
- async deleteSuccess() {
245
- await methods.read({ ...store.filter, offset: 0 });
246
- },
247
-
248
- defaultFailure(error: string) {
249
- patchState(store, {
250
- loaded: true,
251
- error,
252
- });
253
- },
254
- };
255
-
256
- return methods;
257
- };
258
- }
@@ -1,77 +0,0 @@
1
- import { computed, Signal } from '@angular/core';
2
- import {
3
- signalStore,
4
- withState,
5
- withMethods,
6
- withComputed,
7
- } from '@ngrx/signals';
8
-
9
- import { IEntity } from '@smartsoft001/domain-core';
10
-
11
- import { ICrudCreateManyOptions, ICrudFilter } from '../models';
12
- import { CrudMethodsFactory } from './crud.methods';
13
-
14
- export interface CrudState<T> {
15
- selected?: T;
16
- multiSelected?: Array<T>;
17
- list?: T[];
18
- totalCount?: number;
19
- filter?: ICrudFilter;
20
- links?: any;
21
- loaded: boolean; // has the Auth list been loaded
22
- error?: string | null; // last none error (if any)
23
- }
24
-
25
- export const initialState: CrudState<any> = {
26
- loaded: false,
27
- };
28
-
29
- interface CrudStore<T> extends CrudState<T> {
30
- // State properties are inherited from CrudState
31
-
32
- // Computed properties
33
- getError: Signal<string | null | undefined>;
34
- getLoaded: Signal<boolean>;
35
- getSelected: Signal<T | undefined>;
36
- getMultiSelected: Signal<Array<T> | undefined>;
37
- getList: Signal<Array<T> | undefined>;
38
- getTotalCount: Signal<number | undefined>;
39
- getLinks: Signal<any>;
40
- getFilter: Signal<ICrudFilter | undefined>;
41
-
42
- // Methods
43
- create(item: T): void;
44
- createMany(data: { items: T[]; options: ICrudCreateManyOptions }): void;
45
- export(filter: ICrudFilter, format: any): void;
46
- read(filter: ICrudFilter): void;
47
- clear(): void;
48
- select(id: string): void;
49
- multiSelect(items: Array<T>): void;
50
- unselect(): void;
51
- update(item: Partial<T> & { id: string }): void;
52
- updatePartial(item: Partial<T> & { id: string }): void;
53
- updatePartialMany(items: Array<Partial<T> & { id: string }>): void;
54
- delete(id: string): void;
55
- }
56
-
57
- export function createCrudFeatureStore<T extends IEntity<string>>() {
58
- return signalStore(
59
- { providedIn: 'root' },
60
- withState<CrudState<T>>(initialState),
61
- withComputed((store) => ({
62
- getError: computed(() => store.error()),
63
- getLoaded: computed(() => store.loaded()),
64
- getSelected: computed(() => store.selected()),
65
- getMultiSelected: computed(() => store.multiSelected()),
66
- getList: computed(() => store.list()),
67
- getTotalCount: computed(() => store.totalCount()),
68
- getLinks: computed(() => store.links()),
69
- getFilter: computed(() => store.filter()),
70
- })),
71
- withMethods(CrudMethodsFactory<T>()),
72
- ) as unknown as CrudStore<T>;
73
- }
74
-
75
- export type CrudFeatureStore<T extends IEntity<string>> = ReturnType<
76
- typeof createCrudFeatureStore<T>
77
- >;
@@ -1,58 +0,0 @@
1
- import { CommonModule } from '@angular/common';
2
- import { NgModule } from '@angular/core';
3
- import { FormsModule } from '@angular/forms';
4
- import { DynamicIoModule } from 'ng-dynamic-component';
5
-
6
- import { SharedModule } from '@smartsoft001/angular';
7
-
8
- import { ExportComponent } from './export/export.component';
9
- import {
10
- FilterComponent,
11
- FilterDateComponent,
12
- FilterDateWithEditComponent,
13
- FilterFlagComponent,
14
- FilterRadioComponent,
15
- FilterTextComponent,
16
- FilterCheckComponent,
17
- FilterIntComponent,
18
- FilterDateTimeComponent,
19
- } from './filter';
20
- import { CrudPipesModule } from '../pipes';
21
- import { FiltersComponent } from './filters/filters.component';
22
- import { FiltersConfigComponent } from './filters-config/filters-config.component';
23
- import { MultiselectComponent } from './multiselect/multiselect.component';
24
- import { CrudFacade } from '../+state/crud.facade';
25
- import { GroupComponent } from './group/group.component';
26
- import { CrudListPaginationFactory } from '../factories/list-pagination/list-pagination.factory';
27
- import { CrudService } from '../services/crud/crud.service';
28
-
29
- const COMPONENTS = [
30
- ExportComponent,
31
- FilterComponent,
32
- FilterTextComponent,
33
- FiltersConfigComponent,
34
- FilterDateComponent,
35
- FilterDateWithEditComponent,
36
- FilterDateTimeComponent,
37
- FilterRadioComponent,
38
- FiltersComponent,
39
- FilterFlagComponent,
40
- FilterCheckComponent,
41
- FilterIntComponent,
42
- MultiselectComponent,
43
- GroupComponent,
44
- ];
45
-
46
- @NgModule({
47
- imports: [
48
- ...COMPONENTS,
49
- SharedModule,
50
- CrudPipesModule,
51
- FormsModule,
52
- CommonModule,
53
- DynamicIoModule,
54
- ],
55
- exports: [CrudPipesModule, ...COMPONENTS],
56
- providers: [CrudService, CrudFacade, CrudListPaginationFactory],
57
- })
58
- export class CrudComponentsModule {}
@@ -1,69 +0,0 @@
1
- import { Component, ElementRef, inject, OnInit } from '@angular/core';
2
-
3
- import {
4
- BaseComponent,
5
- ButtonComponent,
6
- IButtonOptions,
7
- PopoverService,
8
- StyleService,
9
- } from '@smartsoft001/angular';
10
- import { IEntity } from '@smartsoft001/domain-core';
11
-
12
- import { CrudFacade } from '../../+state/crud.facade';
13
-
14
- @Component({
15
- selector: 'smart-crud-export',
16
- template: `
17
- <div class="p-5">
18
- <p class="my-2.5 mx-0">
19
- <smart-button [options]="buttonExportCsvOptions" class="w-full block"
20
- >CSV</smart-button
21
- >
22
- </p>
23
- <p>
24
- <smart-button [options]="buttonExportXlsxOptions" class="w-full block"
25
- >XLSX</smart-button
26
- >
27
- </p>
28
- </div>
29
- `,
30
- imports: [ButtonComponent],
31
- })
32
- export class ExportComponent<T extends IEntity<string>>
33
- extends BaseComponent
34
- implements OnInit
35
- {
36
- private facade = inject(CrudFacade<T>);
37
- private popoverService = inject(PopoverService);
38
- private styleService = inject(StyleService);
39
- private elementRef = inject(ElementRef);
40
-
41
- buttonExportCsvOptions: IButtonOptions = this.initButtonExportOptions('csv');
42
- buttonExportXlsxOptions: IButtonOptions =
43
- this.initButtonExportOptions('xlsx');
44
-
45
- ngOnInit(): void {
46
- this.styleService.init(this.elementRef);
47
- }
48
-
49
- private initButtonExportOptions(format: string): IButtonOptions {
50
- return {
51
- click: () => {
52
- this.facade.export(
53
- {
54
- ...this.facade.filter(),
55
- offset: null,
56
- limit: null,
57
- },
58
- format,
59
- );
60
-
61
- const loading = this.facade.loading();
62
- if (loading) return;
63
- this.popoverService.close();
64
- },
65
- loading: this.facade.loading,
66
- expand: 'block',
67
- };
68
- }
69
- }