add BackupList view/route + size filter

This commit is contained in:
Axolotle 2020-09-25 13:41:09 +02:00
parent a073137b30
commit c559678dca
4 changed files with 95 additions and 1 deletions

6
app/src/filters/size.js Normal file
View file

@ -0,0 +1,6 @@
export function humanSize (bytes) {
const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB']
if (bytes === 0) return 'n/a'
const i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024)))
return Math.round(bytes / Math.pow(1024, i), 2) + ' ' + sizes[i]
}

View file

@ -291,6 +291,18 @@ const routes = [
{ name: 'backup', trad: 'backup' } { name: 'backup', trad: 'backup' }
] ]
} }
},
{
name: 'backup-list',
path: '/backup/:id',
component: () => import(/* webpackChunkName: "views/backup" */ '@/views/backup/BackupList'),
props: true,
meta: {
breadcrumb: [
{ name: 'backup', trad: 'backup' },
{ name: 'backup-list', param: 'id' }
]
}
} }
] ]

View file

@ -3,7 +3,7 @@
<b-list-group> <b-list-group>
<b-list-group-item <b-list-group-item
v-for="{ id, name, uri } in storages" :key="id" v-for="{ id, name, uri } in storages" :key="id"
:to="{ name: 'backup-list', params: { name: id }}" :to="{ name: 'backup-list', params: { id }}"
class="d-flex justify-content-between align-items-center pr-0" class="d-flex justify-content-between align-items-center pr-0"
> >
<div> <div>

View file

@ -0,0 +1,76 @@
<template>
<div class="backup-list">
<div class="actions">
<div class="buttons ml-auto">
<b-button variant="success" :to="{ name: 'backup-create' }">
<icon iname="plus" /> {{ $t('backup_new') }}
</b-button>
</div>
</div>
<b-alert v-if="!archives" variant="warning" show>
<icon iname="exclamation-triangle" /> {{ $t('backups_no') }}
</b-alert>
<b-list-group v-else>
<b-list-group-item
v-for="{ name, created_at, path, size } in archives" :key="name"
:to="{ name: 'backup-info', params: { name, id }}"
:title="created_at | readableDate"
class="d-flex justify-content-between align-items-center pr-0"
>
<div>
<h5>
{{ created_at | distanceToNow }}
<small>{{ name }} ({{ size | humanSize }})</small>
</h5>
<p class="mb-0">{{ path }}</p>
</div>
<icon iname="chevron-right" class="lg fs-sm ml-auto" />
</b-list-group-item>
</b-list-group>
</div>
</template>
<script>
import api from '@/helpers/api'
import { distanceToNow, readableDate } from '@/filters/date'
import { humanSize } from '@/filters/size'
export default {
name: 'BackupList',
props: {
id: {
type: String,
required: true
}
},
data () {
return {
archives: undefined
}
},
filters: {
distanceToNow,
readableDate,
humanSize
},
methods: {
fetchData () {
api.get('backup/archives?with_info').then(({ archives }) => {
this.archives = Object.entries(archives).map(([name, data]) => {
data.name = name
return data
}).reverse()
})
}
},
created () {
this.fetchData()
}
}
</script>