refactor(client): refactor settings/drive to use Composition API (#8573)

This commit is contained in:
Andreas Nedbal 2022-05-04 03:14:48 +02:00 committed by GitHub
parent 7a51f0ac94
commit fc02f8fc93
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,41 +1,41 @@
<template> <template>
<div class="_formRoot"> <div class="_formRoot">
<FormSection v-if="!fetching"> <FormSection v-if="!fetching">
<template #label>{{ $ts.usageAmount }}</template> <template #label>{{ i18n.ts.usageAmount }}</template>
<div class="_formBlock uawsfosz"> <div class="_formBlock uawsfosz">
<div class="meter"><div :style="meterStyle"></div></div> <div class="meter"><div :style="meterStyle"></div></div>
</div> </div>
<FormSplit> <FormSplit>
<MkKeyValue class="_formBlock"> <MkKeyValue class="_formBlock">
<template #key>{{ $ts.capacity }}</template> <template #key>{{ i18n.ts.capacity }}</template>
<template #value>{{ bytes(capacity, 1) }}</template> <template #value>{{ bytes(capacity, 1) }}</template>
</MkKeyValue> </MkKeyValue>
<MkKeyValue class="_formBlock"> <MkKeyValue class="_formBlock">
<template #key>{{ $ts.inUse }}</template> <template #key>{{ i18n.ts.inUse }}</template>
<template #value>{{ bytes(usage, 1) }}</template> <template #value>{{ bytes(usage, 1) }}</template>
</MkKeyValue> </MkKeyValue>
</FormSplit> </FormSplit>
</FormSection> </FormSection>
<FormSection> <FormSection>
<template #label>{{ $ts.statistics }}</template> <template #label>{{ i18n.ts.statistics }}</template>
<MkChart src="per-user-drive" :args="{ user: $i }" span="day" :limit="7 * 5" :bar="true" :stacked="true" :detailed="false" :aspect-ratio="6"/> <MkChart src="per-user-drive" :args="{ user: $i }" span="day" :limit="7 * 5" :bar="true" :stacked="true" :detailed="false" :aspect-ratio="6"/>
</FormSection> </FormSection>
<FormSection> <FormSection>
<FormLink @click="chooseUploadFolder()"> <FormLink @click="chooseUploadFolder()">
{{ $ts.uploadFolder }} {{ i18n.ts.uploadFolder }}
<template #suffix>{{ uploadFolder ? uploadFolder.name : '-' }}</template> <template #suffix>{{ uploadFolder ? uploadFolder.name : '-' }}</template>
<template #suffixIcon><i class="fas fa-folder-open"></i></template> <template #suffixIcon><i class="fas fa-folder-open"></i></template>
</FormLink> </FormLink>
<FormSwitch v-model="keepOriginalUploading" class="_formBlock">{{ $ts.keepOriginalUploading }}<template #caption>{{ $ts.keepOriginalUploadingDescription }}</template></FormSwitch> <FormSwitch v-model="keepOriginalUploading" class="_formBlock">{{ i18n.ts.keepOriginalUploading }}<template #caption>{{ i18n.ts.keepOriginalUploadingDescription }}</template></FormSwitch>
</FormSection> </FormSection>
</div> </div>
</template> </template>
<script lang="ts"> <script lang="ts" setup>
import { defineComponent } from 'vue'; import { computed, defineExpose, ref } from 'vue';
import tinycolor from 'tinycolor2'; import * as tinycolor from 'tinycolor2';
import FormLink from '@/components/form/link.vue'; import FormLink from '@/components/form/link.vue';
import FormSwitch from '@/components/form/switch.vue'; import FormSwitch from '@/components/form/switch.vue';
import FormSection from '@/components/form/section.vue'; import FormSection from '@/components/form/section.vue';
@ -46,80 +46,59 @@ import bytes from '@/filters/bytes';
import * as symbols from '@/symbols'; import * as symbols from '@/symbols';
import { defaultStore } from '@/store'; import { defaultStore } from '@/store';
import MkChart from '@/components/chart.vue'; import MkChart from '@/components/chart.vue';
import { i18n } from '@/i18n';
export default defineComponent({ const fetching = ref(true);
components: { const usage = ref<any>(null);
FormLink, const capacity = ref<any>(null);
FormSwitch, const uploadFolder = ref<any>(null);
FormSection,
MkKeyValue,
FormSplit,
MkChart,
},
emits: ['info'], const meterStyle = computed(() => {
data() {
return { return {
[symbols.PAGE_INFO]: { width: `${usage.value / capacity.value * 100}%`,
title: this.$ts.drive,
icon: 'fas fa-cloud',
bg: 'var(--bg)',
},
fetching: true,
usage: null,
capacity: null,
uploadFolder: null,
}
},
computed: {
meterStyle(): any {
return {
width: `${this.usage / this.capacity * 100}%`,
background: tinycolor({ background: tinycolor({
h: 180 - (this.usage / this.capacity * 180), h: 180 - (usage.value / capacity.value * 180),
s: 0.7, s: 0.7,
l: 0.5 l: 0.5
}) })
}; };
}, });
keepOriginalUploading: defaultStore.makeGetterSetter('keepOriginalUploading'),
}, const keepOriginalUploading = computed(defaultStore.makeGetterSetter('keepOriginalUploading'));
async created() {
os.api('drive').then(info => { os.api('drive').then(info => {
this.capacity = info.capacity; capacity.value = info.capacity;
this.usage = info.usage; usage.value = info.usage;
this.fetching = false; fetching.value = false;
this.$nextTick(() => {
this.renderChart();
});
}); });
if (this.$store.state.uploadFolder) { if (defaultStore.state.uploadFolder) {
this.uploadFolder = await os.api('drive/folders/show', { os.api('drive/folders/show', {
folderId: this.$store.state.uploadFolder folderId: defaultStore.state.uploadFolder
}).then(response => {
uploadFolder.value = response;
}); });
} }
},
methods: { function chooseUploadFolder() {
chooseUploadFolder() {
os.selectDriveFolder(false).then(async folder => { os.selectDriveFolder(false).then(async folder => {
this.$store.set('uploadFolder', folder ? folder.id : null); defaultStore.set('uploadFolder', folder ? folder.id : null);
os.success(); os.success();
if (this.$store.state.uploadFolder) { if (defaultStore.state.uploadFolder) {
this.uploadFolder = await os.api('drive/folders/show', { uploadFolder.value = await os.api('drive/folders/show', {
folderId: this.$store.state.uploadFolder folderId: defaultStore.state.uploadFolder
}); });
} else { } else {
this.uploadFolder = null; uploadFolder.value = null;
} }
}); });
}, }
bytes defineExpose({
[symbols.PAGE_INFO]: {
title: i18n.ts.drive,
icon: 'fas fa-cloud',
bg: 'var(--bg)',
} }
}); });
</script> </script>