blob: 71a78f29b612c25b20cd0d33f368ab46fa4a5e8c [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>
Dixsie Wolmers4d1dbb52020-08-24 21:43:25 -050048 <b-button variant="primary" type="submit" class="mb-3">
Yoshie Muranakac05ff642020-02-26 14:23:15 -080049 {{ $t('global.action.save') }}
50 </b-button>
51 </b-form>
52 </div>
53</template>
54
55<script>
56import { mapState } from 'vuex';
57import BVToastMixin from '../../../components/Mixins/BVToastMixin';
Yoshie Muranaka5c977972020-04-30 09:48:23 -070058import LoadingBarMixin from '@/components/Mixins/LoadingBarMixin';
Yoshie Muranakac05ff642020-02-26 14:23:15 -080059
60export default {
61 name: 'BootSettings',
Yoshie Muranaka5c977972020-04-30 09:48:23 -070062 mixins: [BVToastMixin, LoadingBarMixin],
Yoshie Muranakac05ff642020-02-26 14:23:15 -080063 data() {
64 return {
65 form: {
66 bootOption: this.$store.getters['hostBootSettings/bootSource'],
67 oneTimeBoot: this.$store.getters['hostBootSettings/overrideEnabled'],
68 tpmPolicyOn: this.$store.getters['hostBootSettings/tpmEnabled']
69 }
70 };
71 },
72 computed: {
73 ...mapState('hostBootSettings', [
74 'bootSourceOptions',
75 'bootSource',
76 'overrideEnabled',
77 'tpmEnabled'
78 ])
79 },
80 watch: {
81 bootSource: function(value) {
82 this.form.bootOption = value;
83 },
84 overrideEnabled: function(value) {
85 this.form.oneTimeBoot = value;
86 },
87 tpmEnabled: function(value) {
88 this.form.tpmPolicyOn = value;
89 }
90 },
91 validations: {
92 // Empty validations to leverage vuelidate form states
93 // to check for changed values
94 form: {
95 bootOption: {},
96 oneTimeBoot: {},
97 tpmPolicyOn: {}
98 }
99 },
100 created() {
Yoshie Muranaka5c977972020-04-30 09:48:23 -0700101 Promise.all([
102 this.$store.dispatch('hostBootSettings/getBootSettings'),
103 this.$store.dispatch('hostBootSettings/getTpmPolicy')
Dixsie Wolmersbb316062020-08-04 19:17:33 -0500104 ]).finally(() =>
105 this.$root.$emit('serverPowerOperations::bootSettings::complete')
106 );
Yoshie Muranakac05ff642020-02-26 14:23:15 -0800107 },
108 methods: {
109 handleSubmit() {
Yoshie Muranaka5c977972020-04-30 09:48:23 -0700110 this.startLoader();
Yoshie Muranakac05ff642020-02-26 14:23:15 -0800111 const bootSettingsChanged =
112 this.$v.form.bootOption.$dirty || this.$v.form.oneTimeBoot.$dirty;
113 const tpmPolicyChanged = this.$v.form.tpmPolicyOn.$dirty;
114 let settings;
115 let bootSource = null;
116 let overrideEnabled = null;
117 let tpmEnabled = null;
118
119 if (bootSettingsChanged) {
120 // If bootSource or overrideEnabled changed get
121 // both current values to send with request
122 bootSource = this.form.bootOption;
123 overrideEnabled = this.form.oneTimeBoot;
124 }
125 if (tpmPolicyChanged) tpmEnabled = this.form.tpmPolicyOn;
126 settings = { bootSource, overrideEnabled, tpmEnabled };
127
128 this.$store
129 .dispatch('hostBootSettings/saveSettings', settings)
130 .then(message => this.successToast(message))
131 .catch(({ message }) => this.errorToast(message))
132 .finally(() => {
133 this.$v.form.$reset();
Yoshie Muranaka5c977972020-04-30 09:48:23 -0700134 this.endLoader();
Yoshie Muranakac05ff642020-02-26 14:23:15 -0800135 });
136 },
137 onChangeSelect(selectedOption) {
138 this.$v.form.bootOption.$touch();
139 // Disable one time boot if selected boot option is 'None'
140 if (selectedOption === 'None') this.form.oneTimeBoot = false;
141 }
142 }
143};
144</script>