FileUpload: Added fileSizeTypes (#4377)

* added fileSizeTypes

* Added filesizeTypes fileupload, refactor and docs

* Added format
pull/4142/head
Diego Franchina 2023-09-05 04:01:27 +02:00 committed by GitHub
parent b867022473
commit 430958237d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 57 additions and 29 deletions

View File

@ -300,6 +300,7 @@ export interface PrimeVueLocaleOptions {
cancel?: string;
completed?: string;
pending?: string;
fileSizeTypes: string[];
dayNames: string[];
dayNamesShort: string[];
dayNamesMin: string[];

View File

@ -33,6 +33,7 @@ export const defaultOptions = {
cancel: 'Cancel',
completed: 'Completed',
pending: 'Pending',
fileSizeTypes: ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'],
dayNames: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'],
dayNamesShort: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],
dayNamesMin: ['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa'],

View File

@ -52,16 +52,18 @@ export default {
},
methods: {
formatSize(bytes) {
const k = 1024;
const dm = 3;
const sizes = this.$primevue.config.locale.fileSizeTypes;
if (bytes === 0) {
return '0 B';
return `0 ${sizes[0]}`;
}
let k = 1000,
dm = 3,
sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'],
i = Math.floor(Math.log(bytes) / Math.log(k));
const i = Math.floor(Math.log(bytes) / Math.log(k));
const formattedSize = parseFloat((bytes / Math.pow(k, i)).toFixed(dm));
return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i];
return `${formattedSize} ${sizes[i]}`;
}
},
components: {

View File

@ -326,16 +326,18 @@ export default {
}
},
formatSize(bytes) {
const k = 1024;
const dm = 3;
const sizes = this.$primevue.config.locale.fileSizeTypes;
if (bytes === 0) {
return '0 B';
return `0 ${sizes[0]}`;
}
let k = 1000,
dm = 3,
sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'],
i = Math.floor(Math.log(bytes) / Math.log(k));
const i = Math.floor(Math.log(bytes) / Math.log(k));
const formattedSize = parseFloat((bytes / Math.pow(k, i)).toFixed(dm));
return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i];
return `${formattedSize} ${sizes[i]}`;
},
isFileLimitExceeded() {
if (this.fileLimit && this.fileLimit <= this.files.length + this.uploadedFileCount && this.focused) {

View File

@ -13342,6 +13342,13 @@
"type": "string",
"default": ""
},
{
"name": "fileSizeTypes",
"optional": true,
"readonly": false,
"type": "string[]",
"default": ""
},
{
"name": "dayNames",
"optional": false,

View File

@ -124,6 +124,10 @@
<td>pending</td>
<td>Pending</td>
</tr>
<tr>
<td>fileSizeTypes</td>
<td>['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']</td>
</tr>
<tr>
<td>dayNames</td>
<td>['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'</td>

View File

@ -208,16 +208,18 @@ export default {
this.$toast.add({ severity: 'info', summary: 'Success', detail: 'File Uploaded', life: 3000 });
},
formatSize(bytes) {
const k = 1024;
const dm = 3;
const sizes = this.$primevue.config.locale.fileSizeTypes;
if (bytes === 0) {
return '0 B';
return \`0 \${sizes[0]}\`;
}
let k = 1000,
dm = 3,
sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'],
i = Math.floor(Math.log(bytes) / Math.log(k));
const i = Math.floor(Math.log(bytes) / Math.log(k));
const formattedSize = parseFloat((bytes / Math.pow(k, i)).toFixed(dm));
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 });
};
const formatSize = (bytes) => {
if (bytes === 0) return "0 B";
formatSize(bytes) {
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));
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>`
}
};
@ -351,16 +360,18 @@ const formatSize = (bytes) => {
this.$toast.add({ severity: 'info', summary: 'Success', detail: 'File Uploaded', life: 3000 });
},
formatSize(bytes) {
const k = 1024;
const dm = 3;
const sizes = this.$primevue.config.locale.fileSizeTypes;
if (bytes === 0) {
return '0 B';
return `0 ${sizes[0]}`;
}
let k = 1000,
dm = 3,
sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'],
i = Math.floor(Math.log(bytes) / Math.log(k));
const i = Math.floor(Math.log(bytes) / Math.log(k));
const formattedSize = parseFloat((bytes / Math.pow(k, i)).toFixed(dm));
return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i];
return `${formattedSize} ${sizes[i]}`;
}
}
};