From 0237b9c60425bbcd2417bf31000cbd74d0112645 Mon Sep 17 00:00:00 2001
From: Vitalii Lysak <v.lysak@dunice.net>
Date: Wed, 17 Aug 2022 10:01:26 +0300
Subject: SILABMC-256: add fields for power, temp

---
 src/views/_sila/Power/Dynamic/PowerTemp.vue | 85 +++++++++++++++++++++--------
 1 file changed, 61 insertions(+), 24 deletions(-)

(limited to 'src/views/_sila/Power/Dynamic/PowerTemp.vue')

diff --git a/src/views/_sila/Power/Dynamic/PowerTemp.vue b/src/views/_sila/Power/Dynamic/PowerTemp.vue
index e0d4d154..1d18e8b1 100644
--- a/src/views/_sila/Power/Dynamic/PowerTemp.vue
+++ b/src/views/_sila/Power/Dynamic/PowerTemp.vue
@@ -8,43 +8,42 @@
       <img src="@/assets/images/_sila/collapsed/temperature.svg" />
     </template>
     <page-section>
-      <!-- <b-row class="align-items-end limit-container">
+      <b-row class="align-items-end limit-container">
         <b-col xs="12" sm="6" xl="3" class="pt-4">
-          <b-form-group :label="$t('pagePowerSup.labels.notNormal')">
+          <b-form-group :label="$t('pagePowerSup.labels.warning')">
             <b-form-input
-              v-model="notNormal"
+              v-model.number="warning"
               type="number"
               :min="0"
               :max="100"
-            ></b-form-input>
-          </b-form-group>
-        </b-col>
-        <b-col xs="12" sm="6" xl="3" class="pt-4">
-          <b-form-group :label="$t('pagePowerSup.labels.critical')">
-            <b-form-input v-model="critical" type="number" :min="0" :max="100">
+            >
             </b-form-input>
           </b-form-group>
         </b-col>
         <b-col xs="12" sm="6" xl="3" class="pt-4">
-          <b-form-group :label="$t('pagePowerSup.labels.warning')">
-            <b-form-input v-model="warning" type="number" :min="0" :max="100">
+          <b-form-group :label="$t('pagePowerSup.labels.critical')">
+            <b-form-input
+              v-model.number="critical"
+              type="number"
+              :min="0"
+              :max="100"
+            >
             </b-form-input>
           </b-form-group>
         </b-col>
         <b-col xs="12" sm="6" xl="3" class="pt-4">
-          <b-button variant="primary" style="height: 35px">
+          <b-button variant="primary" style="height: 35px" @click="saveLimit">
             {{ $t('global.action.save') }}
           </b-button>
         </b-col>
-      </b-row> -->
+      </b-row>
       <chart
         type="processors"
         :time-scale="timeScale"
         :data="allSensors"
         :colors="colors"
-        :warning="+warning"
-        :not-normal="+notNormal"
-        :critical="+critical"
+        :warning="warningLimit"
+        :critical="criticalLimit"
       ></chart>
       <b-table
         responsive="md"
@@ -90,13 +89,14 @@ import PageSection from '@/components/Global/PageSection';
 import DataFormatterMixin from '@/components/_sila/Mixins/DataFormatterMixin';
 import TableFilterMixin from '@/components/_sila/Mixins/TableFilterMixin';
 import LoadingBarMixin from '@/components/_sila/Mixins/LoadingBarMixin';
+import BVToastMixin from '@/components/_sila/Mixins/BVToastMixin';
 import Collapse from '@/components/_sila/Global/Collapse';
 
-import { getItems } from '@/utilities/_sila/metricProperties';
+import { getGroups, getItems } from '@/utilities/_sila/metricProperties';
 
 export default {
   components: { PageSection, Chart, Collapse },
-  mixins: [DataFormatterMixin, TableFilterMixin, LoadingBarMixin],
+  mixins: [DataFormatterMixin, TableFilterMixin, LoadingBarMixin, BVToastMixin],
   props: {
     timeScale: {
       type: String,
@@ -105,9 +105,8 @@ export default {
   },
   data() {
     return {
-      warning: 72,
-      notNormal: 44,
-      critical: 55,
+      warning: null,
+      critical: null,
       isBusy: true,
       fields: [
         {
@@ -144,10 +143,35 @@ export default {
   },
 
   computed: {
+    groups() {
+      return getGroups(this.allSensors);
+    },
+
     items() {
       return getItems(this.allSensors);
     },
 
+    limits() {
+      return this.$store.getters['powerSupply/limitsTemp'];
+    },
+
+    warningLimit() {
+      return this.limits.find((limit) => {
+        return (
+          limit?.UpperThresholdNonCritical &&
+          this.groups.includes(limit.MemberId)
+        );
+      })?.UpperThresholdNonCritical;
+    },
+
+    criticalLimit() {
+      return this.limits.find((limit) => {
+        return (
+          limit?.UpperThresholdCritical && this.groups.includes(limit.MemberId)
+        );
+      })?.UpperThresholdCritical;
+    },
+
     allSensors() {
       return this.timeScale === 'hour'
         ? this.$store.getters['powerSupply/psuTempLastHour']
@@ -171,6 +195,16 @@ export default {
     this.loadData();
   },
   methods: {
+    saveLimit() {
+      this.startLoader();
+      this.$store
+        .dispatch('powerSupply/patchLimitsTemp', {
+          warning: this.warning,
+          groups: this.groups,
+        })
+        .catch(({ message }) => this.errorToast(message))
+        .finally(() => this.endLoader());
+    },
     onOpened(state) {
       if (state) {
         this.loadData();
@@ -183,9 +217,12 @@ export default {
       }
       this.startLoader();
       this.$store.dispatch('powerSupply/getPsu', payload).finally(() => {
-        this.$root.$emit('psu-temp');
-        this.isBusy = false;
-        this.endLoader();
+        this.$store.dispatch('powerSupply/getLimitsTemp').finally(() => {
+          this.warning = this.warningLimit;
+          this.critical = this.criticalLimit;
+          this.endLoader();
+          this.isBusy = false;
+        });
       });
     },
   },
-- 
cgit v1.2.3

