cat-documents-ng 0.1.27 → 0.1.30
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.
- package/ng-package.json +11 -0
- package/package.json +20 -25
- package/{Shared/constant/ERROR.d.ts → src/Shared/constant/ERROR.ts} +38 -36
- package/src/Shared/constant/PERMISSIONS.ts +16 -0
- package/src/Shared/constant/SHARED.ts +312 -0
- package/{Shared/constant/URLS.d.ts → src/Shared/constant/URLS.ts} +65 -60
- package/src/Shared/services/app-config.service.spec.ts +19 -0
- package/src/Shared/services/app-config.service.ts +73 -0
- package/{Shared/services/global-error.handler.d.ts → src/Shared/services/global-error.handler.ts} +29 -27
- package/src/Shared/services/session.service.spec.ts +16 -0
- package/src/Shared/services/session.service.ts +76 -0
- package/src/assets/config/api.config.json +20 -0
- package/src/lib/document/components/document-container/document-container.component.html +14 -0
- package/src/lib/document/components/document-container/document-container.component.scss +8 -0
- package/src/lib/document/components/document-container/document-container.component.spec.ts +110 -0
- package/src/lib/document/components/document-container/document-container.component.ts +173 -0
- package/src/lib/document/components/document-list/document-list.component.html +81 -0
- package/src/lib/document/components/document-list/document-list.component.scss +82 -0
- package/src/lib/document/components/document-list/document-list.component.spec.ts +96 -0
- package/src/lib/document/components/document-list/document-list.component.ts +244 -0
- package/src/lib/document/components/document-list-item/document-list-item.component.html +36 -0
- package/src/lib/document/components/document-list-item/document-list-item.component.scss +34 -0
- package/src/lib/document/components/document-list-item/document-list-item.component.spec.ts +75 -0
- package/src/lib/document/components/document-list-item/document-list-item.component.ts +40 -0
- package/src/lib/document/components/document-upload/document-upload.component.html +56 -0
- package/src/lib/document/components/document-upload/document-upload.component.scss +32 -0
- package/src/lib/document/components/document-upload/document-upload.component.spec.ts +95 -0
- package/src/lib/document/components/document-upload/document-upload.component.ts +162 -0
- package/src/lib/document/components/document-viewer/document-viewer.component.html +98 -0
- package/src/lib/document/components/document-viewer/document-viewer.component.scss +54 -0
- package/src/lib/document/components/document-viewer/document-viewer.component.spec.ts +79 -0
- package/src/lib/document/components/document-viewer/document-viewer.component.ts +106 -0
- package/src/lib/document/components/folder-block/folder-block.component.html +46 -0
- package/src/lib/document/components/folder-block/folder-block.component.scss +9 -0
- package/src/lib/document/components/folder-block/folder-block.component.spec.ts +70 -0
- package/{lib/document/components/folder-block/folder-block.component.d.ts → src/lib/document/components/folder-block/folder-block.component.ts} +53 -37
- package/src/lib/document/components/folder-container/folder-container.component.html +2 -0
- package/src/lib/document/components/folder-container/folder-container.component.scss +0 -0
- package/src/lib/document/components/folder-container/folder-container.component.spec.ts +27 -0
- package/src/lib/document/components/folder-container/folder-container.component.ts +37 -0
- package/src/lib/document/components/linked-document/linked-document.component.html +23 -0
- package/src/lib/document/components/linked-document/linked-document.component.scss +10 -0
- package/src/lib/document/components/linked-document/linked-document.component.spec.ts +61 -0
- package/src/lib/document/components/linked-document/linked-document.component.ts +49 -0
- package/src/lib/document/directives/document.directive.ts +32 -0
- package/src/lib/document/directives/permission.directive.spec.ts +0 -0
- package/src/lib/document/directives/permission.directive.ts +66 -0
- package/src/lib/document/document.module.ts +241 -0
- package/{lib/document/models/document-alert.model.d.ts → src/lib/document/models/document-alert.model.ts} +45 -38
- package/src/lib/document/models/document-type.model.ts +44 -0
- package/src/lib/document/models/document.model.ts +53 -0
- package/{lib/document/models/folder.model.d.ts → src/lib/document/models/folder.model.ts} +35 -29
- package/src/lib/document/services/document-http.service.spec.ts +119 -0
- package/src/lib/document/services/document-http.service.ts +125 -0
- package/src/lib/document/services/document-upload.service.spec.ts +99 -0
- package/src/lib/document/services/document-upload.service.ts +127 -0
- package/src/lib/document/services/document.service.ts +29 -0
- package/src/lib/document/services/file-format.service.spec.ts +16 -0
- package/src/lib/document/services/file-format.service.ts +41 -0
- package/src/lib/document/state/document.query.ts +52 -0
- package/{lib/document/state/document.service.d.ts → src/lib/document/state/document.service.ts} +95 -64
- package/{lib/document/state/document.state.d.ts → src/lib/document/state/document.state.ts} +52 -36
- package/src/lib/document/state/document.store.ts +51 -0
- package/{public-api.d.ts → src/public-api.ts} +10 -6
- package/tsconfig.lib.json +15 -0
- package/tsconfig.lib.prod.json +11 -0
- package/tsconfig.spec.json +15 -0
- package/Shared/constant/PERMISSIONS.d.ts +0 -15
- package/Shared/constant/SHARED.d.ts +0 -209
- package/Shared/services/app-config.service.d.ts +0 -51
- package/Shared/services/session.service.d.ts +0 -46
- package/fesm2022/cat-documents-ng.mjs +0 -2508
- package/fesm2022/cat-documents-ng.mjs.map +0 -1
- package/index.d.ts +0 -5
- package/lib/document/components/document-container/document-container.component.d.ts +0 -85
- package/lib/document/components/document-list/document-list.component.d.ts +0 -157
- package/lib/document/components/document-list-item/document-list-item.component.d.ts +0 -28
- package/lib/document/components/document-upload/document-upload.component.d.ts +0 -120
- package/lib/document/components/document-viewer/document-viewer.component.d.ts +0 -72
- package/lib/document/components/folder-container/folder-container.component.d.ts +0 -29
- package/lib/document/components/linked-document/linked-document.component.d.ts +0 -38
- package/lib/document/directives/document.directive.d.ts +0 -20
- package/lib/document/directives/permission.directive.d.ts +0 -38
- package/lib/document/document.module.d.ts +0 -40
- package/lib/document/models/document-type.model.d.ts +0 -37
- package/lib/document/models/document.model.d.ts +0 -44
- package/lib/document/services/document-http.service.d.ts +0 -69
- package/lib/document/services/document-upload.service.d.ts +0 -67
- package/lib/document/services/document.service.d.ts +0 -20
- package/lib/document/services/file-format.service.d.ts +0 -23
- package/lib/document/state/document.query.d.ts +0 -41
- package/lib/document/state/document.store.d.ts +0 -28
package/{Shared/services/global-error.handler.d.ts → src/Shared/services/global-error.handler.ts}
RENAMED
|
@@ -1,27 +1,29 @@
|
|
|
1
|
-
import { ErrorHandler, Injector } from '@angular/core';
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* @
|
|
8
|
-
* @
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
*
|
|
15
|
-
* @
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
1
|
+
import { ErrorHandler, Injectable, Injector } from '@angular/core';
|
|
2
|
+
import { HttpErrorResponse } from '@angular/common/http';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* GlobalErrorHandler is a custom error handler that implements the ErrorHandler interface.
|
|
6
|
+
* It is used to handle both HTTP errors and other types of errors globally in the application.
|
|
7
|
+
* @class
|
|
8
|
+
* @implements {ErrorHandler}
|
|
9
|
+
* @decorator {Injectable}
|
|
10
|
+
*/
|
|
11
|
+
@Injectable()
|
|
12
|
+
export class GlobalErrorHandler implements ErrorHandler {
|
|
13
|
+
/**
|
|
14
|
+
* Creates an instance of GlobalErrorHandler.
|
|
15
|
+
* @constructor
|
|
16
|
+
* @param {Injector} injector - The Angular injector used to get instances of services.
|
|
17
|
+
*/
|
|
18
|
+
constructor(private injector: Injector) { }
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Handles errors globally in the application.
|
|
22
|
+
*
|
|
23
|
+
* @param {any} error - The error object that needs to be handled.
|
|
24
|
+
* @returns {void}
|
|
25
|
+
*/
|
|
26
|
+
handleError(error: any): void {
|
|
27
|
+
console.error('GlobalErrorHandler:', error);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { TestBed } from '@angular/core/testing';
|
|
2
|
+
|
|
3
|
+
import { SessionService } from './session.service';
|
|
4
|
+
|
|
5
|
+
describe('SessionService', () => {
|
|
6
|
+
let service: SessionService;
|
|
7
|
+
|
|
8
|
+
beforeEach(() => {
|
|
9
|
+
TestBed.configureTestingModule({});
|
|
10
|
+
service = TestBed.inject(SessionService);
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
it('should be created', () => {
|
|
14
|
+
expect(service).toBeTruthy();
|
|
15
|
+
});
|
|
16
|
+
});
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { Injectable } from '@angular/core';
|
|
2
|
+
import { Router } from '@angular/router';
|
|
3
|
+
import { SHARED } from '../constant/SHARED';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Service for managing user session details.
|
|
7
|
+
* @class SessionService
|
|
8
|
+
* @typedef {SessionService}
|
|
9
|
+
*/
|
|
10
|
+
@Injectable({
|
|
11
|
+
providedIn: 'root'
|
|
12
|
+
})
|
|
13
|
+
export class SessionService {
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Creates an instance of SessionService.
|
|
17
|
+
* @param {Router} router - Angular Router for navigation.
|
|
18
|
+
*/
|
|
19
|
+
constructor(public router: Router) {}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Retrieves the current user's role from local storage.
|
|
23
|
+
* @returns {string | null} The user's role, or null if not found.
|
|
24
|
+
*/
|
|
25
|
+
getUserRole(): string | null {
|
|
26
|
+
return localStorage.getItem('role');
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Stores the user session data in local storage.
|
|
31
|
+
* @param {any} data - The session data to store.
|
|
32
|
+
*/
|
|
33
|
+
setUserSession(data: any): void {
|
|
34
|
+
localStorage.setItem(SHARED.SESSIONKEY, JSON.stringify(data));
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Retrieves the stored user session data.
|
|
39
|
+
* @returns {any | null} The parsed session data, or null if not found.
|
|
40
|
+
*/
|
|
41
|
+
getUserSession(): any | null {
|
|
42
|
+
const sessionData = localStorage.getItem(SHARED.SESSIONKEY);
|
|
43
|
+
return sessionData ? JSON.parse(sessionData) : null;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Retrieves the user's permissions from the stored session data.
|
|
48
|
+
* @returns {any | null} The user's permissions, or null if not found.
|
|
49
|
+
*/
|
|
50
|
+
getUserPermissions(): any | null {
|
|
51
|
+
const sessionData = localStorage.getItem(SHARED.SESSIONKEY);
|
|
52
|
+
return sessionData ? JSON.parse(sessionData).permissions : null;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Retrieves the session ID from the stored session data.
|
|
57
|
+
* @returns {any | null} The session ID, or null if not found.
|
|
58
|
+
*/
|
|
59
|
+
getSessionID(): any | null {
|
|
60
|
+
const sessionData = localStorage.getItem(SHARED.SESSIONKEY);
|
|
61
|
+
console.log(sessionData);
|
|
62
|
+
if (sessionData) {
|
|
63
|
+
const sessionId = JSON.parse(sessionData);
|
|
64
|
+
console.log(sessionId);
|
|
65
|
+
return sessionId;
|
|
66
|
+
}
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Clears all stored session data from local storage.
|
|
72
|
+
*/
|
|
73
|
+
clearSession(): void {
|
|
74
|
+
localStorage.clear();
|
|
75
|
+
}
|
|
76
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"catQwUrl": "https://qa-qw-api.dynamatix.com/api/",
|
|
3
|
+
"apiUrl": "https://gatehouse-qa.dynamatix.com/api/",
|
|
4
|
+
"swaggerUrl": "https://qa-qw-api.dynamatix.com/api-docs/",
|
|
5
|
+
"adminEmail": "neeraj.kumar@catura.co.uk",
|
|
6
|
+
"interactBaseApi": "https://qa-interact-api.dynamatix.com/api/",
|
|
7
|
+
"actionBaseApi": "https://qa-qw-api.dynamatix.com/api/",
|
|
8
|
+
"documentApiUrl": "http://localhost:5100/api/",
|
|
9
|
+
"adminPhoneNumber": "+447380300545",
|
|
10
|
+
"visibilityOption": {
|
|
11
|
+
"isRationalVisible": false,
|
|
12
|
+
"isChecklistVisible": false,
|
|
13
|
+
"isAudit": false,
|
|
14
|
+
"isConversation": true,
|
|
15
|
+
"isOverview": true,
|
|
16
|
+
"isDocuments": true
|
|
17
|
+
},
|
|
18
|
+
"env": "qa"
|
|
19
|
+
|
|
20
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
<div class="grid m-0 h-full">
|
|
2
|
+
<div class="col-12 md:col-12 lg:col-12 p-0 h-full" [ngClass]="showFolderList ? 'custom-scroll' : ''">
|
|
3
|
+
@if(showFolderList){
|
|
4
|
+
<div>
|
|
5
|
+
<lib-folder-container [documentList]="documentList" [folderList]="folderList" [contextId]="contextId"></lib-folder-container>
|
|
6
|
+
</div>
|
|
7
|
+
}
|
|
8
|
+
<div [ngClass]="showFolderList ? 'mt-3' : ''">
|
|
9
|
+
<lib-document-list [isCollapsed]="isCollapsed" [documentList]="documentList" [contextId]="contextId" [isUploadButtonVisible]="isUploadButtonVisible" (onRefresh)="fetchFolder()">
|
|
10
|
+
<ng-content></ng-content>
|
|
11
|
+
</lib-document-list>
|
|
12
|
+
</div>
|
|
13
|
+
</div>
|
|
14
|
+
</div>
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
|
2
|
+
import { DocumentContainerComponent } from './document-container.component';
|
|
3
|
+
import { of, throwError } from 'rxjs';
|
|
4
|
+
import { DocumentHttpService } from '../../services/document-http.service';
|
|
5
|
+
import { DocumentStore } from '../../state/document.store';
|
|
6
|
+
import { DocumentQuery } from '../../state/document.query';
|
|
7
|
+
import { DocumentService } from '../../state/document.service';
|
|
8
|
+
import { CommonModule } from '@angular/common';
|
|
9
|
+
import { HttpClientModule } from '@angular/common/http';
|
|
10
|
+
import { SHARED } from '../../../../Shared/constant/SHARED';
|
|
11
|
+
import { DocumentListComponent } from '../document-list/document-list.component';
|
|
12
|
+
import { MessageService } from 'primeng/api';
|
|
13
|
+
import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
|
|
14
|
+
import { DialogModule } from 'primeng/dialog';
|
|
15
|
+
|
|
16
|
+
describe('DocumentContainerComponent', () => {
|
|
17
|
+
let component: DocumentContainerComponent;
|
|
18
|
+
let fixture: ComponentFixture<DocumentContainerComponent>;
|
|
19
|
+
let mockDocumentHttpService: jasmine.SpyObj<DocumentHttpService>;
|
|
20
|
+
let mockDocumentStore: jasmine.SpyObj<DocumentStore>;
|
|
21
|
+
let mockDocumentQuery: jasmine.SpyObj<DocumentQuery>;
|
|
22
|
+
let mockDocumentService: jasmine.SpyObj<DocumentService>;
|
|
23
|
+
|
|
24
|
+
const dummyFolders = [
|
|
25
|
+
{ _id: '1', name: 'Folder A', documentCount: 2 },
|
|
26
|
+
{ _id: '2', name: 'Folder B', documentCount: 0 }
|
|
27
|
+
];
|
|
28
|
+
|
|
29
|
+
const dummyDocuments = [
|
|
30
|
+
{ _id: 'doc1', name: 'Document 1' },
|
|
31
|
+
{ _id: 'doc2', name: 'Document 2' }
|
|
32
|
+
];
|
|
33
|
+
|
|
34
|
+
beforeEach(async () => {
|
|
35
|
+
mockDocumentHttpService = jasmine.createSpyObj('DocumentHttpService', [
|
|
36
|
+
'getFoldersData',
|
|
37
|
+
'getDocumentByFolderID',
|
|
38
|
+
'getDocumentTypes' // ✅ Fix added here
|
|
39
|
+
]);
|
|
40
|
+
mockDocumentHttpService.getDocumentTypes.and.returnValue(of([])); // ✅ Return dummy value
|
|
41
|
+
|
|
42
|
+
mockDocumentStore = jasmine.createSpyObj('DocumentStore', ['setDocumentList']);
|
|
43
|
+
mockDocumentQuery = jasmine.createSpyObj('DocumentQuery', ['selectParentDocumentTypeId']);
|
|
44
|
+
mockDocumentService = jasmine.createSpyObj('DocumentService', ['dummy']);
|
|
45
|
+
|
|
46
|
+
await TestBed.configureTestingModule({
|
|
47
|
+
declarations: [DocumentContainerComponent, DocumentListComponent],
|
|
48
|
+
imports: [CommonModule, HttpClientModule, DialogModule],
|
|
49
|
+
providers: [
|
|
50
|
+
{ provide: DocumentHttpService, useValue: mockDocumentHttpService },
|
|
51
|
+
{ provide: DocumentStore, useValue: mockDocumentStore },
|
|
52
|
+
{ provide: DocumentQuery, useValue: mockDocumentQuery },
|
|
53
|
+
{ provide: DocumentService, useValue: mockDocumentService },
|
|
54
|
+
MessageService
|
|
55
|
+
],
|
|
56
|
+
schemas: [CUSTOM_ELEMENTS_SCHEMA]
|
|
57
|
+
}).compileComponents();
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
beforeEach(() => {
|
|
61
|
+
fixture = TestBed.createComponent(DocumentContainerComponent);
|
|
62
|
+
component = fixture.componentInstance;
|
|
63
|
+
component.contextId = 'abc123';
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it('should create', () => {
|
|
67
|
+
expect(component).toBeTruthy();
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it('should fetch folders and documents on ngOnInit', () => {
|
|
71
|
+
mockDocumentHttpService.getFoldersData.and.returnValue(of(dummyFolders));
|
|
72
|
+
mockDocumentQuery.selectParentDocumentTypeId.and.returnValue(of(null));
|
|
73
|
+
mockDocumentHttpService.getDocumentByFolderID.and.returnValue(of(dummyDocuments));
|
|
74
|
+
|
|
75
|
+
fixture.detectChanges(); // triggers ngOnInit
|
|
76
|
+
|
|
77
|
+
expect(mockDocumentHttpService.getFoldersData).toHaveBeenCalledWith('abc123');
|
|
78
|
+
expect(mockDocumentHttpService.getDocumentByFolderID).toHaveBeenCalledWith('1', 'abc123');
|
|
79
|
+
expect(mockDocumentStore.setDocumentList).toHaveBeenCalledWith(dummyDocuments);
|
|
80
|
+
expect(component.folderList.length).toBe(1); // Only folder with doc count > 0
|
|
81
|
+
expect(component.documentList.length).toBe(2);
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it('should handle folder fetch error', () => {
|
|
85
|
+
const consoleSpy = spyOn(console, 'error');
|
|
86
|
+
mockDocumentHttpService.getFoldersData.and.returnValue(throwError(() => new Error('Error fetching folders')));
|
|
87
|
+
mockDocumentQuery.selectParentDocumentTypeId.and.returnValue(of(null));
|
|
88
|
+
|
|
89
|
+
fixture.detectChanges();
|
|
90
|
+
|
|
91
|
+
expect(consoleSpy).toHaveBeenCalled();
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
it('should handle document fetch error', () => {
|
|
95
|
+
const consoleSpy = spyOn(console, 'error');
|
|
96
|
+
mockDocumentHttpService.getFoldersData.and.returnValue(of(dummyFolders));
|
|
97
|
+
mockDocumentQuery.selectParentDocumentTypeId.and.returnValue(of(null));
|
|
98
|
+
mockDocumentHttpService.getDocumentByFolderID.and.returnValue(throwError(() => new Error('Error fetching docs')));
|
|
99
|
+
|
|
100
|
+
fixture.detectChanges();
|
|
101
|
+
|
|
102
|
+
expect(consoleSpy).toHaveBeenCalled();
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
it('should unsubscribe on destroy', () => {
|
|
106
|
+
spyOn(component['subscription'], 'unsubscribe');
|
|
107
|
+
component.ngOnDestroy();
|
|
108
|
+
expect(component['subscription'].unsubscribe).toHaveBeenCalled();
|
|
109
|
+
});
|
|
110
|
+
});
|
|
@@ -0,0 +1,173 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
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>
|
|
@@ -0,0 +1,82 @@
|
|
|
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
|
+
}
|