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 }>
|
system: Record<BackupHookKeys, { paths: string[]; size: number }>
|
||||||
from_yunohost_version: string
|
from_yunohost_version: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type BackupList = {
|
||||||
|
archives: Obj<{
|
||||||
|
path: string
|
||||||
|
created_at: string
|
||||||
|
description: string
|
||||||
|
size: number
|
||||||
|
}>
|
||||||
|
}
|
||||||
|
|
|
@ -1,37 +1,25 @@
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref } from 'vue'
|
import api from '@/api'
|
||||||
|
import { toEntries } from '@/helpers/commons'
|
||||||
import { useInitialQueries } from '@/composables/useInitialQueries'
|
|
||||||
import { distanceToNow, readableDate } from '@/helpers/filters/date'
|
import { distanceToNow, readableDate } from '@/helpers/filters/date'
|
||||||
import { humanSize } from '@/helpers/filters/human'
|
import { humanSize } from '@/helpers/filters/human'
|
||||||
|
import type { BackupList } from '@/types/core/api'
|
||||||
|
|
||||||
const props = defineProps<{
|
defineProps<{
|
||||||
id: string
|
id: string
|
||||||
}>()
|
}>()
|
||||||
|
|
||||||
const { loading } = useInitialQueries([{ uri: 'backups?with_info' }], {
|
const archives = await api
|
||||||
onQueriesResponse,
|
.get<BackupList>({ uri: 'backups?with_info', initial: true })
|
||||||
})
|
.then((data) => {
|
||||||
const archives = ref<any[] | null>(null)
|
return toEntries(data.archives)
|
||||||
|
.map(([name, archive]) => ({ ...archive, name }))
|
||||||
function onQueriesResponse(data: any) {
|
|
||||||
const archives_ = Object.entries(data.archives)
|
|
||||||
if (archives_.length) {
|
|
||||||
archives.value = archives_
|
|
||||||
.map(([name, infos]) => {
|
|
||||||
infos.name = name
|
|
||||||
return infos
|
|
||||||
})
|
|
||||||
.reverse()
|
.reverse()
|
||||||
} else {
|
})
|
||||||
archives.value = null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<ViewBase :loading="loading" skeleton="ListGroupSkeleton">
|
<div>
|
||||||
<template #top>
|
|
||||||
<TopBar
|
<TopBar
|
||||||
:button="{
|
:button="{
|
||||||
text: $t('backup_new'),
|
text: $t('backup_new'),
|
||||||
|
@ -39,9 +27,8 @@ function onQueriesResponse(data: any) {
|
||||||
to: { name: 'backup-create' },
|
to: { name: 'backup-create' },
|
||||||
}"
|
}"
|
||||||
/>
|
/>
|
||||||
</template>
|
|
||||||
|
|
||||||
<BAlert v-if="!archives" :modelValue="!archives" variant="warning">
|
<BAlert v-if="!archives.length" :model-value="true" variant="warning">
|
||||||
<YIcon iname="exclamation-triangle" />
|
<YIcon iname="exclamation-triangle" />
|
||||||
{{ $t('items_verbose_count', { items: $t('items.backups', 0) }, 0) }}
|
{{ $t('items_verbose_count', { items: $t('items.backups', 0) }, 0) }}
|
||||||
</BAlert>
|
</BAlert>
|
||||||
|
@ -68,5 +55,5 @@ function onQueriesResponse(data: any) {
|
||||||
<YIcon iname="chevron-right" class="lg fs-sm ms-auto" />
|
<YIcon iname="chevron-right" class="lg fs-sm ms-auto" />
|
||||||
</BListGroupItem>
|
</BListGroupItem>
|
||||||
</BListGroup>
|
</BListGroup>
|
||||||
</ViewBase>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
Loading…
Add table
Reference in a new issue