handy-uploader 1.1.8 → 2.0.1

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 (43) hide show
  1. package/README.md +391 -30
  2. package/dist/components/InsertButton.vue.d.ts +24 -0
  3. package/dist/components/SelectFileIconType.vue.d.ts +29 -0
  4. package/dist/components/SimpleUploader.vue.d.ts +60 -0
  5. package/dist/components/TableUploader.vue.d.ts +62 -0
  6. package/dist/components/ThumbnailUploader.vue.d.ts +59 -0
  7. package/dist/components/handyUploader.vue.d.ts +146 -0
  8. package/dist/composables/useErrorHandler.d.ts +39 -0
  9. package/dist/composables/useFileUpload.d.ts +33 -0
  10. package/dist/favicon.ico +0 -0
  11. package/dist/handy-uploader.es.js +2407 -0
  12. package/dist/handy-uploader.umd.js +1 -0
  13. package/dist/lib/index.d.ts +713 -0
  14. package/dist/lib/language.d.ts +39 -0
  15. package/dist/types/index.d.ts +129 -0
  16. package/dist/utils/documentation.d.ts +95 -0
  17. package/dist/utils/fileUtils.d.ts +41 -0
  18. package/dist/utils/propValidation.d.ts +71 -0
  19. package/package.json +59 -56
  20. package/.eslintrc.js +0 -14
  21. package/LICENSE +0 -21
  22. package/babel.config.js +0 -3
  23. package/dist/demo.html +0 -10
  24. package/dist/handyUploader.common.js +0 -30712
  25. package/dist/handyUploader.common.js.map +0 -1
  26. package/dist/handyUploader.css +0 -5
  27. package/dist/handyUploader.umd.js +0 -30722
  28. package/dist/handyUploader.umd.js.map +0 -1
  29. package/dist/handyUploader.umd.min.js +0 -11
  30. package/dist/handyUploader.umd.min.js.map +0 -1
  31. package/package-lock.json +0 -11831
  32. package/src/App.vue +0 -69
  33. package/src/components/InsertButton.vue +0 -61
  34. package/src/components/SelectFileIconType.vue +0 -103
  35. package/src/components/SimpleUploader.vue +0 -401
  36. package/src/components/TableUploader.vue +0 -350
  37. package/src/components/ThumbnailUploader.vue +0 -371
  38. package/src/components/handyUploader.vue +0 -883
  39. package/src/components/index.js +0 -10
  40. package/src/components/language.js +0 -148
  41. package/src/main.js +0 -10
  42. package/src/plugins/vuetify.js +0 -11
  43. package/vue.config.js +0 -3
@@ -1,883 +0,0 @@
1
- <template>
2
- <v-container>
3
- <v-row>
4
- <v-col cols="12" md="12" xs="12">
5
- <InsertButton
6
- :documentAttachment="documentAttachment"
7
- :selectedLang="selectedLang"
8
- :lang="lang"
9
- :badgeCounter="badgeCounter"
10
- :btnColor="btnColor"
11
- :maxFileCount="maxFileCount"
12
- @openInputDocumentModal="openInputDocumentModal"
13
- >
14
- </InsertButton>
15
- <SimpleUploader
16
- v-if="fileUploaderType === 'simple'"
17
- :documentAttachment="documentAttachment"
18
- :cols="cols"
19
- :thumb="thumb"
20
- :outlined="outlined"
21
- :raised="raised"
22
- :shaped="shaped"
23
- :tile="tile"
24
- :lang="lang"
25
- :cardType="cardType"
26
- :deletePermission="deletePermission"
27
- :editPermission="editPermission"
28
- :selectedLang="selectedLang"
29
- @setCardTheme="setCardTheme"
30
- @openDeleteDialog="openDeleteDialog"
31
- @openEditDocumentDialog="openEditDocumentDialog"
32
- >
33
- </SimpleUploader>
34
- <ThumbnailUploader
35
- v-if="fileUploaderType === 'thumbnail'"
36
- :documentAttachment="documentAttachment"
37
- :cols="cols"
38
- :thumb="thumb"
39
- :outlined="outlined"
40
- :raised="raised"
41
- :shaped="shaped"
42
- :tile="tile"
43
- :lang="lang"
44
- :cardType="cardType"
45
- :deletePermission="deletePermission"
46
- :editPermission="editPermission"
47
- :selectedLang="selectedLang"
48
- @setCardTheme="setCardTheme"
49
- @openDeleteDialog="openDeleteDialog"
50
- @openEditDocumentDialog="openEditDocumentDialog"
51
- >
52
- </ThumbnailUploader>
53
- <TableUploader
54
- v-if="fileUploaderType === 'table'"
55
- :documentAttachment="documentAttachment"
56
- :cols="cols"
57
- :thumb="thumb"
58
- :outlined="outlined"
59
- :raised="raised"
60
- :shaped="shaped"
61
- :tile="tile"
62
- :lang="lang"
63
- :tableThumbColumn="tableThumbColumn"
64
- :tableFixedHeader="tableFixedHeader"
65
- :tableHeight="tableHeight"
66
- :cardType="cardType"
67
- :deletePermission="deletePermission"
68
- :editPermission="editPermission"
69
- :selectedLang="selectedLang"
70
- @setCardTheme="setCardTheme"
71
- @openDeleteDialog="openDeleteDialog"
72
- @openEditDocumentDialog="openEditDocumentDialog"
73
- >
74
- </TableUploader>
75
- </v-col>
76
- </v-row>
77
- <!--Insert New Document Dialog Start-->
78
- <v-row justify="center">
79
- <v-dialog
80
- v-model="insertDocumentDialog"
81
- :scrollable="false"
82
- persistent
83
- width="50%"
84
- >
85
- <v-card>
86
- <v-card-title>
87
- <v-icon @click="insertDocumentDialog = false">mdi-close</v-icon>
88
- </v-card-title>
89
- <v-card-text class="BYekan">
90
- <template v-if="tempAttachment.length === 0">
91
- <v-file-input
92
- v-if="fileAccept !== ''"
93
- multiple
94
- :accept="fileAccept"
95
- chip
96
- v-model="tempAttachment"
97
- :label="selectedLang[lang].insertNewFile"
98
- ></v-file-input>
99
- <v-file-input
100
- v-else
101
- multiple
102
- v-model="tempAttachment"
103
- :label="selectedLang[lang].insertNewFile"
104
- ></v-file-input>
105
- </template>
106
- <template>
107
- <v-expansion-panels
108
- v-if="addFileTag || addFileDescription || changeFileName"
109
- >
110
- <v-expansion-panel
111
- v-for="(attachment, index) in tempAttachmentChanged"
112
- :key="`attachment-${index}`"
113
- >
114
- <v-expansion-panel-header>{{
115
- attachment.name
116
- }}</v-expansion-panel-header>
117
- <v-expansion-panel-content>
118
- <v-row align="center" justify="center">
119
- <v-col cols="12" lg="9" md="9" xs="12">
120
- <v-text-field
121
- v-if="changeFileName"
122
- :label="selectedLang[lang].fileName"
123
- v-model="attachment.name"
124
- :prepend-icon="attachment.icon"
125
- >
126
- </v-text-field>
127
- <v-textarea
128
- v-if="addFileDescription"
129
- :label="selectedLang[lang].fileDescription"
130
- auto-grow
131
- row-height="1"
132
- v-model="attachment.description"
133
- >
134
- </v-textarea>
135
- <v-autocomplete
136
- v-if="addFileTag"
137
- v-model="attachment.tags"
138
- :items="tags"
139
- dense
140
- chips
141
- :label="selectedLang[lang].fileTags"
142
- multiple
143
- ></v-autocomplete>
144
- </v-col>
145
- <v-col align="center" cols="12" lg="3" md="3" xs="12">
146
- <template
147
- v-if="
148
- attachment.format === 'jpg' ||
149
- attachment.format === 'jpeg' ||
150
- attachment.format === 'png' ||
151
- attachment.format === 'tif' ||
152
- attachment.format === 'bmp'
153
- "
154
- >
155
- <v-card>
156
- <v-img :src="attachment.base64"></v-img>
157
- </v-card>
158
- </template>
159
- <template v-else>
160
- <select-file-icon-type
161
- :file-format="attachment.format"
162
- :size="60"
163
- >
164
- </select-file-icon-type>
165
- </template>
166
- </v-col>
167
- </v-row>
168
- </v-expansion-panel-content>
169
- </v-expansion-panel>
170
- </v-expansion-panels>
171
- <v-card v-else class="mx-auto" tile>
172
- <v-list-item
173
- v-for="(attachment, index) in tempAttachmentChanged"
174
- :key="`attachment-${index}`"
175
- style="border-bottom: 1px solid #E0E0E0"
176
- >
177
- <v-list-item-content>
178
- <v-list-item-title>
179
- <select-file-icon-type :file-format="attachment.format">
180
- </select-file-icon-type>
181
- {{ attachment.name }}.{{ attachment.format }}
182
- </v-list-item-title>
183
- </v-list-item-content>
184
- </v-list-item>
185
- </v-card>
186
- </template>
187
- </v-card-text>
188
- <v-card-actions>
189
- <v-btn
190
- class="BYekan"
191
- :disabled="tempAttachment == null || btnLoader"
192
- :loading="btnLoader"
193
- :color="btnColor"
194
- @click="uploadFieldChange"
195
- >{{ selectedLang[lang].add }}</v-btn
196
- >
197
- </v-card-actions>
198
- </v-card>
199
- </v-dialog>
200
- </v-row>
201
- <!--Insert New Document Dialog End-------------------------------------------------------------------->
202
- <!--Update Document Dialog Start---------------------------------------------------------------------->
203
- <v-row justify="center">
204
- <v-dialog
205
- v-model="editDocumentDialog"
206
- :scrollable="false"
207
- persistent
208
- width="50%"
209
- >
210
- <v-card>
211
- <v-card-title>
212
- <v-icon @click="editDocumentDialog = false">mdi-close</v-icon>
213
- </v-card-title>
214
- <v-card-text
215
- v-for="(attachment, index) in tempAttachmentChanged"
216
- :key="`attachment-${index}`"
217
- class="BYekan"
218
- >
219
- <v-row align="center" justify="center">
220
- <v-col cols="12" lg="9" md="9" xs="12">
221
- <v-text-field
222
- v-if="changeFileName"
223
- :label="selectedLang[lang].fileName"
224
- v-model="attachment.name"
225
- :prepend-icon="attachment.icon"
226
- >
227
- </v-text-field>
228
- <v-textarea
229
- v-if="addFileDescription"
230
- :label="selectedLang[lang].fileDescription"
231
- auto-grow
232
- row-height="1"
233
- v-model="attachment.description"
234
- >
235
- </v-textarea>
236
- <v-autocomplete
237
- v-if="addFileTag"
238
- v-model="attachment.tags"
239
- :items="tags"
240
- dense
241
- chips
242
- :label="selectedLang[lang].fileTags"
243
- multiple
244
- ></v-autocomplete>
245
- </v-col>
246
- <v-col align="center" cols="12" lg="3" md="3" xs="12">
247
- <template
248
- v-if="
249
- attachment.name
250
- .split('.')
251
- .pop()
252
- .toLowerCase() === 'jpg' ||
253
- attachment.name
254
- .split('.')
255
- .pop()
256
- .toLowerCase() === 'jpeg' ||
257
- attachment.name
258
- .split('.')
259
- .pop()
260
- .toLowerCase() === 'png' ||
261
- attachment.name
262
- .split('.')
263
- .pop()
264
- .toLowerCase() === 'tif' ||
265
- attachment.name
266
- .split('.')
267
- .pop()
268
- .toLowerCase() === 'bmp'
269
- "
270
- >
271
- <v-card>
272
- <v-img
273
- :src="
274
- 'data:' + attachment.format + ',' + attachment.base64
275
- "
276
- ></v-img>
277
- </v-card>
278
- </template>
279
- <template v-else>
280
- <select-file-icon-type
281
- :file-format="attachment.format"
282
- :size="60"
283
- >
284
- </select-file-icon-type>
285
- </template>
286
- </v-col>
287
- </v-row>
288
- </v-card-text>
289
- <v-card-actions>
290
- <v-btn
291
- class="BYekan"
292
- :disabled="tempAttachment === null || btnLoader"
293
- :loading="btnLoader"
294
- :color="btnColor"
295
- @click="editDocument"
296
- >{{ selectedLang[lang].edit }}</v-btn
297
- >
298
- </v-card-actions>
299
- </v-card>
300
- </v-dialog>
301
- </v-row>
302
- <!--Update Document Dialog End------------------------------------------------------------------------>
303
-
304
- <!--File Uploader SnackBar Alert Start --------------------------------------------------------------->
305
- <v-snackbar
306
- class="BYekan"
307
- v-model="fileUploaderSnackBarAlert"
308
- right
309
- bottom
310
- :color="fileUploaderSnackBarAlertColor"
311
- :timeout="3000"
312
- >
313
- {{ fileUploaderSnackText }}
314
- <v-btn color="white" text @click="fileUploaderSnackBarAlert = false">
315
- <v-icon>mdi-close</v-icon>
316
- </v-btn>
317
- </v-snackbar>
318
- <!--File Uploader SnackBar Alert Start -->
319
- <!--DELETE Dialog End----------------------------------------------------------START---->
320
- <v-row justify="center">
321
- <v-dialog v-model="deleteDocumentDialog" persistent width="30%">
322
- <v-card>
323
- <v-card-title>
324
- <v-icon color="red"></v-icon>
325
- </v-card-title>
326
- <v-card-text class="BYekan">
327
- {{ selectedLang[lang].deleteDialog.message }}
328
- </v-card-text>
329
- <v-card-actions>
330
- <v-spacer></v-spacer>
331
- <v-btn
332
- class="BYekan"
333
- color="green darken-1"
334
- text
335
- @click="deleteDocumentDialog = false"
336
- >{{ selectedLang[lang].deleteDialog.cancel }}</v-btn
337
- >
338
- <v-btn
339
- class="BYekan"
340
- color="primary"
341
- :disabled="btnLoader"
342
- :loading="btnLoader"
343
- @click="deleteDocument"
344
- >{{ selectedLang[lang].delete }}
345
- </v-btn>
346
- </v-card-actions>
347
- </v-card>
348
- </v-dialog>
349
- </v-row>
350
- <!--DELETE Dialog End----------------------------------------------------------------END---->
351
- </v-container>
352
- </template>
353
-
354
- <script>
355
- /**
356
- * This is an example of uploading files. with this component you can see, insert, delete files.
357
- * @version 1.0
358
- * @author [ali jahanpak](https://github.com/alijahanpak)
359
- * @since Version 1.0
360
- */
361
- import InsertButton from "./InsertButton";
362
- import SimpleUploader from "./SimpleUploader";
363
- import ThumbnailUploader from "./ThumbnailUploader.vue";
364
- import TableUploader from "./TableUploader.vue";
365
- import SelectFileIconType from "./SelectFileIconType.vue";
366
- import languages from "./language";
367
- export default {
368
- components: {
369
- InsertButton,
370
- SimpleUploader,
371
- ThumbnailUploader,
372
- TableUploader,
373
- SelectFileIconType
374
- },
375
- props: {
376
- /**
377
- * Array contain files
378
- */
379
- documentAttachment: [Array],
380
- /**
381
- * Send api url for 'add' and 'delete'.
382
- * f.e: /building/add or /building/delete
383
- */
384
- maxFileSize: {
385
- type: Number,
386
- default: 5120
387
- },
388
- /**
389
- * choose File Uploader Type
390
- */
391
- fileUploaderType: {
392
- type: String,
393
- default: "thumbnail"
394
- },
395
- /**
396
- * Maximum file Upload
397
- */
398
- maxFileCount: {
399
- type: Number,
400
- default: 0
401
- },
402
- /**
403
- * choose File Uploader Card Type
404
- */
405
- cardType: String,
406
- /**
407
- * Badge file counter state
408
- */
409
- badgeCounter: {
410
- type: Boolean,
411
- default: true
412
- },
413
- /**
414
- * change Button Color
415
- */
416
- btnColor: {
417
- type: String,
418
- default: "info"
419
- },
420
- /**
421
- * Enable / Disable image compressor
422
- */
423
- imageCompressor: Boolean,
424
- /**
425
- * Image compress level (0 to 1)
426
- */
427
- imageCompressLevel: {
428
- type: Number,
429
- default: 0.5
430
- },
431
- /**
432
- * Accept uploaded files
433
- */
434
- fileAccept: String,
435
- /**
436
- * show / hidden thumb for images in table and simple file uploader
437
- */
438
- thumb: {
439
- type: Boolean,
440
- default: true
441
- },
442
- /**
443
- * show / hidden thumb column in table file uploader
444
- */
445
- tableThumbColumn: Boolean,
446
- /**
447
- * enable / disable table fixed header
448
- */
449
- tableFixedHeader: {
450
- type: Boolean,
451
- default: true
452
- },
453
- /**
454
- * set table height
455
- */
456
- tableHeight: {
457
- type: Number,
458
- default: 400
459
- },
460
- /**
461
- * Enable RTL support languages
462
- */
463
- rtlSupport: {
464
- type: Boolean,
465
- default: false
466
- },
467
- /**
468
- * Change file uploader languages
469
- */
470
- lang: {
471
- type: String,
472
- default: "en"
473
- },
474
- /**
475
- * Change file Name before upload
476
- */
477
- changeFileName: {
478
- type: Boolean,
479
- default: false
480
- },
481
- /**
482
- * Add file Description before upload
483
- */
484
- addFileDescription: {
485
- type: Boolean,
486
- default: false
487
- },
488
- /**
489
- * Add file tags before upload
490
- */
491
- addFileTag: {
492
- type: Boolean,
493
- default: false
494
- },
495
- /**
496
- * Array of file tags
497
- */
498
- tags: {
499
- type: Array
500
- },
501
- /**
502
- * Change count of columns
503
- */
504
- cols: {
505
- type: Number,
506
- default: 4
507
- },
508
- /**
509
- * Define Custom language for uploader
510
- */
511
- customLang: {
512
- type: Object,
513
- default: null
514
- },
515
- /**
516
- * Set Insert/Add new file Permission
517
- */
518
- insertPermission: {
519
- type: Boolean,
520
- default: true
521
- },
522
- /**
523
- * Set edit Permission
524
- */
525
- editPermission: {
526
- type: Boolean,
527
- default: true
528
- },
529
- /**
530
- * Set delete Permission
531
- */
532
- deletePermission: {
533
- type: Boolean,
534
- default: true
535
- }
536
- },
537
- data: () => ({
538
- insertDocumentDialog: false,
539
- editDocumentDialog: false,
540
- deleteDocumentDialog: false,
541
- tempAttachment: [],
542
- tempAttachmentChanged: [],
543
- fileUploaderSnackBarAlert: false,
544
- fileUploaderSnackText: "",
545
- fileUploaderSnackBarAlertColor: "green",
546
- readerFile: null,
547
- registryDocFile: [],
548
- documentAttachmentAPI: [],
549
- btnLoader: false,
550
- showDetail: false,
551
- showDetailState: [],
552
- selectedIndex: "",
553
- selectedId: "",
554
- returnedRecord: {},
555
- //Card Theme
556
- outlined: false,
557
- raised: false,
558
- shaped: false,
559
- tile: false,
560
- selectedLang: {},
561
- beforeInsertAttachments: {},
562
- attachmentIndex: ""
563
- }),
564
- watch: {
565
- tempAttachment: function(newValue) {
566
- if (this.tempAttachment.length > 0) this.getAttachmentDetails(newValue);
567
- else this.tempAttachmentChanged = [];
568
- },
569
- cardType: function() {
570
- this.$emit("update:cardType", this.cardType);
571
- this.setCardTheme();
572
- },
573
- badgeCounter: function() {
574
- this.$emit("update:badgeCounter", this.badgeCounter);
575
- },
576
- maxFileCount: function() {
577
- this.$emit("update:maxFileCount", this.maxFileCount);
578
- },
579
- maxFileSize: function() {
580
- this.$emit("update:maxFileSize", Number(this.maxFileSize));
581
- },
582
- imageCompressor: function() {
583
- this.$emit("update:imageCompressor", this.imageCompressor);
584
- },
585
- imageCompressLevel: function() {
586
- this.$emit("update:imageCompressLevel", this.imageCompressLevel);
587
- },
588
- fileAccept: function() {
589
- this.$emit("update:fileAccept", this.fileAccept);
590
- },
591
- thumb: function() {
592
- this.$emit("update:thumb", this.thumb);
593
- },
594
- changeFileName: function() {
595
- this.$emit("update:changeFileName", this.changeFileName);
596
- },
597
- addFileDescription: function() {
598
- this.$emit("update:addFileDescription", this.addFileDescription);
599
- },
600
- addFileTag: function() {
601
- this.$emit("update:addFileTag", this.addFileTag);
602
- },
603
- tableThumbColumn: function() {
604
- this.$emit("update:tableThumbColumn", this.tableThumbColumn);
605
- },
606
- tableFixedHeader: function() {
607
- this.$emit("update:tableFixedHeader", this.tableFixedHeader);
608
- },
609
- tableHeight: function() {
610
- this.$emit("update:tableHeight", this.tableHeight);
611
- },
612
- lang: function() {
613
- this.$emit("update:lang", this.lang);
614
- }
615
- },
616
- created() {
617
- if (this.rtlSupport) this.changeRTL();
618
- this.setLang();
619
- this.setCardTheme();
620
- },
621
- mounted() {
622
- this.registryDocFile = this.documentAttachment;
623
- },
624
- destroyed() {
625
- this.registryDocFile = [];
626
- },
627
- methods: {
628
- openInputDocumentModal() {
629
- this.btnLoader = false;
630
- this.tempAttachment = [];
631
- this.insertDocumentDialog = true;
632
- },
633
-
634
- setLang() {
635
- if (this.customLang !== null) this.selectedLang = this.customLang;
636
- else this.selectedLang = languages;
637
- },
638
- changeRTL() {
639
- this.$vuetify.rtl = true;
640
- },
641
- setCardTheme() {
642
- switch (this.cardType) {
643
- case "default":
644
- this.outlined = false;
645
- this.raised = false;
646
- this.shaped = false;
647
- this.tile = false;
648
- break;
649
- case "outlined":
650
- this.outlined = true;
651
- this.raised = false;
652
- this.shaped = false;
653
- this.tile = false;
654
- break;
655
- case "shaped":
656
- this.shaped = true;
657
- this.raised = false;
658
- this.outlined = false;
659
- this.tile = false;
660
- break;
661
- case "raised":
662
- this.raised = true;
663
- this.shaped = false;
664
- this.outlined = false;
665
- this.tile = false;
666
- break;
667
- case "tile":
668
- this.tile = true;
669
- this.shaped = false;
670
- this.outlined = false;
671
- this.raised = false;
672
- break;
673
- }
674
- },
675
-
676
- handleUpload(fileAttachment) {
677
- let reader = new FileReader();
678
- return new Promise(function(resolve) {
679
- reader.onloadend = () => {
680
- resolve(reader.result);
681
- };
682
- reader.readAsDataURL(fileAttachment);
683
- });
684
- },
685
-
686
- /**
687
- * asynchronous method to insert selected file(s)
688
- *
689
- * @public
690
- * @returns {Array} selected file(s)
691
- */
692
- async uploadFieldChange() {
693
- this.btnLoader = true;
694
- for (let [index, item] of this.tempAttachment.entries()) {
695
- if (this.documentAttachment.length < this.maxFileCount) {
696
- if ((item.size / 1000).toFixed(1) > this.maxFileSize) {
697
- this.fileUploaderSnackBarAlertColor = "red";
698
- this.fileUploaderSnackText = `${
699
- this.selectedLang[this.lang].maxFileSizeAlert
700
- } ${Math.round(this.maxFileSize / 1024)} ${
701
- this.selectedLang[this.lang].size.mb
702
- }`;
703
- this.fileUploaderSnackBarAlert = true;
704
- } else {
705
- let tempFile = {};
706
- let file = {};
707
- try {
708
- // console.log(item);
709
- this.readerFile = await this.handleUpload(item);
710
- } catch (e) {
711
- console.log(e);
712
- }
713
- let fullFileType = this.readerFile.split(";");
714
- let fileType = fullFileType[0].split(":");
715
- let status = false;
716
- let imgFile = "";
717
- let sizeInKb = 0;
718
- if (this.imageCompressor) {
719
- if (
720
- fileType[1] === "image/png" ||
721
- fileType[1] === "image/jpg" ||
722
- fileType[1] === "image/jpeg" ||
723
- fileType[1] === "application/octet-stream" ||
724
- fileType[1] === "image/webp"
725
- ) {
726
- status = true;
727
- imgFile = await this.compressImage(
728
- this.readerFile,
729
- fileType[1]
730
- );
731
- }
732
- }
733
- //tempFile.subject= this.tempAttachmentChanged[index].name + '.' + this.tempAttachmentChanged[index].format;
734
- let strTemp = this.readerFile.split(",");
735
- if (status) {
736
- let imgTemp = imgFile.split(",");
737
- tempFile.base64 = imgTemp[1];
738
- sizeInKb = new Buffer(imgFile, "base64").length;
739
- tempFile.size = String(sizeInKb);
740
- } else {
741
- tempFile.base64 = strTemp[1];
742
- tempFile.size = String(item.size);
743
- }
744
- tempFile.name =
745
- this.tempAttachmentChanged[index].name +
746
- "." +
747
- this.tempAttachmentChanged[index].format;
748
- if (this.tempAttachmentChanged[index].tags === undefined)
749
- tempFile.tags = [];
750
- else tempFile.tags = this.tempAttachmentChanged[index].tags;
751
- if (this.tempAttachmentChanged[index].description === undefined)
752
- tempFile.description = "";
753
- else
754
- tempFile.description = this.tempAttachmentChanged[
755
- index
756
- ].description;
757
- tempFile.showDetailState = false;
758
-
759
- tempFile.format = strTemp[0].replace("data:", "");
760
- file.file = tempFile;
761
- /* const convertedToFile = this.convertBase64ToFile(
762
- imgFile,
763
- tempFile.name
764
- ); */
765
- // console.log(convertedToFile)
766
- this.registryDocFile.push(file);
767
- this.$emit("update:documentAttachment", this.registryDocFile);
768
- }
769
- } else {
770
- this.fileUploaderSnackBarAlertColor = "red";
771
- this.fileUploaderSnackText = `${
772
- this.selectedLang[this.lang].maxFileCountAlert
773
- } ${this.maxFileCount}`;
774
- this.fileUploaderSnackBarAlert = true;
775
- }
776
- }
777
- this.documentAttachmentAPI = [];
778
- this.tempAttachmentChanged = [];
779
- this.insertDocumentDialog = false;
780
- },
781
-
782
- compressImage(base64) {
783
- const canvas = document.createElement("canvas");
784
- const img = document.createElement("img");
785
-
786
- return new Promise((resolve, reject) => {
787
- let imageCompressLevelTemp = this.imageCompressLevel;
788
- img.onload = function() {
789
- let width = img.width;
790
- let height = img.height;
791
- canvas.width = width;
792
- canvas.height = height;
793
-
794
- const ctx = canvas.getContext("2d");
795
- ctx.drawImage(img, 0, 0, width, height);
796
-
797
- resolve(canvas.toDataURL("image/jpeg", imageCompressLevelTemp));
798
- };
799
- img.onerror = function(err) {
800
- reject(err);
801
- };
802
- img.src = base64;
803
- });
804
- },
805
-
806
- convertBase64ToFile(base64, fileName) {
807
- const byteString = atob(base64.split(",")[1]);
808
- const ab = new ArrayBuffer(byteString.length);
809
- const ia = new Uint8Array(ab);
810
- for (let i = 0; i < byteString.length; i += 1) {
811
- ia[i] = byteString.charCodeAt(i);
812
- }
813
- const newBlob = new Blob([ab], {
814
- type: "image/jpeg"
815
- });
816
- return new File([newBlob], fileName);
817
- },
818
-
819
- openDeleteDialog(index, deleteId) {
820
- this.btnLoader = false;
821
- this.selectedIndex = index;
822
- this.selectedId = deleteId;
823
- this.deleteDocumentDialog = true;
824
- },
825
-
826
- deleteDocument() {
827
- this.registryDocFile.splice(this.selectedIndex, 1);
828
- this.$emit("update:documentAttachment", this.registryDocFile);
829
- this.deleteDocumentDialog = false;
830
- },
831
-
832
- async getAttachmentDetails(selectedAttachment) {
833
- for (let item of selectedAttachment) {
834
- try {
835
- this.readerFile = await this.handleUpload(item);
836
- } catch (e) {
837
- console.log(e);
838
- }
839
- let obj = {};
840
- let name = "";
841
- name = item.name.split(".");
842
- obj.format = item.name.substr(item.name.lastIndexOf(".") + 1);
843
- obj.name = name[0];
844
- obj.base64 = this.readerFile;
845
- this.tempAttachmentChanged.push(obj);
846
- }
847
- },
848
-
849
- openEditDocumentDialog(item, index) {
850
- this.btnLoader = false;
851
- this.attachmentIndex = index;
852
- this.editDocumentDialog = true;
853
- this.tempAttachmentChanged = item;
854
- },
855
-
856
- editDocument() {
857
- this.documentAttachment.splice(
858
- this.attachmentIndex,
859
- 1,
860
- this.tempAttachmentChanged
861
- );
862
- this.editDocumentDialog = false;
863
- },
864
-
865
- /*getBinaryFile(attachment) {
866
- let fileUrl = '/file/' + attachment.file.url;
867
- window.open(process.env.apiBaseUrl +fileUrl );
868
- },*/
869
-
870
- getShowDetailState(index) {
871
- this.showDetailState[index] = !this.showDetailState[index];
872
- console.log("showDetailState" + JSON.stringify(this.showDetailState));
873
- },
874
-
875
- destroyFileUploader() {
876
- this.documentAttachmentAPI = [];
877
- this.documentAttachment = [];
878
- this.registryDocFile = [];
879
- this.tempAttachment = [];
880
- }
881
- }
882
- };
883
- </script>