xref: /openbmc/webui-vue/src/views/Operations/ServerPowerOperations/BootSettings.vue (revision 450bdb0a31778b8da885a172f8456ba31e08ad86)
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';
56
57export default {
58  name: 'BootSettings',
59  mixins: [BVToastMixin, LoadingBarMixin],
60  data() {
61    return {
62      form: {
63        bootOption: this.$store.getters['serverBootSettings/bootSource'],
64        oneTimeBoot: this.$store.getters['serverBootSettings/overrideEnabled'],
65        tpmPolicyOn: this.$store.getters['serverBootSettings/tpmEnabled'],
66      },
67    };
68  },
69  computed: {
70    ...mapState('serverBootSettings', [
71      'bootSourceOptions',
72      'bootSource',
73      'overrideEnabled',
74      'tpmEnabled',
75    ]),
76  },
77  watch: {
78    bootSource: function (value) {
79      this.form.bootOption = value;
80    },
81    overrideEnabled: function (value) {
82      this.form.oneTimeBoot = value;
83    },
84    tpmEnabled: function (value) {
85      this.form.tpmPolicyOn = value;
86    },
87  },
88  validations: {
89    // Empty validations to leverage vuelidate form states
90    // to check for changed values
91    form: {
92      bootOption: {},
93      oneTimeBoot: {},
94      tpmPolicyOn: {},
95    },
96  },
97  created() {
98    this.$store
99      .dispatch('serverBootSettings/getTpmPolicy')
100      .finally(() =>
101        this.$root.$emit('server-power-operations-boot-settings-complete')
102      );
103  },
104  methods: {
105    handleSubmit() {
106      this.startLoader();
107      const bootSettingsChanged =
108        this.$v.form.bootOption.$dirty || this.$v.form.oneTimeBoot.$dirty;
109      const tpmPolicyChanged = this.$v.form.tpmPolicyOn.$dirty;
110      let settings;
111      let bootSource = null;
112      let overrideEnabled = null;
113      let tpmEnabled = null;
114
115      if (bootSettingsChanged) {
116        // If bootSource or overrideEnabled changed get
117        // both current values to send with request
118        bootSource = this.form.bootOption;
119        overrideEnabled = this.form.oneTimeBoot;
120      }
121      if (tpmPolicyChanged) tpmEnabled = this.form.tpmPolicyOn;
122      settings = { bootSource, overrideEnabled, tpmEnabled };
123
124      this.$store
125        .dispatch('serverBootSettings/saveSettings', settings)
126        .then((message) => this.successToast(message))
127        .catch(({ message }) => this.errorToast(message))
128        .finally(() => {
129          this.$v.form.$reset();
130          this.endLoader();
131        });
132    },
133    onChangeSelect(selectedOption) {
134      this.$v.form.bootOption.$touch();
135      // Disable one time boot if selected boot option is 'None'
136      if (selectedOption === 'None') this.form.oneTimeBoot = false;
137    },
138  },
139};
140</script>
141