Yoshie Muranaka | c05ff64 | 2020-02-26 14:23:15 -0800 | [diff] [blame] | 1 | <template> |
Dixsie Wolmers | d7e7a16 | 2020-07-20 18:35:33 -0500 | [diff] [blame] | 2 | <div class="form-background p-3"> |
Yoshie Muranaka | c05ff64 | 2020-02-26 14:23:15 -0800 | [diff] [blame] | 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> |
Dixsie Wolmers | 4d1dbb5 | 2020-08-24 21:43:25 -0500 | [diff] [blame] | 48 | <b-button variant="primary" type="submit" class="mb-3"> |
Yoshie Muranaka | c05ff64 | 2020-02-26 14:23:15 -0800 | [diff] [blame] | 49 | {{ $t('global.action.save') }} |
| 50 | </b-button> |
| 51 | </b-form> |
| 52 | </div> |
| 53 | </template> |
| 54 | |
| 55 | <script> |
| 56 | import { mapState } from 'vuex'; |
| 57 | import BVToastMixin from '../../../components/Mixins/BVToastMixin'; |
Yoshie Muranaka | 5c97797 | 2020-04-30 09:48:23 -0700 | [diff] [blame] | 58 | import LoadingBarMixin from '@/components/Mixins/LoadingBarMixin'; |
Yoshie Muranaka | c05ff64 | 2020-02-26 14:23:15 -0800 | [diff] [blame] | 59 | |
| 60 | export default { |
| 61 | name: 'BootSettings', |
Yoshie Muranaka | 5c97797 | 2020-04-30 09:48:23 -0700 | [diff] [blame] | 62 | mixins: [BVToastMixin, LoadingBarMixin], |
Yoshie Muranaka | c05ff64 | 2020-02-26 14:23:15 -0800 | [diff] [blame] | 63 | 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 Muranaka | 5c97797 | 2020-04-30 09:48:23 -0700 | [diff] [blame] | 101 | Promise.all([ |
| 102 | this.$store.dispatch('hostBootSettings/getBootSettings'), |
| 103 | this.$store.dispatch('hostBootSettings/getTpmPolicy') |
Dixsie Wolmers | bb31606 | 2020-08-04 19:17:33 -0500 | [diff] [blame] | 104 | ]).finally(() => |
| 105 | this.$root.$emit('serverPowerOperations::bootSettings::complete') |
| 106 | ); |
Yoshie Muranaka | c05ff64 | 2020-02-26 14:23:15 -0800 | [diff] [blame] | 107 | }, |
| 108 | methods: { |
| 109 | handleSubmit() { |
Yoshie Muranaka | 5c97797 | 2020-04-30 09:48:23 -0700 | [diff] [blame] | 110 | this.startLoader(); |
Yoshie Muranaka | c05ff64 | 2020-02-26 14:23:15 -0800 | [diff] [blame] | 111 | 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 Muranaka | 5c97797 | 2020-04-30 09:48:23 -0700 | [diff] [blame] | 134 | this.endLoader(); |
Yoshie Muranaka | c05ff64 | 2020-02-26 14:23:15 -0800 | [diff] [blame] | 135 | }); |
| 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> |