FileUpload: Added fileSizeTypes (#4377)
* added fileSizeTypes * Added filesizeTypes fileupload, refactor and docs * Added formatpull/4142/head
parent
b867022473
commit
430958237d
|
@ -300,6 +300,7 @@ export interface PrimeVueLocaleOptions {
|
||||||
cancel?: string;
|
cancel?: string;
|
||||||
completed?: string;
|
completed?: string;
|
||||||
pending?: string;
|
pending?: string;
|
||||||
|
fileSizeTypes: string[];
|
||||||
dayNames: string[];
|
dayNames: string[];
|
||||||
dayNamesShort: string[];
|
dayNamesShort: string[];
|
||||||
dayNamesMin: string[];
|
dayNamesMin: string[];
|
||||||
|
|
|
@ -33,6 +33,7 @@ export const defaultOptions = {
|
||||||
cancel: 'Cancel',
|
cancel: 'Cancel',
|
||||||
completed: 'Completed',
|
completed: 'Completed',
|
||||||
pending: 'Pending',
|
pending: 'Pending',
|
||||||
|
fileSizeTypes: ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'],
|
||||||
dayNames: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'],
|
dayNames: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'],
|
||||||
dayNamesShort: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],
|
dayNamesShort: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],
|
||||||
dayNamesMin: ['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa'],
|
dayNamesMin: ['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa'],
|
||||||
|
|
|
@ -52,16 +52,18 @@ export default {
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
formatSize(bytes) {
|
formatSize(bytes) {
|
||||||
|
const k = 1024;
|
||||||
|
const dm = 3;
|
||||||
|
const sizes = this.$primevue.config.locale.fileSizeTypes;
|
||||||
|
|
||||||
if (bytes === 0) {
|
if (bytes === 0) {
|
||||||
return '0 B';
|
return `0 ${sizes[0]}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
let k = 1000,
|
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
||||||
dm = 3,
|
const formattedSize = parseFloat((bytes / Math.pow(k, i)).toFixed(dm));
|
||||||
sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'],
|
|
||||||
i = Math.floor(Math.log(bytes) / Math.log(k));
|
|
||||||
|
|
||||||
return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i];
|
return `${formattedSize} ${sizes[i]}`;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
components: {
|
components: {
|
||||||
|
|
|
@ -326,16 +326,18 @@ export default {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
formatSize(bytes) {
|
formatSize(bytes) {
|
||||||
|
const k = 1024;
|
||||||
|
const dm = 3;
|
||||||
|
const sizes = this.$primevue.config.locale.fileSizeTypes;
|
||||||
|
|
||||||
if (bytes === 0) {
|
if (bytes === 0) {
|
||||||
return '0 B';
|
return `0 ${sizes[0]}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
let k = 1000,
|
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
||||||
dm = 3,
|
const formattedSize = parseFloat((bytes / Math.pow(k, i)).toFixed(dm));
|
||||||
sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'],
|
|
||||||
i = Math.floor(Math.log(bytes) / Math.log(k));
|
|
||||||
|
|
||||||
return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i];
|
return `${formattedSize} ${sizes[i]}`;
|
||||||
},
|
},
|
||||||
isFileLimitExceeded() {
|
isFileLimitExceeded() {
|
||||||
if (this.fileLimit && this.fileLimit <= this.files.length + this.uploadedFileCount && this.focused) {
|
if (this.fileLimit && this.fileLimit <= this.files.length + this.uploadedFileCount && this.focused) {
|
||||||
|
|
|
@ -13342,6 +13342,13 @@
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"default": ""
|
"default": ""
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "fileSizeTypes",
|
||||||
|
"optional": true,
|
||||||
|
"readonly": false,
|
||||||
|
"type": "string[]",
|
||||||
|
"default": ""
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "dayNames",
|
"name": "dayNames",
|
||||||
"optional": false,
|
"optional": false,
|
||||||
|
|
|
@ -124,6 +124,10 @@
|
||||||
<td>pending</td>
|
<td>pending</td>
|
||||||
<td>Pending</td>
|
<td>Pending</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>fileSizeTypes</td>
|
||||||
|
<td>['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']</td>
|
||||||
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>dayNames</td>
|
<td>dayNames</td>
|
||||||
<td>['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'</td>
|
<td>['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'</td>
|
||||||
|
|
|
@ -208,16 +208,18 @@ export default {
|
||||||
this.$toast.add({ severity: 'info', summary: 'Success', detail: 'File Uploaded', life: 3000 });
|
this.$toast.add({ severity: 'info', summary: 'Success', detail: 'File Uploaded', life: 3000 });
|
||||||
},
|
},
|
||||||
formatSize(bytes) {
|
formatSize(bytes) {
|
||||||
|
const k = 1024;
|
||||||
|
const dm = 3;
|
||||||
|
const sizes = this.$primevue.config.locale.fileSizeTypes;
|
||||||
|
|
||||||
if (bytes === 0) {
|
if (bytes === 0) {
|
||||||
return '0 B';
|
return \`0 \${sizes[0]}\`;
|
||||||
}
|
}
|
||||||
|
|
||||||
let k = 1000,
|
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
||||||
dm = 3,
|
const formattedSize = parseFloat((bytes / Math.pow(k, i)).toFixed(dm));
|
||||||
sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'],
|
|
||||||
i = Math.floor(Math.log(bytes) / Math.log(k));
|
|
||||||
|
|
||||||
return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i];
|
return \`\${formattedSize} \${sizes[i]}\`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -315,13 +317,20 @@ const onTemplatedUpload = () => {
|
||||||
toast.add({ severity: "info", summary: "Success", detail: "File Uploaded", life: 3000 });
|
toast.add({ severity: "info", summary: "Success", detail: "File Uploaded", life: 3000 });
|
||||||
};
|
};
|
||||||
|
|
||||||
const formatSize = (bytes) => {
|
formatSize(bytes) {
|
||||||
if (bytes === 0) return "0 B";
|
|
||||||
const k = 1024;
|
const k = 1024;
|
||||||
const sizes = ["B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"];
|
const dm = 3;
|
||||||
|
const sizes = this.$primevue.config.locale.fileSizeTypes;
|
||||||
|
|
||||||
|
if (bytes === 0) {
|
||||||
|
return \`0 \${sizes[0]}\`;
|
||||||
|
}
|
||||||
|
|
||||||
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
||||||
return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + " " + sizes[i];
|
const formattedSize = parseFloat((bytes / Math.pow(k, i)).toFixed(dm));
|
||||||
};
|
|
||||||
|
return \`\${formattedSize} \${sizes[i]}\`;
|
||||||
|
},
|
||||||
<\/script>`
|
<\/script>`
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -351,16 +360,18 @@ const formatSize = (bytes) => {
|
||||||
this.$toast.add({ severity: 'info', summary: 'Success', detail: 'File Uploaded', life: 3000 });
|
this.$toast.add({ severity: 'info', summary: 'Success', detail: 'File Uploaded', life: 3000 });
|
||||||
},
|
},
|
||||||
formatSize(bytes) {
|
formatSize(bytes) {
|
||||||
|
const k = 1024;
|
||||||
|
const dm = 3;
|
||||||
|
const sizes = this.$primevue.config.locale.fileSizeTypes;
|
||||||
|
|
||||||
if (bytes === 0) {
|
if (bytes === 0) {
|
||||||
return '0 B';
|
return `0 ${sizes[0]}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
let k = 1000,
|
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
||||||
dm = 3,
|
const formattedSize = parseFloat((bytes / Math.pow(k, i)).toFixed(dm));
|
||||||
sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'],
|
|
||||||
i = Math.floor(Math.log(bytes) / Math.log(k));
|
|
||||||
|
|
||||||
return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i];
|
return `${formattedSize} ${sizes[i]}`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue