cat-documents-ng 1.0.4 → 1.0.6

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 (210) hide show
  1. package/ng-package.json +10 -0
  2. package/package.json +5 -11
  3. package/src/Shared/components/confirmation-dialog/confirmation-dialog.component.html +3 -0
  4. package/src/Shared/components/confirmation-dialog/confirmation-dialog.component.scss +13 -0
  5. package/src/Shared/components/confirmation-dialog/confirmation-dialog.component.spec.ts +70 -0
  6. package/src/Shared/components/confirmation-dialog/confirmation-dialog.component.ts +133 -0
  7. package/src/Shared/components/table-primary/table-primary.component.html +66 -0
  8. package/src/Shared/components/table-primary/table-primary.component.scss +227 -0
  9. package/src/Shared/components/table-primary/table-primary.component.spec.ts +23 -0
  10. package/src/Shared/components/table-primary/table-primary.component.ts +143 -0
  11. package/src/Shared/components/table-primary/table-primary.model.ts +21 -0
  12. package/src/Shared/constant/ERROR.ts +55 -0
  13. package/src/Shared/constant/PERMISSIONS.ts +17 -0
  14. package/src/Shared/constant/SHARED.ts +936 -0
  15. package/{Shared/constant/URLS.d.ts → src/Shared/constant/URLS.ts} +31 -25
  16. package/src/Shared/services/app-config.service.spec.ts +19 -0
  17. package/src/Shared/services/app-config.service.ts +73 -0
  18. package/{Shared/services/global-error.handler.d.ts → src/Shared/services/global-error.handler.ts} +11 -9
  19. package/src/Shared/services/session.service.spec.ts +16 -0
  20. package/src/Shared/services/session.service.ts +76 -0
  21. package/src/Shared/shared.module.ts +25 -0
  22. package/src/lib/document/components/csv-viewer/csv-viewer.component.ts +1 -0
  23. package/src/lib/document/components/document-actions/document-actions.component.html +59 -0
  24. package/src/lib/document/components/document-actions/document-actions.component.scss +362 -0
  25. package/src/lib/document/components/document-actions/document-actions.component.spec.ts +297 -0
  26. package/src/lib/document/components/document-actions/document-actions.component.ts +163 -0
  27. package/src/lib/document/components/document-container/document-container.component.html +36 -0
  28. package/src/lib/document/components/document-container/document-container.component.scss +144 -0
  29. package/src/lib/document/components/document-container/document-container.component.spec.ts +110 -0
  30. package/src/lib/document/components/document-container/document-container.component.ts +363 -0
  31. package/src/lib/document/components/document-content-viewer/document-content-viewer.component.html +332 -0
  32. package/src/lib/document/components/document-content-viewer/document-content-viewer.component.scss +1877 -0
  33. package/src/lib/document/components/document-content-viewer/document-content-viewer.component.spec.ts +258 -0
  34. package/src/lib/document/components/document-content-viewer/document-content-viewer.component.ts +664 -0
  35. package/src/lib/document/components/document-history/document-history.component.html +96 -0
  36. package/src/lib/document/components/document-history/document-history.component.scss +392 -0
  37. package/src/lib/document/components/document-history/document-history.component.spec.ts +93 -0
  38. package/src/lib/document/components/document-history/document-history.component.ts +373 -0
  39. package/src/lib/document/components/document-list/document-list.component.html +46 -0
  40. package/src/lib/document/components/document-list/document-list.component.scss +513 -0
  41. package/src/lib/document/components/document-list/document-list.component.spec.ts +486 -0
  42. package/src/lib/document/components/document-list/document-list.component.ts +682 -0
  43. package/src/lib/document/components/document-list-item/document-list-item.component.html +36 -0
  44. package/src/lib/document/components/document-list-item/document-list-item.component.scss +34 -0
  45. package/src/lib/document/components/document-list-item/document-list-item.component.spec.ts +75 -0
  46. package/src/lib/document/components/document-list-item/document-list-item.component.ts +40 -0
  47. package/src/lib/document/components/document-search/document-search.component.html +64 -0
  48. package/src/lib/document/components/document-search/document-search.component.scss +206 -0
  49. package/src/lib/document/components/document-search/document-search.component.spec.ts +82 -0
  50. package/src/lib/document/components/document-search/document-search.component.ts +163 -0
  51. package/src/lib/document/components/document-status/document-status.component.html +31 -0
  52. package/src/lib/document/components/document-status/document-status.component.scss +192 -0
  53. package/src/lib/document/components/document-status/document-status.component.spec.ts +23 -0
  54. package/src/lib/document/components/document-status/document-status.component.ts +87 -0
  55. package/src/lib/document/components/document-upload/document-upload.component.html +160 -0
  56. package/src/lib/document/components/document-upload/document-upload.component.scss +235 -0
  57. package/src/lib/document/components/document-upload/document-upload.component.spec.ts +95 -0
  58. package/src/lib/document/components/document-upload/document-upload.component.ts +668 -0
  59. package/src/lib/document/components/document-viewer/document-viewer.component.html +50 -0
  60. package/src/lib/document/components/document-viewer/document-viewer.component.scss +187 -0
  61. package/src/lib/document/components/document-viewer/document-viewer.component.spec.ts +79 -0
  62. package/src/lib/document/components/document-viewer/document-viewer.component.ts +261 -0
  63. package/src/lib/document/components/document-zoom-controls/document-zoom-controls.component.html +48 -0
  64. package/src/lib/document/components/document-zoom-controls/document-zoom-controls.component.scss +320 -0
  65. package/src/lib/document/components/document-zoom-controls/document-zoom-controls.component.spec.ts +59 -0
  66. package/src/lib/document/components/document-zoom-controls/document-zoom-controls.component.ts +150 -0
  67. package/src/lib/document/components/documents-menu/documents-menu.component.html +44 -0
  68. package/src/lib/document/components/documents-menu/documents-menu.component.scss +363 -0
  69. package/src/lib/document/components/documents-menu/documents-menu.component.spec.ts +23 -0
  70. package/src/lib/document/components/documents-menu/documents-menu.component.ts +316 -0
  71. package/src/lib/document/components/folder-block/folder-block.component.html +46 -0
  72. package/src/lib/document/components/folder-block/folder-block.component.scss +9 -0
  73. package/src/lib/document/components/folder-block/folder-block.component.spec.ts +70 -0
  74. package/{lib/document/components/folder-block/folder-block.component.d.ts → src/lib/document/components/folder-block/folder-block.component.ts} +28 -12
  75. package/src/lib/document/components/folder-container/folder-container.component.html +56 -0
  76. package/src/lib/document/components/folder-container/folder-container.component.scss +20 -0
  77. package/src/lib/document/components/folder-container/folder-container.component.spec.ts +27 -0
  78. package/src/lib/document/components/folder-container/folder-container.component.ts +328 -0
  79. package/src/lib/document/components/linked-document/linked-document.component.html +23 -0
  80. package/src/lib/document/components/linked-document/linked-document.component.scss +10 -0
  81. package/src/lib/document/components/linked-document/linked-document.component.spec.ts +61 -0
  82. package/src/lib/document/components/linked-document/linked-document.component.ts +49 -0
  83. package/src/lib/document/components/request-document/request-document.component.html +86 -0
  84. package/src/lib/document/components/request-document/request-document.component.scss +16 -0
  85. package/src/lib/document/components/request-document/request-document.component.ts +278 -0
  86. package/src/lib/document/components/sidebar/sidebar.component.html +75 -0
  87. package/src/lib/document/components/sidebar/sidebar.component.scss +157 -0
  88. package/src/lib/document/components/sidebar/sidebar.component.spec.ts +114 -0
  89. package/src/lib/document/components/sidebar/sidebar.component.ts +223 -0
  90. package/src/lib/document/components/user-list/user-list.component.html +33 -0
  91. package/src/lib/document/components/user-list/user-list.component.scss +118 -0
  92. package/src/lib/document/components/user-list/user-list.component.spec.ts +23 -0
  93. package/src/lib/document/components/user-list/user-list.component.ts +181 -0
  94. package/src/lib/document/constant/DOCUMENT_HISTORY.ts +52 -0
  95. package/src/lib/document/directives/document.directive.ts +32 -0
  96. package/src/lib/document/directives/permission.directive.spec.ts +0 -0
  97. package/src/lib/document/directives/permission.directive.ts +72 -0
  98. package/src/lib/document/document.module.ts +351 -0
  99. package/{lib/document/models/document-alert.model.d.ts → src/lib/document/models/document-alert.model.ts} +11 -4
  100. package/src/lib/document/models/document-category.model.ts +30 -0
  101. package/src/lib/document/models/document-history.model.ts +109 -0
  102. package/src/lib/document/models/document-list-response.model.ts +37 -0
  103. package/src/lib/document/models/document-type.model.ts +44 -0
  104. package/src/lib/document/models/document.model.ts +53 -0
  105. package/{lib/document/models/folder.model.d.ts → src/lib/document/models/folder.model.ts} +10 -4
  106. package/src/lib/document/models/status-data.model.ts +31 -0
  107. package/src/lib/document/models/uploaded-file-response.model.ts +7 -0
  108. package/src/lib/document/models/user-list.model.ts +10 -0
  109. package/src/lib/document/services/csv-parser.service.spec.ts +97 -0
  110. package/src/lib/document/services/csv-parser.service.ts +303 -0
  111. package/src/lib/document/services/document-actions.service.ts +125 -0
  112. package/src/lib/document/services/document-content-type.service.ts +193 -0
  113. package/src/lib/document/services/document-history-style.service.ts +138 -0
  114. package/src/lib/document/services/document-history.service.ts +129 -0
  115. package/src/lib/document/services/document-http.service.spec.ts +119 -0
  116. package/src/lib/document/services/document-http.service.ts +497 -0
  117. package/src/lib/document/services/document-list.service.ts +195 -0
  118. package/src/lib/document/services/document-menu.service.ts +277 -0
  119. package/src/lib/document/services/document-scroll.service.ts +138 -0
  120. package/src/lib/document/services/document-severity.service.ts +98 -0
  121. package/src/lib/document/services/document-table-builder.service.ts +82 -0
  122. package/src/lib/document/services/document-upload-business.service.ts +326 -0
  123. package/src/lib/document/services/document-upload-data.service.ts +82 -0
  124. package/src/lib/document/services/document-upload-form.service.ts +149 -0
  125. package/src/lib/document/services/document-upload.service.spec.ts +99 -0
  126. package/src/lib/document/services/document-upload.service.ts +209 -0
  127. package/src/lib/document/services/document-viewer.service.ts +279 -0
  128. package/src/lib/document/services/document-zoom.service.spec.ts +56 -0
  129. package/src/lib/document/services/document-zoom.service.ts +164 -0
  130. package/src/lib/document/services/document.service.ts +356 -0
  131. package/src/lib/document/services/eml-parser.service.ts +444 -0
  132. package/src/lib/document/services/excel-parser.service.spec.ts +66 -0
  133. package/src/lib/document/services/excel-parser.service.ts +483 -0
  134. package/src/lib/document/services/file-format.service.spec.ts +16 -0
  135. package/src/lib/document/services/file-format.service.ts +63 -0
  136. package/src/lib/document/services/status-calculator.service.ts +44 -0
  137. package/src/lib/document/services/user-list.service.ts +77 -0
  138. package/src/lib/document/state/document.query.ts +378 -0
  139. package/{lib/document/state/document.service.d.ts → src/lib/document/state/document.service.ts} +46 -15
  140. package/src/lib/document/state/document.state.ts +100 -0
  141. package/src/lib/document/state/document.store.ts +200 -0
  142. package/{public-api.d.ts → src/public-api.ts} +4 -0
  143. package/tsconfig.lib.json +15 -0
  144. package/tsconfig.lib.prod.json +11 -0
  145. package/tsconfig.spec.json +15 -0
  146. package/Shared/components/confirmation-dialog/confirmation-dialog.component.d.ts +0 -44
  147. package/Shared/components/table-primary/table-primary.component.d.ts +0 -31
  148. package/Shared/components/table-primary/table-primary.model.d.ts +0 -19
  149. package/Shared/constant/ERROR.d.ts +0 -52
  150. package/Shared/constant/SHARED.d.ts +0 -546
  151. package/Shared/services/app-config.service.d.ts +0 -51
  152. package/Shared/services/session.service.d.ts +0 -46
  153. package/Shared/shared.module.d.ts +0 -14
  154. package/fesm2022/cat-documents-ng.mjs +0 -11392
  155. package/fesm2022/cat-documents-ng.mjs.map +0 -1
  156. package/index.d.ts +0 -5
  157. package/lib/document/components/document-actions/document-actions.component.d.ts +0 -78
  158. package/lib/document/components/document-container/document-container.component.d.ts +0 -162
  159. package/lib/document/components/document-content-viewer/document-content-viewer.component.d.ts +0 -291
  160. package/lib/document/components/document-history/document-history.component.d.ts +0 -160
  161. package/lib/document/components/document-list/document-list.component.d.ts +0 -299
  162. package/lib/document/components/document-list-item/document-list-item.component.d.ts +0 -28
  163. package/lib/document/components/document-search/document-search.component.d.ts +0 -77
  164. package/lib/document/components/document-status/document-status.component.d.ts +0 -24
  165. package/lib/document/components/document-upload/document-upload.component.d.ts +0 -321
  166. package/lib/document/components/document-viewer/document-viewer.component.d.ts +0 -137
  167. package/lib/document/components/document-zoom-controls/document-zoom-controls.component.d.ts +0 -33
  168. package/lib/document/components/documents-menu/documents-menu.component.d.ts +0 -110
  169. package/lib/document/components/folder-container/folder-container.component.d.ts +0 -162
  170. package/lib/document/components/linked-document/linked-document.component.d.ts +0 -39
  171. package/lib/document/components/request-document/request-document.component.d.ts +0 -69
  172. package/lib/document/components/sidebar/sidebar.component.d.ts +0 -109
  173. package/lib/document/components/user-list/user-list.component.d.ts +0 -34
  174. package/lib/document/constant/DOCUMENT_HISTORY.d.ts +0 -41
  175. package/lib/document/directives/document.directive.d.ts +0 -20
  176. package/lib/document/directives/permission.directive.d.ts +0 -38
  177. package/lib/document/document.module.d.ts +0 -60
  178. package/lib/document/models/document-category.model.d.ts +0 -24
  179. package/lib/document/models/document-history.model.d.ts +0 -94
  180. package/lib/document/models/document-list-response.model.d.ts +0 -33
  181. package/lib/document/models/document-type.model.d.ts +0 -37
  182. package/lib/document/models/document.model.d.ts +0 -44
  183. package/lib/document/models/status-data.model.d.ts +0 -27
  184. package/lib/document/models/uploaded-file-response.model.d.ts +0 -7
  185. package/lib/document/models/user-list.model.d.ts +0 -8
  186. package/lib/document/services/csv-parser.service.d.ts +0 -88
  187. package/lib/document/services/document-actions.service.d.ts +0 -48
  188. package/lib/document/services/document-content-type.service.d.ts +0 -85
  189. package/lib/document/services/document-history-style.service.d.ts +0 -34
  190. package/lib/document/services/document-history.service.d.ts +0 -42
  191. package/lib/document/services/document-http.service.d.ts +0 -179
  192. package/lib/document/services/document-list.service.d.ts +0 -74
  193. package/lib/document/services/document-menu.service.d.ts +0 -122
  194. package/lib/document/services/document-scroll.service.d.ts +0 -55
  195. package/lib/document/services/document-table-builder.service.d.ts +0 -38
  196. package/lib/document/services/document-upload-business.service.d.ts +0 -107
  197. package/lib/document/services/document-upload-data.service.d.ts +0 -40
  198. package/lib/document/services/document-upload-form.service.d.ts +0 -41
  199. package/lib/document/services/document-upload.service.d.ts +0 -99
  200. package/lib/document/services/document-viewer.service.d.ts +0 -97
  201. package/lib/document/services/document-zoom.service.d.ts +0 -81
  202. package/lib/document/services/document.service.d.ts +0 -161
  203. package/lib/document/services/eml-parser.service.d.ts +0 -116
  204. package/lib/document/services/excel-parser.service.d.ts +0 -169
  205. package/lib/document/services/file-format.service.d.ts +0 -34
  206. package/lib/document/services/status-calculator.service.d.ts +0 -20
  207. package/lib/document/services/user-list.service.d.ts +0 -29
  208. package/lib/document/state/document.query.d.ts +0 -243
  209. package/lib/document/state/document.state.d.ts +0 -61
  210. package/lib/document/state/document.store.d.ts +0 -56
@@ -0,0 +1,497 @@
1
+ import { Injectable } from '@angular/core';
2
+ import { catchError, EMPTY, Observable, of, tap, throwError } from 'rxjs';
3
+ import { URLS } from '../../../Shared/constant/URLS';
4
+ import { SHARED } from '../../../Shared/constant/SHARED';
5
+ import { AppConfigService } from '../../../Shared/services/app-config.service';
6
+ import { DocumentStore } from '../state/document.store';
7
+ import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http';
8
+ import { DocumentTypeModel } from '../models/document-type.model';
9
+ import { DocumentAlertModel } from '../models/document-alert.model';
10
+ import { DocumentModel } from '../models/document.model';
11
+ import { FolderBlockModel } from '../models/folder.model';
12
+ import { DocumentCategory } from '../models/document-category.model';
13
+ import { UserListModel } from '../models/user-list.model';
14
+ import { StatusDataModel } from '../models/status-data.model';
15
+ import { DocumentListResponse } from '../models/document-list-response.model';
16
+ import { DocumentHistorySection } from '../models/document-history.model';
17
+
18
+ /**
19
+ * Service for making HTTP requests related to documents.
20
+ * Authentication is handled automatically by the HTTP interceptor in the main project.
21
+ * @class DocumentHttpService
22
+ * @typedef {DocumentHttpService}
23
+ */
24
+ @Injectable({
25
+ providedIn: 'root'
26
+ })
27
+
28
+ export class DocumentHttpService {
29
+
30
+ /**
31
+ * Creates an instance of DocumentService.
32
+ * @param {DocumentStore} documentStore - Store managing the state of documents.
33
+ * @param {HttpClient} http - Angular HTTP client for making API requests.
34
+ * @param {AppConfigService} appConfigService - Service for retrieving application configuration, such as API base URL.
35
+ */
36
+ constructor(
37
+ public documentStore: DocumentStore,
38
+ private http: HttpClient,
39
+ public appConfigService: AppConfigService
40
+ ) { }
41
+
42
+ /**
43
+ * Get api url from appConfigService.
44
+ * @readonly
45
+ * @type {string}
46
+ */
47
+ get apiUrl(): string {
48
+ return this.appConfigService.apiBaseUrl;
49
+ }
50
+
51
+ /**
52
+ * Fetches a document by its path name and transforms the response for dropdown options.
53
+ * Includes error handling for failed API requests.
54
+ * @param {string} contextId - The context ID to fetch the document.
55
+ * @returns {Observable<any>} Observable that emits the transformed data for dropdown options.
56
+ */
57
+ getFoldersData(contextId:string | undefined): Observable<FolderBlockModel[]> {
58
+ if(!contextId) return EMPTY;
59
+
60
+ return this.http.get<FolderBlockModel[]>(`${this.apiUrl}${URLS.DOCUMENT_UPLOAD}${URLS.FOLDERS}${contextId}`).pipe(
61
+ tap((folders: FolderBlockModel[]) => {
62
+ this.documentStore.setFolders(folders);
63
+ }),
64
+ catchError((error) => {
65
+ return throwError(() => new Error(error));
66
+ })
67
+ );
68
+ }
69
+
70
+ /**
71
+ * Fetches a document catagories by its path name.
72
+ * Includes error handling for failed API requests.
73
+ * @param {string} contextId - The context ID to fetch the document.
74
+ * @returns {Observable<any>} Observable that emits the transformed data for dropdown options.
75
+ */
76
+ getDocumentCatagories(contextId:string): Observable<any> {
77
+ let headers = new HttpHeaders( {
78
+ 'Authorization': `Bearer 4fe17947-30bf-4079-b4ea-798ff73cd473`
79
+ });
80
+ return this.http.get<any>(`${this.apiUrl}${URLS.DOCUMENTS_CATAGORIES}/${contextId}`, { headers })
81
+ .pipe(
82
+ tap((response: any) => {
83
+ if (response && response.categories) {
84
+ this.documentStore.setDocumentCategories(response.categories);
85
+ }
86
+ }),
87
+ catchError((error) => {
88
+ return throwError(() => new Error(error));
89
+ })
90
+ );
91
+ }
92
+ /**
93
+ * Fetches a document by its path name and transforms the response for dropdown options.
94
+ * Includes error handling for failed API requests.
95
+ * @returns {Observable<any>} Observable that emits the transformed data for dropdown options.
96
+ */
97
+ // getDocumentTypes(): Observable<DocumentTypeModel[]> {
98
+ // return this.http.get<DocumentTypeModel[]>(`${this.apiUrl}${URLS.DOCUMENT_UPLOAD}/${URLS.DOCUMENT_TYPES}`).pipe(
99
+ // tap((documentTypes: DocumentTypeModel[]) => {
100
+ // this.documentStore.setDocumentTypes(documentTypes);
101
+ // }),
102
+ // catchError((error) => {
103
+ // return throwError(() => new Error(error));
104
+ // })
105
+ // );
106
+ // }
107
+
108
+ /**
109
+ * Fetches a document by its path name and transforms the response for dropdown options.
110
+ * @param {string} documentId - The document ID to fetch the document.
111
+ * @returns {Observable<any>} Observable that emits the transformed data for dropdown options.
112
+ */
113
+ getAlertsByDocumentID(documentId:string): Observable<DocumentAlertModel> {
114
+ return this.http.get<DocumentAlertModel>(`${this.apiUrl}${URLS.ALERT_BY_DOCUMENT_ID}${documentId}`).pipe(
115
+ tap((documentAlert: DocumentAlertModel) => {
116
+ this.documentStore.setDocumentAlert(documentAlert);
117
+ }),
118
+ catchError((error) => {
119
+ return throwError(() => new Error(error));
120
+ })
121
+ );
122
+ }
123
+
124
+ /**
125
+ * Fetches a document by its folder ID and transforms the response for dropdown options.
126
+ * @param {string} folderId - The folder ID to fetch the document.
127
+ * @param {string} contextId - The context ID to fetch the document.
128
+ * @returns {Observable<any>} Observable that emits the transformed data for dropdown options.
129
+ */
130
+ getDocumentByFolderID(folderId:string, contextId:string): Observable<DocumentModel[]> {
131
+ let headers = new HttpHeaders( {
132
+ 'Authorization': `Bearer 4fe17947-30bf-4079-b4ea-798ff73cd473`
133
+ });
134
+ return this.http.get<DocumentModel[]>(`${this.apiUrl}${URLS.DOCUMENT_UPLOAD}/${URLS.PARENT_DOCUMENT_TYPE_ID}${folderId}${URLS.CONTEXT_ID}${contextId}`, { headers }).pipe(
135
+ tap((records: DocumentModel[]) => {
136
+ this.documentStore.set(records);
137
+ }),
138
+ catchError((error) => {
139
+ return throwError(() => new Error(error));
140
+ })
141
+ );
142
+ }
143
+
144
+ /**
145
+ * Updates the name of a document.
146
+ * This method sends an HTTP PUT request to update the document's file name using the provided document ID and payload.
147
+ * In case of an error, it will return an observable that throws an Error.
148
+ * @param {string} documentId - The unique identifier of the document to update.
149
+ * @param {any} payload - The payload containing the updated document data (e.g., fileName).
150
+ * @returns {Observable<DocumentModel>} An observable that emits the updated DocumentModel.
151
+ */
152
+ updateDocumentName(documentId: string, payload: any): Observable<DocumentModel> {
153
+ let headers = new HttpHeaders( {
154
+ 'Authorization': `Bearer 4fe17947-30bf-4079-b4ea-798ff73cd473`
155
+ });
156
+ return this.http.put<DocumentModel>(`${this.apiUrl}${URLS.ALIAS_NAME}${documentId}`, payload, { headers }).pipe(
157
+ catchError((error) => {
158
+ return throwError(() => new Error(error));
159
+ })
160
+ );
161
+ }
162
+
163
+ /**
164
+ * Fetches a userlist by its path name.
165
+ * @param {string} contextId - The document ID to fetch the document.
166
+ * @returns {Observable<UserListModel[]>} Observable that emits the user list data.
167
+ */
168
+ getUserListByContextId(contextId : string): Observable<UserListModel[]> {
169
+ let headers = new HttpHeaders( {
170
+ 'Authorization': `Bearer 4fe17947-30bf-4079-b4ea-798ff73cd473`
171
+ });
172
+ if(!contextId) return EMPTY;
173
+ return this.http.get<UserListModel[]>(`${this.apiUrl}${URLS.USERLIST}${contextId}`, { headers }).pipe(
174
+ tap((userList: UserListModel[]) => {
175
+ this.documentStore.setUserList(userList);
176
+ }),
177
+ catchError((error) => {
178
+ return throwError(() => new Error(error));
179
+ })
180
+ );
181
+ }
182
+
183
+ /**
184
+ * Fetches document status count data by application ID with optional context ID and category parameters.
185
+ * @param {string} applicationId - The application ID to fetch status data.
186
+ * @param {string | null} contextId - The context ID (applicant ID) to filter by. If null, uses applicationId.
187
+ * @param {string | null} categoryId - The category ID to filter by.
188
+ * @returns {Observable<StatusDataModel[]>} Observable that emits the status data.
189
+ */
190
+ getStatusDocumentCount(applicationId: string, contextId: string | null = null, categoryId: string | null = null): Observable<StatusDataModel[]> {
191
+ if(!applicationId) return EMPTY;
192
+ let headers = new HttpHeaders( {
193
+ 'Authorization': `Bearer 4fe17947-30bf-4079-b4ea-798ff73cd473`
194
+ });
195
+ let url = `${this.apiUrl}${URLS.STATUS_DOCUMENT_COUNT}${applicationId}`;
196
+ let params = new HttpParams();
197
+ const contextParam = contextId || null;
198
+ if (contextParam) {
199
+ params = params.set(SHARED.CONTEXT_ID, contextParam);
200
+ }
201
+ if (categoryId) {
202
+ params = params.set(SHARED.CATEGORY, categoryId);
203
+ }
204
+ return this.http.get<StatusDataModel[]>(url, { params, headers }).pipe(
205
+ tap((statusData: StatusDataModel[]) => {
206
+ this.documentStore.setStatusData(statusData);
207
+ }),
208
+ catchError((error) => {
209
+ return throwError(() => new Error(error));
210
+ })
211
+ );
212
+ }
213
+
214
+
215
+ /**
216
+ * Fetches documents based on selection criteria (user ID, status, and search key).
217
+ * This method sends an HTTP GET request with query parameters for the selected filters.
218
+ * Note: Menu item filtering has been removed - menu items are now used for navigation only.
219
+ * @param {string} contextId - The context ID (applicationId or applicantId).
220
+ * @param {string | null} menuItem - Reserved parameter (no longer used for filtering).
221
+ * @param {string | null} userId - The selected user ID filter.
222
+ * @param {string | null} status - The selected status filter.
223
+ * @param {string | null} searchKey - The search key filter.
224
+ * @returns {Observable<any>} An observable that emits the filtered document data.
225
+ */
226
+ getDocumentsBySelection(contextId: string, menuItem: string | null, userId: string | null, status: string | null, searchKey: string | null = null): Observable<any> {
227
+ let headers = new HttpHeaders( {
228
+ 'Authorization': `Bearer 4fe17947-30bf-4079-b4ea-798ff73cd473`
229
+ });
230
+ let params = new HttpParams();
231
+ if (userId) {
232
+ params = params.set(SHARED.CONTEXT_ID, userId);
233
+ }
234
+
235
+ if (status) {
236
+ params = params.set(SHARED.STATUS_PARAM, status);
237
+ }
238
+
239
+ if (searchKey) {
240
+ params = params.set(SHARED.SEARCH_KEY, searchKey);
241
+ }
242
+ return this.http.get<any>(`${this.apiUrl}${URLS.GETALL}/${contextId}`, { params, headers }).pipe(
243
+ tap((response: any) => {
244
+ if (response.documents) {
245
+ this.documentStore.setDocumentList(response.documents);
246
+ }
247
+ }),
248
+ catchError((error) => {
249
+ return throwError(() => new Error(error));
250
+ })
251
+ );
252
+ }
253
+
254
+ getDocumentHistory(documentId: string): Observable<DocumentHistorySection[]> {
255
+ let headers = new HttpHeaders( {
256
+ 'Authorization': `Bearer 4fe17947-30bf-4079-b4ea-798ff73cd473`
257
+ });
258
+ if (!documentId) {
259
+ return of([]);
260
+ }
261
+ return this.http.get<DocumentHistorySection[]>(`${this.apiUrl}${URLS.DOCUMENT_HISTORY}${documentId}`, { headers }).pipe(
262
+ catchError((error) => {
263
+ return throwError(() => new Error(error));
264
+ })
265
+ );
266
+ }
267
+
268
+ /**
269
+ * Fetches document categories by source (Applicant/Application).
270
+ * @param {string} source - The source type (Applicant or Application).
271
+ * @returns {Observable<DocumentCategory[]>} Observable that emits the categories.
272
+ */
273
+ getCategoriesBySource(source: string): Observable<DocumentCategory[]> {
274
+ if (!source) return EMPTY;
275
+ let headers = new HttpHeaders( {
276
+ 'Authorization': `Bearer 4fe17947-30bf-4079-b4ea-798ff73cd473`
277
+ });
278
+ return this.http.get<DocumentCategory[]>(`${this.apiUrl}${URLS.GET_CATEGORIES_BY_SOURCE}${source}`, { headers }).pipe(
279
+ catchError((error) => {
280
+ return throwError(() => new Error(error));
281
+ })
282
+ );
283
+ }
284
+
285
+ /**
286
+ * Fetches document types by category ID.
287
+ * @param {string} categoryId - The category ID to fetch document types for.
288
+ * @returns {Observable<DocumentTypeModel[]>} Observable that emits the document types.
289
+ */
290
+ getDocumentTypesByCategory(categoryId: string): Observable<DocumentTypeModel[]> {
291
+ let headers = new HttpHeaders( {
292
+ 'Authorization': `Bearer 4fe17947-30bf-4079-b4ea-798ff73cd473`
293
+ });
294
+ if (!categoryId) return EMPTY;
295
+ return this.http.get<DocumentTypeModel[]>(`${this.apiUrl}${URLS.GET_DOCUMENT_TYPES_BY_CATEGORY}${categoryId}`, { headers }).pipe(
296
+ catchError((error) => {
297
+ return throwError(() => new Error(error));
298
+ })
299
+ );
300
+ }
301
+
302
+ /**
303
+ * Uploads a single file using the uploadFile API.
304
+ * @param {FormData} formData - The form data containing the file and metadata.
305
+ * @returns {Observable<any>} Observable that emits the upload response.
306
+ */
307
+ uploadFile(formData: FormData): Observable<any> {
308
+ let headers = new HttpHeaders( {
309
+ 'Authorization': `Bearer 4fe17947-30bf-4079-b4ea-798ff73cd473`
310
+ });
311
+ return this.http.post<any>(`${this.apiUrl}${URLS.DOCUMENT_UPLOAD_FILE}`, formData, { headers }).pipe(
312
+ catchError((error) => {
313
+ return throwError(() => new Error(error));
314
+ })
315
+ );
316
+ }
317
+
318
+ /**
319
+ * Saves the complete document upload data.
320
+ * @param {any} payload - The document upload payload containing all necessary data.
321
+ * @returns {Observable<any>} Observable that emits the save response.
322
+ */
323
+ saveDocumentUpload(payload: any): Observable<any> {
324
+ let headers = new HttpHeaders( {
325
+ 'Authorization': `Bearer 4fe17947-30bf-4079-b4ea-798ff73cd473`
326
+ });
327
+ return this.http.post<any>(`${this.apiUrl}${URLS.SAVE_DOCUMENT_UPLOAD}`, payload, { headers }).pipe(
328
+ catchError((error) => {
329
+ return throwError(() => new Error(error));
330
+ })
331
+ );
332
+ }
333
+
334
+ /**
335
+ * Updates the status of a document by document ID
336
+ * @param {string} documentId - The ID of the document to update
337
+ * @param {string} status - The new status (Approved, Rejected, etc.)
338
+ * @param {string} statusUpdateDescription - The description/note for the status update
339
+ * @returns {Observable<any>} Observable that emits the updated document data with normalized status
340
+ */
341
+ updateDocumentStatus(documentId: string, status: string, statusUpdateDescription: string): Observable<any> {
342
+ let headers = new HttpHeaders( {
343
+ 'Authorization': `Bearer 4fe17947-30bf-4079-b4ea-798ff73cd473`
344
+ });
345
+ const payload = {
346
+ statusUpdateDescription: statusUpdateDescription
347
+ };
348
+ return this.http.put<any>(`${this.apiUrl}${URLS.UPDATE_DOCUMENT_STATUS}${documentId}/${status}`, payload, { headers }).pipe(
349
+ tap((response) => {
350
+ if (response && response.status) {
351
+ const normalizedStatus = this.normalizeStatus(response.status);
352
+ response.normalizedStatus = normalizedStatus;
353
+ }
354
+ }),
355
+ catchError((error) => {
356
+ return throwError(() => new Error(error));
357
+ })
358
+ );
359
+ }
360
+
361
+ /**
362
+ * Normalizes the status from API response to match component expectations
363
+ * @param {string} status - The status from API response (Approved, Rejected, etc.)
364
+ * @returns {string} Normalized status value
365
+ */
366
+ private normalizeStatus(status: string): string {
367
+ switch (status.toLowerCase()) {
368
+ case SHARED.APPROVED:
369
+ return SHARED.STATUS_ACCEPTED;
370
+ case SHARED.STATUS_REJECTED_LOWERCASE:
371
+ return SHARED.STATUS_REJECTED_LOWERCASE;
372
+ case SHARED.STATUS_PENDING:
373
+ return SHARED.STATUS_PENDING;
374
+ default:
375
+ return status.toLowerCase();
376
+ }
377
+ }
378
+
379
+ /**
380
+ * Deletes a document by its ID and refreshes all data (categories, userlist, status, and document list)
381
+ * @param {string} documentId - The ID of the document to delete
382
+ * @param {string} contextId - The context ID to refresh all data
383
+ * @returns {Observable<any>} Observable that emits the delete response
384
+ */
385
+ deleteDocument(documentId: string, contextId: string): Observable<any> {
386
+ let headers = new HttpHeaders( {
387
+ 'Authorization': `Bearer 4fe17947-30bf-4079-b4ea-798ff73cd473`
388
+ });
389
+ return this.http.delete<any>(`${this.apiUrl}${URLS.DELETE_DOCUMENT}${documentId}`, { headers }).pipe(
390
+ tap(() => {
391
+ this.getDocumentCatagories(contextId).subscribe();
392
+ this.getUserListByContextId(contextId).subscribe();
393
+ this.getStatusDocumentCount(contextId).subscribe();
394
+ this.getDocumentsBySelection(contextId, null, null, null, null).subscribe();
395
+ }),
396
+ catchError((error) => {
397
+ return throwError(() => new Error(error));
398
+ })
399
+ );
400
+ }
401
+
402
+ /**
403
+ * Downloads an Excel file with proper authentication headers
404
+ * Authentication is handled automatically by the HTTP interceptor
405
+ * @param {string} documentUrl - The URL of the Excel file to download
406
+ * @returns {Observable<ArrayBuffer>} Observable that emits the file data as ArrayBuffer
407
+ */
408
+ downloadExcelFile(documentUrl: string): Observable<ArrayBuffer> {
409
+ let headers = new HttpHeaders( {
410
+ 'Authorization': `Bearer 4fe17947-30bf-4079-b4ea-798ff73cd473`
411
+ });
412
+ return this.http.get(documentUrl, { headers,
413
+ responseType: 'arraybuffer'
414
+ }).pipe(
415
+ catchError((error) => {
416
+ return throwError(() => new Error(error));
417
+ })
418
+ );
419
+ }
420
+
421
+ /**
422
+ * Downloads a CSV file with proper authentication headers
423
+ * Authentication is handled automatically by the HTTP interceptor
424
+ * @param {string} documentUrl - The URL of the CSV file to download
425
+ * @returns {Observable<string>} Observable that emits the file data as string
426
+ */
427
+ downloadCsvFile(documentUrl: string): Observable<string> {
428
+ let headers = new HttpHeaders( {
429
+ 'Authorization': `Bearer 4fe17947-30bf-4079-b4ea-798ff73cd473`
430
+ });
431
+ return this.http.get(documentUrl, { headers,
432
+ responseType: 'text'
433
+ }).pipe(
434
+ catchError((error) => {
435
+ return throwError(() => new Error(error));
436
+ })
437
+ );
438
+ }
439
+
440
+
441
+ /**
442
+ * Downloads an email file (EML) with appropriate handling for different storage types
443
+ * @param documentUrl - URL of the email file
444
+ * @returns Observable of file content as text
445
+ */
446
+ downloadEmailFile(documentUrl: string): Observable<string> {
447
+ let headers = new HttpHeaders( {
448
+ 'Authorization': `Bearer 4fe17947-30bf-4079-b4ea-798ff73cd473`
449
+ });
450
+ const isAzureBlobStorage = documentUrl.includes('.blob.core.windows.net');
451
+ if (isAzureBlobStorage) {
452
+ return this.http.get(documentUrl, { headers,
453
+ responseType: 'text'
454
+ }).pipe(
455
+ catchError((error) => {
456
+ return throwError(() => new Error('Failed to download email file. Please check if the file URL is valid and accessible.'));
457
+ })
458
+ );
459
+ } else {
460
+ return this.http.get<string>(documentUrl, { headers }
461
+ ).pipe(
462
+ catchError((error) => {
463
+ return throwError(() => new Error('Failed to download email file. Please check if the file URL is valid and accessible.'));
464
+ })
465
+ );
466
+ }
467
+ }
468
+
469
+ documentRequest(payload: any): Observable<any> {
470
+ let headers = new HttpHeaders( {
471
+ 'Authorization': `Bearer 4fe17947-30bf-4079-b4ea-798ff73cd473`
472
+ });
473
+ return this.http.post<any>(`${this.apiUrl}${URLS.DOCUMENT_REQUEST}`, payload, { headers }).pipe(
474
+ catchError((error) => {
475
+ return throwError(() => new Error(error));
476
+ })
477
+ );
478
+ }
479
+
480
+ /**
481
+ * Checks if valuation report data exists for the given context ID
482
+ * @param {string} contextId - The context ID to check for valuation report data
483
+ * @returns {Observable<any>} Observable that emits the valuation report data or empty object
484
+ */
485
+ getValuationReportByContextId(contextId: string): Observable<any> {
486
+ let headers = new HttpHeaders( {
487
+ 'Authorization': `Bearer 4fe17947-30bf-4079-b4ea-798ff73cd473`
488
+ });
489
+ if (!contextId) return EMPTY;
490
+ return this.http.get<any>(`${this.apiUrl}${URLS.VALUATION_REPORT}${contextId}`, { headers }).pipe(
491
+ catchError((error) => {
492
+ // Return empty object if no data found or error occurs
493
+ return of(null);
494
+ })
495
+ );
496
+ }
497
+ }
@@ -0,0 +1,195 @@
1
+ import { Injectable } from '@angular/core';
2
+ import { Observable, of, throwError } from 'rxjs';
3
+ import { DocumentUploadService } from './document-upload.service';
4
+ import { DocumentHttpService } from './document-http.service';
5
+ import { DocumentQuery } from '../state/document.query';
6
+ import { DocumentStore } from '../state/document.store';
7
+ import { DocumentTableBuilderService } from './document-table-builder.service';
8
+ import { DocumentHelperService } from './document.service';
9
+ import { DocumentListItem, DocumentListResponse } from '../models/document-list-response.model';
10
+ import { TableData } from '../../../Shared/components/table-primary/table-primary.model';
11
+ import { SHARED } from '../../../Shared/constant/SHARED';
12
+ import { ERRORS } from '../../../Shared/constant/ERROR';
13
+ import { Message } from 'primeng/api';
14
+ import { DocumentCategory } from '../models/document-category.model';
15
+
16
+
17
+ @Injectable({
18
+ providedIn: 'root'
19
+ })
20
+ export class DocumentListService {
21
+
22
+ constructor(
23
+ private documentUploadService: DocumentUploadService,
24
+ private documentHttpService: DocumentHttpService,
25
+ private documentQuery: DocumentQuery,
26
+ private documentStore: DocumentStore,
27
+ private documentTableBuilder: DocumentTableBuilderService,
28
+ private documentHelperService: DocumentHelperService
29
+ ) {}
30
+
31
+ /**
32
+ * Handle file upload click event
33
+ */
34
+ handleFileUploadClick(): void {
35
+ this.documentStore.setMessage(SHARED.EMPTY_ARRAY);
36
+ }
37
+
38
+ /**
39
+ * Handle save click to update document name
40
+ */
41
+ handleSaveClick(fileName: string, selectedDocument: DocumentListItem): Observable<any> {
42
+ const payload = { fileName };
43
+ return this.documentHttpService.updateDocumentName(selectedDocument._id, payload);
44
+ }
45
+
46
+
47
+ /**
48
+ * Get completion count for a category
49
+ */
50
+ getCompletionCount(category: DocumentListResponse): string {
51
+ return this.documentTableBuilder.getCompletionCount(category);
52
+ }
53
+
54
+ /**
55
+ * Get pending document count for a category
56
+ */
57
+ getPendingDocumentCount(category: DocumentListResponse): number {
58
+ return this.documentTableBuilder.getPendingDocumentCount(category);
59
+ }
60
+
61
+ /**
62
+ * Get approved document count for a category
63
+ */
64
+ getApprovedDocumentCount(category: DocumentListResponse): number {
65
+ return this.documentTableBuilder.getApprovedDocumentCount(category);
66
+ }
67
+
68
+
69
+
70
+ /**
71
+ * Build document categories from API response
72
+ */
73
+ buildDocumentCategories(documentListResponse: DocumentListResponse[] | null): {
74
+ documentCategories: DocumentListResponse[];
75
+ categoryTables: TableData[];
76
+ categoryCompletionCounts: string[];
77
+ categorySeverities: ('success' | 'info' | 'warning' | 'danger')[];
78
+ } {
79
+ if (!documentListResponse) {
80
+ return {
81
+ documentCategories: SHARED.EMPTY_ARRAY,
82
+ categoryTables: SHARED.EMPTY_ARRAY,
83
+ categoryCompletionCounts: SHARED.EMPTY_ARRAY,
84
+ categorySeverities: SHARED.EMPTY_ARRAY
85
+ };
86
+ }
87
+
88
+ // Handle empty response - create a default category to show "No records found"
89
+ if (documentListResponse.length === 0) {
90
+ const defaultCategory = {
91
+ label: SHARED.EMPTY,
92
+ categoryDescription: SHARED.NO_DOCUMENTS_FOUND,
93
+ list: SHARED.EMPTY_ARRAY,
94
+ totalDocs: 0,
95
+ acceptedDocs: 0,
96
+ completed: '0/0'
97
+ };
98
+
99
+ return {
100
+ documentCategories: [defaultCategory],
101
+ categoryTables: [this.documentTableBuilder.buildDocumentTable([])],
102
+ categoryCompletionCounts: ['0/0'],
103
+ categorySeverities: ['info']
104
+ };
105
+ }
106
+
107
+ const documentCategories = [...documentListResponse];
108
+ const categoryTables = documentListResponse.map(category =>
109
+ this.documentTableBuilder.buildDocumentTable(category.list)
110
+ );
111
+ const categoryCompletionCounts = documentListResponse.map(category =>
112
+ this.getCompletionCount(category)
113
+ );
114
+
115
+ // Use the same severity calculation logic as menu items for consistency
116
+ const categorySeverities = documentListResponse.map(category => {
117
+ // Create a status object similar to what menu items use
118
+ const status = {
119
+ Pending: category.list.filter(doc => doc.status.toLowerCase() === SHARED.PENDING_STATUS).length,
120
+ Reviewing: category.list.filter(doc => doc.status.toLowerCase() === SHARED.REVIEWING_STATUS).length,
121
+ Accepted: category.list.filter(doc => doc.status.toLowerCase() === SHARED.APPROVED_STATUS || doc.status.toLowerCase() === SHARED.UPLOADED_STATUS).length,
122
+ Rejected: category.list.filter(doc => doc.status.toLowerCase() === SHARED.REJECTED_STATUS).length
123
+ };
124
+
125
+ // Use the same severity calculation as menu items
126
+ const total = status.Pending + status.Reviewing + status.Accepted + status.Rejected;
127
+ if (total === 0) return 'info';
128
+ if (status.Pending > 0) return 'info';
129
+ if (status.Rejected > 0) return 'danger';
130
+ if (status.Reviewing > 0) return 'warning';
131
+ if (status.Accepted === total && total > 0) return 'success';
132
+ return 'warning';
133
+ });
134
+
135
+ return {
136
+ documentCategories,
137
+ categoryTables,
138
+ categoryCompletionCounts,
139
+ categorySeverities
140
+ };
141
+ }
142
+
143
+
144
+
145
+ /**
146
+ * Handle table row click
147
+ */
148
+ handleTableRowClick(rowData: any): DocumentListItem {
149
+ return rowData;
150
+ }
151
+
152
+ /**
153
+ * Handle delete action
154
+ */
155
+ handleDeleteAction(rowData: any, contextId: string): Observable<any> {
156
+ if (!rowData._id || !contextId) {
157
+ return throwError(() => new Error('Missing required parameters for delete'));
158
+ }
159
+
160
+ return this.documentHttpService.deleteDocument(rowData._id, contextId);
161
+ }
162
+
163
+ /**
164
+ * Refresh document list for new context
165
+ */
166
+ refreshDocumentListForNewContext(contextId: string): void {
167
+ if (contextId && contextId !== SHARED.EMPTY) {
168
+ this.documentStore.setDocumentListResponse(null);
169
+ this.documentHelperService.refreshDocumentsWithoutFilters(contextId);
170
+ }
171
+ }
172
+
173
+ /**
174
+ * Refresh document list after status update
175
+ */
176
+ refreshDocumentList(contextId: string): void {
177
+ if (contextId) {
178
+ this.documentHelperService.refreshDocumentsWithCurrentSelection(contextId);
179
+ }
180
+ }
181
+
182
+ /**
183
+ * Setup subscription to document list response
184
+ */
185
+ setupDocumentListSubscription(): Observable<DocumentListResponse[] | null> {
186
+ return this.documentQuery.selectDocumentListResponse();
187
+ }
188
+
189
+ /**
190
+ * Refresh all data with current filters
191
+ */
192
+ refreshAllDataWithCurrentFilters(contextId: string): void {
193
+ this.documentHelperService.refreshAllDataWithCurrentFilters(contextId);
194
+ }
195
+ }