blob: efd8d347487efacfb8ba9986036fafbcfef9be30 [file] [log] [blame]
Yoshie Muranakac05ff642020-02-26 14:23:15 -08001<template>
Dixsie Wolmersd7e7a162020-07-20 18:35:33 -05002 <div class="form-background p-3">
Yoshie Muranakac05ff642020-02-26 14:23:15 -08003 <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"
Yoshie Muranakac05ff642020-02-26 14:23:15 -080039 aria-describedby="tpm-required-policy-help-block"
40 @change="$v.form.tpmPolicyOn.$touch()"
41 >
SurenNewaref295d1b2020-08-26 14:50:56 +053042 {{ $t('global.status.enabled') }}
Yoshie Muranakac05ff642020-02-26 14:23:15 -080043 </b-form-checkbox>
44 </b-form-group>
Dixsie Wolmers4d1dbb52020-08-24 21:43:25 -050045 <b-button variant="primary" type="submit" class="mb-3">
Yoshie Muranakac05ff642020-02-26 14:23:15 -080046 {{ $t('global.action.save') }}
47 </b-button>
48 </b-form>
49 </div>
50</template>
51
52<script>
53import { mapState } from 'vuex';
SurenNewaref295d1b2020-08-26 14:50:56 +053054import BVToastMixin from '@/components/Mixins/BVToastMixin';
Yoshie Muranaka5c977972020-04-30 09:48:23 -070055import LoadingBarMixin from '@/components/Mixins/LoadingBarMixin';
Yoshie Muranakac05ff642020-02-26 14:23:15 -080056
57export default {
58 name: 'BootSettings',
Yoshie Muranaka5c977972020-04-30 09:48:23 -070059 mixins: [BVToastMixin, LoadingBarMixin],
Yoshie Muranakac05ff642020-02-26 14:23:15 -080060 data() {
61 return {
62 form: {
Derick Montague71114fe2021-05-06 18:17:34 -050063 bootOption: this.$store.getters['serverBootSettings/bootSource'],
64 oneTimeBoot: this.$store.getters['serverBootSettings/overrideEnabled'],
65 tpmPolicyOn: this.$store.getters['serverBootSettings/tpmEnabled'],
Derick Montague602e98a2020-10-21 16:20:00 -050066 },
Yoshie Muranakac05ff642020-02-26 14:23:15 -080067 };
68 },
69 computed: {
Derick Montague71114fe2021-05-06 18:17:34 -050070 ...mapState('serverBootSettings', [
Yoshie Muranakac05ff642020-02-26 14:23:15 -080071 'bootSourceOptions',
72 'bootSource',
73 'overrideEnabled',
Derick Montague602e98a2020-10-21 16:20:00 -050074 'tpmEnabled',
75 ]),
Yoshie Muranakac05ff642020-02-26 14:23:15 -080076 },
77 watch: {
Derick Montague602e98a2020-10-21 16:20:00 -050078 bootSource: function (value) {
Yoshie Muranakac05ff642020-02-26 14:23:15 -080079 this.form.bootOption = value;
80 },
Derick Montague602e98a2020-10-21 16:20:00 -050081 overrideEnabled: function (value) {
Yoshie Muranakac05ff642020-02-26 14:23:15 -080082 this.form.oneTimeBoot = value;
83 },
Derick Montague602e98a2020-10-21 16:20:00 -050084 tpmEnabled: function (value) {
Yoshie Muranakac05ff642020-02-26 14:23:15 -080085 this.form.tpmPolicyOn = value;
Derick Montague602e98a2020-10-21 16:20:00 -050086 },
Yoshie Muranakac05ff642020-02-26 14:23:15 -080087 },
88 validations: {
89 // Empty validations to leverage vuelidate form states
90 // to check for changed values
91 form: {
92 bootOption: {},
93 oneTimeBoot: {},
Derick Montague602e98a2020-10-21 16:20:00 -050094 tpmPolicyOn: {},
95 },
Yoshie Muranakac05ff642020-02-26 14:23:15 -080096 },
97 created() {
Sukanya Pandey7f6edb62021-03-30 19:49:08 +053098 this.$store
Derick Montague71114fe2021-05-06 18:17:34 -050099 .dispatch('serverBootSettings/getTpmPolicy')
Sukanya Pandey7f6edb62021-03-30 19:49:08 +0530100 .finally(() =>
101 this.$root.$emit('server-power-operations-boot-settings-complete')
102 );
Yoshie Muranakac05ff642020-02-26 14:23:15 -0800103 },
104 methods: {
105 handleSubmit() {
Yoshie Muranaka5c977972020-04-30 09:48:23 -0700106 this.startLoader();
Yoshie Muranakac05ff642020-02-26 14:23:15 -0800107 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
Derick Montague71114fe2021-05-06 18:17:34 -0500125 .dispatch('serverBootSettings/saveSettings', settings)
Derick Montague602e98a2020-10-21 16:20:00 -0500126 .then((message) => this.successToast(message))
Yoshie Muranakac05ff642020-02-26 14:23:15 -0800127 .catch(({ message }) => this.errorToast(message))
128 .finally(() => {
129 this.$v.form.$reset();
Yoshie Muranaka5c977972020-04-30 09:48:23 -0700130 this.endLoader();
Yoshie Muranakac05ff642020-02-26 14:23:15 -0800131 });
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;
Derick Montague602e98a2020-10-21 16:20:00 -0500137 },
138 },
Yoshie Muranakac05ff642020-02-26 14:23:15 -0800139};
140</script>