blob: 48ce71c6a847056d72dfca01b71bd20ccebcbb4c [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>
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 Vde23ea22024-07-11 15:19:46 +053056import { useI18n } from 'vue-i18n';
Surya Venkatesan1a814b92024-09-23 16:29:01 +053057import { useVuelidate } from '@vuelidate/core';
Yoshie Muranakac05ff642020-02-26 14:23:15 -080058
59export default {
60 name: 'BootSettings',
Yoshie Muranaka5c977972020-04-30 09:48:23 -070061 mixins: [BVToastMixin, LoadingBarMixin],
Surya Venkatesan1a814b92024-09-23 16:29:01 +053062 setup() {
63 return {
64 v$: useVuelidate(),
65 };
66 },
Yoshie Muranakac05ff642020-02-26 14:23:15 -080067 data() {
68 return {
Surya Vde23ea22024-07-11 15:19:46 +053069 $t: useI18n().t,
Yoshie Muranakac05ff642020-02-26 14:23:15 -080070 form: {
Derick Montague71114fe2021-05-06 18:17:34 -050071 bootOption: this.$store.getters['serverBootSettings/bootSource'],
72 oneTimeBoot: this.$store.getters['serverBootSettings/overrideEnabled'],
73 tpmPolicyOn: this.$store.getters['serverBootSettings/tpmEnabled'],
Derick Montague602e98a2020-10-21 16:20:00 -050074 },
Yoshie Muranakac05ff642020-02-26 14:23:15 -080075 };
76 },
77 computed: {
Derick Montague71114fe2021-05-06 18:17:34 -050078 ...mapState('serverBootSettings', [
Yoshie Muranakac05ff642020-02-26 14:23:15 -080079 'bootSourceOptions',
80 'bootSource',
81 'overrideEnabled',
Derick Montague602e98a2020-10-21 16:20:00 -050082 'tpmEnabled',
83 ]),
Yoshie Muranakac05ff642020-02-26 14:23:15 -080084 },
85 watch: {
Derick Montague602e98a2020-10-21 16:20:00 -050086 bootSource: function (value) {
Yoshie Muranakac05ff642020-02-26 14:23:15 -080087 this.form.bootOption = value;
88 },
Derick Montague602e98a2020-10-21 16:20:00 -050089 overrideEnabled: function (value) {
Yoshie Muranakac05ff642020-02-26 14:23:15 -080090 this.form.oneTimeBoot = value;
91 },
Derick Montague602e98a2020-10-21 16:20:00 -050092 tpmEnabled: function (value) {
Yoshie Muranakac05ff642020-02-26 14:23:15 -080093 this.form.tpmPolicyOn = value;
Derick Montague602e98a2020-10-21 16:20:00 -050094 },
Yoshie Muranakac05ff642020-02-26 14:23:15 -080095 },
96 validations: {
97 // Empty validations to leverage vuelidate form states
98 // to check for changed values
99 form: {
100 bootOption: {},
101 oneTimeBoot: {},
Derick Montague602e98a2020-10-21 16:20:00 -0500102 tpmPolicyOn: {},
103 },
Yoshie Muranakac05ff642020-02-26 14:23:15 -0800104 },
105 created() {
Sukanya Pandey7f6edb62021-03-30 19:49:08 +0530106 this.$store
Derick Montague71114fe2021-05-06 18:17:34 -0500107 .dispatch('serverBootSettings/getTpmPolicy')
Sukanya Pandey7f6edb62021-03-30 19:49:08 +0530108 .finally(() =>
Ed Tanous81323992024-02-27 11:26:24 -0800109 this.$root.$emit('server-power-operations-boot-settings-complete'),
Sukanya Pandey7f6edb62021-03-30 19:49:08 +0530110 );
Yoshie Muranakac05ff642020-02-26 14:23:15 -0800111 },
112 methods: {
113 handleSubmit() {
Yoshie Muranaka5c977972020-04-30 09:48:23 -0700114 this.startLoader();
Surya Vde23ea22024-07-11 15:19:46 +0530115 const tpmPolicyChanged = this.v$.form.tpmPolicyOn.$dirty;
Yoshie Muranakac05ff642020-02-26 14:23:15 -0800116 let settings;
Lei YUe6807a42021-06-29 09:13:22 +0800117 let bootSource = this.form.bootOption;
118 let overrideEnabled = this.form.oneTimeBoot;
Yoshie Muranakac05ff642020-02-26 14:23:15 -0800119 let tpmEnabled = null;
120
Yoshie Muranakac05ff642020-02-26 14:23:15 -0800121 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(() => {
Surya Vde23ea22024-07-11 15:19:46 +0530129 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) {
Surya Vde23ea22024-07-11 15:19:46 +0530134 this.v$.form.bootOption.$touch();
Yoshie Muranakac05ff642020-02-26 14:23:15 -0800135 // 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>