update api calls for Domain views

This commit is contained in:
axolotle 2021-02-19 18:43:58 +01:00
parent 4658c3d712
commit 9ede3740a8
5 changed files with 33 additions and 22 deletions

View file

@ -8,6 +8,7 @@
</template> </template>
<script> <script>
import api from '@/api'
import { DomainForm } from '@/views/_partials' import { DomainForm } from '@/views/_partials'
export default { export default {
@ -15,23 +16,24 @@ export default {
data () { data () {
return { return {
queries: [{ uri: 'domains' }], queries: [
['GET', { uri: 'domains' }]
],
serverError: '' serverError: ''
} }
}, },
methods: { methods: {
onSubmit ({ domain, domainType }) { onSubmit ({ domain, domainType }) {
const query = { const uri = 'domains' + (domainType === 'dynDomain' ? '?dyndns' : '')
uri: 'domains' + (domainType === 'dynDomain' ? '?dyndns' : ''), api.post(
data: { domain }, { uri, storeKey: 'domains' },
storeKey: 'domains' { domain }
} ).then(() => {
this.$store.dispatch('POST', query).then(() => {
this.$router.push({ name: 'domain-list' }) this.$router.push({ name: 'domain-list' })
}).catch(error => { }).catch(err => {
this.serverError = error.message if (err.name !== 'APIBadRequestError') throw err
this.serverError = err.message
}) })
} }
}, },

View file

@ -1,5 +1,5 @@
<template> <template>
<view-base :queries="queries" @queries-response="formatCertData" ref="view"> <view-base :queries="queries" @queries-response="onQueriesResponse" ref="view">
<card v-if="cert" :title="$t('certificate_status')" icon="lock"> <card v-if="cert" :title="$t('certificate_status')" icon="lock">
<p :class="'alert alert-' + cert.alert.type"> <p :class="'alert alert-' + cert.alert.type">
<icon :iname="cert.alert.icon" /> {{ $t('certificate_alert_' + cert.alert.trad) }} <icon :iname="cert.alert.icon" /> {{ $t('certificate_alert_' + cert.alert.trad) }}
@ -83,7 +83,9 @@ export default {
data () { data () {
return { return {
queries: [`domains/cert-status/${this.name}?full`], queries: [
['GET', `domains/cert-status/${this.name}?full`]
],
cert: undefined, cert: undefined,
actionsEnabled: undefined actionsEnabled: undefined
} }
@ -106,7 +108,7 @@ export default {
} }
}, },
formatCertData (data) { onQueriesResponse (data) {
const certData = data.certificates[this.name] const certData = data.certificates[this.name]
const cert = { const cert = {

View file

@ -22,7 +22,9 @@ export default {
data () { data () {
return { return {
queries: [`domains/${this.name}/dns`], queries: [
['GET', `domains/${this.name}/dns`]
],
dnsConfig: '' dnsConfig: ''
} }
} }

View file

@ -48,6 +48,8 @@
<script> <script>
import { mapGetters } from 'vuex' import { mapGetters } from 'vuex'
import api from '@/api'
export default { export default {
name: 'DomainInfo', name: 'DomainInfo',
@ -58,9 +60,11 @@ export default {
} }
}, },
data () { data: () => {
return { return {
queries: [{ uri: 'domains/main', storeKey: 'main_domain' }] queries: [
['GET', { uri: 'domains/main', storeKey: 'main_domain' }]
]
} }
}, },
@ -78,7 +82,7 @@ export default {
const confirmed = await this.$askConfirmation(this.$i18n.t('confirm_delete', { name: this.name })) const confirmed = await this.$askConfirmation(this.$i18n.t('confirm_delete', { name: this.name }))
if (!confirmed) return if (!confirmed) return
this.$store.dispatch('DELETE', api.delete(
{ uri: 'domains', param: this.name } { uri: 'domains', param: this.name }
).then(() => { ).then(() => {
this.$router.push({ name: 'domain-list' }) this.$router.push({ name: 'domain-list' })
@ -89,10 +93,11 @@ export default {
const confirmed = await this.$askConfirmation(this.$i18n.t('confirm_change_maindomain')) const confirmed = await this.$askConfirmation(this.$i18n.t('confirm_change_maindomain'))
if (!confirmed) return if (!confirmed) return
this.$store.dispatch('PUT', api.put(
{ uri: 'domains/main', data: { new_main_domain: this.name }, storeKey: 'main_domain' } { uri: 'domains/main', storeKey: 'main_domain' },
{ new_main_domain: this.name }
).then(() => { ).then(() => {
// Have to commit by hand here since the response is empty // FIXME Have to commit by hand here since the response is empty (should return the given name)
this.$store.commit('UPDATE_MAIN_DOMAIN', this.name) this.$store.commit('UPDATE_MAIN_DOMAIN', this.name)
}) })
} }

View file

@ -47,8 +47,8 @@ export default {
data () { data () {
return { return {
queries: [ queries: [
{ uri: 'domains/main', storeKey: 'main_domain' }, ['GET', { uri: 'domains/main', storeKey: 'main_domain' }],
{ uri: 'domains' } ['GET', { uri: 'domains' }]
], ],
search: '' search: ''
} }