From 257b9b29b1c5ffb608b015bd780d1491de99bff6 Mon Sep 17 00:00:00 2001 From: Vitalii Lysak Date: Wed, 6 Jul 2022 10:59:45 +0300 Subject: add dynamic info for motherboard --- src/components/AppNavigation/AppNavigationMixin.js | 8 ++-- src/store/modules/HardwareStatus/SensorsStore.js | 46 ++++++++++++++++++++++ .../DynamicInfo/MotherboardDynamicPage.vue | 21 ++++++++++ src/views/Motherboard/DynamicInfo/helpers.js | 2 +- 4 files changed, 72 insertions(+), 5 deletions(-) diff --git a/src/components/AppNavigation/AppNavigationMixin.js b/src/components/AppNavigation/AppNavigationMixin.js index f420ab56..f3a6b6b9 100644 --- a/src/components/AppNavigation/AppNavigationMixin.js +++ b/src/components/AppNavigation/AppNavigationMixin.js @@ -168,23 +168,23 @@ export const AppNavigationMixin = { // label: this.$t('appNavigation.virtualDrivers'), // route: '/virtual-drivers', // }, - /*{ + { id: 'motherboard', label: this.$t('appNavigation.motherboard'), icon: 'iconChevronUp', children: [ - { + /*{ id: 'motherboard-specification', label: this.$t('appNavigation.specification'), route: '/motherboard-specification', - }, + },*/ { id: 'motherboard-dynamic-info', label: this.$t('appNavigation.analyticalPanel'), route: '/motherboard-dynamic-info', }, ], - },*/ + }, // { // id: 'network-adapters', // label: this.$t('appNavigation.networkAdapters'), diff --git a/src/store/modules/HardwareStatus/SensorsStore.js b/src/store/modules/HardwareStatus/SensorsStore.js index 896297e3..59872718 100644 --- a/src/store/modules/HardwareStatus/SensorsStore.js +++ b/src/store/modules/HardwareStatus/SensorsStore.js @@ -6,10 +6,12 @@ const SensorsStore = { state: { sensors: [], fanSensors: [], + tempSensors: [], }, getters: { sensors: (state) => state.sensors, fanSensors: (state) => state.fanSensors, + tempSensors: (state) => state.tempSensors, }, mutations: { setSensors: (state, sensors) => { @@ -18,6 +20,12 @@ const SensorsStore = { setFanSensors: (state, fanSensors) => { state.fanSensors = uniqBy([...state.fanSensors, ...fanSensors], 'name'); }, + setTempSensors: (state, tempSensors) => { + state.tempSensors = uniqBy( + [...state.tempSensors, ...tempSensors], + 'name' + ); + }, }, actions: { async getAllSensors({ dispatch }) { @@ -31,6 +39,15 @@ const SensorsStore = { }, []); return await api.all(promises); }, + async getTempSensors({ dispatch }) { + const collection = await dispatch('getChassisCollection'); + if (!collection) return; + const promises = collection.reduce((acc, id) => { + acc.push(dispatch('getOnlyTempSensors', id)); + return acc; + }, []); + return await api.all(promises); + }, async getFanSensors({ dispatch }) { const collection = await dispatch('getChassisCollection'); if (!collection) return; @@ -78,6 +95,35 @@ const SensorsStore = { }) ); }, + async getOnlyTempSensors({ commit }, id) { + const sensors = await api + .get(`${id}/Sensors`) + .then((response) => response.data.Members) + .catch((error) => console.log(error)); + const tempSensors = sensors.filter((sensor) => { + return sensor['@odata.id'].toLowerCase().includes('temp'); + }); + if (!tempSensors) return; + const promises = tempSensors.map((sensor) => { + return api.get(sensor['@odata.id']).catch((error) => { + console.log(error); + return error; + }); + }); + return await api.all(promises).then( + api.spread((...responses) => { + const sensorData = responses.map(({ data }) => { + return { + name: data.Name, + status: data.Status.Health, + currentValue: data.Reading, + units: data.ReadingUnits, + }; + }); + commit('setTempSensors', sensorData); + }) + ); + }, async getOnlyFanSensors({ commit }, id) { const sensors = await api .get(`${id}/Sensors`) diff --git a/src/views/Motherboard/DynamicInfo/MotherboardDynamicPage.vue b/src/views/Motherboard/DynamicInfo/MotherboardDynamicPage.vue index e50bc399..cb937ce3 100644 --- a/src/views/Motherboard/DynamicInfo/MotherboardDynamicPage.vue +++ b/src/views/Motherboard/DynamicInfo/MotherboardDynamicPage.vue @@ -45,6 +45,8 @@ import TemperatureTable from './TemperatureTable'; import AccessoryTable from '@/components/Global/SilaComponents/Tables/AccessoryTableWithLabel'; import iconChevronUp from '@carbon/icons-vue/es/chevron--up/16'; +import TableFilterMixin from '@/components/Mixins/TableFilterMixin'; + import { AccessoryData } from './helpers'; export default { @@ -54,16 +56,35 @@ export default { TemperatureTable, AccessoryTable, }, + mixins: [TableFilterMixin], data() { return { + isBusy: true, timeScale: 'hour', temperatureWarning: 72, temperatureWarningInput: 72, notificationInput: 42, accessoryData: AccessoryData, iconChevronUp: iconChevronUp, + activeFilters: [], }; }, + + computed: { + allSensors() { + let sensors = this.$store.getters['sensors/tempSensors']; + return sensors; + }, + }, + created() { + this.$store.dispatch('sensors/getTempSensors').finally(() => { + this.accessoryData.temperatureTable.items = this.getFilteredTableData( + this.allSensors, + this.activeFilters + ); + this.isBusy = false; + }); + }, methods: { switchTimeScale(period) { this.timeScale = period; diff --git a/src/views/Motherboard/DynamicInfo/helpers.js b/src/views/Motherboard/DynamicInfo/helpers.js index 807de83a..157c5ffe 100644 --- a/src/views/Motherboard/DynamicInfo/helpers.js +++ b/src/views/Motherboard/DynamicInfo/helpers.js @@ -431,7 +431,7 @@ export const AccessoryData = { tdClass: 'bootstrap-fans-table__td light-12px', }, { - key: 'currentTemperature', + key: 'currentValue', label: 'Текущее, С°', thClass: 'bootstrap-fans-table__th semi-bold-12px', tdClass: 'bootstrap-fans-table__td light-12px', -- cgit v1.2.3