diff --git a/src/components/InfobaseList.vue b/src/components/InfobaseList.vue index 988461d..f7adbbf 100644 --- a/src/components/InfobaseList.vue +++ b/src/components/InfobaseList.vue @@ -84,7 +84,6 @@ export default { }, computed: mapGetters([ "allInfobases", - "getInfobaseByName", "isLoading", "isLoadingError", "errorMessage", diff --git a/src/store/modules/apache_restart.js b/src/store/modules/apache_restart.js new file mode 100644 index 0000000..2c4f7ea --- /dev/null +++ b/src/store/modules/apache_restart.js @@ -0,0 +1,53 @@ +import axios from "axios"; + +import config from "@/config.js"; + +const api_base = config.api; + +export default { + state: { + apache_need_restart: false, + restart_flag: false, + }, + mutations: { + setApacheNeedRestart(state) { + state.apache_need_restart = true; + console.log("restart need"); + }, + setApacheRestartFlag(state, flag) { + state.restart_flag = flag; + }, + }, + actions: { + async fetchApacheRestartFlag(ctx) { + try { + await axios.get(`${api_base}/apache-restart`); + ctx.commit("setApacheRestartFlag", true); + } catch (err) { + ctx.commit("setApacheRestartFlag", false); + } + }, + async updateApacheRestartFlag(ctx) { + if ( + ctx.getters.isApacheRestartPending || + !ctx.getters.isApacheNeedRestart + ) { + return; + } + try { + await axios.put(`${api_base}/apache-restart`); + ctx.commit("setApacheRestartFlag", true); + } catch (err) { + ctx.commit("setApacheRestartFlag", false); + } + }, + }, + getters: { + isApacheNeedRestart(state) { + return state.apache_need_restart; + }, + isApacheRestartPending(state) { + return state.restart_flag; + }, + }, +}; diff --git a/src/store/modules/infobases.js b/src/store/modules/infobases.js index ed8f4f2..8abd31c 100644 --- a/src/store/modules/infobases.js +++ b/src/store/modules/infobases.js @@ -131,6 +131,7 @@ export default { try { await axios.post(`${api_base}/publications`, data); ctx.commit("setInfobaseURL", { name, url }); + ctx.commit("setApacheNeedRestart", null, { root: true }); ctx.commit("setErrorMessage", ""); } catch (err) { ctx.commit("setErrorMessage", `Ошибка обновления URL для базы ${name}`); @@ -146,6 +147,7 @@ export default { try { await axios.put(`${api_base}/publications`, { id: name, name }); ctx.commit("setErrorMessage", ""); + ctx.commit("setApacheNeedRestart", null, { root: true }); ctx.dispatch("fetchInfobase", name); } catch (err) { ctx.commit("setErrorMessage", `Ошибка публикации базы ${name}`); @@ -160,6 +162,7 @@ export default { try { await axios.delete(`${api_base}/publications/${name}`); ctx.commit("setErrorMessage", ""); + ctx.commit("setApacheNeedRestart", null, { root: true }); ctx.dispatch("fetchInfobase", name); } catch (err) { ctx.commit("setErrorMessage", `Ошибка отмены публикации базы ${name}`);