feat: dispatch quota fetch events

pull/3756/head
Laurynas Gadliauskas 2021-06-11 16:06:58 +03:00
parent ebb53e715b
commit 7f4593d2cc
9 changed files with 38 additions and 18 deletions

View File

@ -1,14 +1,20 @@
<template> <template>
<div id="quota"> <div id="quota">
<div> <div>
<label>{{ $t("sidebar.quota.space") }}</label> <div class="label">
<div class="bar" :title="spaceUsageTitle"> <span>{{ $t("sidebar.quota.space") }}</span>
<span v-if="loaded" class="metric">{{ spaceUsageTitle }}</span>
</div>
<div class="bar" :title="spaceProgress + '%'">
<div class="progress" :style="{ width: spaceProgress + '%' }"></div> <div class="progress" :style="{ width: spaceProgress + '%' }"></div>
</div> </div>
</div> </div>
<div> <div>
<label>{{ $t("sidebar.quota.inodes") }}</label> <div class="label">
<div class="bar" :title="inodeUsageTitle"> <span>{{ $t("sidebar.quota.inodes") }}</span>
<span v-if="loaded" class="metric">{{ inodeUsageTitle }}</span>
</div>
<div class="bar" :title="inodeProgress + '%'">
<div class="progress" :style="{ width: inodeProgress + '%' }"></div> <div class="progress" :style="{ width: inodeProgress + '%' }"></div>
</div> </div>
</div> </div>
@ -64,6 +70,7 @@ export default {
methods: { methods: {
progress(metric) { progress(metric) {
let prc = (metric.usage / metric.quota) * 100; let prc = (metric.usage / metric.quota) * 100;
prc = Math.round((prc + Number.EPSILON) * 100) / 100;
return Math.min(prc, 100); return Math.min(prc, 100);
}, },
}, },

View File

@ -84,6 +84,7 @@ export default {
} finally { } finally {
buttons.done("archive"); buttons.done("archive");
} }
this.$store.dispatch("quota/fetch", 3000);
}, },
}, },
}; };

View File

@ -86,7 +86,7 @@ export default {
if (this.$route.path === this.dest) { if (this.$route.path === this.dest) {
this.$store.commit("closeHovers"); this.$store.commit("closeHovers");
action(false, true); action(false, true);
this.$store.dispatch("quota/fetch", 3000);
return; return;
} }
@ -106,6 +106,7 @@ export default {
event.preventDefault(); event.preventDefault();
this.$store.commit("closeHovers"); this.$store.commit("closeHovers");
action(overwrite, rename); action(overwrite, rename);
this.$store.dispatch("quota/fetch", 3000);
}, },
}); });
@ -113,6 +114,7 @@ export default {
} }
action(overwrite, rename); action(overwrite, rename);
this.$store.dispatch("quota/fetch", 3000);
}, },
}, },
}; };

View File

@ -100,6 +100,7 @@ export default {
await Promise.all(promises); await Promise.all(promises);
buttons.success("delete"); buttons.success("delete");
this.$store.commit("setReload", true); this.$store.commit("setReload", true);
this.$store.dispatch("quota/fetch", 3000);
} catch (e) { } catch (e) {
buttons.done("delete"); buttons.done("delete");
this.$showError(e); this.$showError(e);

View File

@ -74,6 +74,7 @@ export default {
} }
this.$store.commit("closeHovers"); this.$store.commit("closeHovers");
this.$store.dispatch("quota/fetch", 3000);
}, },
}, },
}; };

View File

@ -74,6 +74,7 @@ export default {
} }
this.$store.commit("closeHovers"); this.$store.commit("closeHovers");
this.$store.dispatch("quota/fetch", 3000);
}, },
}, },
}; };

View File

@ -73,6 +73,7 @@ export default {
} finally { } finally {
buttons.done("unarchive"); buttons.done("unarchive");
} }
this.$store.dispatch("quota/fetch", 3000);
}, },
}, },
}; };

View File

@ -153,10 +153,14 @@ main {
margin-top: .5em; margin-top: .5em;
} }
#quota label { #quota .label {
color: #546E7A; color: #546E7A;
} }
#quota .label .metric {
float: right;
}
#quota .bar { #quota .bar {
width: 100%; width: 100%;
height: 10px; height: 10px;

View File

@ -13,19 +13,21 @@ const mutations = {
}; };
const actions = { const actions = {
fetch: async (context) => { fetch: async (context, delay = 0) => {
try { setTimeout(async () => {
let data = await api.getQuota(); try {
if ( let data = await api.getQuota();
data !== null && if (
data.inodes != undefined && data !== null &&
data.space != undefined data.inodes != undefined &&
) { data.space != undefined
context.commit("setQuota", data); ) {
context.commit("setQuota", data);
}
} catch (e) {
console.log(e);
} }
} catch (e) { }, delay);
console.log(e);
}
}, },
}; };