blob: c912749fd3ac8be94108ccd625e7cf12ffdfd873 [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';
63
64export default {
65 name: 'BootSettings',
66 mixins: [BVToastMixin],
67 data() {
68 return {
69 form: {
70 bootOption: this.$store.getters['hostBootSettings/bootSource'],
71 oneTimeBoot: this.$store.getters['hostBootSettings/overrideEnabled'],
72 tpmPolicyOn: this.$store.getters['hostBootSettings/tpmEnabled']
73 }
74 };
75 },
76 computed: {
77 ...mapState('hostBootSettings', [
78 'bootSourceOptions',
79 'bootSource',
80 'overrideEnabled',
81 'tpmEnabled'
82 ])
83 },
84 watch: {
85 bootSource: function(value) {
86 this.form.bootOption = value;
87 },
88 overrideEnabled: function(value) {
89 this.form.oneTimeBoot = value;
90 },
91 tpmEnabled: function(value) {
92 this.form.tpmPolicyOn = value;
93 }
94 },
95 validations: {
96 // Empty validations to leverage vuelidate form states
97 // to check for changed values
98 form: {
99 bootOption: {},
100 oneTimeBoot: {},
101 tpmPolicyOn: {}
102 }
103 },
104 created() {
105 this.$store.dispatch('hostBootSettings/getBootSettings');
106 this.$store.dispatch('hostBootSettings/getTpmPolicy');
107 },
108 methods: {
109 handleSubmit() {
110 const bootSettingsChanged =
111 this.$v.form.bootOption.$dirty || this.$v.form.oneTimeBoot.$dirty;
112 const tpmPolicyChanged = this.$v.form.tpmPolicyOn.$dirty;
113 let settings;
114 let bootSource = null;
115 let overrideEnabled = null;
116 let tpmEnabled = null;
117
118 if (bootSettingsChanged) {
119 // If bootSource or overrideEnabled changed get
120 // both current values to send with request
121 bootSource = this.form.bootOption;
122 overrideEnabled = this.form.oneTimeBoot;
123 }
124 if (tpmPolicyChanged) tpmEnabled = this.form.tpmPolicyOn;
125 settings = { bootSource, overrideEnabled, tpmEnabled };
126
127 this.$store
128 .dispatch('hostBootSettings/saveSettings', settings)
129 .then(message => this.successToast(message))
130 .catch(({ message }) => this.errorToast(message))
131 .finally(() => {
132 this.$v.form.$reset();
133 });
134 },
135 onChangeSelect(selectedOption) {
136 this.$v.form.bootOption.$touch();
137 // Disable one time boot if selected boot option is 'None'
138 if (selectedOption === 'None') this.form.oneTimeBoot = false;
139 }
140 }
141};
142</script>
143
144<style lang="scss" scoped>
145.boot-settings {
146 background-color: $gray-200;
147}
148</style>