From b8b6f7914f9371fc386fd5b4ea2e4b7a89892730 Mon Sep 17 00:00:00 2001 From: Yoshie Muranaka Date: Tue, 3 Dec 2019 14:47:32 -0800 Subject: Add GlobalStore module Create a GlobalStore to store global variables, including data in app header. Signed-off-by: Yoshie Muranaka Signed-off-by: Derick Montague Change-Id: Id498dec3925feec9a7e31ede91328f89ae591a0b --- src/components/AppHeader/AppHeader.vue | 79 ++++++++++++++++++++++++++-------- src/store/index.js | 2 + src/store/modules/GlobalStore.js | 35 +++++++++++++++ 3 files changed, 99 insertions(+), 17 deletions(-) create mode 100644 src/store/modules/GlobalStore.js diff --git a/src/components/AppHeader/AppHeader.vue b/src/components/AppHeader/AppHeader.vue index b28927ee..9177403c 100644 --- a/src/components/AppHeader/AppHeader.vue +++ b/src/components/AppHeader/AppHeader.vue @@ -2,24 +2,49 @@
Skip to main content
- -
- {{ orgName }} System Management -
-
- {{ serverName }} - {{ ipAddress }} -
-
- - - Refresh Data - - + + + BMC System Management + + + User Avatar - -
+ + +
+ + + + {{ orgName }} + + + + {{ hostName }} + {{ ipAddress }} + + + + + + Server health + Critical + + + + + Server power + Running + + + + + + Refresh Data + + + +
@@ -31,14 +56,34 @@ import Renew20 from "@carbon/icons-vue/es/renew/20"; export default { name: "AppHeader", components: { Renew20, UserAvatar20 }, + created() { + this.getHostInfo(); + }, data() { return { orgName: "OpenBMC", serverName: "Server Name", ipAddress: "127.0.0.0" }; + }, + computed: { + hostName() { + return this.$store.getters["global/hostName"]; + }, + hostStatus() { + return this.$store.getters["global/hostStatus"]; + } + }, + methods: { + getHostInfo() { + this.$store.dispatch("global/getHostName"); + } } }; - + diff --git a/src/store/index.js b/src/store/index.js index 3b86bfe2..af06a471 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -2,6 +2,7 @@ import Vue from "vue"; import Vuex from "vuex"; import LocalUserManagementStore from "./modules/AccessControl/LocalUserMangementStore"; +import GlobalStore from "./modules/GlobalStore"; Vue.use(Vuex); @@ -10,6 +11,7 @@ export default new Vuex.Store({ mutations: {}, actions: {}, modules: { + global: GlobalStore, localUsers: LocalUserManagementStore } }); diff --git a/src/store/modules/GlobalStore.js b/src/store/modules/GlobalStore.js new file mode 100644 index 00000000..332c8017 --- /dev/null +++ b/src/store/modules/GlobalStore.js @@ -0,0 +1,35 @@ +import api from "../api"; + +const GlobalStore = { + namespaced: true, + state: { + hostName: "--", + hostStatus: null + }, + getters: { + hostName(state) { + return state.hostName; + }, + hostStatus(state) { + return state.hostStatus; + } + }, + mutations: { + setHostName(state, hostName) { + state.hostName = hostName; + } + }, + actions: { + getHostName({ commit }) { + api + .get("/xyz/openbmc_project/network/config/attr/HostName") + .then(response => { + const hostName = response.data.data; + commit("setHostName", hostName); + }) + .catch(error => console.log(error)); + } + } +}; + +export default GlobalStore; -- cgit v1.2.3