mirror of
https://github.com/YunoHost/yunohost-admin.git
synced 2024-09-03 20:06:15 +02:00
refactor: rework async BackupList
This commit is contained in:
parent
a0dc769461
commit
dd6522a8b3
2 changed files with 29 additions and 33 deletions
|
@ -188,3 +188,12 @@ export type BackupInfo = {
|
|||
system: Record<BackupHookKeys, { paths: string[]; size: number }>
|
||||
from_yunohost_version: string
|
||||
}
|
||||
|
||||
export type BackupList = {
|
||||
archives: Obj<{
|
||||
path: string
|
||||
created_at: string
|
||||
description: string
|
||||
size: number
|
||||
}>
|
||||
}
|
||||
|
|
|
@ -1,47 +1,34 @@
|
|||
<script setup lang="ts">
|
||||
import { ref } from 'vue'
|
||||
|
||||
import { useInitialQueries } from '@/composables/useInitialQueries'
|
||||
import api from '@/api'
|
||||
import { toEntries } from '@/helpers/commons'
|
||||
import { distanceToNow, readableDate } from '@/helpers/filters/date'
|
||||
import { humanSize } from '@/helpers/filters/human'
|
||||
import type { BackupList } from '@/types/core/api'
|
||||
|
||||
const props = defineProps<{
|
||||
defineProps<{
|
||||
id: string
|
||||
}>()
|
||||
|
||||
const { loading } = useInitialQueries([{ uri: 'backups?with_info' }], {
|
||||
onQueriesResponse,
|
||||
})
|
||||
const archives = ref<any[] | null>(null)
|
||||
|
||||
function onQueriesResponse(data: any) {
|
||||
const archives_ = Object.entries(data.archives)
|
||||
if (archives_.length) {
|
||||
archives.value = archives_
|
||||
.map(([name, infos]) => {
|
||||
infos.name = name
|
||||
return infos
|
||||
})
|
||||
const archives = await api
|
||||
.get<BackupList>({ uri: 'backups?with_info', initial: true })
|
||||
.then((data) => {
|
||||
return toEntries(data.archives)
|
||||
.map(([name, archive]) => ({ ...archive, name }))
|
||||
.reverse()
|
||||
} else {
|
||||
archives.value = null
|
||||
}
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<ViewBase :loading="loading" skeleton="ListGroupSkeleton">
|
||||
<template #top>
|
||||
<TopBar
|
||||
:button="{
|
||||
text: $t('backup_new'),
|
||||
icon: 'plus',
|
||||
to: { name: 'backup-create' },
|
||||
}"
|
||||
/>
|
||||
</template>
|
||||
<div>
|
||||
<TopBar
|
||||
:button="{
|
||||
text: $t('backup_new'),
|
||||
icon: 'plus',
|
||||
to: { name: 'backup-create' },
|
||||
}"
|
||||
/>
|
||||
|
||||
<BAlert v-if="!archives" :modelValue="!archives" variant="warning">
|
||||
<BAlert v-if="!archives.length" :model-value="true" variant="warning">
|
||||
<YIcon iname="exclamation-triangle" />
|
||||
{{ $t('items_verbose_count', { items: $t('items.backups', 0) }, 0) }}
|
||||
</BAlert>
|
||||
|
@ -68,5 +55,5 @@ function onQueriesResponse(data: any) {
|
|||
<YIcon iname="chevron-right" class="lg fs-sm ms-auto" />
|
||||
</BListGroupItem>
|
||||
</BListGroup>
|
||||
</ViewBase>
|
||||
</div>
|
||||
</template>
|
||||
|
|
Loading…
Add table
Reference in a new issue