Merge branch 'edit-api' into develop

This commit is contained in:
Net 2024-07-19 14:32:54 +07:00
commit 491103637f
3 changed files with 59 additions and 5 deletions

View file

@ -28,6 +28,7 @@ const {
deleteBackUp,
backupRunningList,
restoreRunningList,
getSize,
} = useDataStore();
const storeData = useDataStore();
const { dataBackUp, backupRunTotal, restoreRunTotal } = storeToRefs(storeData);
@ -41,7 +42,13 @@ const tab = defineModel<string>("tab", { required: true });
* Table
*/
const filter = ref<string>("");
const visibleColumns = ref<string[]>(["name", "createAt", "status"]);
const visibleColumns = ref<string[]>([
"name",
"createAt",
"databaseSize",
"storageSize",
"status",
]);
const baseColumns = ref<QTableProps["columns"]>([
{
name: "name",
@ -63,6 +70,26 @@ const baseColumns = ref<QTableProps["columns"]>([
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
{
name: "databaseSize",
align: "center",
label: "ขนาดของฐานข้อมูล ",
sortable: true,
// field: (v) => date2Thai(v, false, true),
field: "databaseSize",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
{
name: "storageSize",
align: "center",
label: "ขนาดของไฟล์ ",
sortable: true,
// field: (v) => date2Thai(v, false, true),
field: "storageSize",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
{
name: "status",
align: "center",
@ -188,8 +215,16 @@ onMounted(async () => {
<template v-slot:body="props">
<q-tr :props="props">
<q-td v-for="(col, i) in props.cols" :key="col.name" :props="props">
<div :class="{ 'text-center': i === 2 }">
{{ i !== 2 ? col.value : col.value === "สำเร็จ" ? "สำเร็จ" : "" }}
<div :class="{ 'text-center': i === 4 }">
{{
i !== 4 && i !== 2 && i !== 3
? col.value
: col.value === "สำเร็จ"
? "สำเร็จ"
: i === 2 || i === 3
? getSize(col.value)
: ""
}}
<q-circular-progress
v-if="props.row.status === 'running' && col.name === 'status'"

View file

@ -2,6 +2,8 @@ interface DataBackup {
id: string;
name: string;
timestamp: Date;
databaseSize: number;
storageSize: number;
status: string;
}

View file

@ -66,7 +66,7 @@ export const useDataStore = defineStore("systemStore", () => {
showLoader();
await http
.delete(config.API.backup + "/delete", {
data: { filename: filename },
data: { name: filename },
})
.then(async (res) => {
await fetchListBackup();
@ -79,7 +79,7 @@ export const useDataStore = defineStore("systemStore", () => {
async function restore(filename: string) {
await http
.post<string>(config.API.restore, {
filename: filename,
name: filename,
})
.then(async (res) => {
const tempValue = dataBackUp.value.find((item) => {
@ -122,6 +122,8 @@ export const useDataStore = defineStore("systemStore", () => {
dataBackUp.value.unshift({
id: item.created_at.toString(),
name: "-",
databaseSize: 0,
storageSize: 0,
timestamp: item.created_at,
status: item.running ? "running" : "success",
});
@ -163,6 +165,19 @@ export const useDataStore = defineStore("systemStore", () => {
});
}
function getSize(size: number): string {
if (size === undefined) return "Unknow size";
const units = ["B", "KB", "MB", "GB", "TB"];
let i = 0;
let sizeNumber = typeof size === "string" ? parseFloat(size) : size;
while (sizeNumber >= 1024 && i++ < units.length - 1) {
sizeNumber /= 1024;
}
return sizeNumber.toFixed(2) + " " + units[i];
}
return {
dataBackUp,
backupRunTotal,
@ -175,5 +190,7 @@ export const useDataStore = defineStore("systemStore", () => {
backupRunningList,
restoreRunningList,
getSize,
};
});