blob: a7bcfaa99c00fca8c02cc1fa4b8ed4744194b837 [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'"
Surya V603cfbf2024-07-11 15:19:46 +053024 @change="v$.form.oneTimeBoot.$touch()"
Yoshie Muranakac05ff642020-02-26 14:23:15 -080025 >
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"
Surya V603cfbf2024-07-11 15:19:46 +053040 @change="v$.form.tpmPolicyOn.$touch()"
Yoshie Muranakac05ff642020-02-26 14:23:15 -080041 >
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';
Surya V603cfbf2024-07-11 15:19:46 +053056import { useI18n } from 'vue-i18n';
Yoshie Muranakac05ff642020-02-26 14:23:15 -080057
58export default {
59 name: 'BootSettings',
Yoshie Muranaka5c977972020-04-30 09:48:23 -070060 mixins: [BVToastMixin, LoadingBarMixin],
Yoshie Muranakac05ff642020-02-26 14:23:15 -080061 data() {
62 return {
Surya V603cfbf2024-07-11 15:19:46 +053063 $t: useI18n().t,
Yoshie Muranakac05ff642020-02-26 14:23:15 -080064 form: {
Derick Montague71114fe2021-05-06 18:17:34 -050065 bootOption: this.$store.getters['serverBootSettings/bootSource'],
66 oneTimeBoot: this.$store.getters['serverBootSettings/overrideEnabled'],
67 tpmPolicyOn: this.$store.getters['serverBootSettings/tpmEnabled'],
Derick Montague602e98a2020-10-21 16:20:00 -050068 },
Yoshie Muranakac05ff642020-02-26 14:23:15 -080069 };
70 },
71 computed: {
Derick Montague71114fe2021-05-06 18:17:34 -050072 ...mapState('serverBootSettings', [
Yoshie Muranakac05ff642020-02-26 14:23:15 -080073 'bootSourceOptions',
74 'bootSource',
75 'overrideEnabled',
Derick Montague602e98a2020-10-21 16:20:00 -050076 'tpmEnabled',
77 ]),
Yoshie Muranakac05ff642020-02-26 14:23:15 -080078 },
79 watch: {
Derick Montague602e98a2020-10-21 16:20:00 -050080 bootSource: function (value) {
Yoshie Muranakac05ff642020-02-26 14:23:15 -080081 this.form.bootOption = value;
82 },
Derick Montague602e98a2020-10-21 16:20:00 -050083 overrideEnabled: function (value) {
Yoshie Muranakac05ff642020-02-26 14:23:15 -080084 this.form.oneTimeBoot = value;
85 },
Derick Montague602e98a2020-10-21 16:20:00 -050086 tpmEnabled: function (value) {
Yoshie Muranakac05ff642020-02-26 14:23:15 -080087 this.form.tpmPolicyOn = value;
Derick Montague602e98a2020-10-21 16:20:00 -050088 },
Yoshie Muranakac05ff642020-02-26 14:23:15 -080089 },
90 validations: {
91 // Empty validations to leverage vuelidate form states
92 // to check for changed values
93 form: {
94 bootOption: {},
95 oneTimeBoot: {},
Derick Montague602e98a2020-10-21 16:20:00 -050096 tpmPolicyOn: {},
97 },
Yoshie Muranakac05ff642020-02-26 14:23:15 -080098 },
99 created() {
Sukanya Pandey7f6edb62021-03-30 19:49:08 +0530100 this.$store
Derick Montague71114fe2021-05-06 18:17:34 -0500101 .dispatch('serverBootSettings/getTpmPolicy')
Sukanya Pandey7f6edb62021-03-30 19:49:08 +0530102 .finally(() =>
Ed Tanous81323992024-02-27 11:26:24 -0800103 this.$root.$emit('server-power-operations-boot-settings-complete'),
Sukanya Pandey7f6edb62021-03-30 19:49:08 +0530104 );
Yoshie Muranakac05ff642020-02-26 14:23:15 -0800105 },
106 methods: {
107 handleSubmit() {
Yoshie Muranaka5c977972020-04-30 09:48:23 -0700108 this.startLoader();
Surya V603cfbf2024-07-11 15:19:46 +0530109 const tpmPolicyChanged = this.v$.form.tpmPolicyOn.$dirty;
Yoshie Muranakac05ff642020-02-26 14:23:15 -0800110 let settings;
Lei YUe6807a42021-06-29 09:13:22 +0800111 let bootSource = this.form.bootOption;
112 let overrideEnabled = this.form.oneTimeBoot;
Yoshie Muranakac05ff642020-02-26 14:23:15 -0800113 let tpmEnabled = null;
114
Yoshie Muranakac05ff642020-02-26 14:23:15 -0800115 if (tpmPolicyChanged) tpmEnabled = this.form.tpmPolicyOn;
116 settings = { bootSource, overrideEnabled, tpmEnabled };
117
118 this.$store
Derick Montague71114fe2021-05-06 18:17:34 -0500119 .dispatch('serverBootSettings/saveSettings', settings)
Derick Montague602e98a2020-10-21 16:20:00 -0500120 .then((message) => this.successToast(message))
Yoshie Muranakac05ff642020-02-26 14:23:15 -0800121 .catch(({ message }) => this.errorToast(message))
122 .finally(() => {
Surya V603cfbf2024-07-11 15:19:46 +0530123 this.v$.form.$reset();
Yoshie Muranaka5c977972020-04-30 09:48:23 -0700124 this.endLoader();
Yoshie Muranakac05ff642020-02-26 14:23:15 -0800125 });
126 },
127 onChangeSelect(selectedOption) {
Surya V603cfbf2024-07-11 15:19:46 +0530128 this.v$.form.bootOption.$touch();
Yoshie Muranakac05ff642020-02-26 14:23:15 -0800129 // Disable one time boot if selected boot option is 'None'
130 if (selectedOption === 'None') this.form.oneTimeBoot = false;
Derick Montague602e98a2020-10-21 16:20:00 -0500131 },
132 },
Yoshie Muranakac05ff642020-02-26 14:23:15 -0800133};
134</script>