From 9055d9880b35b8c076f2ff12e726f1cf22f237fc Mon Sep 17 00:00:00 2001
From: Sukanya Pandey <sukapan1@in.ibm.com>
Date: Tue, 31 Mar 2020 17:37:53 +0530
Subject: Add manage power usage page

 -The page is used to control the power.
 -Maximum power can be set between 1 to 10000.
 -The API used to get and set the power
  limit:/redfish/v1/Chassis/chassis/Power

Signed-off-by: Sukanya Pandey <sukapan1@in.ibm.com>
Change-Id: I1cab4876e9149d92de75014d7680ac11410ca4fe
---
 .../Control/ManagePowerUsage/ManagePowerUsage.vue  | 139 +++++++++++++++++++++
 1 file changed, 139 insertions(+)
 create mode 100644 src/views/Control/ManagePowerUsage/ManagePowerUsage.vue

(limited to 'src/views/Control/ManagePowerUsage/ManagePowerUsage.vue')

diff --git a/src/views/Control/ManagePowerUsage/ManagePowerUsage.vue b/src/views/Control/ManagePowerUsage/ManagePowerUsage.vue
new file mode 100644
index 00000000..8a16b88b
--- /dev/null
+++ b/src/views/Control/ManagePowerUsage/ManagePowerUsage.vue
@@ -0,0 +1,139 @@
+<template>
+  <b-container fluid="xl">
+    <page-title :description="$t('pageManagePowerUsage.description')" />
+
+    <b-row>
+      <b-col sm="8" md="6" xl="12">
+        <dl>
+          <dt>{{ $t('pageManagePowerUsage.powerConsumption') }}</dt>
+          <dd>
+            {{
+              powerConsumptionValue
+                ? `${powerConsumptionValue} W`
+                : $t('global.status.notAvailable')
+            }}
+          </dd>
+        </dl>
+      </b-col>
+    </b-row>
+
+    <b-form @submit.prevent="submitForm">
+      <b-row>
+        <b-col sm="8" md="6" xl="12">
+          <b-form-group
+            :label="$t('pageManagePowerUsage.powerCapSettingLabel')"
+          >
+            <b-form-checkbox
+              v-model="isPowerCapFieldEnabled"
+              name="power-cap-setting"
+            >
+              {{ $t('pageManagePowerUsage.powerCapSettingData') }}
+            </b-form-checkbox>
+          </b-form-group>
+        </b-col>
+      </b-row>
+
+      <b-row>
+        <b-col sm="8" md="6" xl="3">
+          <b-form-group
+            id="input-group-1"
+            :label="$t('pageManagePowerUsage.powerCapLabel')"
+            label-for="input-1"
+          >
+            <b-form-text id="power-help-text">
+              {{
+                $t('pageManagePowerUsage.powerCapLabelTextInfo', {
+                  min: 1,
+                  max: 10000
+                })
+              }}
+            </b-form-text>
+
+            <b-form-input
+              id="input-1"
+              v-model.number="powerCapValue"
+              :disabled="!isPowerCapFieldEnabled"
+              type="number"
+              aria-describedby="power-help-text"
+              :state="getValidationState($v.powerCapValue)"
+            ></b-form-input>
+
+            <b-form-invalid-feedback id="input-live-feedback" role="alert">
+              <template v-if="!$v.powerCapValue.required">
+                {{ $t('global.form.fieldRequired') }}
+              </template>
+              <template v-else-if="!$v.powerCapValue.between">
+                {{ $t('global.form.invalidValue') }}
+              </template>
+            </b-form-invalid-feedback>
+          </b-form-group>
+        </b-col>
+      </b-row>
+
+      <b-button variant="primary" type="submit">
+        {{ $t('global.action.save') }}
+      </b-button>
+    </b-form>
+  </b-container>
+</template>
+
+<script>
+import PageTitle from '@/components/Global/PageTitle';
+import VuelidateMixin from '@/components/Mixins/VuelidateMixin.js';
+import BVToastMixin from '@/components/Mixins/BVToastMixin';
+import { requiredIf, between } from 'vuelidate/lib/validators';
+import { mapGetters } from 'vuex';
+
+export default {
+  name: 'ManagePowerUsage',
+  components: { PageTitle },
+  mixins: [VuelidateMixin, BVToastMixin],
+  computed: {
+    ...mapGetters({
+      powerConsumptionValue: 'powerControl/powerConsumptionValue'
+    }),
+
+    /**
+      Computed property isPowerCapFieldEnabled is used to enable or disable the input field.
+      The input field is enabled when the powercapValue property is not null.
+   **/
+    isPowerCapFieldEnabled: {
+      get() {
+        return this.powerCapValue !== null;
+      },
+      set(value) {
+        let newValue = value ? '' : null;
+        this.$v.$reset();
+        this.$store.dispatch('powerControl/setPowerCapUpdatedValue', newValue);
+      }
+    },
+    powerCapValue: {
+      get() {
+        return this.$store.getters['powerControl/powerCapValue'];
+      },
+      set(value) {
+        this.$v.$touch();
+        this.$store.dispatch('powerControl/setPowerCapUpdatedValue', value);
+      }
+    }
+  },
+  validations: {
+    powerCapValue: {
+      between: between(1, 10000),
+      required: requiredIf(function() {
+        return this.isPowerCapFieldEnabled;
+      })
+    }
+  },
+  methods: {
+    submitForm() {
+      this.$v.$touch();
+      if (this.$v.$invalid) return;
+      this.$store
+        .dispatch('powerControl/setPowerControl', this.powerCapValue)
+        .then(message => this.successToast(message))
+        .catch(({ message }) => this.errorToast(message));
+    }
+  }
+};
+</script>
-- 
cgit v1.2.3

