trashposs/packages/client/src/pages/settings/drive.vue

125 lines
3.3 KiB
Vue
Raw Normal View History

<template>
2021-11-28 12:07:37 +01:00
<div class="_formRoot">
<FormSection v-if="!fetching">
<template #label>{{ i18n.ts.usageAmount }}</template>
2021-11-28 12:07:37 +01:00
<div class="_formBlock uawsfosz">
<div class="meter"><div :style="meterStyle"></div></div>
2021-01-23 10:14:57 +01:00
</div>
2021-12-30 13:47:48 +01:00
<FormSplit>
2021-11-28 12:07:37 +01:00
<MkKeyValue class="_formBlock">
<template #key>{{ i18n.ts.capacity }}</template>
2021-11-28 12:07:37 +01:00
<template #value>{{ bytes(capacity, 1) }}</template>
</MkKeyValue>
<MkKeyValue class="_formBlock">
<template #key>{{ i18n.ts.inUse }}</template>
2021-11-28 12:07:37 +01:00
<template #value>{{ bytes(usage, 1) }}</template>
</MkKeyValue>
2021-12-30 13:47:48 +01:00
</FormSplit>
2021-11-28 12:07:37 +01:00
</FormSection>
<FormSection>
<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"/>
2021-11-28 12:07:37 +01:00
</FormSection>
<FormSection>
<FormLink @click="chooseUploadFolder()">
{{ i18n.ts.uploadFolder }}
2021-11-28 12:07:37 +01:00
<template #suffix>{{ uploadFolder ? uploadFolder.name : '-' }}</template>
<template #suffixIcon><i class="fas fa-folder-open"></i></template>
</FormLink>
<FormSwitch v-model="keepOriginalUploading" class="_formBlock">{{ i18n.ts.keepOriginalUploading }}<template #caption>{{ i18n.ts.keepOriginalUploadingDescription }}</template></FormSwitch>
2021-11-28 12:07:37 +01:00
</FormSection>
</div>
</template>
<script lang="ts" setup>
import { computed, defineExpose, ref } from 'vue';
import * as tinycolor from 'tinycolor2';
2021-11-28 12:07:37 +01:00
import FormLink from '@/components/form/link.vue';
import FormSwitch from '@/components/form/switch.vue';
2021-11-28 12:07:37 +01:00
import FormSection from '@/components/form/section.vue';
import MkKeyValue from '@/components/key-value.vue';
2021-12-30 13:47:48 +01:00
import FormSplit from '@/components/form/split.vue';
2021-11-11 18:02:25 +01:00
import * as os from '@/os';
import bytes from '@/filters/bytes';
import * as symbols from '@/symbols';
import { defaultStore } from '@/store';
import MkChart from '@/components/chart.vue';
import { i18n } from '@/i18n';
const fetching = ref(true);
const usage = ref<any>(null);
const capacity = ref<any>(null);
const uploadFolder = ref<any>(null);
const meterStyle = computed(() => {
return {
width: `${usage.value / capacity.value * 100}%`,
background: tinycolor({
h: 180 - (usage.value / capacity.value * 180),
s: 0.7,
l: 0.5
})
};
});
2021-10-24 05:32:41 +02:00
const keepOriginalUploading = computed(defaultStore.makeGetterSetter('keepOriginalUploading'));
2021-01-23 10:14:57 +01:00
os.api('drive').then(info => {
capacity.value = info.capacity;
usage.value = info.usage;
fetching.value = false;
});
2021-01-23 10:14:57 +01:00
if (defaultStore.state.uploadFolder) {
os.api('drive/folders/show', {
folderId: defaultStore.state.uploadFolder
}).then(response => {
uploadFolder.value = response;
});
}
2021-01-23 10:14:57 +01:00
function chooseUploadFolder() {
os.selectDriveFolder(false).then(async folder => {
defaultStore.set('uploadFolder', folder ? folder.id : null);
os.success();
if (defaultStore.state.uploadFolder) {
uploadFolder.value = await os.api('drive/folders/show', {
folderId: defaultStore.state.uploadFolder
});
} else {
uploadFolder.value = null;
}
});
}
2021-01-23 10:14:57 +01:00
defineExpose({
[symbols.PAGE_INFO]: {
title: i18n.ts.drive,
icon: 'fas fa-cloud',
bg: 'var(--bg)',
}
});
</script>
<style lang="scss" scoped>
@use "sass:math";
2020-01-30 03:10:42 +01:00
.uawsfosz {
2021-01-23 10:14:57 +01:00
2021-11-28 12:07:37 +01:00
> .meter {
$size: 12px;
background: rgba(0, 0, 0, 0.1);
border-radius: math.div($size, 2);
overflow: hidden;
2021-11-28 12:07:37 +01:00
> div {
height: $size;
border-radius: math.div($size, 2);
2021-01-23 10:14:57 +01:00
}
}
}
</style>