cat-documents-ng 0.0.3 → 0.0.5

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 (66) hide show
  1. package/jest.config.mjs +18 -0
  2. package/ng-package.json +11 -0
  3. package/package.json +5 -11
  4. package/setup-jest.ts +10 -0
  5. package/src/assets/config/app.config.json +4 -0
  6. package/src/lib/document/components/document-container/document-container.component.html +6 -0
  7. package/src/lib/document/components/document-container/document-container.component.scss +0 -0
  8. package/src/lib/document/components/document-container/document-container.component.spec.ts +0 -0
  9. package/src/lib/document/components/document-container/document-container.component.ts +82 -0
  10. package/src/lib/document/components/document-list/document-list.component.html +35 -0
  11. package/src/lib/document/components/document-list/document-list.component.scss +12 -0
  12. package/src/lib/document/components/document-list/document-list.component.spec.ts +0 -0
  13. package/src/lib/document/components/document-list/document-list.component.ts +73 -0
  14. package/src/lib/document/components/document-list-item/document-list-item.component.html +33 -0
  15. package/src/lib/document/components/document-list-item/document-list-item.component.scss +22 -0
  16. package/src/lib/document/components/document-list-item/document-list-item.component.spec.ts +23 -0
  17. package/src/lib/document/components/document-list-item/document-list-item.component.ts +40 -0
  18. package/src/lib/document/components/document-upload/document-upload.component.html +56 -0
  19. package/src/lib/document/components/document-upload/document-upload.component.scss +26 -0
  20. package/src/lib/document/components/document-upload/document-upload.component.spec.ts +24 -0
  21. package/src/lib/document/components/document-upload/document-upload.component.ts +184 -0
  22. package/src/lib/document/components/document-viewer/document-viewer.component.html +244 -0
  23. package/src/lib/document/components/document-viewer/document-viewer.component.scss +36 -0
  24. package/src/lib/document/components/document-viewer/document-viewer.component.spec.ts +21 -0
  25. package/src/lib/document/components/document-viewer/document-viewer.component.ts +125 -0
  26. package/src/lib/document/components/folder-block/folder-block.component.html +46 -0
  27. package/src/lib/document/components/folder-block/folder-block.component.scss +0 -0
  28. package/src/lib/document/components/folder-block/folder-block.component.spec.ts +0 -0
  29. package/{lib/document/components/folder-block/folder-block.component.d.ts → src/lib/document/components/folder-block/folder-block.component.ts} +26 -12
  30. package/src/lib/document/components/folder-container/folder-container.component.html +2 -0
  31. package/src/lib/document/components/folder-container/folder-container.component.scss +0 -0
  32. package/src/lib/document/components/folder-container/folder-container.component.spec.ts +0 -0
  33. package/src/lib/document/components/folder-container/folder-container.component.ts +29 -0
  34. package/src/lib/document/document.module.ts +191 -0
  35. package/src/lib/document/models/document.model.ts +39 -0
  36. package/{lib/document/models/folder.model.d.ts → src/lib/document/models/folder.model.ts} +10 -4
  37. package/src/lib/document/services/file-format.service.spec.ts +16 -0
  38. package/src/lib/document/services/file-format.service.ts +41 -0
  39. package/src/lib/document/state/document.query.ts +23 -0
  40. package/{lib/document/state/document.service.d.ts → src/lib/document/state/document.service.ts} +46 -15
  41. package/{lib/document/state/document.state.d.ts → src/lib/document/state/document.state.ts} +19 -10
  42. package/src/lib/document/state/document.store.ts +23 -0
  43. package/{public-api.d.ts → src/public-api.ts} +6 -1
  44. package/src/shared/constant/SHARED.ts +232 -0
  45. package/{Shared/constant/URLS.d.ts → src/shared/constant/URLS.ts} +6 -4
  46. package/src/shared/services/app-config.service.spec.ts +16 -0
  47. package/src/shared/services/app-config.service.ts +73 -0
  48. package/{Shared/services/global-error.handler.d.ts → src/shared/services/global-error.handler.ts} +11 -9
  49. package/tsconfig.lib.json +15 -0
  50. package/tsconfig.lib.prod.json +11 -0
  51. package/tsconfig.spec.json +15 -0
  52. package/Shared/constant/SHARED.d.ts +0 -150
  53. package/Shared/services/app-config.service.d.ts +0 -51
  54. package/fesm2022/cat-documents-ng.mjs +0 -1411
  55. package/fesm2022/cat-documents-ng.mjs.map +0 -1
  56. package/index.d.ts +0 -5
  57. package/lib/document/components/document-container/document-container.component.d.ts +0 -44
  58. package/lib/document/components/document-list/document-list.component.d.ts +0 -47
  59. package/lib/document/components/document-list-item/document-list-item.component.d.ts +0 -28
  60. package/lib/document/components/document-upload/document-upload.component.d.ts +0 -113
  61. package/lib/document/components/document-viewer/document-viewer.component.d.ts +0 -113
  62. package/lib/document/components/folder-container/folder-container.component.d.ts +0 -28
  63. package/lib/document/document.module.d.ts +0 -35
  64. package/lib/document/models/document.model.d.ts +0 -33
  65. package/lib/document/services/file-format.service.d.ts +0 -23
  66. package/lib/document/state/document.store.d.ts +0 -20
@@ -1,37 +1,51 @@
1
+ import { Component, Input } from '@angular/core';
1
2
  import { DocumentStore } from '../../state/document.store';
2
3
  import { FolderBlockModel } from '../../models/folder.model';
3
- import * as i0 from "@angular/core";
4
+ import { SHARED } from '../../../../Shared/constant/SHARED';
5
+
4
6
  /**
5
7
  * The `FolderBlockComponent` is responsible for displaying a block of folders and
6
8
  * providing filtering functionality based on folder IDs.
7
9
  *
8
- * It uses data from the `DocumentStore` and constants from the `SHARED` configuration
10
+ * It uses data from the `DocumentStore` and constants from the `SHARED` configuration
9
11
  * to display missing and pending file counts.
10
12
  */
11
- export declare class FolderBlockComponent {
12
- documentStore: DocumentStore;
13
+ @Component({
14
+ selector: 'lib-folder-block',
15
+ standalone: false,
16
+ templateUrl: './folder-block.component.html',
17
+ styleUrl: './folder-block.component.scss'
18
+ })
19
+ export class FolderBlockComponent {
13
20
  /**
14
21
  * Array of folder blocks data to display.
15
22
  * Each folder is represented as a `FolderBlockModel`.
16
23
  */
17
- folderBlocks: FolderBlockModel[];
24
+ @Input() folderBlocks: FolderBlockModel[] = [];
25
+
18
26
  /** Number of missing files, sourced from the `SHARED` constants. */
19
- missingFileCount: number;
27
+ missingFileCount = SHARED.MISSINGCOUNT;
28
+
20
29
  /** Number of pending files, sourced from the `SHARED` constants. */
21
- pendingFileCount: number;
30
+ pendingFileCount = SHARED.PENDINGCOUNT;
31
+
22
32
  /**
23
33
  * Injects the `DocumentStore` service to manage and access document-related state.
24
34
  * @param {DocumentStore} documentStore - The state management store for documents.
25
35
  */
26
- constructor(documentStore: DocumentStore);
36
+ constructor(public documentStore: DocumentStore) {}
37
+
27
38
  /**
28
39
  * Handles the click event for filtering based on the provided folder ID.
29
- * This method validates the folder ID and returns it for further processing.
40
+ * This method validates the folder ID and returns it for further processing.
30
41
  * If the folder ID is not provided, an empty string is returned.
31
42
  * @param {string} folderBlockId - The unique identifier of the folder to filter by.
32
43
  * @returns {string} The validated folder ID, or an empty string if the input is invalid.
33
44
  */
34
- handleClickForFilter(folderBlockId: string): string;
35
- static ɵfac: i0.ɵɵFactoryDeclaration<FolderBlockComponent, never>;
36
- static ɵcmp: i0.ɵɵComponentDeclaration<FolderBlockComponent, "lib-folder-block", never, { "folderBlocks": { "alias": "folderBlocks"; "required": false; }; }, {}, never, never, false, never>;
45
+ handleClickForFilter(folderBlockId: string): string {
46
+ if (!folderBlockId) {
47
+ return SHARED.EMPTY;
48
+ }
49
+ return folderBlockId;
50
+ }
37
51
  }
@@ -0,0 +1,2 @@
1
+
2
+ <lib-folder-block [folderBlocks]="folderBlocks"></lib-folder-block>
@@ -0,0 +1,29 @@
1
+ import { Component, Input } from '@angular/core';
2
+ import { FOLDERPANEL } from '../../../../Shared/constant/SHARED';
3
+ import { DocumentModel } from '../../models/document.model';
4
+
5
+ /**
6
+ * The `FolderContainerComponent` is responsible for rendering a container
7
+ * that displays a list of documents and associated folder panel data.
8
+ *
9
+ * This component utilizes the `FOLDERPANEL` constant for folder panel data
10
+ * and accepts a document list input of type `DocumentModel`.
11
+ */
12
+ @Component({
13
+ selector: 'lib-folder-container',
14
+ standalone: false,
15
+ templateUrl: './folder-container.component.html',
16
+ styleUrl: './folder-container.component.scss'
17
+ })
18
+ export class FolderContainerComponent {
19
+ /**
20
+ * A list of documents passed as input to the component.
21
+ * Represents the document data to be displayed in the folder container.
22
+ */
23
+ @Input() documentList?: DocumentModel[];
24
+
25
+ /**
26
+ * Folder blocks data, sourced from the `SHARED` constants.
27
+ */
28
+ folderBlocks = FOLDERPANEL;
29
+ }
@@ -0,0 +1,191 @@
1
+ import { APP_INITIALIZER, NgModule } from '@angular/core';
2
+ import { CommonModule } from '@angular/common';
3
+ import { DocumentContainerComponent } from './components/document-container/document-container.component';
4
+ import { FolderContainerComponent } from './components/folder-container/folder-container.component';
5
+ import { FolderBlockComponent } from './components/folder-block/folder-block.component';
6
+ import { DocumentListComponent } from './components/document-list/document-list.component';
7
+ import { AccordionModule } from 'primeng/accordion';
8
+ import { DocumentListItemComponent } from './components/document-list-item/document-list-item.component';
9
+ import { ButtonModule } from 'primeng/button';
10
+ import { SidebarModule } from 'primeng/sidebar';
11
+ import { FileUploadModule } from 'primeng/fileupload';
12
+ import { DocumentUploadComponent } from './components/document-upload/document-upload.component';
13
+ import { MessageService } from 'primeng/api';
14
+ import { HttpClientModule } from '@angular/common/http';
15
+ import { ProgressBarModule } from 'primeng/progressbar';
16
+ import { BadgeModule } from 'primeng/badge';
17
+ import { ListboxModule } from 'primeng/listbox';
18
+ import { TimelineModule } from 'primeng/timeline';
19
+ import { CheckboxModule } from 'primeng/checkbox';
20
+ import { InputTextareaModule } from 'primeng/inputtextarea';
21
+ import { FormsModule } from '@angular/forms';
22
+ import { DocumentViewerComponent } from './components/document-viewer/document-viewer.component';
23
+ import { PdfViewerModule } from 'ng2-pdf-viewer';
24
+ import { DialogModule } from 'primeng/dialog';
25
+ import { AppConfigService } from '../../Shared/services/app-config.service';
26
+ import { GlobalErrorHandler } from '../../Shared/services/global-error.handler';
27
+
28
+ /**
29
+ * @module DocumentModule
30
+ *
31
+ * The `DocumentModule` handles the organization and display of document and folder components
32
+ * in the application. This module is designed to support features like folder containers,
33
+ * document lists, and individual document items.
34
+ */
35
+ @NgModule({
36
+ declarations: [
37
+ /**
38
+ * The main container for managing documents.
39
+ * DocumentContainerComponent
40
+ */
41
+ DocumentContainerComponent,
42
+
43
+ /**
44
+ * A container component to manage folders.
45
+ * FolderContainerComponent
46
+ */
47
+ FolderContainerComponent,
48
+
49
+ /**
50
+ * A block component that represents an individual folder.
51
+ * FolderBlockComponent
52
+ */
53
+ FolderBlockComponent,
54
+
55
+ /**
56
+ * A component to display a list of documents.
57
+ * DocumentListComponent
58
+ */
59
+ DocumentListComponent,
60
+
61
+ /**
62
+ * A component representing an individual item in the document list.
63
+ * DocumentListItemComponent
64
+ */
65
+ DocumentListItemComponent,
66
+
67
+ /**
68
+ * A component representing to upload a file.
69
+ */
70
+ DocumentUploadComponent,
71
+
72
+ /**
73
+ * A component representing and allow you to view the document.
74
+ */
75
+ DocumentViewerComponent,
76
+
77
+ ],
78
+ imports: [
79
+ /**
80
+ * Angular's CommonModule is imported to access common directives like `ngIf` and `ngFor`.
81
+ */
82
+ CommonModule,
83
+
84
+ /**
85
+ * PrimeNG AccordionModule is used for creating collapsible sections in the UI.
86
+ */
87
+ AccordionModule,
88
+
89
+ /**
90
+ * HttpClienModule for the http calls
91
+ */
92
+ HttpClientModule,
93
+
94
+ /**
95
+ * PrimeNG ButtonModule is used for creating buttons in the UI.
96
+ */
97
+ ButtonModule,
98
+
99
+ /**
100
+ * PrimeNG SidebarModule is used for creating sidebar in the UI.
101
+ */
102
+ SidebarModule,
103
+
104
+ /**
105
+ * PrimeNG FileUploadModule is used for uploading file.
106
+ */
107
+ FileUploadModule,
108
+
109
+ /**
110
+ * PrimeNG ProgressBarModule is used for showing progress.
111
+ */
112
+ ProgressBarModule,
113
+
114
+ /**
115
+ * PrimeNG BadgeModule is used for showing badge value.
116
+ */
117
+ BadgeModule,
118
+
119
+ /**
120
+ * PrimeNG ListboxModule is used for showing listbox value.
121
+ */
122
+ ListboxModule,
123
+
124
+ /**
125
+ * PrimeNG CheckboxModule is used for showing checkbox value.
126
+ */
127
+ CheckboxModule,
128
+
129
+ /**
130
+ * PrimeNG TimelineModule is used for showing timeline value.
131
+ */
132
+ TimelineModule,
133
+ /**
134
+ * PrimeNG InputTextareaModule is used for showing textarea value.
135
+ */
136
+ InputTextareaModule,
137
+ /**
138
+ * FormsModule to handle the forms.
139
+ */
140
+ FormsModule,
141
+ /**
142
+ * PdfViewerModule to handle and make visible the pdf.
143
+ */
144
+ PdfViewerModule,
145
+ /**
146
+ * PrimeNG DialogModule is used for showing dialog.
147
+ */
148
+ DialogModule
149
+ ],
150
+ exports: [
151
+ /**
152
+ * Exports the `DocumentContainerComponent` to be used in other modules.
153
+ */
154
+ DocumentContainerComponent,
155
+ /**
156
+ * Exports the `DocumentViewerComponent` to be used in other modules.
157
+ */
158
+ DocumentViewerComponent
159
+ ],
160
+ providers: [
161
+ /**
162
+ * Provide the messageservice to be used in other components.
163
+ */
164
+ MessageService,
165
+
166
+ /**
167
+ * Provide the messageservice to be used in other components.
168
+ */
169
+ { provide: GlobalErrorHandler, useClass: GlobalErrorHandler },
170
+ /**
171
+ * Initializes the application configuration by loading it from the AppConfigService
172
+ * before the application starts.
173
+ * This ensures that the configuration is available for the rest of the app when needed.
174
+ * The configuration is loaded asynchronously using the APP_INITIALIZER.
175
+ * @returns {Function} - A function that loads the configuration from the AppConfigService.
176
+ */
177
+ {
178
+ provide: APP_INITIALIZER,
179
+ /**
180
+ * This useFactory is executed when the app initializes.
181
+ */
182
+ useFactory: (configService: AppConfigService) => () =>
183
+ configService.loadAppConfig().catch((error) => {
184
+ throw new Error(error);
185
+ }),
186
+ deps: [AppConfigService],
187
+ multi: true,
188
+ }
189
+ ]
190
+ })
191
+ export class DocumentModule { }
@@ -0,0 +1,39 @@
1
+ import { SHARED } from "../../../Shared/constant/SHARED";
2
+
3
+ /**
4
+ * Represents a document model.
5
+ *
6
+ * This class contains the structure for document-related data, including file name,
7
+ * status, and document URL.
8
+ */
9
+ export class DocumentModel {
10
+ /**
11
+ * The unique identifier for the document.
12
+ * @type {number}
13
+ */
14
+ _id: number = SHARED.INITIAL_COUNT;
15
+
16
+ /**
17
+ * The name of the document file.
18
+ * @type {?string}
19
+ */
20
+ fileName?: string;
21
+
22
+ /**
23
+ * The current status of the document.
24
+ * @type {?string}
25
+ */
26
+ status?: string;
27
+
28
+ /**
29
+ * The URL where the document is hosted or stored.
30
+ * @type {?string}
31
+ */
32
+ documentUrl?: string;
33
+
34
+ /**
35
+ * Date of document get uploaded
36
+ * @type {?Date}
37
+ */
38
+ createdAt?: Date
39
+ }
@@ -1,27 +1,33 @@
1
+ import { SHARED } from "../../../Shared/constant/SHARED";
2
+
1
3
  /**
2
4
  * Represents the model for a folder block.
3
- *
4
- * This class provides the structure for folder block data, including properties
5
+ *
6
+ * This class provides the structure for folder block data, including properties
5
7
  * for ID, file counts, descriptive text, and counts for missing and pending files.
6
8
  */
7
- export declare class FolderBlockModel {
9
+ export class FolderBlockModel {
8
10
  /**
9
11
  * Unique identifier for the folder block.
10
12
  * Defaults to an empty string sourced from `SHARED.EMPTY`.
11
13
  */
12
- _id: string;
14
+ _id: string = SHARED.EMPTY;
15
+
13
16
  /**
14
17
  * Total number of files within the folder block.
15
18
  */
16
19
  fileCount?: number;
20
+
17
21
  /**
18
22
  * Descriptive text associated with the folder block.
19
23
  */
20
24
  text?: string;
25
+
21
26
  /**
22
27
  * Number of files marked as missing in the folder block.
23
28
  */
24
29
  missingFiles?: number;
30
+
25
31
  /**
26
32
  * Number of files marked as pending in the folder block.
27
33
  */
@@ -0,0 +1,16 @@
1
+ import { TestBed } from '@angular/core/testing';
2
+
3
+ import { FileFormatService } from './file-format.service';
4
+
5
+ describe('FileFormatService', () => {
6
+ let service: FileFormatService;
7
+
8
+ beforeEach(() => {
9
+ TestBed.configureTestingModule({});
10
+ service = TestBed.inject(FileFormatService);
11
+ });
12
+
13
+ it('should be created', () => {
14
+ expect(service).toBeTruthy();
15
+ });
16
+ });
@@ -0,0 +1,41 @@
1
+ import { Injectable } from '@angular/core';
2
+ import { SHARED } from '../../../Shared/constant/SHARED';
3
+ import { PrimeNGConfig } from 'primeng/api';
4
+
5
+ /**
6
+ * Description placeholder
7
+ * @class FileFormatService
8
+ * @typedef {FileFormatService}
9
+ */
10
+ @Injectable({
11
+ providedIn: 'root'
12
+ })
13
+ export class FileFormatService {
14
+
15
+ /**
16
+ * Creates an instance of FileFormatService.
17
+ * @constructor
18
+ */
19
+ constructor() { }
20
+
21
+ /**
22
+ * Description placeholder
23
+ * @param {number} bytes
24
+ * @param {PrimeNGConfig} config
25
+ * @returns {string}
26
+ */
27
+ formatFileSize(bytes: number, config:PrimeNGConfig): string {
28
+ const kilobyte = 1024;
29
+ const decimalPlaces = SHARED.ONE;
30
+ const sizes = config.translation.fileSizeTypes || SHARED.FILE_SIZE_UNITS;
31
+ if (bytes < kilobyte) {
32
+ return `${bytes} ${sizes[SHARED.INITIAL_COUNT]}`;
33
+ } else if (bytes < kilobyte * kilobyte) {
34
+ const kbSize = bytes / kilobyte;
35
+ return `${parseFloat(kbSize.toFixed(decimalPlaces))} ${sizes[SHARED.ONE]}`;
36
+ } else {
37
+ const mbSize = bytes / (kilobyte * kilobyte);
38
+ return `${parseFloat(mbSize.toFixed(decimalPlaces))} ${sizes[SHARED.TWO]}`;
39
+ }
40
+ }
41
+ }
@@ -0,0 +1,23 @@
1
+ import { Injectable } from '@angular/core';
2
+ import { QueryEntity } from '@datorama/akita';
3
+ import { DocumentStore } from './document.store';
4
+ import { DocumentState } from './document.state';
5
+
6
+ /**
7
+ * Service that provides querying capabilities for the `DocumentStore`.
8
+ *
9
+ * The `DocumentQuery` class extends Akita's `QueryEntity`, allowing consumers
10
+ * to retrieve, observe, and filter data from the `DocumentStore` in a reactive manner.
11
+ *
12
+ * @extends QueryEntity<DocumentState>
13
+ * * Creates an instance of `DocumentQuery`.
14
+ *
15
+ * @param {DocumentStore} store - The underlying store that holds the document state.
16
+ */
17
+
18
+ @Injectable({ providedIn: 'root' })
19
+ export class DocumentQuery extends QueryEntity<DocumentState> {
20
+ constructor(protected override store: DocumentStore) {
21
+ super(store);
22
+ }
23
+ }
@@ -1,9 +1,11 @@
1
+ import { Injectable } from '@angular/core';
1
2
  import { HttpClient } from '@angular/common/http';
2
3
  import { DocumentStore } from './document.store';
3
- import { Observable } from 'rxjs';
4
+ import { Observable, tap } from 'rxjs';
4
5
  import { AppConfigService } from '../../../Shared/services/app-config.service';
6
+ import { URLS } from '../../../Shared/constant/URLS';
5
7
  import { DocumentModel } from '../models/document.model';
6
- import * as i0 from "@angular/core";
8
+
7
9
  /**
8
10
  * Service for managing document-related operations.
9
11
  * The `DocumentService` acts as a bridge between the application and the backend API for handling document-related data.
@@ -12,53 +14,82 @@ import * as i0 from "@angular/core";
12
14
  * @param {DocumentStore} documentStore - The store that manages the state of documents.
13
15
  * @param {HttpClient} http - The Angular HTTP client for making API requests.
14
16
  */
15
- export declare class DocumentService {
16
- documentStore: DocumentStore;
17
- private http;
18
- appConfigService: AppConfigService;
17
+ @Injectable({ providedIn: 'root' })
18
+ export class DocumentService {
19
+
19
20
  /**
20
21
  * Creates an instance of DocumentService.
21
22
  * @param {DocumentStore} documentStore - Store managing the state of documents.
22
23
  * @param {HttpClient} http - Angular HTTP client for making API requests.
23
24
  * @param {AppConfigService} appConfigService - Service for retrieving application configuration, such as API base URL.
24
25
  */
25
- constructor(documentStore: DocumentStore, http: HttpClient, appConfigService: AppConfigService);
26
+ constructor(
27
+ public documentStore: DocumentStore,
28
+ private http: HttpClient,
29
+ public appConfigService: AppConfigService
30
+ ) { }
31
+
26
32
  /**
27
33
  * Get api url from appConfigService.
28
34
  * @readonly
29
35
  * @type {string}
30
36
  */
31
- get apiUrl(): string;
37
+ get apiUrl(): string {
38
+ return this.appConfigService.apiBaseUrl;
39
+ }
40
+
32
41
  /**
33
42
  * Sends a request to create a new document.
34
43
  * @param {*} entity - The data of the document to be created.
35
44
  * @returns {Observable<any>} Observable that emits the newly created document.
36
45
  */
37
- create(entity: any): Observable<any>;
46
+ create(entity: any): Observable<any> {
47
+ return this.http.post<any>(`${this.apiUrl}${URLS.DOCUMENT_UPLOAD}`, entity).pipe(
48
+ tap((newEntity: any) => this.documentStore.add(newEntity))
49
+ );
50
+ }
51
+
38
52
  /**
39
53
  * Fetches all documents from the backend.
40
54
  * @returns {Observable<DocumentModel[]>} Observable that emits an array of documents.
41
55
  */
42
- getAll(): Observable<DocumentModel[]>;
56
+ getAll(): Observable<DocumentModel[]> {
57
+ return this.http.get<DocumentModel[]>(`${this.apiUrl}${URLS.DOCUMENT_UPLOAD}`).pipe(
58
+ tap((entities: DocumentModel[]) => this.documentStore.set(entities))
59
+ );
60
+ }
61
+
43
62
  /**
44
63
  * Fetches a document by its ID.
45
64
  * @param {string} id - The unique identifier of the document.
46
65
  * @returns {Observable<any>} Observable that emits the retrieved document.
47
66
  */
48
- getById(id: string): Observable<any>;
67
+ getById(id: string): Observable<any> {
68
+ return this.http.get<any>(`${this.apiUrl}${URLS.DOCUMENT_UPLOAD}/${id}`).pipe(
69
+ tap((entity: any) => this.documentStore.upsert(id, entity))
70
+ );
71
+ }
72
+
49
73
  /**
50
74
  * Updates an existing document by its ID.
51
75
  * @param {string} id - The unique identifier of the document.
52
76
  * @param {DocumentModel} entity - The updated data of the document.
53
77
  * @returns {Observable<DocumentModel>} Observable that emits the updated document.
54
78
  */
55
- update(id: string, entity: DocumentModel): Observable<DocumentModel>;
79
+ update(id: string, entity: DocumentModel): Observable<DocumentModel> {
80
+ return this.http.put<DocumentModel>(`${this.apiUrl}${URLS.DOCUMENT_UPLOAD}/${id}`, entity).pipe(
81
+ tap((updatedEntity: DocumentModel) => this.documentStore.update(id, updatedEntity))
82
+ );
83
+ }
84
+
56
85
  /**
57
86
  * Deletes a document by its ID.
58
87
  * @param {string} id - The unique identifier of the document to be deleted.
59
88
  * @returns {Observable<void>} Observable that completes when the document is deleted.
60
89
  */
61
- delete(id: string): Observable<void>;
62
- static ɵfac: i0.ɵɵFactoryDeclaration<DocumentService, never>;
63
- static ɵprov: i0.ɵɵInjectableDeclaration<DocumentService>;
90
+ delete(id: string): Observable<void> {
91
+ return this.http.delete<void>(`${this.apiUrl}${URLS.DOCUMENT_UPLOAD}/${id}`).pipe(
92
+ tap(() => this.documentStore.remove(id))
93
+ );
94
+ }
64
95
  }
@@ -1,30 +1,39 @@
1
1
  import { EntityState } from '@datorama/akita';
2
2
  import { DocumentModel } from '../models/document.model';
3
+
3
4
  /**
4
5
  * Represents the state of the documents in the application.
5
- *
6
+ *
6
7
  * This interface extends Akita's `EntityState` to include additional properties
7
8
  * for managing document-specific data, such as `records`, `filteredRecords` and `folderId`.
8
- *
9
+ *
9
10
  * @extends EntityState<DocumentModel, string>
10
- *
11
+ *
11
12
  * @property {any[]} records - A collection of records related to documents.
12
13
  * @property {any[]} filteredRecords - A collection of filteredRecords related to documents.
13
14
  * @property {string | null} folderId - The ID of the currently selected folder, or `null` if no folder is selected.
14
15
  * @property {boolean} isDialogOpen - A flag indicating whether a dialog is open.
15
16
  */
16
17
  export interface DocumentState extends EntityState<DocumentModel, string> {
17
- records: DocumentModel[];
18
- folderId: string | null;
19
- isDialogOpen: boolean;
20
- filteredRecords: DocumentModel[];
18
+ records: DocumentModel[];
19
+ folderId: string | null;
20
+ isDialogOpen: boolean;
21
+ filteredRecords:DocumentModel[]
21
22
  }
23
+
22
24
  /**
23
25
  * Creates the initial state for the `DocumentState` store.
24
- *
26
+ *
25
27
  * This function provides default values for all properties in the `DocumentState` interface,
26
28
  * ensuring the store starts with a consistent initial structure.
27
- *
29
+ *
28
30
  * @returns {DocumentState} The initial state of the document store.
29
31
  */
30
- export declare function createInitialState(): DocumentState;
32
+ export function createInitialState(): DocumentState {
33
+ return {
34
+ records: [],
35
+ filteredRecords: [],
36
+ folderId: null,
37
+ isDialogOpen: false,
38
+ };
39
+ }
@@ -0,0 +1,23 @@
1
+ import { Injectable } from '@angular/core';
2
+ import { EntityStore, StoreConfig } from '@datorama/akita';
3
+ import { createInitialState, DocumentState } from './document.state';
4
+
5
+ /**
6
+ * Store that manages the state of documents in the application.
7
+ *
8
+ * The `DocumentStore` class extends Akita's `EntityStore` to manage the entity state for documents.
9
+ * It uses the `createInitialState` function to initialize the store with default values and
10
+ * is configured with the name `'documents'`.
11
+ *
12
+ * @extends EntityStore<DocumentState>
13
+ */
14
+ @Injectable({ providedIn: 'root' })
15
+ @StoreConfig({ name: 'documents' })
16
+ export class DocumentStore extends EntityStore<DocumentState> {
17
+ /**
18
+ * Creates an instance of `DocumentStore` with the initial state of the documents.
19
+ */
20
+ constructor() {
21
+ super(createInitialState());
22
+ }
23
+ }
@@ -1,3 +1,8 @@
1
+ /*
2
+ * Public API Surface of cat-document-lib
3
+ */
4
+
1
5
  export * from './lib/document/document.module';
2
6
  export * from './lib/document/components/document-container/document-container.component';
3
- export * from './lib/document/components/document-viewer/document-viewer.component';
7
+ export * from './lib/document/components/document-viewer/document-viewer.component'
8
+