blob: ea66baa6c915ed2737159bb540312fd4a02a6f87 [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 Vde23ea22024-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 Vde23ea22024-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>
Aravinth S99fe2282025-08-20 15:08:17 +053045 <b-button
46 variant="primary"
47 type="submit"
48 class="mb-3"
49 :disabled="isButtonDisable"
50 >
Yoshie Muranakac05ff642020-02-26 14:23:15 -080051 {{ $t('global.action.save') }}
52 </b-button>
53 </b-form>
54 </div>
55</template>
56
57<script>
58import { mapState } from 'vuex';
SurenNewaref295d1b2020-08-26 14:50:56 +053059import BVToastMixin from '@/components/Mixins/BVToastMixin';
Yoshie Muranaka5c977972020-04-30 09:48:23 -070060import LoadingBarMixin from '@/components/Mixins/LoadingBarMixin';
Surya Vde23ea22024-07-11 15:19:46 +053061import { useI18n } from 'vue-i18n';
Surya Venkatesan1a814b92024-09-23 16:29:01 +053062import { useVuelidate } from '@vuelidate/core';
Yoshie Muranakac05ff642020-02-26 14:23:15 -080063
64export default {
65 name: 'BootSettings',
Yoshie Muranaka5c977972020-04-30 09:48:23 -070066 mixins: [BVToastMixin, LoadingBarMixin],
Aravinth S99fe2282025-08-20 15:08:17 +053067 props: {
68 isButtonDisable: {
69 required: true,
70 type: Boolean,
71 default: false,
72 },
73 },
Surya Venkatesan1a814b92024-09-23 16:29:01 +053074 setup() {
75 return {
76 v$: useVuelidate(),
77 };
78 },
Yoshie Muranakac05ff642020-02-26 14:23:15 -080079 data() {
80 return {
Surya Vde23ea22024-07-11 15:19:46 +053081 $t: useI18n().t,
Yoshie Muranakac05ff642020-02-26 14:23:15 -080082 form: {
Derick Montague71114fe2021-05-06 18:17:34 -050083 bootOption: this.$store.getters['serverBootSettings/bootSource'],
84 oneTimeBoot: this.$store.getters['serverBootSettings/overrideEnabled'],
85 tpmPolicyOn: this.$store.getters['serverBootSettings/tpmEnabled'],
Derick Montague602e98a2020-10-21 16:20:00 -050086 },
Yoshie Muranakac05ff642020-02-26 14:23:15 -080087 };
88 },
89 computed: {
Derick Montague71114fe2021-05-06 18:17:34 -050090 ...mapState('serverBootSettings', [
Yoshie Muranakac05ff642020-02-26 14:23:15 -080091 'bootSourceOptions',
92 'bootSource',
93 'overrideEnabled',
Derick Montague602e98a2020-10-21 16:20:00 -050094 'tpmEnabled',
95 ]),
Yoshie Muranakac05ff642020-02-26 14:23:15 -080096 },
97 watch: {
Derick Montague602e98a2020-10-21 16:20:00 -050098 bootSource: function (value) {
Yoshie Muranakac05ff642020-02-26 14:23:15 -080099 this.form.bootOption = value;
100 },
Derick Montague602e98a2020-10-21 16:20:00 -0500101 overrideEnabled: function (value) {
Yoshie Muranakac05ff642020-02-26 14:23:15 -0800102 this.form.oneTimeBoot = value;
103 },
Derick Montague602e98a2020-10-21 16:20:00 -0500104 tpmEnabled: function (value) {
Yoshie Muranakac05ff642020-02-26 14:23:15 -0800105 this.form.tpmPolicyOn = value;
Derick Montague602e98a2020-10-21 16:20:00 -0500106 },
Yoshie Muranakac05ff642020-02-26 14:23:15 -0800107 },
108 validations: {
109 // Empty validations to leverage vuelidate form states
110 // to check for changed values
111 form: {
112 bootOption: {},
113 oneTimeBoot: {},
Derick Montague602e98a2020-10-21 16:20:00 -0500114 tpmPolicyOn: {},
115 },
Yoshie Muranakac05ff642020-02-26 14:23:15 -0800116 },
117 created() {
Sukanya Pandey7f6edb62021-03-30 19:49:08 +0530118 this.$store
Derick Montague71114fe2021-05-06 18:17:34 -0500119 .dispatch('serverBootSettings/getTpmPolicy')
Sukanya Pandey7f6edb62021-03-30 19:49:08 +0530120 .finally(() =>
Ed Tanous81323992024-02-27 11:26:24 -0800121 this.$root.$emit('server-power-operations-boot-settings-complete'),
Sukanya Pandey7f6edb62021-03-30 19:49:08 +0530122 );
Yoshie Muranakac05ff642020-02-26 14:23:15 -0800123 },
124 methods: {
125 handleSubmit() {
Yoshie Muranaka5c977972020-04-30 09:48:23 -0700126 this.startLoader();
Surya Vde23ea22024-07-11 15:19:46 +0530127 const tpmPolicyChanged = this.v$.form.tpmPolicyOn.$dirty;
Yoshie Muranakac05ff642020-02-26 14:23:15 -0800128 let settings;
Lei YUe6807a42021-06-29 09:13:22 +0800129 let bootSource = this.form.bootOption;
130 let overrideEnabled = this.form.oneTimeBoot;
Yoshie Muranakac05ff642020-02-26 14:23:15 -0800131 let tpmEnabled = null;
132
Yoshie Muranakac05ff642020-02-26 14:23:15 -0800133 if (tpmPolicyChanged) tpmEnabled = this.form.tpmPolicyOn;
134 settings = { bootSource, overrideEnabled, tpmEnabled };
135
136 this.$store
Derick Montague71114fe2021-05-06 18:17:34 -0500137 .dispatch('serverBootSettings/saveSettings', settings)
Derick Montague602e98a2020-10-21 16:20:00 -0500138 .then((message) => this.successToast(message))
Yoshie Muranakac05ff642020-02-26 14:23:15 -0800139 .catch(({ message }) => this.errorToast(message))
140 .finally(() => {
Surya Vde23ea22024-07-11 15:19:46 +0530141 this.v$.form.$reset();
Yoshie Muranaka5c977972020-04-30 09:48:23 -0700142 this.endLoader();
Yoshie Muranakac05ff642020-02-26 14:23:15 -0800143 });
144 },
145 onChangeSelect(selectedOption) {
Surya Vde23ea22024-07-11 15:19:46 +0530146 this.v$.form.bootOption.$touch();
Yoshie Muranakac05ff642020-02-26 14:23:15 -0800147 // Disable one time boot if selected boot option is 'None'
148 if (selectedOption === 'None') this.form.oneTimeBoot = false;
Derick Montague602e98a2020-10-21 16:20:00 -0500149 },
150 },
Yoshie Muranakac05ff642020-02-26 14:23:15 -0800151};
152</script>