blob: 3435f1c658fa212152d503a6d508ae06f9f8d7f2 [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"
Yoshie Muranakac05ff642020-02-26 14:23:15 -080039 aria-describedby="tpm-required-policy-help-block"
40 @change="$v.form.tpmPolicyOn.$touch()"
41 >
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';
Yoshie Muranakac05ff642020-02-26 14:23:15 -080056
57export default {
58 name: 'BootSettings',
Yoshie Muranaka5c977972020-04-30 09:48:23 -070059 mixins: [BVToastMixin, LoadingBarMixin],
Yoshie Muranakac05ff642020-02-26 14:23:15 -080060 data() {
61 return {
62 form: {
63 bootOption: this.$store.getters['hostBootSettings/bootSource'],
64 oneTimeBoot: this.$store.getters['hostBootSettings/overrideEnabled'],
65 tpmPolicyOn: this.$store.getters['hostBootSettings/tpmEnabled']
66 }
67 };
68 },
69 computed: {
70 ...mapState('hostBootSettings', [
71 'bootSourceOptions',
72 'bootSource',
73 'overrideEnabled',
74 'tpmEnabled'
75 ])
76 },
77 watch: {
78 bootSource: function(value) {
79 this.form.bootOption = value;
80 },
81 overrideEnabled: function(value) {
82 this.form.oneTimeBoot = value;
83 },
84 tpmEnabled: function(value) {
85 this.form.tpmPolicyOn = value;
86 }
87 },
88 validations: {
89 // Empty validations to leverage vuelidate form states
90 // to check for changed values
91 form: {
92 bootOption: {},
93 oneTimeBoot: {},
94 tpmPolicyOn: {}
95 }
96 },
97 created() {
Yoshie Muranaka5c977972020-04-30 09:48:23 -070098 Promise.all([
99 this.$store.dispatch('hostBootSettings/getBootSettings'),
100 this.$store.dispatch('hostBootSettings/getTpmPolicy')
Dixsie Wolmersbb316062020-08-04 19:17:33 -0500101 ]).finally(() =>
102 this.$root.$emit('serverPowerOperations::bootSettings::complete')
103 );
Yoshie Muranakac05ff642020-02-26 14:23:15 -0800104 },
105 methods: {
106 handleSubmit() {
Yoshie Muranaka5c977972020-04-30 09:48:23 -0700107 this.startLoader();
Yoshie Muranakac05ff642020-02-26 14:23:15 -0800108 const bootSettingsChanged =
109 this.$v.form.bootOption.$dirty || this.$v.form.oneTimeBoot.$dirty;
110 const tpmPolicyChanged = this.$v.form.tpmPolicyOn.$dirty;
111 let settings;
112 let bootSource = null;
113 let overrideEnabled = null;
114 let tpmEnabled = null;
115
116 if (bootSettingsChanged) {
117 // If bootSource or overrideEnabled changed get
118 // both current values to send with request
119 bootSource = this.form.bootOption;
120 overrideEnabled = this.form.oneTimeBoot;
121 }
122 if (tpmPolicyChanged) tpmEnabled = this.form.tpmPolicyOn;
123 settings = { bootSource, overrideEnabled, tpmEnabled };
124
125 this.$store
126 .dispatch('hostBootSettings/saveSettings', settings)
127 .then(message => this.successToast(message))
128 .catch(({ message }) => this.errorToast(message))
129 .finally(() => {
130 this.$v.form.$reset();
Yoshie Muranaka5c977972020-04-30 09:48:23 -0700131 this.endLoader();
Yoshie Muranakac05ff642020-02-26 14:23:15 -0800132 });
133 },
134 onChangeSelect(selectedOption) {
135 this.$v.form.bootOption.$touch();
136 // Disable one time boot if selected boot option is 'None'
137 if (selectedOption === 'None') this.form.oneTimeBoot = false;
138 }
139 }
140};
141</script>