cat-documents-ng 1.0.1 → 1.0.3
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/package.json +1 -1
- package/projects/cat-document-lib/package.json +6 -2
- package/projects/cat-document-lib/src/lib/document/components/document-container/document-container.component.ts +2 -2
- package/projects/cat-document-lib/src/lib/document/components/document-list/document-list.component.html +1 -1
- package/projects/cat-document-lib/src/lib/document/components/document-list/document-list.component.ts +7 -0
- package/projects/cat-document-lib/src/lib/document/components/document-upload/document-upload.component.ts +56 -47
- package/projects/cat-document-lib/src/public-api.ts +1 -0
- package/projects/cat-document-lib/src/shared/constant/SHARED.ts +14 -0
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"name": "cat-
|
|
2
|
+
"name": "cat-documents-ng",
|
|
3
3
|
"version": "0.0.1",
|
|
4
4
|
"peerDependencies": {
|
|
5
5
|
"@angular/common": "^19.0.0",
|
|
@@ -8,5 +8,9 @@
|
|
|
8
8
|
"dependencies": {
|
|
9
9
|
"tslib": "^2.3.0"
|
|
10
10
|
},
|
|
11
|
-
"
|
|
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
|
}
|
|
@@ -29,9 +29,9 @@ export class DocumentContainerComponent implements OnInit{
|
|
|
29
29
|
}
|
|
30
30
|
/**
|
|
31
31
|
* Get contextId in input.
|
|
32
|
-
* @type {
|
|
32
|
+
* @type {string}
|
|
33
33
|
*/
|
|
34
|
-
@Input() contextId :
|
|
34
|
+
@Input() contextId : string = SHARED.EMPTY;
|
|
35
35
|
/**
|
|
36
36
|
* The list of dummy documents.
|
|
37
37
|
* @type {Array}
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
<div class="grid">
|
|
30
30
|
<div class="col-12">
|
|
31
31
|
<p-sidebar [(visible)]="isSidebarVisible" position="right" [styleClass]="'right-sidebar'">
|
|
32
|
-
<lib-document-upload></lib-document-upload>
|
|
32
|
+
<lib-document-upload [contextId]="contextId"></lib-document-upload>
|
|
33
33
|
</p-sidebar>
|
|
34
34
|
</div>
|
|
35
35
|
</div>
|
|
@@ -16,6 +16,13 @@ import { SHARED } from '../../../../Shared/constant/SHARED';
|
|
|
16
16
|
encapsulation: ViewEncapsulation.None
|
|
17
17
|
})
|
|
18
18
|
export class DocumentListComponent {
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Represent contextId
|
|
22
|
+
* @type {string}
|
|
23
|
+
*/
|
|
24
|
+
@Input() contextId : string = SHARED.EMPTY
|
|
25
|
+
|
|
19
26
|
selectedDocument !: DocumentModel
|
|
20
27
|
/**
|
|
21
28
|
* Default visbility of sidebar
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ChangeDetectorRef, Component, EventEmitter, Output, ViewChild, ViewEncapsulation } from '@angular/core';
|
|
1
|
+
import { ChangeDetectorRef, Component, EventEmitter, Input, input, Output, ViewChild, ViewEncapsulation } from '@angular/core';
|
|
2
2
|
import { FileUpload } from 'primeng/fileupload';
|
|
3
3
|
import { MessageService } from 'primeng/api';
|
|
4
4
|
import { PrimeNGConfig } from 'primeng/api';
|
|
@@ -18,6 +18,13 @@ import { DocumentService } from '../../state/document.service';
|
|
|
18
18
|
encapsulation: ViewEncapsulation.None
|
|
19
19
|
})
|
|
20
20
|
export class DocumentUploadComponent {
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Represent contextId
|
|
24
|
+
* @type {string}
|
|
25
|
+
*/
|
|
26
|
+
@Input() contextId: string = SHARED.EMPTY
|
|
27
|
+
|
|
21
28
|
/**
|
|
22
29
|
* Provide id of file after upload.
|
|
23
30
|
* @type {*}
|
|
@@ -38,12 +45,6 @@ export class DocumentUploadComponent {
|
|
|
38
45
|
*/
|
|
39
46
|
uploadedFiles: any[] = [];
|
|
40
47
|
|
|
41
|
-
/**
|
|
42
|
-
* Total size of the uploaded files in bytes.
|
|
43
|
-
* @type {number}
|
|
44
|
-
*/
|
|
45
|
-
totalSize: number = SHARED.INITIAL_COUNT;
|
|
46
|
-
|
|
47
48
|
/**
|
|
48
49
|
* Percentage of the total size calculated for displaying upload progress.
|
|
49
50
|
* @type {number}
|
|
@@ -78,6 +79,8 @@ export class DocumentUploadComponent {
|
|
|
78
79
|
callback();
|
|
79
80
|
}
|
|
80
81
|
|
|
82
|
+
|
|
83
|
+
|
|
81
84
|
/**
|
|
82
85
|
* Prepares the files for upload by creating a FormData object.
|
|
83
86
|
* This method appends each file to the FormData for submission.
|
|
@@ -85,25 +88,25 @@ export class DocumentUploadComponent {
|
|
|
85
88
|
* @returns {void}
|
|
86
89
|
*/
|
|
87
90
|
handleTemplatedUpload(file: File) {
|
|
88
|
-
|
|
89
|
-
formData.append(SHARED.FILE, file, file.name);
|
|
91
|
+
let formData = this.handleCreateFormData(file)
|
|
90
92
|
this.uploadService.create(formData)
|
|
91
93
|
.subscribe({
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
94
|
+
/**
|
|
95
|
+
* Handles the successful upload event.
|
|
96
|
+
* Updates the list of uploaded files and emits the file ID.
|
|
97
|
+
* @param {any} event - The event emitted by the upload service on success.
|
|
98
|
+
*/
|
|
97
99
|
next: (event) => {
|
|
98
|
-
this.uploadedFiles.push(event)
|
|
100
|
+
this.uploadedFiles.push(event);
|
|
99
101
|
this.fileProgress.set(event, 100);
|
|
100
102
|
this.onInput.emit(event._id)
|
|
103
|
+
this.totalSizePercent = 100;
|
|
101
104
|
},
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
105
|
+
/**
|
|
106
|
+
* Handles the error event during file upload.
|
|
107
|
+
* Updates the progress of the file to indicate failure.
|
|
108
|
+
* @param {any} error - The error object returned by the upload service.
|
|
109
|
+
*/
|
|
107
110
|
error: (error) => {
|
|
108
111
|
this.fileProgress.set(file, SHARED.INITIAL_COUNT);
|
|
109
112
|
this.messageService.add({
|
|
@@ -115,20 +118,29 @@ export class DocumentUploadComponent {
|
|
|
115
118
|
});
|
|
116
119
|
}
|
|
117
120
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
this.
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Handle the creation of formdata.
|
|
124
|
+
* @param {File} file - The file to append in formdata.
|
|
125
|
+
* @returns {*}
|
|
126
|
+
*/
|
|
127
|
+
handleCreateFormData(file: File) {
|
|
128
|
+
const formData = new FormData();
|
|
129
|
+
formData.append(SHARED.FILE, file, file.name);
|
|
130
|
+
formData.append(SHARED.CONTEXT_ID, this.contextId)
|
|
131
|
+
return formData;
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Handles the event when new files are selected.
|
|
135
|
+
* @param { { currentFiles: File[] } } event - The event containing the newly selected files.
|
|
136
|
+
* @returns {void}
|
|
137
|
+
*/
|
|
138
|
+
onSelectedFiles(event: { currentFiles: File[] }): void {
|
|
139
|
+
event.currentFiles.forEach((file: File) => {
|
|
140
|
+
this.handleTemplatedUpload(file);
|
|
141
|
+
});
|
|
142
|
+
this.fileUploader.clear();
|
|
143
|
+
}
|
|
132
144
|
|
|
133
145
|
/**
|
|
134
146
|
* Formats the given file size in bytes into a readable format (e.g., KB, MB).
|
|
@@ -141,32 +153,29 @@ export class DocumentUploadComponent {
|
|
|
141
153
|
|
|
142
154
|
/**
|
|
143
155
|
* Handles the removal of a file from the uploaded files list.
|
|
144
|
-
* Resets the total size and upload progress after removing the file.
|
|
145
156
|
* @param {File} file - The file to be removed.
|
|
146
157
|
* @param {number} index - The index of the file in the uploaded files list.
|
|
147
158
|
*/
|
|
148
159
|
handleDocumentRemove(file: File, index: number): void {
|
|
149
160
|
this.uploadedFiles.splice(index, 1);
|
|
150
161
|
this.fileProgress.delete(file);
|
|
151
|
-
this.totalSize -= file.size;
|
|
152
|
-
this.totalSizePercent = this.totalSize / SHARED.TEN;
|
|
153
162
|
this.cdr.detectChanges();
|
|
154
163
|
}
|
|
155
164
|
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
165
|
+
/**
|
|
166
|
+
* Major progress for the progress bar.
|
|
167
|
+
* @param {File} file - File to check progress for.
|
|
168
|
+
* @returns {number} - The progress percentage for the file.
|
|
169
|
+
*/
|
|
161
170
|
getProgress(file: File): number {
|
|
162
171
|
return this.fileProgress.get(file) || SHARED.INITIAL_COUNT;
|
|
163
172
|
}
|
|
164
173
|
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
174
|
+
/**
|
|
175
|
+
* Triggers the file upload dialog.
|
|
176
|
+
* Opens the file explorer for selecting files.
|
|
177
|
+
* @returns {void}
|
|
178
|
+
*/
|
|
170
179
|
triggerFileUpload() {
|
|
171
180
|
this.fileUploader.choose();
|
|
172
181
|
}
|
|
@@ -97,6 +97,20 @@ export class SHARED {
|
|
|
97
97
|
* @type {{}}
|
|
98
98
|
*/
|
|
99
99
|
static EMPTY_ARRAY = []
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Represent contextId.
|
|
103
|
+
* @static
|
|
104
|
+
* @type {string}
|
|
105
|
+
*/
|
|
106
|
+
static CONTEXT_ID : string = 'contextId'
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Represent fileSize.
|
|
110
|
+
* @static
|
|
111
|
+
* @type {string}
|
|
112
|
+
*/
|
|
113
|
+
static FILE_SIZE : string = 'fileSize'
|
|
100
114
|
}
|
|
101
115
|
|
|
102
116
|
/**
|