diff --git a/client/api/misc.js b/client/api/misc.js
index 3fcbc42b..53a5604f 100644
--- a/client/api/misc.js
+++ b/client/api/misc.js
@@ -1,8 +1,8 @@
import axios from 'axios';
class Misc {
- async getConfig() {
- const response = await axios.post('/api/config', {params: ['name', 'version']});
+ async loadConfig() {
+ const response = await axios.post('/api/config1', {params: ['name', 'version']});
return response.data;
}
}
diff --git a/client/components/App.vue b/client/components/App.vue
index 1efd8a0e..89a6a013 100644
--- a/client/components/App.vue
+++ b/client/components/App.vue
@@ -1,6 +1,7 @@
+ {{ appName }}
- Main
+ {{ apiError }}
@@ -44,7 +45,23 @@ export default @Component({
class App extends Vue {
created() {
this.commit = this.$store.commit;
- this.uistate = this.$store.state.uistate;
+ this.dispatch = this.$store.dispatch;
+ this.state = this.$store.state;
+ this.uistate = this.$store.state.uistate;
+ this.config = this.$store.state.config;
+ }
+
+ mounted() {
+ this.dispatch('config/loadConfig');
+ this.$watch('apiError', function(newError, oldError) {
+ if (newError) {
+ this.$notify.error({
+ title: 'Error',
+ dangerouslyUseHTMLString: true,
+ message: newError.response.config.url + '
' + newError.response.statusText
+ });
+ }
+ });
}
handleSelect(key, keyPath) {
@@ -74,6 +91,14 @@ class App extends Vue {
return 'el-icon-d-arrow-left';
}
}
+
+ get appName() {
+ return `${this.config.name} v${this.config.version}`;
+ }
+
+ get apiError() {
+ return this.state.apiError;
+ }
}
diff --git a/client/store/index.js b/client/store/index.js
index 3cb6917f..53d78d75 100644
--- a/client/store/index.js
+++ b/client/store/index.js
@@ -2,16 +2,19 @@ import Vue from 'vue';
import Vuex from 'vuex';
import createPersistedState from 'vuex-persistedstate';
+import root from './root.js';
import uistate from './modules/uistate';
+import config from './modules/config';
Vue.use(Vuex);
const debug = process.env.NODE_ENV !== 'production';
-export default new Vuex.Store({
+export default new Vuex.Store(Object.assign({}, root, {
modules: {
- uistate
+ uistate,
+ config
},
strict: debug,
plugins: [createPersistedState()]
-});
+}));
diff --git a/client/store/modules/config.js b/client/store/modules/config.js
new file mode 100644
index 00000000..cb6ce9e9
--- /dev/null
+++ b/client/store/modules/config.js
@@ -0,0 +1,38 @@
+import miscApi from '../../api/misc';
+// initial state
+const state = {
+ name: null,
+ version: null,
+};
+
+// getters
+const getters = {};
+
+// actions
+const actions = {
+ async loadConfig({ commit, state }) {
+ commit('setApiError', null, { root: true });
+ commit('setConfig', {});
+ try {
+ const config = await miscApi.loadConfig();
+ commit('setConfig', config);
+ } catch (e) {
+ commit('setApiError', e, { root: true });
+ }
+ },
+};
+
+// mutations
+const mutations = {
+ setConfig(state, value) {
+ Object.assign(state, value);
+ },
+};
+
+export default {
+ namespaced: true,
+ state,
+ getters,
+ actions,
+ mutations
+};
diff --git a/client/store/modules/uistate.js b/client/store/modules/uistate.js
index f82993c8..4f36b482 100644
--- a/client/store/modules/uistate.js
+++ b/client/store/modules/uistate.js
@@ -1,6 +1,6 @@
// initial state
const state = {
- asideBarCollapse: false,
+ asideBarCollapse: false,
};
// getters
@@ -11,15 +11,15 @@ const actions = {};
// mutations
const mutations = {
- setAsideBarCollapse(state, value) {
- state.asideBarCollapse = value;
- },
+ setAsideBarCollapse(state, value) {
+ state.asideBarCollapse = value;
+ },
};
export default {
- namespaced: true,
- state,
- getters,
- actions,
- mutations
+ namespaced: true,
+ state,
+ getters,
+ actions,
+ mutations
};
diff --git a/client/store/root.js b/client/store/root.js
new file mode 100644
index 00000000..1cd73ad7
--- /dev/null
+++ b/client/store/root.js
@@ -0,0 +1,25 @@
+// initial state
+const state = {
+ apiError: null,
+};
+
+// getters
+const getters = {};
+
+// actions
+const actions = {};
+
+// mutations
+const mutations = {
+ setApiError(state, value) {
+ state.apiError = value;
+ },
+};
+
+export default {
+ namespaced: true,
+ state,
+ getters,
+ actions,
+ mutations
+};