blob: 16d567a7119f0c9a18a161d78be7690a287f52f8 [file] [log] [blame]
Yoshie Muranakac05ff642020-02-26 14:23:15 -08001<template>
2 <div class="boot-settings p-3">
3 <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')
109 ]).finally(() => this.endLoader());
Yoshie Muranakac05ff642020-02-26 14:23:15 -0800110 },
111 methods: {
112 handleSubmit() {
Yoshie Muranaka5c977972020-04-30 09:48:23 -0700113 this.startLoader();
Yoshie Muranakac05ff642020-02-26 14:23:15 -0800114 const bootSettingsChanged =
115 this.$v.form.bootOption.$dirty || this.$v.form.oneTimeBoot.$dirty;
116 const tpmPolicyChanged = this.$v.form.tpmPolicyOn.$dirty;
117 let settings;
118 let bootSource = null;
119 let overrideEnabled = null;
120 let tpmEnabled = null;
121
122 if (bootSettingsChanged) {
123 // If bootSource or overrideEnabled changed get
124 // both current values to send with request
125 bootSource = this.form.bootOption;
126 overrideEnabled = this.form.oneTimeBoot;
127 }
128 if (tpmPolicyChanged) tpmEnabled = this.form.tpmPolicyOn;
129 settings = { bootSource, overrideEnabled, tpmEnabled };
130
131 this.$store
132 .dispatch('hostBootSettings/saveSettings', settings)
133 .then(message => this.successToast(message))
134 .catch(({ message }) => this.errorToast(message))
135 .finally(() => {
136 this.$v.form.$reset();
Yoshie Muranaka5c977972020-04-30 09:48:23 -0700137 this.endLoader();
Yoshie Muranakac05ff642020-02-26 14:23:15 -0800138 });
139 },
140 onChangeSelect(selectedOption) {
141 this.$v.form.bootOption.$touch();
142 // Disable one time boot if selected boot option is 'None'
143 if (selectedOption === 'None') this.form.oneTimeBoot = false;
144 }
145 }
146};
147</script>
148
149<style lang="scss" scoped>
Derick Montague40865722020-04-13 17:01:19 -0500150@import 'src/assets/styles/helpers';
151
Yoshie Muranakac05ff642020-02-26 14:23:15 -0800152.boot-settings {
Derick Montague40865722020-04-13 17:01:19 -0500153 background-color: gray('200');
Yoshie Muranakac05ff642020-02-26 14:23:15 -0800154}
155</style>