xref: /openbmc/webui-vue/src/views/Operations/ServerPowerOperations/BootSettings.vue (revision de23ea23d88451a2fa2774ec72053772603c23ae)
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 variant="primary" type="submit" class="mb-3">
46        {{ $t('global.action.save') }}
47      </b-button>
48    </b-form>
49  </div>
50</template>
51
52<script>
53import { mapState } from 'vuex';
54import BVToastMixin from '@/components/Mixins/BVToastMixin';
55import LoadingBarMixin from '@/components/Mixins/LoadingBarMixin';
56import { useI18n } from 'vue-i18n';
57
58export default {
59  name: 'BootSettings',
60  mixins: [BVToastMixin, LoadingBarMixin],
61  data() {
62    return {
63      $t: useI18n().t,
64      form: {
65        bootOption: this.$store.getters['serverBootSettings/bootSource'],
66        oneTimeBoot: this.$store.getters['serverBootSettings/overrideEnabled'],
67        tpmPolicyOn: this.$store.getters['serverBootSettings/tpmEnabled'],
68      },
69    };
70  },
71  computed: {
72    ...mapState('serverBootSettings', [
73      'bootSourceOptions',
74      'bootSource',
75      'overrideEnabled',
76      'tpmEnabled',
77    ]),
78  },
79  watch: {
80    bootSource: function (value) {
81      this.form.bootOption = value;
82    },
83    overrideEnabled: function (value) {
84      this.form.oneTimeBoot = value;
85    },
86    tpmEnabled: function (value) {
87      this.form.tpmPolicyOn = value;
88    },
89  },
90  validations: {
91    // Empty validations to leverage vuelidate form states
92    // to check for changed values
93    form: {
94      bootOption: {},
95      oneTimeBoot: {},
96      tpmPolicyOn: {},
97    },
98  },
99  created() {
100    this.$store
101      .dispatch('serverBootSettings/getTpmPolicy')
102      .finally(() =>
103        this.$root.$emit('server-power-operations-boot-settings-complete'),
104      );
105  },
106  methods: {
107    handleSubmit() {
108      this.startLoader();
109      const tpmPolicyChanged = this.v$.form.tpmPolicyOn.$dirty;
110      let settings;
111      let bootSource = this.form.bootOption;
112      let overrideEnabled = this.form.oneTimeBoot;
113      let tpmEnabled = null;
114
115      if (tpmPolicyChanged) tpmEnabled = this.form.tpmPolicyOn;
116      settings = { bootSource, overrideEnabled, tpmEnabled };
117
118      this.$store
119        .dispatch('serverBootSettings/saveSettings', settings)
120        .then((message) => this.successToast(message))
121        .catch(({ message }) => this.errorToast(message))
122        .finally(() => {
123          this.v$.form.$reset();
124          this.endLoader();
125        });
126    },
127    onChangeSelect(selectedOption) {
128      this.v$.form.bootOption.$touch();
129      // Disable one time boot if selected boot option is 'None'
130      if (selectedOption === 'None') this.form.oneTimeBoot = false;
131    },
132  },
133};
134</script>
135