update api calls for Backup views

This commit is contained in:
axolotle 2021-02-19 18:47:04 +01:00
parent aa70e7e102
commit d5f5e0ca5a
3 changed files with 17 additions and 9 deletions

View file

@ -1,5 +1,5 @@
<template> <template>
<view-base :queries="queries" @queries-response="formatData" skeleton="card-list-skeleton"> <view-base :queries="queries" @queries-response="onQueriesResponse" skeleton="card-list-skeleton">
<!-- FIXME switch to <card-form> ? --> <!-- FIXME switch to <card-form> ? -->
<card :title="$t('backup_create')" icon="archive" no-body> <card :title="$t('backup_create')" icon="archive" no-body>
<b-form-checkbox-group <b-form-checkbox-group
@ -104,7 +104,10 @@ export default {
data () { data () {
return { return {
queries: ['hooks/backup', 'apps?with_backup'], queries: [
['GET', 'hooks/backup'],
['GET', 'apps?with_backup']
],
selected: [], selected: [],
// api data // api data
system: undefined, system: undefined,
@ -131,7 +134,7 @@ export default {
return data return data
}, },
formatData ({ hooks }, { apps }) { onQueriesResponse ({ hooks }, { apps }) {
this.system = this.formatHooks(hooks) this.system = this.formatHooks(hooks)
// transform app array into literal object to match hooks data structure // transform app array into literal object to match hooks data structure
this.apps = apps.reduce((obj, app) => { this.apps = apps.reduce((obj, app) => {

View file

@ -1,5 +1,5 @@
<template> <template>
<view-base :queries="queries" @queries-response="formatBackupData"> <view-base :queries="queries" @queries-response="onQueriesResponse">
<!-- BACKUP INFO --> <!-- BACKUP INFO -->
<card :title="$t('infos')" icon="info-circle" button-unbreak="sm"> <card :title="$t('infos')" icon="info-circle" button-unbreak="sm">
<template #header-buttons> <template #header-buttons>
@ -131,7 +131,9 @@ export default {
data () { data () {
return { return {
queries: [`backup/archives/${this.name}?with_details`], queries: [
['GET', `backup/archives/${this.name}?with_details`]
],
selected: [], selected: [],
error: '', error: '',
isValid: null, isValid: null,
@ -169,7 +171,7 @@ export default {
return data return data
}, },
formatBackupData (data) { onQueriesResponse (data) {
this.infos = { this.infos = {
name: this.name, name: this.name,
created_at: data.created_at, created_at: data.created_at,
@ -211,6 +213,7 @@ export default {
api.post('backup/restore/' + this.name, data).then(response => { api.post('backup/restore/' + this.name, data).then(response => {
this.isValid = null this.isValid = null
}).catch(err => { }).catch(err => {
if (err.name !== 'APIBadRequestError') throw err
this.error = err.message this.error = err.message
this.isValid = false this.isValid = false
}) })

View file

@ -1,5 +1,5 @@
<template> <template>
<view-base :queries="queries" @queries-response="formatBackupList" skeleton="list-group-skeleton"> <view-base :queries="queries" @queries-response="onQueriesResponse" skeleton="list-group-skeleton">
<template #top> <template #top>
<top-bar :button="{ text: $t('backup_new'), icon: 'plus', to: { name: 'backup-create' } }" /> <top-bar :button="{ text: $t('backup_new'), icon: 'plus', to: { name: 'backup-create' } }" />
</template> </template>
@ -44,13 +44,15 @@ export default {
data () { data () {
return { return {
queries: ['backup/archives?with_info'], queries: [
['GET', 'backup/archives?with_info']
],
archives: undefined archives: undefined
} }
}, },
methods: { methods: {
formatBackupList (data) { onQueriesResponse (data) {
const archives = Object.entries(data.archives) const archives = Object.entries(data.archives)
if (archives.length) { if (archives.length) {
this.archives = archives.map(([name, infos]) => { this.archives = archives.map(([name, infos]) => {