diff --git a/dashboard/src/components/ApplinkDialog.vue b/dashboard/src/components/ApplinkDialog.vue index 5c3623068..466087750 100644 --- a/dashboard/src/components/ApplinkDialog.vue +++ b/dashboard/src/components/ApplinkDialog.vue @@ -121,13 +121,13 @@ export default { data.icon = this.icon.data.replace(/^data:image\/[a-z]+;base64,/, ''); } - try { - if (this.mode === 'edit') await applinksModel.update(this.id, data); - else await applinksModel.add(data); - } catch (e) { - console.error('Failed to edit or add applink', e); + let error; + if (this.mode === 'edit') [error] = await applinksModel.update(this.id, data); + else [error] = await applinksModel.add(data); + + if (error) { this.busy = false; - return; + return console.error(error); } this.busy = false; @@ -145,10 +145,11 @@ export default { if (!yes) return; - // TODO - console.log('remove', this.id) - // await volumesModel.remove(volume.id); - // await this.refresh(); + const [error] = await applinksModel.remove(this.id); + if (error) return console.error(error); + + this.$emit('success'); + this.$refs.applinkDialog.close(); } }, }; @@ -161,8 +162,8 @@ export default { :alternate-label="mode === 'edit' ? 'Delete' : ''" alternate-style="danger" :reject-label="$t('main.dialog.cancel')" + reject-style="secondary" :confirm-label="$t('main.dialog.save')" - confirm-style="success" :confirm-active="isValid" :confirm-busy="busy" @confirm="onSubmit()" diff --git a/dashboard/src/models/ApplinksModel.js b/dashboard/src/models/ApplinksModel.js index f94c5ab07..371740261 100644 --- a/dashboard/src/models/ApplinksModel.js +++ b/dashboard/src/models/ApplinksModel.js @@ -8,60 +8,52 @@ function create() { return { name: 'ApplinksModel', async list() { - let error, result; + let result; try { result = await fetcher.get(`${origin}/api/v1/applinks`, { access_token: accessToken }); } catch (e) { - error = e; + return [e]; } - if (error || result.status !== 200) { - console.error('Failed to list applinks.', error || result.status); - return []; - } - - return result.body.applinks; + if (result.status !== 200) return [result]; + return [null, result.body.applinks]; }, async add(applink) { const data = applink; - let error, result; + let result; try { result = await fetcher.post(`${origin}/api/v1/applinks`, data, { access_token: accessToken }); } catch (e) { - error = e; + return [e]; } - if (error || result.status !== 201) { - console.error('Failed to add applink.', error || result.status); - throw(error ? error : result); - } + if (result.status !== 201) return [result]; + return [null]; }, async update(id, applink) { const data = applink; - let error, result; + let result; try { result = await fetcher.post(`${origin}/api/v1/applinks/${id}`, data, { access_token: accessToken }); } catch (e) { - error = e; + return [e]; } - if (error || result.status !== 200) { - console.error('Failed to update applink.', error || result.status); - } + if (result.status !== 200) return [result]; + return [null]; }, async remove(id) { - let error, result; + let result; try { result = await fetcher.del(`${origin}/api/v1/applinks/${id}`, { access_token: accessToken }); } catch (e) { - error = e; + return [e]; } - if (error || result.status !== 204) { - console.error('Failed to remove applink.', error || result.status); - } + if (result.status !== 204) return [result]; + return [null]; }, }; } diff --git a/dashboard/src/views/AppsView.vue b/dashboard/src/views/AppsView.vue index 758f33e59..6cf737070 100644 --- a/dashboard/src/views/AppsView.vue +++ b/dashboard/src/views/AppsView.vue @@ -145,7 +145,8 @@ async function refreshApps() { const [error, result] = await appsModel.list(); if (error) return console.error(error); - const applinks = await applinksModel.list(); + const [applinkError, applinks] = await applinksModel.list(); + if (applinkError) return console.error(applinkError); // amend properties to mimick full app for (const applink of applinks) {