cat-documents-ng 1.0.0 → 1.0.2

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 (34) hide show
  1. package/angular.json +2 -2
  2. package/package.json +3 -1
  3. package/projects/cat-document-lib/ng-package.json +2 -3
  4. package/projects/cat-document-lib/package.json +5 -1
  5. package/projects/cat-document-lib/src/assets/images/document.png +0 -0
  6. package/projects/cat-document-lib/src/lib/document/components/document-container/document-container.component.html +6 -1
  7. package/projects/cat-document-lib/src/lib/document/components/document-container/document-container.component.ts +79 -11
  8. package/projects/cat-document-lib/src/lib/document/components/document-list/document-list.component.html +35 -1
  9. package/projects/cat-document-lib/src/lib/document/components/document-list/document-list.component.scss +12 -0
  10. package/projects/cat-document-lib/src/lib/document/components/document-list/document-list.component.ts +70 -11
  11. package/projects/cat-document-lib/src/lib/document/components/document-list-item/document-list-item.component.html +33 -0
  12. package/projects/cat-document-lib/src/lib/document/components/document-list-item/document-list-item.component.scss +22 -0
  13. package/projects/cat-document-lib/src/lib/document/components/document-list-item/document-list-item.component.spec.ts +23 -0
  14. package/projects/cat-document-lib/src/lib/document/components/document-list-item/document-list-item.component.ts +40 -0
  15. package/projects/cat-document-lib/src/lib/document/components/document-upload/document-upload.component.html +56 -0
  16. package/projects/cat-document-lib/src/lib/document/components/document-upload/document-upload.component.scss +26 -0
  17. package/projects/cat-document-lib/src/lib/document/components/document-upload/document-upload.component.spec.ts +24 -0
  18. package/projects/cat-document-lib/src/lib/document/components/document-upload/document-upload.component.ts +184 -0
  19. package/projects/cat-document-lib/src/lib/document/components/document-viewer/document-viewer.component.html +244 -0
  20. package/projects/cat-document-lib/src/lib/document/components/document-viewer/document-viewer.component.scss +36 -0
  21. package/projects/cat-document-lib/src/lib/document/components/document-viewer/document-viewer.component.spec.ts +21 -0
  22. package/projects/cat-document-lib/src/lib/document/components/document-viewer/document-viewer.component.ts +125 -0
  23. package/projects/cat-document-lib/src/lib/document/document.module.ts +171 -8
  24. package/projects/cat-document-lib/src/lib/document/models/document.model.ts +39 -3
  25. package/projects/cat-document-lib/src/lib/document/services/file-format.service.spec.ts +16 -0
  26. package/projects/cat-document-lib/src/lib/document/services/file-format.service.ts +41 -0
  27. package/projects/cat-document-lib/src/lib/document/state/document.service.ts +83 -11
  28. package/projects/cat-document-lib/src/public-api.ts +1 -0
  29. package/projects/cat-document-lib/src/shared/constant/SHARED.ts +139 -0
  30. package/projects/cat-document-lib/src/shared/constant/URLS.ts +31 -0
  31. package/projects/cat-document-lib/src/shared/services/app-config.service.spec.ts +16 -0
  32. package/projects/cat-document-lib/src/shared/services/app-config.service.ts +73 -0
  33. package/src/app/app.module.ts +4 -3
  34. package/src/styles.scss +38 -4
package/angular.json CHANGED
@@ -28,8 +28,8 @@
28
28
  "src/assets",
29
29
  {
30
30
  "glob": "**/*",
31
- "input": "projects/cat-document-lib/src/assets",
32
- "output": "assets/cat-document-lib"
31
+ "input": "dist/cat-document-lib/src/assets",
32
+ "output": "assets"
33
33
  }
34
34
  ],
35
35
  "styles": [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cat-documents-ng",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "scripts": {
5
5
  "ng": "ng",
6
6
  "start": "ng serve",
@@ -23,6 +23,8 @@
23
23
  "@angular/router": "^19.0.0",
24
24
  "@datorama/akita": "^8.0.1",
25
25
  "jsdocs": "^1.0.0",
26
+ "moment": "^2.30.1",
27
+ "ng2-pdf-viewer": "^9.1.5",
26
28
  "primeflex": "^3.3.1",
27
29
  "primeicons": "^7.0.0",
28
30
  "primeng": "^17.18.10",
@@ -5,8 +5,7 @@
5
5
  "entryFile": "src/public-api.ts"
6
6
  },
7
7
  "assets": [
8
- "src/assets",
9
- "src/favicon.ico"
10
- ]
8
+ "src/assets"
9
+ ]
11
10
 
12
11
  }
@@ -8,5 +8,9 @@
8
8
  "dependencies": {
9
9
  "tslib": "^2.3.0"
10
10
  },
11
- "sideEffects": false
11
+ "typings": "index.d.ts",
12
+ "sideEffects": false,
13
+ "main": "bundles/cat-document-lib.umd.js",
14
+ "module": "fesm2015/cat-document-lib.js",
15
+ "es2015": "fesm2015/cat-document-lib.js"
12
16
  }
@@ -1 +1,6 @@
1
- <p>document-container works!</p>
1
+ <div class="grid m-0">
2
+ <div class="col-12 md:col-12 lg:col-12 overflow-y-scroll py-0 pl-0" >
3
+ <lib-folder-container [documentList]="documentList"></lib-folder-container>
4
+ <lib-document-list [documentList]="documentList"></lib-document-list>
5
+ </div>
6
+ </div>
@@ -1,14 +1,82 @@
1
- // import { Component } from '@angular/core';
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
+
2
8
 
3
9
  /**
4
- *
10
+ *This component is responsible for managing and displaying a list of documents.
11
+ * @class DocumentContainerComponent
12
+ * @typedef {DocumentContainerComponent}
5
13
  */
6
- // @Component({
7
- // selector: 'lib-document-container',
8
- // standalone: false,
9
- // templateUrl: './document-container.component.html',
10
- // styleUrl: './document-container.component.scss'
11
- // })
12
- // export class DocumentContainerComponent {
13
-
14
- // }
14
+ @Component({
15
+ selector: 'lib-document-container',
16
+ standalone: false,
17
+ templateUrl: './document-container.component.html',
18
+ styleUrl: './document-container.component.scss'
19
+ })
20
+ export class DocumentContainerComponent implements OnInit{
21
+
22
+ /**
23
+ * Creates an instance of DocumentContainerComponent.
24
+ * @class
25
+ * @param {DocumentService} documentService - Service to manage document-related operations.
26
+ */
27
+ constructor(public documentService : DocumentService){
28
+
29
+ }
30
+ /**
31
+ * Get contextId in input.
32
+ * @type {string}
33
+ */
34
+ @Input() contextId : string = SHARED.EMPTY;
35
+ /**
36
+ * The list of dummy documents.
37
+ * @type {Array}
38
+ */
39
+ documentList : DocumentModel[] = []
40
+
41
+ /**
42
+ * Holds the subscription to manage observable cleanup.
43
+ * @private
44
+ * @type {Subscription}
45
+ */
46
+ private subscription: Subscription = new Subscription();
47
+
48
+ /**
49
+ * Call document service method to get the document by contextId.
50
+ */
51
+ ngOnInit(): void {
52
+ const documentSubscription = this.documentService
53
+ .getById(`${URLS.CONTEXT}${this.contextId}`)
54
+ .subscribe({
55
+ /**
56
+ * Handles the successful API response.
57
+ * @param {DocumentModel[]} res - The list of documents returned by the API.
58
+ */
59
+ next: (res: DocumentModel[]) => {
60
+ if (res) {
61
+ this.documentList = res;
62
+ }
63
+ },
64
+ /**
65
+ * Handles errors that occur during the API call.
66
+ * Logs the error to the console.
67
+ * @param {any} err - The error object returned from the API.
68
+ */
69
+ error: (err) => {
70
+ throw new Error(err)
71
+ }
72
+ });
73
+ this.subscription.add(documentSubscription);
74
+ }
75
+
76
+ /**
77
+ * Unsubscribe subscription on destroy of component .
78
+ */
79
+ ngOnDestroy(): void {
80
+ this.subscription.unsubscribe();
81
+ }
82
+ }
@@ -1 +1,35 @@
1
- <p>document-list works!</p>
1
+ <div class="document-viewer">
2
+ <p-dialog [(visible)]="isdialogVisible" [modal]="true" (onHide)="handleCloseModel()" [style]="{ width: '100vw' }"
3
+ [draggable]="false" [closable]="true">
4
+ <document-viewer [selectedDocument]="selectedDocument"></document-viewer>
5
+ </p-dialog>
6
+ </div>
7
+
8
+ <div class="col-12 p-0">
9
+ <div class="card p-0 document-list-wrapper">
10
+ <p-accordion>
11
+ <p-accordionTab [selected]="true" class="line-height-2 m-0">
12
+ <ng-template pTemplate="header" let-active="active">
13
+ <div class="flex align-items-center justify-content-between w-full">
14
+ <span class="flex align-items-center gap-2">
15
+ Documents
16
+ </span>
17
+ <button pButton pRipple class="p-button-raised" type="button" label="Upload File"
18
+ style="border-radius: 10px;" (click)="handleFileUploadClick($event)"></button>
19
+ </div>
20
+ </ng-template>
21
+ @for(document of documentList; track document){
22
+ <lib-document-list-item [document]="document"
23
+ (documentClick)="handleClickForDocument($event)"></lib-document-list-item>
24
+ }
25
+ </p-accordionTab>
26
+ </p-accordion>
27
+ </div>
28
+ </div>
29
+ <div class="grid">
30
+ <div class="col-12">
31
+ <p-sidebar [(visible)]="isSidebarVisible" position="right" [styleClass]="'right-sidebar'">
32
+ <lib-document-upload [contextId]="contextId"></lib-document-upload>
33
+ </p-sidebar>
34
+ </div>
35
+ </div>
@@ -0,0 +1,12 @@
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
+ }
@@ -1,14 +1,73 @@
1
- // import { Component } from '@angular/core';
1
+ import { Component, Input, ViewEncapsulation } from '@angular/core';
2
+ import { DocumentModel } from '../../models/document.model';
3
+ import { SHARED } from '../../../../Shared/constant/SHARED';
4
+
2
5
 
3
6
  /**
4
- *
7
+ * This component is responsible for displaying a list of documents.
8
+ * @class DocumentListComponent
9
+ * @typedef {DocumentListComponent}
5
10
  */
6
- // @Component({
7
- // selector: 'lib-document-list',
8
- // standalone : false,
9
- // templateUrl: './document-list.component.html',
10
- // styleUrl: './document-list.component.scss'
11
- // })
12
- // export class DocumentListComponent {
13
-
14
- // }
11
+ @Component({
12
+ selector: 'lib-document-list',
13
+ standalone: false,
14
+ templateUrl: './document-list.component.html',
15
+ styleUrls: ['./document-list.component.scss'],
16
+ encapsulation: ViewEncapsulation.None
17
+ })
18
+ export class DocumentListComponent {
19
+
20
+ /**
21
+ * Represent contextId
22
+ * @type {string}
23
+ */
24
+ @Input() contextId : string = SHARED.EMPTY
25
+
26
+ selectedDocument !: DocumentModel
27
+ /**
28
+ * Default visbility of sidebar
29
+ * @type {boolean}
30
+ */
31
+ isSidebarVisible: boolean = SHARED.FALSE
32
+
33
+ /**
34
+ * Default visbility of dialog
35
+ * @type {boolean}
36
+ */
37
+ isdialogVisible: boolean = SHARED.FALSE
38
+
39
+ /**
40
+ * The list of documents to display.
41
+ * @type {DocumentModel[]}
42
+ */
43
+ @Input() documentList: DocumentModel[] = [];
44
+
45
+
46
+ /**
47
+ * Handles the click event for file upload.
48
+ * Prevents event propagation and displays the sidebar.
49
+ * @param {MouseEvent} event - The click event triggered by the user.
50
+ */
51
+ handleFileUploadClick(event: MouseEvent): void {
52
+ event.stopPropagation();
53
+ this.isSidebarVisible = SHARED.TRUE;
54
+ }
55
+
56
+
57
+ /**
58
+ * Select a individual document.
59
+ * @param {*} docuemnt - The document that was clicked by the user.
60
+ */
61
+ handleClickForDocument(docuemnt: DocumentModel) {
62
+ this.isdialogVisible = SHARED.TRUE
63
+ this.selectedDocument = docuemnt
64
+ }
65
+
66
+ /**
67
+ * Close dialog.
68
+ */
69
+ handleCloseModel(){
70
+ this.selectedDocument = {_id : SHARED.INITIAL_VALUE};
71
+ this.isdialogVisible = SHARED.FALSE
72
+ }
73
+ }
@@ -0,0 +1,33 @@
1
+ <div class="grid">
2
+ <div
3
+ class="col-12 flex align-items-center justify-content-between md:col-6 xl:col-12"
4
+ >
5
+ <div
6
+ class="col-5 flex cursor-pointer align-items-center pl-0"
7
+ (click)="handleOpenDocument(document)"
8
+ >
9
+ <img src="../../../../assets/images/Frame.png" alt="" />
10
+ <span class="ml-4">{{ document.fileName }}</span>
11
+ </div>
12
+ <div class="col-4 flex align-items-center justify-content-center">
13
+ <span
14
+ [class]="'product-badge status-' + document.status?.toLowerCase()"
15
+ class="flex align-items-center justify-content-center pl-2 pr-2 pt-1 pb-1 "
16
+ >
17
+ <ng-container *ngIf="document.status?.toLowerCase() === 'pending'">
18
+ <i class="pi pi-clock pr-1" style="font-size: 12px;"></i>
19
+ Pending
20
+ </ng-container>
21
+ <ng-container *ngIf="document.status?.toLowerCase() === 'verified'">
22
+ <i class="pi pi-check-circle pr-1" style="font-size: 12px;"></i>
23
+ Verified
24
+ </ng-container>
25
+ <ng-container *ngIf="document.status?.toLowerCase() === 'sentreminder'">
26
+ <i class="pi pi-bell pr-1" style="font-size: 12px;"></i>
27
+ Sent Reminder
28
+ </ng-container>
29
+ </span>
30
+ </div>
31
+ </div>
32
+ </div>
33
+
@@ -0,0 +1,22 @@
1
+ .product-badge.status-pending {
2
+ background: #e9b127;
3
+ color: #ffffff;
4
+ border-radius: 4px;
5
+ }
6
+ .product-badge.status-verified {
7
+ background: #4caf50;
8
+ color: #ffffff;
9
+ border-radius: 4px;
10
+ }
11
+ .product-badge.status-sentreminder {
12
+ background: #f57c00;
13
+ color: #ffffff;
14
+ border-radius: 4px;
15
+ }
16
+ .product-badge {
17
+ text-transform: none;
18
+ font-weight: 500;
19
+ font-size: 12px;
20
+
21
+ }
22
+
@@ -0,0 +1,23 @@
1
+ import { ComponentFixture, TestBed } from '@angular/core/testing';
2
+
3
+ import { DocumentListItemComponent } from './document-list-item.component';
4
+
5
+ describe('DocumentListItemComponent', () => {
6
+ let component: DocumentListItemComponent;
7
+ let fixture: ComponentFixture<DocumentListItemComponent>;
8
+
9
+ beforeEach(async () => {
10
+ await TestBed.configureTestingModule({
11
+ imports: [DocumentListItemComponent]
12
+ })
13
+ .compileComponents();
14
+
15
+ fixture = TestBed.createComponent(DocumentListItemComponent);
16
+ component = fixture.componentInstance;
17
+ fixture.detectChanges();
18
+ });
19
+
20
+ it('should create', () => {
21
+ expect(component).toBeTruthy();
22
+ });
23
+ });
@@ -0,0 +1,40 @@
1
+ import { Component, EventEmitter, Input, Output } from '@angular/core';
2
+ import { DocumentModel } from '../../models/document.model';
3
+
4
+ /**
5
+ * DocumentListItemComponent
6
+ *
7
+ * This component displays individual document items within a list.
8
+ * It accepts a list of documents as input and handles interactions with documents.
9
+ */
10
+ @Component({
11
+ selector: 'lib-document-list-item',
12
+ standalone: false,
13
+ templateUrl: './document-list-item.component.html',
14
+ styleUrls: ['./document-list-item.component.scss']
15
+ })
16
+ export class DocumentListItemComponent {
17
+ /**
18
+ * Emit the selected document.
19
+ * @type {EventEmitter<DocumentModel>}
20
+ */
21
+ @Output() documentClick = new EventEmitter<DocumentModel>();
22
+
23
+ /**
24
+ * The document to display.
25
+ * @type {DocumentModel[]}
26
+ */
27
+ @Input() document!: DocumentModel;
28
+
29
+ /**
30
+ * Handles interactions with a document.
31
+ * @param {DocumentModel} document - The document to be opened or interacted with.
32
+ */
33
+ handleOpenDocument(document: DocumentModel): void {
34
+ if (!document) {
35
+ console.error('Error: Document is null or undefined:', document);
36
+ return;
37
+ }
38
+ this.documentClick.emit(document);
39
+ }
40
+ }
@@ -0,0 +1,56 @@
1
+ <div class="grid">
2
+ <div class="col-12 md:col-12">
3
+ <p-fileUpload #fileUploader [multiple]="true" auto="true" accept="image/png,application/pdf" maxFileSize="1000000"
4
+ (onSelect)="onSelectedFiles($event)">
5
+ <ng-template pTemplate="header" let-chooseCallback="chooseCallback" let-clearCallback="clearCallback">
6
+ <div class="p-2 flex flex-wrap justify-content-between align-items-center flex-1 gap-2">
7
+ <div class="flex gap-2">
8
+ <p-button (onClick)="choose($event, chooseCallback)" icon="pi pi-images" [rounded]="true"
9
+ [outlined]="true" />
10
+ </div>
11
+ </div>
12
+ </ng-template>
13
+ <ng-template pTemplate="content" let-removeFileCallback="removeFileCallback"
14
+ let-removeUploadedFileCallback="removeUploadedFileCallback">
15
+ <div class="col-12 md:col-12 p-0">
16
+ <div class="col-12 md:col-12 p-0" *ngIf="uploadedFiles.length > 0">
17
+ <div *ngFor="let file of uploadedFiles; let i = index"
18
+ class="m-0 flex flex-column align-items-center gap-1 mt-3">
19
+ <div class="col-12 md:col-12 p-0 flex documentInfo">
20
+ <div class="documentImage">
21
+ <img src="../../../../assets/images/document.png" [alt]="file.name" width="45"
22
+ height="50" class="object-contain" />
23
+ </div>
24
+ <div class="flex w-full flex-column mt-2 ml-2">
25
+ <div class="flex justify-content-between">
26
+ <div style=" font-weight: bold;font-size: 14px">
27
+ {{ file.fileName }}
28
+ </div>
29
+ <i class="pi pi-times cursor-pointer" (click)="handleDocumentRemove(file,i)"></i>
30
+ </div>
31
+ <div class="flex justify-content-between mt-1">
32
+ <div style="color: #676B89; font-size: 12px;"></div>
33
+ <div class="white-space-nowrap" style="color: #0F8BFD; font-family: 14px;">{{ getProgress(file) }} %
34
+ </div>
35
+ </div>
36
+ </div>
37
+ </div>
38
+ <div class="col-12 md:col-12 p-0">
39
+ <p-progressBar [value]="totalSizePercent" [showValue]="false" styleClass="h-1/2rem md:ml-auto relative"
40
+ [ngClass]="{ 'exceeded-progress-bar': totalSizePercent > 100 }">
41
+ </p-progressBar>
42
+ </div>
43
+ </div>
44
+ </div>
45
+ </div>
46
+ </ng-template>
47
+ <ng-template pTemplate="empty" let-chooseCallback="chooseCallback" >
48
+ <div *ngIf="!uploadedFiles.length" class="flex align-items-center justify-content-center flex-column" (click)="triggerFileUpload()">
49
+ <i class="pi pi-cloud-upload border-2 border-circle p-5 text-8xl text-400 border-400"></i>
50
+ <p class="mt-4 mb-0">Drag and drop files here to upload.</p>
51
+ </div>
52
+ </ng-template>
53
+ <ng-template pTemplate="file"> </ng-template>
54
+ </p-fileUpload>
55
+ </div>
56
+ </div>
@@ -0,0 +1,26 @@
1
+ .flex {
2
+ display: flex;
3
+ }
4
+ .items-center {
5
+ align-items: center;
6
+ }
7
+ .justify-center {
8
+ justify-content: center;
9
+ }
10
+ .flex-col {
11
+ flex-direction: column;
12
+ }
13
+ .text-muted-color {
14
+ color: #6c757d; // Adjust to match your theme
15
+ }
16
+ .p-fileupload-buttonbar {
17
+ padding: 0px;
18
+ }
19
+ .p-fileupload-content {
20
+ background-color: #0f8bfd1a;
21
+ }
22
+ .p-fileupload {
23
+ .p-fileupload-content {
24
+ padding: 1rem 1rem;
25
+ }
26
+ }
@@ -0,0 +1,24 @@
1
+ import { ComponentFixture, TestBed } from '@angular/core/testing';
2
+
3
+ import { DocumentUploadComponent } from './document-upload.component';
4
+
5
+ describe('DocumentUploadComponent', () => {
6
+ let component: DocumentUploadComponent;
7
+ let fixture: ComponentFixture<DocumentUploadComponent>;
8
+
9
+ beforeEach(async () => {
10
+ await TestBed.configureTestingModule({
11
+ imports: [DocumentUploadComponent]
12
+ })
13
+ .compileComponents();
14
+
15
+ fixture = TestBed.createComponent(DocumentUploadComponent);
16
+ component = fixture.componentInstance;
17
+ fixture.detectChanges();
18
+ });
19
+
20
+ it('should create', () => {
21
+ expect(component).toBeTruthy();
22
+ });
23
+
24
+ });