blob: 37de1e76aa2f5cee3867fceaabcce13b895ee4db [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"
39 switch
40 aria-describedby="tpm-required-policy-help-block"
41 @change="$v.form.tpmPolicyOn.$touch()"
42 >
43 {{
44 form.tpmPolicyOn ? $t('global.status.on') : $t('global.status.off')
45 }}
46 </b-form-checkbox>
47 </b-form-group>
48 <b-button
49 variant="primary"
50 type="submit"
51 class="mb-3"
52 :disabled="!$v.form.$anyDirty"
53 >
54 {{ $t('global.action.save') }}
55 </b-button>
56 </b-form>
57 </div>
58</template>
59
60<script>
61import { mapState } from 'vuex';
62import BVToastMixin from '../../../components/Mixins/BVToastMixin';
Yoshie Muranaka5c977972020-04-30 09:48:23 -070063import LoadingBarMixin from '@/components/Mixins/LoadingBarMixin';
Yoshie Muranakac05ff642020-02-26 14:23:15 -080064
65export default {
66 name: 'BootSettings',
Yoshie Muranaka5c977972020-04-30 09:48:23 -070067 mixins: [BVToastMixin, LoadingBarMixin],
Yoshie Muranakac05ff642020-02-26 14:23:15 -080068 data() {
69 return {
70 form: {
71 bootOption: this.$store.getters['hostBootSettings/bootSource'],
72 oneTimeBoot: this.$store.getters['hostBootSettings/overrideEnabled'],
73 tpmPolicyOn: this.$store.getters['hostBootSettings/tpmEnabled']
74 }
75 };
76 },
77 computed: {
78 ...mapState('hostBootSettings', [
79 'bootSourceOptions',
80 'bootSource',
81 'overrideEnabled',
82 'tpmEnabled'
83 ])
84 },
85 watch: {
86 bootSource: function(value) {
87 this.form.bootOption = value;
88 },
89 overrideEnabled: function(value) {
90 this.form.oneTimeBoot = value;
91 },
92 tpmEnabled: function(value) {
93 this.form.tpmPolicyOn = value;
94 }
95 },
96 validations: {
97 // Empty validations to leverage vuelidate form states
98 // to check for changed values
99 form: {
100 bootOption: {},
101 oneTimeBoot: {},
102 tpmPolicyOn: {}
103 }
104 },
105 created() {
Yoshie Muranaka5c977972020-04-30 09:48:23 -0700106 Promise.all([
107 this.$store.dispatch('hostBootSettings/getBootSettings'),
108 this.$store.dispatch('hostBootSettings/getTpmPolicy')
Dixsie Wolmersbb316062020-08-04 19:17:33 -0500109 ]).finally(() =>
110 this.$root.$emit('serverPowerOperations::bootSettings::complete')
111 );
Yoshie Muranakac05ff642020-02-26 14:23:15 -0800112 },
113 methods: {
114 handleSubmit() {
Yoshie Muranaka5c977972020-04-30 09:48:23 -0700115 this.startLoader();
Yoshie Muranakac05ff642020-02-26 14:23:15 -0800116 const bootSettingsChanged =
117 this.$v.form.bootOption.$dirty || this.$v.form.oneTimeBoot.$dirty;
118 const tpmPolicyChanged = this.$v.form.tpmPolicyOn.$dirty;
119 let settings;
120 let bootSource = null;
121 let overrideEnabled = null;
122 let tpmEnabled = null;
123
124 if (bootSettingsChanged) {
125 // If bootSource or overrideEnabled changed get
126 // both current values to send with request
127 bootSource = this.form.bootOption;
128 overrideEnabled = this.form.oneTimeBoot;
129 }
130 if (tpmPolicyChanged) tpmEnabled = this.form.tpmPolicyOn;
131 settings = { bootSource, overrideEnabled, tpmEnabled };
132
133 this.$store
134 .dispatch('hostBootSettings/saveSettings', settings)
135 .then(message => this.successToast(message))
136 .catch(({ message }) => this.errorToast(message))
137 .finally(() => {
138 this.$v.form.$reset();
Yoshie Muranaka5c977972020-04-30 09:48:23 -0700139 this.endLoader();
Yoshie Muranakac05ff642020-02-26 14:23:15 -0800140 });
141 },
142 onChangeSelect(selectedOption) {
143 this.$v.form.bootOption.$touch();
144 // Disable one time boot if selected boot option is 'None'
145 if (selectedOption === 'None') this.form.oneTimeBoot = false;
146 }
147 }
148};
149</script>