xref: /openbmc/webui-vue/src/views/Operations/ServerPowerOperations/BootSettings.vue (revision 99fe228eef84d018125712187e04b24a328d292b)
1<template>
2  <div class="form-background p-3">
3    <b-form novalidate @submit.prevent="handleSubmit">
4      <b-form-group
5        :label="
6          $t('pageServerPowerOperations.bootSettings.bootSettingsOverride')
7        "
8        label-for="boot-option"
9        class="mb-3"
10      >
11        <b-form-select
12          id="boot-option"
13          v-model="form.bootOption"
14          :disabled="bootSourceOptions.length === 0"
15          :options="bootSourceOptions"
16          @change="onChangeSelect"
17        >
18        </b-form-select>
19      </b-form-group>
20      <b-form-checkbox
21        v-model="form.oneTimeBoot"
22        class="mb-4"
23        :disabled="form.bootOption === 'None'"
24        @change="v$.form.oneTimeBoot.$touch()"
25      >
26        {{ $t('pageServerPowerOperations.bootSettings.enableOneTimeBoot') }}
27      </b-form-checkbox>
28      <b-form-group
29        :label="$t('pageServerPowerOperations.bootSettings.tpmRequiredPolicy')"
30      >
31        <b-form-text id="tpm-required-policy-help-block">
32          {{
33            $t('pageServerPowerOperations.bootSettings.tpmRequiredPolicyHelper')
34          }}
35        </b-form-text>
36        <b-form-checkbox
37          id="tpm-required-policy"
38          v-model="form.tpmPolicyOn"
39          aria-describedby="tpm-required-policy-help-block"
40          @change="v$.form.tpmPolicyOn.$touch()"
41        >
42          {{ $t('global.status.enabled') }}
43        </b-form-checkbox>
44      </b-form-group>
45      <b-button
46        variant="primary"
47        type="submit"
48        class="mb-3"
49        :disabled="isButtonDisable"
50      >
51        {{ $t('global.action.save') }}
52      </b-button>
53    </b-form>
54  </div>
55</template>
56
57<script>
58import { mapState } from 'vuex';
59import BVToastMixin from '@/components/Mixins/BVToastMixin';
60import LoadingBarMixin from '@/components/Mixins/LoadingBarMixin';
61import { useI18n } from 'vue-i18n';
62import { useVuelidate } from '@vuelidate/core';
63
64export default {
65  name: 'BootSettings',
66  mixins: [BVToastMixin, LoadingBarMixin],
67  props: {
68    isButtonDisable: {
69      required: true,
70      type: Boolean,
71      default: false,
72    },
73  },
74  setup() {
75    return {
76      v$: useVuelidate(),
77    };
78  },
79  data() {
80    return {
81      $t: useI18n().t,
82      form: {
83        bootOption: this.$store.getters['serverBootSettings/bootSource'],
84        oneTimeBoot: this.$store.getters['serverBootSettings/overrideEnabled'],
85        tpmPolicyOn: this.$store.getters['serverBootSettings/tpmEnabled'],
86      },
87    };
88  },
89  computed: {
90    ...mapState('serverBootSettings', [
91      'bootSourceOptions',
92      'bootSource',
93      'overrideEnabled',
94      'tpmEnabled',
95    ]),
96  },
97  watch: {
98    bootSource: function (value) {
99      this.form.bootOption = value;
100    },
101    overrideEnabled: function (value) {
102      this.form.oneTimeBoot = value;
103    },
104    tpmEnabled: function (value) {
105      this.form.tpmPolicyOn = value;
106    },
107  },
108  validations: {
109    // Empty validations to leverage vuelidate form states
110    // to check for changed values
111    form: {
112      bootOption: {},
113      oneTimeBoot: {},
114      tpmPolicyOn: {},
115    },
116  },
117  created() {
118    this.$store
119      .dispatch('serverBootSettings/getTpmPolicy')
120      .finally(() =>
121        this.$root.$emit('server-power-operations-boot-settings-complete'),
122      );
123  },
124  methods: {
125    handleSubmit() {
126      this.startLoader();
127      const tpmPolicyChanged = this.v$.form.tpmPolicyOn.$dirty;
128      let settings;
129      let bootSource = this.form.bootOption;
130      let overrideEnabled = this.form.oneTimeBoot;
131      let tpmEnabled = null;
132
133      if (tpmPolicyChanged) tpmEnabled = this.form.tpmPolicyOn;
134      settings = { bootSource, overrideEnabled, tpmEnabled };
135
136      this.$store
137        .dispatch('serverBootSettings/saveSettings', settings)
138        .then((message) => this.successToast(message))
139        .catch(({ message }) => this.errorToast(message))
140        .finally(() => {
141          this.v$.form.$reset();
142          this.endLoader();
143        });
144    },
145    onChangeSelect(selectedOption) {
146      this.v$.form.bootOption.$touch();
147      // Disable one time boot if selected boot option is 'None'
148      if (selectedOption === 'None') this.form.oneTimeBoot = false;
149    },
150  },
151};
152</script>
153