update DomainConfig & AppConfigPanel with new API calls for apply and action

This commit is contained in:
axolotle 2022-03-02 20:28:13 +01:00
parent fd60748301
commit 368f890ff1
3 changed files with 37 additions and 29 deletions

View file

@ -378,13 +378,14 @@
"human_routes": {
"adminpw": "Change admin password",
"apps": {
"action_config": "Run action '{action}' of app '{name}' configuration",
"change_label": "Change label of '{prevName}' for '{nextName}'",
"change_url": "Change access URL of '{name}'",
"install": "Install app '{name}'",
"set_default": "Redirect '{domain}' domain root to '{name}'",
"perform_action": "Perform action '{action}' of app '{name}'",
"uninstall": "Uninstall app '{name}'",
"update_config": "Update app '{name}' configuration"
"update_config": "Update panel '{id}' of app '{name}' configuration"
},
"backups": {
"create": "Create a backup",
@ -406,13 +407,11 @@
"domains": {
"add": "Add domain '{name}'",
"delete": "Delete domain '{name}'",
"install_LE": "Install certificate for '{name}'",
"manual_renew_LE": "Renew certificate for '{name}'",
"cert_install": "Install certificate for '{name}'",
"cert_renew": "Renew certificate for '{name}'",
"push_dns_changes": "Push DNS records to registrar for '{name}'",
"regen_selfsigned": "Renew self-signed certificate for '{name}'",
"revert_to_selfsigned": "Revert to self-signed certificate for '{name}'",
"set_default": "Set '{name}' as default domain",
"update_config": "Update '{name}' configuration"
"update_config": "Update panel '{id}' of domain '{name}' configuration"
},
"firewall": {
"ports": "{action} port {port} ({protocol}, {connection})",

View file

@ -3,7 +3,10 @@
:queries="queries" @queries-response="onQueriesResponse"
ref="view" skeleton="card-form-skeleton"
>
<config-panels v-if="config.panels" v-bind="config" @submit="applyConfig" />
<config-panels
v-if="config.panels" v-bind="config"
@submit="onConfigSubmit"
/>
<b-alert v-else-if="config.panels === null" variant="warning">
<icon iname="exclamation-triangle" /> {{ $t('app_config_panel_no_panel') }}
@ -34,7 +37,7 @@ export default {
data () {
return {
queries: [
['GET', `apps/${this.id}/config-panel?full`]
['GET', `apps/${this.id}/config?full`]
],
config: {}
}
@ -49,23 +52,22 @@ export default {
}
},
async applyConfig (id_) {
const args = await formatFormData(
this.config.forms[id_],
{ removeEmpty: false, removeNull: true }
)
async onConfigSubmit ({ id, form, action, name }) {
const args = await formatFormData(form, { removeEmpty: false, removeNull: true })
api.put(
`apps/${this.id}/config`,
{ key: id_, args: objectToParams(args) },
{ key: 'apps.update_config', name: this.id }
action
? `apps/${this.id}/actions/${action}`
: `apps/${this.id}/config/${id}`,
{ args: objectToParams(args) },
{ key: `apps.${action ? 'action' : 'update'}_config`, id, name: this.id }
).then(() => {
this.$refs.view.fetchQueries({ triggerLoading: true })
}).catch(err => {
if (err.name !== 'APIBadRequestError') throw err
const panel = this.config.panels.find(({ id }) => id_ === id)
const panel = this.config.panels.find(panel => panel.id === id)
if (err.data.name) {
this.config.errors[id_][err.data.name].message = err.message
this.config.errors[id][err.data.name].message = err.message
} else this.$set(panel, 'serverError', err.message)
})
}

View file

@ -3,7 +3,10 @@
:queries="queries" @queries-response="onQueriesResponse"
ref="view" skeleton="card-form-skeleton"
>
<config-panels v-if="config.panels" v-bind="config" @submit="applyConfig" />
<config-panels
v-if="config.panels" v-bind="config"
@submit="onConfigSubmit"
/>
</view-base>
</template>
@ -41,17 +44,21 @@ export default {
this.config = formatYunoHostConfigPanels(config)
},
async applyConfig (id) {
const args = await formatFormData(
this.config.forms[id],
{ removeEmpty: false, removeNull: true }
)
async onConfigSubmit ({ id, form, action, name }) {
const args = await formatFormData(form, { removeEmpty: false, removeNull: true })
const call = action
? api.put(
`domain/${this.name}/actions/${action}`,
{ args: objectToParams(args) },
{ key: 'domains.' + name, name: this.name }
)
: api.put(
`domains/${this.name}/config/${id}`,
{ args: objectToParams(args) },
{ key: 'domains.update_config', id, name: this.name }
)
api.put(
`domains/${this.name}/config`,
{ key: id, args: objectToParams(args) },
{ key: 'domains.update_config', name: this.name }
).then(() => {
call.then(() => {
this.$refs.view.fetchQueries({ triggerLoading: true })
}).catch(err => {
if (err.name !== 'APIBadRequestError') throw err