cat-documents-ng 0.1.30 → 0.1.32

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 (92) hide show
  1. package/{src/Shared/constant/ERROR.ts → Shared/constant/ERROR.d.ts} +43 -38
  2. package/Shared/constant/PERMISSIONS.d.ts +20 -0
  3. package/Shared/constant/SHARED.d.ts +215 -0
  4. package/{src/Shared/constant/URLS.ts → Shared/constant/URLS.d.ts} +60 -65
  5. package/Shared/services/app-config.service.d.ts +51 -0
  6. package/{src/Shared/services/global-error.handler.ts → Shared/services/global-error.handler.d.ts} +27 -29
  7. package/Shared/services/session.service.d.ts +46 -0
  8. package/fesm2022/cat-documents-ng.mjs +2623 -0
  9. package/fesm2022/cat-documents-ng.mjs.map +1 -0
  10. package/index.d.ts +5 -0
  11. package/lib/document/components/document-container/document-container.component.d.ts +101 -0
  12. package/lib/document/components/document-list/document-list.component.d.ts +193 -0
  13. package/lib/document/components/document-list-item/document-list-item.component.d.ts +28 -0
  14. package/lib/document/components/document-upload/document-upload.component.d.ts +120 -0
  15. package/lib/document/components/document-viewer/document-viewer.component.d.ts +77 -0
  16. package/{src/lib/document/components/folder-block/folder-block.component.ts → lib/document/components/folder-block/folder-block.component.d.ts} +37 -53
  17. package/lib/document/components/folder-container/folder-container.component.d.ts +29 -0
  18. package/lib/document/components/linked-document/linked-document.component.d.ts +38 -0
  19. package/lib/document/directives/document.directive.d.ts +20 -0
  20. package/lib/document/directives/permission.directive.d.ts +38 -0
  21. package/lib/document/document.module.d.ts +40 -0
  22. package/{src/lib/document/models/document-alert.model.ts → lib/document/models/document-alert.model.d.ts} +38 -45
  23. package/lib/document/models/document-type.model.d.ts +37 -0
  24. package/lib/document/models/document.model.d.ts +44 -0
  25. package/{src/lib/document/models/folder.model.ts → lib/document/models/folder.model.d.ts} +29 -35
  26. package/lib/document/services/document-http.service.d.ts +69 -0
  27. package/lib/document/services/document-upload.service.d.ts +67 -0
  28. package/lib/document/services/document.service.d.ts +20 -0
  29. package/lib/document/services/file-format.service.d.ts +23 -0
  30. package/lib/document/state/document.query.d.ts +50 -0
  31. package/{src/lib/document/state/document.service.ts → lib/document/state/document.service.d.ts} +64 -95
  32. package/{src/lib/document/state/document.state.ts → lib/document/state/document.state.d.ts} +36 -52
  33. package/lib/document/state/document.store.d.ts +29 -0
  34. package/package.json +25 -20
  35. package/{src/public-api.ts → public-api.d.ts} +6 -10
  36. package/ng-package.json +0 -11
  37. package/src/Shared/constant/PERMISSIONS.ts +0 -16
  38. package/src/Shared/constant/SHARED.ts +0 -312
  39. package/src/Shared/services/app-config.service.spec.ts +0 -19
  40. package/src/Shared/services/app-config.service.ts +0 -73
  41. package/src/Shared/services/session.service.spec.ts +0 -16
  42. package/src/Shared/services/session.service.ts +0 -76
  43. package/src/assets/config/api.config.json +0 -20
  44. package/src/lib/document/components/document-container/document-container.component.html +0 -14
  45. package/src/lib/document/components/document-container/document-container.component.scss +0 -8
  46. package/src/lib/document/components/document-container/document-container.component.spec.ts +0 -110
  47. package/src/lib/document/components/document-container/document-container.component.ts +0 -173
  48. package/src/lib/document/components/document-list/document-list.component.html +0 -81
  49. package/src/lib/document/components/document-list/document-list.component.scss +0 -82
  50. package/src/lib/document/components/document-list/document-list.component.spec.ts +0 -96
  51. package/src/lib/document/components/document-list/document-list.component.ts +0 -244
  52. package/src/lib/document/components/document-list-item/document-list-item.component.html +0 -36
  53. package/src/lib/document/components/document-list-item/document-list-item.component.scss +0 -34
  54. package/src/lib/document/components/document-list-item/document-list-item.component.spec.ts +0 -75
  55. package/src/lib/document/components/document-list-item/document-list-item.component.ts +0 -40
  56. package/src/lib/document/components/document-upload/document-upload.component.html +0 -56
  57. package/src/lib/document/components/document-upload/document-upload.component.scss +0 -32
  58. package/src/lib/document/components/document-upload/document-upload.component.spec.ts +0 -95
  59. package/src/lib/document/components/document-upload/document-upload.component.ts +0 -162
  60. package/src/lib/document/components/document-viewer/document-viewer.component.html +0 -98
  61. package/src/lib/document/components/document-viewer/document-viewer.component.scss +0 -54
  62. package/src/lib/document/components/document-viewer/document-viewer.component.spec.ts +0 -79
  63. package/src/lib/document/components/document-viewer/document-viewer.component.ts +0 -106
  64. package/src/lib/document/components/folder-block/folder-block.component.html +0 -46
  65. package/src/lib/document/components/folder-block/folder-block.component.scss +0 -9
  66. package/src/lib/document/components/folder-block/folder-block.component.spec.ts +0 -70
  67. package/src/lib/document/components/folder-container/folder-container.component.html +0 -2
  68. package/src/lib/document/components/folder-container/folder-container.component.scss +0 -0
  69. package/src/lib/document/components/folder-container/folder-container.component.spec.ts +0 -27
  70. package/src/lib/document/components/folder-container/folder-container.component.ts +0 -37
  71. package/src/lib/document/components/linked-document/linked-document.component.html +0 -23
  72. package/src/lib/document/components/linked-document/linked-document.component.scss +0 -10
  73. package/src/lib/document/components/linked-document/linked-document.component.spec.ts +0 -61
  74. package/src/lib/document/components/linked-document/linked-document.component.ts +0 -49
  75. package/src/lib/document/directives/document.directive.ts +0 -32
  76. package/src/lib/document/directives/permission.directive.spec.ts +0 -0
  77. package/src/lib/document/directives/permission.directive.ts +0 -66
  78. package/src/lib/document/document.module.ts +0 -241
  79. package/src/lib/document/models/document-type.model.ts +0 -44
  80. package/src/lib/document/models/document.model.ts +0 -53
  81. package/src/lib/document/services/document-http.service.spec.ts +0 -119
  82. package/src/lib/document/services/document-http.service.ts +0 -125
  83. package/src/lib/document/services/document-upload.service.spec.ts +0 -99
  84. package/src/lib/document/services/document-upload.service.ts +0 -127
  85. package/src/lib/document/services/document.service.ts +0 -29
  86. package/src/lib/document/services/file-format.service.spec.ts +0 -16
  87. package/src/lib/document/services/file-format.service.ts +0 -41
  88. package/src/lib/document/state/document.query.ts +0 -52
  89. package/src/lib/document/state/document.store.ts +0 -51
  90. package/tsconfig.lib.json +0 -15
  91. package/tsconfig.lib.prod.json +0 -11
  92. package/tsconfig.spec.json +0 -15
@@ -1,173 +0,0 @@
1
- import { Component, Input, OnInit } from '@angular/core';
2
- import { SHARED } from '../../../../Shared/constant/SHARED';
3
- import { DocumentService } from '../../state/document.service';
4
- import { DocumentModel } from '../../models/document.model';
5
- import { URLS } from '../../../../Shared/constant/URLS';
6
- import { Subscription } from 'rxjs';
7
- import { ERRORS } from '../../../../Shared/constant/ERROR';
8
- import { FolderBlockModel } from '../../models/folder.model';
9
- import { DocumentHttpService } from '../../services/document-http.service';
10
- import { DocumentQuery } from '../../state/document.query';
11
- import { DocumentStore } from '../../state/document.store';
12
-
13
-
14
- /**
15
- *This component is responsible for managing and displaying a list of documents.
16
- * @class DocumentContainerComponent
17
- * @typedef {DocumentContainerComponent}
18
- */
19
- @Component({
20
- selector: 'lib-document-container',
21
- standalone: false,
22
- templateUrl: './document-container.component.html',
23
- styleUrl: './document-container.component.scss'
24
- })
25
- export class DocumentContainerComponent implements OnInit{
26
-
27
- /**
28
- * Creates an instance of DocumentContainerComponent.
29
- * @param {DocumentStore} documentStore - Query Store service to manage store document-related state.
30
- * @param {DocumentService} documentService - Service to manage document-related operations.
31
- * @param {DocumentQuery} documentQuery - Query service to manage document-related state.
32
- * @param {DocumentHttpService} documentHttpService - Service to make HTTP requests related to documents.
33
- */
34
- constructor(public documentStore : DocumentStore,public documentService : DocumentService, public documentQuery : DocumentQuery,public documentHttpService: DocumentHttpService) {
35
-
36
- }
37
- /**
38
- * Get contextId in input.
39
- * @type {string}
40
- */
41
- @Input() contextId : string = SHARED.EMPTY;
42
- /**
43
- * Get isCollapsed in input.
44
- * @type {string}
45
- */
46
- @Input() isCollapsed : boolean = SHARED.FALSE;
47
- /**
48
- * Get showFolderList in input.
49
- * @type {boolean}
50
- */
51
- @Input() showFolderList : boolean = SHARED.TRUE;
52
- /**
53
- * Get isUploadButtonVisible in input.
54
- * @type {boolean}
55
- */
56
- @Input() isUploadButtonVisible : boolean = SHARED.TRUE;
57
- /**
58
- * The list of documents.
59
- * @type {Array}
60
- */
61
- documentList : DocumentModel[] = []
62
- /**
63
- * The list of folders.
64
- * @type {Array}
65
- */
66
- folderList : FolderBlockModel[] = SHARED.EMPTY_ARRAY
67
-
68
- /**
69
- * Holds the subscription to manage observable cleanup.
70
- * @private
71
- * @type {Subscription}
72
- */
73
- private subscription: Subscription = new Subscription();
74
-
75
- /**
76
- * Fetches the folder and document data on initialization.
77
- * @returns {void}
78
- */
79
- ngOnInit(): void {
80
- this.fetchFolder();
81
- const folderSubscription = this.documentQuery
82
- .selectParentDocumentTypeId()
83
- .subscribe((folderBlockId: any) => {
84
- const validFolders = this.folderList.filter(folder => (folder.documentCount ?? 0) > 0);
85
- const idToFetch = folderBlockId ?? validFolders[0]?._id;
86
- if (idToFetch) {
87
- this.fetchDocuments(idToFetch);
88
- } else {
89
- console.warn('No folders with documents available.');
90
- }
91
- });
92
- this.subscription.add(folderSubscription);
93
- }
94
-
95
-
96
-
97
- /**
98
- * Fetches the folder data from the API.
99
- * @returns {void}
100
- */
101
- /**
102
- * Fetches the folder data from the API.
103
- * @returns {void}
104
- */
105
- public fetchFolder(): void {
106
- const folderSubscription = this.documentHttpService.getFoldersData(this.contextId).subscribe({
107
- /**
108
- * Handles the successful API response.
109
- * @param {FolderBlockModel[]} folder - The list of folders returned by the API.
110
- */
111
- next: (folder: FolderBlockModel[]) => {
112
- if (folder && folder.length > 0) {
113
- this.folderList = folder.filter(f => (f.documentCount ?? 0) > 0);
114
- if (this.folderList.length > 0) {
115
- this.fetchDocuments(this.folderList[0]._id);
116
- } else {
117
- console.warn('No folders with documents found.');
118
- }
119
- } else {
120
- console.error(ERRORS.ERROR_ALLDOCUMENT_MISSING);
121
- }
122
- },
123
- /**
124
- * Handles errors if the request fails.
125
- * @param {any} err - The error object returned by the server.
126
- */
127
- error: (err: any) => {
128
- console.error(ERRORS.ERROR_DOCUMENT_TYPES, err);
129
- }
130
- });
131
- this.subscription.add(folderSubscription);
132
- }
133
-
134
-
135
-
136
- /**
137
- * Fetches the document data from the API.
138
- * @param {string} folderBlockId - The folder ID to fetch the document.
139
- * @returns {void}
140
- */
141
- private fetchDocuments(folderBlockId:string): void {
142
- const documentSubscription = this.documentHttpService.getDocumentByFolderID(folderBlockId, this.contextId).subscribe({
143
- /**
144
- * Handles the successful API response.
145
- * @param {DocumentModel[]} documentList - The list of documents returned by the API.
146
- */
147
- next: (documentList: DocumentModel[]) => {
148
- if (documentList) {
149
- this.documentList = documentList;
150
- this.documentStore.setDocumentList(documentList)
151
- } else {
152
- console.error(ERRORS.ERROR_FETCHING_DOCUMENTS);
153
- }
154
- },
155
- /**
156
- * Handles errors if the request fails.
157
- * @param {any} err - The error object returned by the server.
158
- */
159
- error: (err: any) => {
160
- console.error(ERRORS.ERROR_FETCHING_DOCUMENTS, err);
161
- }
162
- }
163
- )
164
- this.subscription.add(documentSubscription);
165
- }
166
-
167
- /**
168
- * Unsubscribe subscription on destroy of component .
169
- */
170
- ngOnDestroy(): void {
171
- this.subscription.unsubscribe();
172
- }
173
- }
@@ -1,81 +0,0 @@
1
-
2
- <div class="document-viewer">
3
- <p-dialog [(visible)]="isdialogVisible" [modal]="true" (onHide)="handleCloseModal()"
4
- class="w-full h-full document-dailog-wrapper"
5
- [draggable]="false" [closable]="true">
6
- <document-viewer [selectedDocument]="selectedDocument" [documentList]="documentList">
7
-
8
- <ng-template pTemplate="header">
9
- <div class="w-full flex align-items-center justify-content-between">
10
- <input
11
- type="text"
12
- class="w-full border-none bg-white h-3rem file-input-wrapper"
13
- pInputText
14
- [(ngModel)]="fileName" />
15
- <button
16
- pButton
17
- pRipple
18
- class="mx-3 w-6rem save-btn-wrapper"
19
- label="Save"
20
- (click)="handleSaveClick()">
21
- </button>
22
- </div>
23
- </ng-template>
24
-
25
-
26
- <ng-content></ng-content>
27
- </document-viewer>
28
- </p-dialog>
29
- </div>
30
-
31
- <div class="col-12 p-0">
32
- <div class="card p-0 mb-0 document-list-wrapper">
33
- <p-accordion [activeIndex]="isCollapsed ? -1 : 0">
34
- <p-accordionTab class="line-height-2 m-0">
35
- <ng-template pTemplate="header" let-active="active">
36
- <div class="flex align-items-center justify-content-between w-full">
37
- <span class="flex align-items-center gap-2 document-title-wrapper">
38
- Documents
39
- </span>
40
- @if(isUploadButtonVisible){
41
- <button pButton pRipple class="p-button-raised col-3" [permission]="PERMISSION.DOCUMENT_POST" type="button" label="Upload File"
42
- style="border-radius: 10px;" (click)="handleFileUploadClick($event)"></button>
43
- }
44
- </div>
45
- </ng-template>
46
- @for(document of documentList; track document){
47
- <lib-document-list-item [document]="document"
48
- (documentClick)="handleClickForDocument($event)"></lib-document-list-item>
49
- }
50
- </p-accordionTab>
51
- </p-accordion>
52
- </div>
53
- </div>
54
- <div class="grid m-0">
55
- <div class="col-12 p-0">
56
- <p-sidebar [(visible)]="isSidebarVisible" position="right" [styleClass]="'right-sidebar'" class="relative">
57
- <ng-template pTemplate="header">
58
- <p-messages [(value)]="messages" [enableService]="false" />
59
- </ng-template>
60
- <ng-template pTemplate="content">
61
- <div class="side-bar-con">
62
- <lib-document-upload [contextId]="contextId"></lib-document-upload>
63
- <div class="p-fluid">
64
- <div class="field">
65
- <label for="city">Select Folder</label>
66
- <p-dropdown id="city" optionLabel="label" optionValue="value" [options]="options"
67
- placeholder="Select a Folder" [(ngModel)]="selectedOption"></p-dropdown>
68
- </div>
69
- </div>
70
- </div>
71
- </ng-template>
72
- <ng-template pTemplate="footer" class="bg-gray-100 p-0">
73
- <div class="bg-gray-100 p-4">
74
- <p-button label="Save" class="p-button-rounded p-button-success save-btn" (click)="handleUploadDocument()"
75
- [disabled]="!selectedOption">
76
- </p-button>
77
- </div>
78
- </ng-template>
79
- </p-sidebar>
80
- </div>
81
- </div>
@@ -1,82 +0,0 @@
1
- .document-list-wrapper{
2
- .p-accordion-header-link {
3
- padding: 0.5rem;
4
- }
5
- .p-sidebar-right{
6
- width: 35%;
7
- }
8
- }
9
-
10
- .right-sidebar{
11
- width: 35%;
12
- }
13
-
14
- .document-title-wrapper{
15
- font-size: 20px;
16
- font-weight: 700;
17
- color: var(--text-color);
18
- }
19
-
20
- .document-input-field{
21
- display: flex;
22
- flex-direction: column;
23
- input{
24
- width:100%;
25
- height: 46px;
26
- padding: 10px 15px 10px 15px;
27
- gap: 10px;
28
- border-radius: 10px;
29
- outline: none;
30
- border: 1px solid #4C62921A;
31
- font-size: 15px;
32
- }
33
- }
34
- label{
35
- color: #0F1729;
36
- font-weight: 600;
37
-
38
- }
39
- .document-list-dropDown{
40
- .p-element{
41
- padding: 10px 0px 10px 15px;
42
- }
43
- .p-dropdown{
44
- border-radius: 10px !important;
45
- }
46
- }
47
-
48
-
49
- .side-bar-con{
50
- display: flex;
51
- flex-direction: column;
52
- }
53
-
54
-
55
- .save-btn-con{
56
- width: 100%;
57
- border-top: 1px solid #4C629233;
58
- background: #4C629214;
59
- padding: 13px 40px 13px 40px
60
-
61
- }
62
-
63
- .save-btn-wrapper{
64
- padding: 10px 4px;
65
- }
66
-
67
- .save-btn{
68
- .p-button{
69
- height: 45px !important;
70
- width: 140px;
71
- border-radius: 10px;
72
- }
73
-
74
-
75
- }
76
- .p-sidebar-footer {
77
- padding: 0px;
78
- }
79
-
80
- .file-input-wrapper.p-inputtext:enabled:focus {
81
- box-shadow: 0 0 0 0.2rem #a6d5fa !important;
82
- }
@@ -1,96 +0,0 @@
1
- import { ComponentFixture, TestBed } from '@angular/core/testing';
2
- import { DocumentListComponent } from './document-list.component';
3
- import { DocumentUploadService } from '../../services/document-upload.service';
4
- import { DocumentHttpService } from '../../services/document-http.service';
5
- import { of } from 'rxjs';
6
- import { NO_ERRORS_SCHEMA } from '@angular/core';
7
- import { DocumentTypeModel } from '../../models/document-type.model';
8
- import { DocumentModel } from '../../models/document.model';
9
- import { SHARED } from '../../../../Shared/constant/SHARED';
10
-
11
- describe('DocumentListComponent', () => {
12
- let component: DocumentListComponent;
13
- let fixture: ComponentFixture<DocumentListComponent>;
14
- let documentUploadService: jasmine.SpyObj<DocumentUploadService>;
15
- let documentHttpService: jasmine.SpyObj<DocumentHttpService>;
16
-
17
- beforeEach(async () => {
18
- // Mock services
19
- documentUploadService = jasmine.createSpyObj('DocumentUploadService', [
20
- 'getDocumentNameAndType',
21
- 'handleTemplatedUpload'
22
- ]);
23
- documentHttpService = jasmine.createSpyObj('DocumentHttpService', ['getDocumentTypes', 'updateDocumentName']);
24
-
25
- // Mock `getDocumentTypes` to return valid `DocumentTypeModel` objects
26
- documentHttpService.getDocumentTypes.and.returnValue(
27
- of([
28
- { _id: 1, label: 'Type 1', matchRules: [], name: 'Type 1', parentDocumentTypeId: null },
29
- { _id: 2, label: 'Type 2', matchRules: [], name: 'Type 2', parentDocumentTypeId: null }
30
- ] as unknown as DocumentTypeModel[])
31
- );
32
-
33
- await TestBed.configureTestingModule({
34
- declarations: [DocumentListComponent],
35
- providers: [
36
- { provide: DocumentUploadService, useValue: documentUploadService },
37
- { provide: DocumentHttpService, useValue: documentHttpService }
38
- ],
39
- schemas: [NO_ERRORS_SCHEMA] // To suppress schema-related errors
40
- }).compileComponents();
41
-
42
- fixture = TestBed.createComponent(DocumentListComponent);
43
- component = fixture.componentInstance;
44
- fixture.detectChanges(); // Trigger lifecycle hooks and initial data binding
45
- });
46
-
47
- it('should create', () => {
48
- expect(component).toBeTruthy();
49
- });
50
-
51
- it('should fetch document types on initialization', () => {
52
- expect(component.options).toEqual([
53
- { label: 'Type 1', value: 1 },
54
- { label: 'Type 2', value: 2 }
55
- ]);
56
- });
57
-
58
- it('should handle file upload click', () => {
59
- const event = new MouseEvent('click');
60
- spyOn(event, 'stopPropagation');
61
- component.handleFileUploadClick(event);
62
- expect(event.stopPropagation).toHaveBeenCalled();
63
- expect(component.isSidebarVisible).toBeTrue();
64
- });
65
-
66
- it('should handle document click and open dialog', () => {
67
- const mockDocument = { _id: "1", documentUrl: 'http://example.com/doc.pdf' } as DocumentModel;
68
-
69
- component.handleClickForDocument(mockDocument);
70
- expect(component.isdialogVisible).toBeTrue();
71
- expect(component.selectedDocument).toBe(mockDocument);
72
- });
73
-
74
- it('should handle dialog close and reset selected document', () => {
75
- component.selectedDocument = { _id: "1" };
76
- component.handleCloseModal();
77
- expect(component.selectedDocument).toEqual({ _id: "" });
78
-
79
-
80
- expect(component.isdialogVisible).toBeFalse();
81
- });
82
-
83
- it('should update document name on handleSaveClick', () => {
84
- component.fileName = 'New Document';
85
- component.selectedDocument = { _id: '1' } as DocumentModel;
86
-
87
- spyOn(console, 'log');
88
-
89
- documentHttpService.updateDocumentName.and.returnValue(of({} as DocumentModel));
90
-
91
- component.handleSaveClick();
92
- expect(documentHttpService.updateDocumentName).toHaveBeenCalledWith('1', { fileName: 'New Document' });
93
- expect(console.log).toHaveBeenCalledWith(`${SHARED.UPDATE_DOCUMENT_NAME} 1`);
94
- });
95
-
96
- });
@@ -1,244 +0,0 @@
1
- import { Component, EventEmitter, Input, OnInit, Output, ViewEncapsulation } from '@angular/core';
2
- import { DocumentModel } from '../../models/document.model';
3
- import { SHARED } from '../../../../Shared/constant/SHARED';
4
- import { ERRORS } from '../../../../Shared/constant/ERROR';
5
- import { DocumentHttpService } from '../../services/document-http.service';
6
- import { DocumentTypeModel } from '../../models/document-type.model';
7
- import { DocumentUploadService } from '../../services/document-upload.service';
8
- import { Message } from 'primeng/api';
9
- import { DocumentQuery } from '../../state/document.query';
10
- import { DocumentStore } from '../../state/document.store';
11
- import { PERMISSIONS } from '../../../../Shared/constant/PERMISSIONS';
12
-
13
- /**
14
- * This component is responsible for displaying and managing a list of documents.
15
- * Provides functionality for file upload, document selection, and dialog management.
16
- * @class DocumentListComponent
17
- */
18
- @Component({
19
- selector: 'lib-document-list',
20
- standalone: false,
21
- templateUrl: './document-list.component.html',
22
- styleUrls: ['./document-list.component.scss'],
23
- encapsulation: ViewEncapsulation.None
24
- })
25
- export class DocumentListComponent implements OnInit{
26
-
27
- @Output() onRefresh = new EventEmitter();
28
- /**
29
- * Represents the context ID for the document list.
30
- * This value is passed from the parent component.
31
- * @type {string}
32
- * @memberof DocumentListComponent
33
- */
34
- @Input() contextId: string = SHARED.EMPTY;
35
-
36
- /**
37
- * Default visibility of the upload button.
38
- * @type {boolean}
39
- * @memberof DocumentListComponent
40
- */
41
- @Input() isUploadButtonVisible:boolean = SHARED.TRUE;
42
-
43
- /**
44
- * The currently selected document.
45
- * @type {DocumentModel}
46
- * @memberof DocumentListComponent
47
- */
48
- selectedDocument!: DocumentModel;
49
-
50
- /**
51
- * Default visibility of the sidebar.
52
- * @type {boolean}
53
- * @memberof DocumentListComponent
54
- */
55
- isSidebarVisible: boolean = SHARED.FALSE;
56
-
57
- /**
58
- * Default visibility of the Accordion.
59
- * @type {boolean}
60
- * @memberof DocumentListComponent
61
- */
62
- @Input() isCollapsed: boolean = SHARED.FALSE;
63
-
64
- /**
65
- * Default visibility of the messages.
66
- * @type {Message[]}
67
- * @memberof DocumentListComponent
68
- */
69
- messages: Message[] = SHARED.EMPTY_ARRAY;
70
-
71
- /**
72
- * Default visibility of the dialog.
73
- * @type {boolean}
74
- * @memberof DocumentListComponent
75
- */
76
- isdialogVisible: boolean = SHARED.FALSE;
77
-
78
- /**
79
- * The list of documents to display.
80
- * This value is passed from the parent component.
81
- * @type {DocumentModel[]}
82
- * @memberof DocumentListComponent
83
- */
84
- @Input() documentList: DocumentModel[] = SHARED.EMPTY_ARRAY;
85
-
86
- /**
87
- * The name of the document being uploaded or managed.
88
- * @type {string}
89
- * @memberof DocumentListComponent
90
- */
91
- documentName: string = SHARED.EMPTY;
92
-
93
- /**
94
- * Available document types for selection.
95
- * @type {string[]}
96
- * @memberof DocumentListComponent
97
- */
98
- options : any[] = SHARED.EMPTY_ARRAY;
99
-
100
- /**
101
- * The selected option for the document type.
102
- * @type {(string | null)}
103
- * @memberof DocumentListComponent
104
- */
105
- selectedOption: string | null = null;
106
-
107
- /**
108
- * The set of permissions available for this component.
109
- */
110
- PERMISSION = PERMISSIONS;
111
- /**
112
- * The file name associated with the document.
113
- * It may be undefined until a file is selected or loaded.
114
- * @type {string | undefined}
115
- */
116
- fileName!: string | undefined;
117
- /**
118
- * Creates an instance of DocumentListComponent.
119
- * @class
120
- * @param {DocumentUploadService} documentUploadService - The service responsible for uploading documents.
121
- * @param {DocumentHttpService} documentHttpService - The service responsible for fetching documents from the server.
122
- * @param {DocumentQuery} documentQuery - The service responsible for geting stored documents.
123
- * @param {DocumentStore} documentStore - The service responsible for storing documents.
124
- */
125
- constructor(public documentUploadService : DocumentUploadService ,public documentHttpService : DocumentHttpService, public documentQuery : DocumentQuery, public documentStore : DocumentStore) {
126
-
127
- }
128
-
129
- /**
130
- * Initializes the component by fetching the document type list.
131
- */
132
- ngOnInit(): void {
133
- this.getDocumentTypeList();
134
- }
135
-
136
- /**
137
- * Handles the click event for file upload.
138
- * Prevents event propagation and displays the sidebar.
139
- * @param {MouseEvent} event - The click event triggered by the user.
140
- * @memberof DocumentListComponent
141
- */
142
- handleFileUploadClick(event: MouseEvent): void {
143
- event.stopPropagation();
144
- this.documentStore.setMessage(SHARED.EMPTY_ARRAY)
145
- this.isSidebarVisible = SHARED.TRUE;
146
- }
147
-
148
- /**
149
- * Handles the selection of an individual document.
150
- * Opens a dialog to display or manage the selected document.
151
- * @param {DocumentModel} document - The document that was clicked by the user.
152
- * @memberof DocumentListComponent
153
- */
154
- handleClickForDocument(document: DocumentModel): void {
155
- this.isdialogVisible = SHARED.TRUE;
156
- this.selectedDocument = document;
157
- this.fileName = document.fileName;
158
- }
159
-
160
- /**
161
- * Handles the save click event to update the document's file name.
162
- * This method creates a payload with the updated file name and calls the
163
- * updateDocumentName() method from the documentHttpService. On a successful update,
164
- * it logs a message with the document's ID.
165
- * @returns {void}
166
- */
167
- handleSaveClick() {
168
- const payload = { fileName: this.fileName };
169
- this.documentHttpService.updateDocumentName(this.selectedDocument._id, payload)
170
- .subscribe((res) => {
171
- console.log(`${SHARED.UPDATE_DOCUMENT_NAME} ${this.selectedDocument._id}`);
172
- })
173
- }
174
- /**
175
- * Closes the dialog and resets the selected document.
176
- * @memberof DocumentListComponent
177
- */
178
- handleCloseModal(): void {
179
- this.selectedDocument = { _id: SHARED.EMPTY };
180
- this.isdialogVisible = SHARED.FALSE;
181
- this.onRefresh.emit();
182
- }
183
-
184
- /**
185
- * Handles the upload action for a document.
186
- * Validates if a document type is selected and logs the result.
187
- * @memberof DocumentListComponent
188
- */
189
- handleUploadDocument(): void {
190
- if (this.selectedOption) {
191
- this.documentUploadService.getDocumentNameAndType(this.selectedOption);
192
- this.documentUploadService.handleTemplatedUpload();
193
- this.documentQuery.selectMessages().subscribe((message:Message[])=>{
194
- if(message.length > 0){
195
- this.messages = message;
196
- this.onRefresh.emit();
197
- this.selectedOption = null;
198
- setTimeout(() => {
199
- this.messages = SHARED.EMPTY_ARRAY
200
- this.handleOpenSideBar(false);
201
- }, 1000);
202
- }
203
- })
204
- } else {
205
- console.error(ERRORS.INVALID_RECIPIENT);
206
- }
207
- }
208
-
209
- /**
210
- * Fetches the list of document types from the server.
211
- * Updates the options array with the available document types.
212
- * @memberof DocumentListComponent
213
- * @returns {void}
214
- */
215
- getDocumentTypeList() {
216
- this.documentHttpService.getDocumentTypes().subscribe({
217
- /**
218
- * Handles the successful API response.
219
- * @param {DocumentTypeModel[]} documentTypes - The list of document types returned by the API.
220
- */
221
- next: (documentTypes: DocumentTypeModel[]) => {
222
- if (documentTypes) {
223
- this.options = documentTypes.map((doc) => ({
224
- label: doc.label,
225
- value: doc._id
226
- }));
227
- } else {
228
- console.error(ERRORS.ERROR_ALLDOCUMENT_MISSING, documentTypes);
229
- }
230
- },
231
- /**
232
- * Handles errors if the request fails.
233
- * @param {any} err - The error object returned by the server.
234
- */
235
- error: (err: any) => {
236
- console.error(ERRORS.ERROR_DOCUMENT_TYPES, err);
237
- }
238
- });
239
- }
240
-
241
- handleOpenSideBar(isVisible : boolean){
242
- this.isSidebarVisible = isVisible
243
- }
244
- }