From 7f2d61bc1570068f66828c00fc4c186292ee5a9a Mon Sep 17 00:00:00 2001 From: Angelina Filippova Date: Tue, 18 Feb 2020 23:08:07 +0300 Subject: [PATCH] Restart application on button click --- src/api/settings.js | 9 +++++++++ src/store/modules/settings.js | 15 ++++++++++++--- src/views/settings/index.vue | 9 +++++++-- 3 files changed, 28 insertions(+), 5 deletions(-) diff --git a/src/api/settings.js b/src/api/settings.js index 9d1c2890..82aa36e7 100644 --- a/src/api/settings.js +++ b/src/api/settings.js @@ -40,4 +40,13 @@ export async function removeSettings(configs, authHost, token) { }) } +export async function restartApp(authHost, token) { + return await request({ + baseURL: baseName(authHost), + url: `/api/pleroma/admin/restart`, + method: 'get', + headers: authHeaders(token) + }) +} + const authHeaders = (token) => token ? { 'Authorization': `Bearer ${getToken()}` } : {} diff --git a/src/store/modules/settings.js b/src/store/modules/settings.js index 84c4a9dd..ab7a3b36 100644 --- a/src/store/modules/settings.js +++ b/src/store/modules/settings.js @@ -1,4 +1,4 @@ -import { fetchDescription, fetchSettings, removeSettings, updateSettings } from '@/api/settings' +import { fetchDescription, fetchSettings, removeSettings, restartApp, updateSettings } from '@/api/settings' import { checkPartialUpdate, parseNonTuples, parseTuples, valueHasTuples, wrapUpdatedSettings } from './normalizers' import _ from 'lodash' @@ -9,10 +9,9 @@ const settings = { db: {}, description: [], loading: true, - needReboot: true, + needReboot: false, settings: {}, updatedSettings: {} - }, mutations: { CLEAR_UPDATED_SETTINGS: (state) => { @@ -52,6 +51,9 @@ const settings = { state.settings = newSettings state.db = newDbSettings }, + TOGGLE_REBOOT: (state, needReboot) => { + state.needReboot = needReboot || false + }, TOGGLE_TABS: (state, status) => { state.configDisabled = status }, @@ -76,6 +78,7 @@ const settings = { const description = await fetchDescription(getters.authHost, getters.token) commit('SET_DESCRIPTION', description.data) commit('SET_SETTINGS', response.data.configs) + commit('TOGGLE_REBOOT', response.data.need_reboot) } catch (_e) { commit('TOGGLE_TABS', true) commit('SET_ACTIVE_TAB', 'relays') @@ -90,8 +93,13 @@ const settings = { const response = await fetchSettings(getters.authHost, getters.token) const { group, key, subkeys } = configs[0] commit('SET_SETTINGS', response.data.configs) + commit('TOGGLE_REBOOT', response.data.need_reboot) commit('REMOVE_SETTING_FROM_UPDATED', { group, key, subkeys: subkeys || [] }) }, + async RestartApplication({ commit, getters }) { + await restartApp(getters.authHost, getters.token) + commit('TOGGLE_REBOOT', false) + }, SetActiveTab({ commit }, tab) { commit('SET_ACTIVE_TAB', tab) }, @@ -104,6 +112,7 @@ const settings = { await updateSettings(configs, getters.authHost, getters.token) const response = await fetchSettings(getters.authHost, getters.token) commit('SET_SETTINGS', response.data.configs) + commit('TOGGLE_REBOOT', response.data.need_reboot) commit('CLEAR_UPDATED_SETTINGS') }, UpdateSettings({ commit }, { group, key, input, value, type }) { diff --git a/src/views/settings/index.vue b/src/views/settings/index.vue index cca7959f..2fe9645b 100644 --- a/src/views/settings/index.vue +++ b/src/views/settings/index.vue @@ -4,7 +4,7 @@

{{ $t('settings.settings') }}

- + {{ $t('settings.instanceReboot') }} @@ -89,7 +89,7 @@

{{ $t('settings.settings') }}

- + {{ $t('settings.instanceReboot') }} @@ -242,6 +242,11 @@ export default { }, mounted: function() { this.$store.dispatch('FetchSettings') + }, + methods: { + restartApp() { + this.$store.dispatch('RestartApplication') + } } }