update api calls for App views

This commit is contained in:
axolotle 2021-02-19 18:55:26 +01:00
parent b65bd23d08
commit 7c8dd388d8
6 changed files with 41 additions and 35 deletions

View file

@ -1,6 +1,6 @@
<template> <template>
<view-base <view-base
:queries="queries" @queries-response="formatAppActions" :queries="queries" @queries-response="onQueriesResponse"
ref="view" skeleton="card-form-skeleton" ref="view" skeleton="card-form-skeleton"
> >
<template v-if="actions" #default> <template v-if="actions" #default>
@ -47,6 +47,8 @@ import { objectToParams } from '@/helpers/commons'
export default { export default {
name: 'AppActions', name: 'AppActions',
mixins: [validationMixin],
props: { props: {
id: { type: String, required: true } id: { type: String, required: true }
}, },
@ -54,10 +56,10 @@ export default {
data () { data () {
return { return {
queries: [ queries: [
`apps/${this.id}/actions`, ['GET', `apps/${this.id}/actions`],
{ uri: 'domains' }, ['GET', { uri: 'domains' }],
{ uri: 'domains/main', storeKey: 'main_domain' }, ['GET', { uri: 'domains/main', storeKey: 'main_domain' }],
{ uri: 'users' } ['GET', { uri: 'users' }]
], ],
actions: undefined actions: undefined
} }
@ -74,7 +76,7 @@ export default {
}, },
methods: { methods: {
formatAppActions (data) { onQueriesResponse (data) {
if (!data.actions) { if (!data.actions) {
this.actions = null this.actions = null
return return
@ -95,17 +97,16 @@ export default {
}, },
performAction (action) { performAction (action) {
// FIXME api expects at least one argument ?! (fake one given with { wut } ) // FIXME api expects at least one argument ?! (fake one given with { dontmindthis } )
const args = objectToParams(action.form ? formatFormData(action.form) : { wut: undefined }) const args = objectToParams(action.form ? formatFormData(action.form) : { dontmindthis: undefined })
api.put(`apps/${this.id}/actions/${action.id}`, { args }).then(response => { api.put(`apps/${this.id}/actions/${action.id}`, { args }).then(response => {
this.$refs.view.fetchQueries() this.$refs.view.fetchQueries()
}).catch(error => { }).catch(err => {
action.serverError = error.message if (err.name !== 'APIBadRequestError') throw err
action.serverError = err.message
}) })
} }
}, }
mixins: [validationMixin]
} }
</script> </script>

View file

@ -1,7 +1,7 @@
<template> <template>
<view-search <view-search
:items="apps" :filtered-items="filteredApps" items-name="apps" :items="apps" :filtered-items="filteredApps" items-name="apps"
:queries="queries" @queries-response="formatAppData" :queries="queries" @queries-response="onQueriesResponse"
> >
<template #top-bar> <template #top-bar>
<div id="view-top-bar"> <div id="view-top-bar">
@ -158,7 +158,9 @@ export default {
data () { data () {
return { return {
queries: ['appscatalog?full&with_categories'], queries: [
['GET', 'appscatalog?full&with_categories']
],
// Data // Data
apps: undefined, apps: undefined,
@ -280,7 +282,7 @@ export default {
return 'danger' return 'danger'
}, },
formatAppData (data) { onQueriesResponse (data) {
// APPS // APPS
const apps = [] const apps = []
for (const key in data.apps) { for (const key in data.apps) {

View file

@ -1,5 +1,5 @@
<template> <template>
<view-base :queries="queries" @queries-response="formatAppConfig" skeleton="card-form-skeleton"> <view-base :queries="queries" @queries-response="onQueriesResponse" skeleton="card-form-skeleton">
<template v-if="panels" #default> <template v-if="panels" #default>
<b-alert variant="warning" class="mb-4"> <b-alert variant="warning" class="mb-4">
<icon iname="exclamation-triangle" /> {{ $t('experimental_warning') }} <icon iname="exclamation-triangle" /> {{ $t('experimental_warning') }}
@ -61,17 +61,17 @@ export default {
data () { data () {
return { return {
queries: [ queries: [
`apps/${this.id}/config-panel`, ['GET', `apps/${this.id}/config-panel`],
{ uri: 'domains' }, ['GET', { uri: 'domains' }],
{ uri: 'domains/main', storeKey: 'main_domain' }, ['GET', { uri: 'domains/main', storeKey: 'main_domain' }],
{ uri: 'users' } ['GET', { uri: 'users' }]
], ],
panels: undefined panels: undefined
} }
}, },
methods: { methods: {
formatAppConfig (data) { onQueriesResponse (data) {
if (!data.config_panel || data.config_panel.length === 0) { if (!data.config_panel || data.config_panel.length === 0) {
this.panels = null this.panels = null
return return

View file

@ -1,5 +1,5 @@
<template> <template>
<view-base :queries="queries" @queries-response="formatAppData" ref="view"> <view-base :queries="queries" @queries-response="onQueriesResponse" ref="view">
<!-- BASIC INFOS --> <!-- BASIC INFOS -->
<card v-if="infos" :title="`${$t('infos')} — ${infos.label}`" icon="info-circle"> <card v-if="infos" :title="`${$t('infos')} — ${infos.label}`" icon="info-circle">
<b-row <b-row
@ -172,9 +172,9 @@ export default {
data () { data () {
return { return {
queries: [ queries: [
`apps/${this.id}?full`, ['GET', `apps/${this.id}?full`],
{ uri: 'users/permissions?full', storeKey: 'permissions' }, ['GET', { uri: 'users/permissions?full', storeKey: 'permissions' }],
{ uri: 'domains' } ['GET', { uri: 'domains' }]
], ],
infos: undefined, infos: undefined,
app: undefined, app: undefined,
@ -203,7 +203,7 @@ export default {
}, },
methods: { methods: {
formatAppData (app) { onQueriesResponse (app) {
const form = { labels: [] } const form = { labels: [] }
const mainPermission = app.permissions[this.id + '.main'] const mainPermission = app.permissions[this.id + '.main']
@ -263,7 +263,7 @@ export default {
api.put( api.put(
`apps/${this.id}/changeurl`, `apps/${this.id}/changeurl`,
{ domain, path: '/' + path } { domain, path: '/' + path }
).then(this.fetchData) ).then(this.$refs.view.fetchQueries)
}, },
async setAsDefaultDomain () { async setAsDefaultDomain () {

View file

@ -132,6 +132,7 @@ export default {
api.post('apps', data).then(response => { api.post('apps', data).then(response => {
this.$router.push({ name: 'app-list' }) this.$router.push({ name: 'app-list' })
}).catch(err => { }).catch(err => {
if (err.name !== 'APIBadRequestError') throw err
this.serverError = err.message this.serverError = err.message
}) })
} }
@ -141,10 +142,10 @@ export default {
const isCustom = this.$route.name === 'app-install-custom' const isCustom = this.$route.name === 'app-install-custom'
Promise.all([ Promise.all([
isCustom ? this.getExternalManifest() : this.getApiManifest(), isCustom ? this.getExternalManifest() : this.getApiManifest(),
this.$store.dispatch('FETCH_ALL', [ api.fetchAll([
{ uri: 'domains' }, ['GET', { uri: 'domains' }],
{ uri: 'domains/main', storeKey: 'main_domain' }, ['GET', { uri: 'domains/main', storeKey: 'main_domain' }],
{ uri: 'users' } ['GET', { uri: 'users' }]
]) ])
]).then((responses) => this.formatManifestData(responses[0])) ]).then((responses) => this.formatManifestData(responses[0]))
} }

View file

@ -5,7 +5,7 @@
:items="apps" :items="apps"
:filtered-items="filteredApps" :filtered-items="filteredApps"
:queries="queries" :queries="queries"
@queries-response="formatAppData" @queries-response="onQueriesResponse"
> >
<template #top-bar-buttons> <template #top-bar-buttons>
<b-button variant="success" :to="{ name: 'app-catalog' }"> <b-button variant="success" :to="{ name: 'app-catalog' }">
@ -42,7 +42,9 @@ export default {
data () { data () {
return { return {
queries: ['apps?full'], queries: [
['GET', 'apps?full']
],
search: '', search: '',
apps: undefined apps: undefined
} }
@ -60,7 +62,7 @@ export default {
}, },
methods: { methods: {
formatAppData ({ apps }) { onQueriesResponse ({ apps }) {
if (apps.length === 0) { if (apps.length === 0) {
this.apps = null this.apps = null
return return