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" |
Yoshie Muranaka | c05ff64 | 2020-02-26 14:23:15 -0800 | [diff] [blame] | 39 | aria-describedby="tpm-required-policy-help-block" |
| 40 | @change="$v.form.tpmPolicyOn.$touch()" |
| 41 | > |
SurenNeware | f295d1b | 2020-08-26 14:50:56 +0530 | [diff] [blame] | 42 | {{ $t('global.status.enabled') }} |
Yoshie Muranaka | c05ff64 | 2020-02-26 14:23:15 -0800 | [diff] [blame] | 43 | </b-form-checkbox> |
| 44 | </b-form-group> |
Dixsie Wolmers | 4d1dbb5 | 2020-08-24 21:43:25 -0500 | [diff] [blame] | 45 | <b-button variant="primary" type="submit" class="mb-3"> |
Yoshie Muranaka | c05ff64 | 2020-02-26 14:23:15 -0800 | [diff] [blame] | 46 | {{ $t('global.action.save') }} |
| 47 | </b-button> |
| 48 | </b-form> |
| 49 | </div> |
| 50 | </template> |
| 51 | |
| 52 | <script> |
| 53 | import { mapState } from 'vuex'; |
SurenNeware | f295d1b | 2020-08-26 14:50:56 +0530 | [diff] [blame] | 54 | import BVToastMixin from '@/components/Mixins/BVToastMixin'; |
Yoshie Muranaka | 5c97797 | 2020-04-30 09:48:23 -0700 | [diff] [blame] | 55 | import LoadingBarMixin from '@/components/Mixins/LoadingBarMixin'; |
Yoshie Muranaka | c05ff64 | 2020-02-26 14:23:15 -0800 | [diff] [blame] | 56 | |
| 57 | export default { |
| 58 | name: 'BootSettings', |
Yoshie Muranaka | 5c97797 | 2020-04-30 09:48:23 -0700 | [diff] [blame] | 59 | mixins: [BVToastMixin, LoadingBarMixin], |
Yoshie Muranaka | c05ff64 | 2020-02-26 14:23:15 -0800 | [diff] [blame] | 60 | data() { |
| 61 | return { |
| 62 | form: { |
Derick Montague | 71114fe | 2021-05-06 18:17:34 -0500 | [diff] [blame^] | 63 | bootOption: this.$store.getters['serverBootSettings/bootSource'], |
| 64 | oneTimeBoot: this.$store.getters['serverBootSettings/overrideEnabled'], |
| 65 | tpmPolicyOn: this.$store.getters['serverBootSettings/tpmEnabled'], |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 66 | }, |
Yoshie Muranaka | c05ff64 | 2020-02-26 14:23:15 -0800 | [diff] [blame] | 67 | }; |
| 68 | }, |
| 69 | computed: { |
Derick Montague | 71114fe | 2021-05-06 18:17:34 -0500 | [diff] [blame^] | 70 | ...mapState('serverBootSettings', [ |
Yoshie Muranaka | c05ff64 | 2020-02-26 14:23:15 -0800 | [diff] [blame] | 71 | 'bootSourceOptions', |
| 72 | 'bootSource', |
| 73 | 'overrideEnabled', |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 74 | 'tpmEnabled', |
| 75 | ]), |
Yoshie Muranaka | c05ff64 | 2020-02-26 14:23:15 -0800 | [diff] [blame] | 76 | }, |
| 77 | watch: { |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 78 | bootSource: function (value) { |
Yoshie Muranaka | c05ff64 | 2020-02-26 14:23:15 -0800 | [diff] [blame] | 79 | this.form.bootOption = value; |
| 80 | }, |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 81 | overrideEnabled: function (value) { |
Yoshie Muranaka | c05ff64 | 2020-02-26 14:23:15 -0800 | [diff] [blame] | 82 | this.form.oneTimeBoot = value; |
| 83 | }, |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 84 | tpmEnabled: function (value) { |
Yoshie Muranaka | c05ff64 | 2020-02-26 14:23:15 -0800 | [diff] [blame] | 85 | this.form.tpmPolicyOn = value; |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 86 | }, |
Yoshie Muranaka | c05ff64 | 2020-02-26 14:23:15 -0800 | [diff] [blame] | 87 | }, |
| 88 | validations: { |
| 89 | // Empty validations to leverage vuelidate form states |
| 90 | // to check for changed values |
| 91 | form: { |
| 92 | bootOption: {}, |
| 93 | oneTimeBoot: {}, |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 94 | tpmPolicyOn: {}, |
| 95 | }, |
Yoshie Muranaka | c05ff64 | 2020-02-26 14:23:15 -0800 | [diff] [blame] | 96 | }, |
| 97 | created() { |
Sukanya Pandey | 7f6edb6 | 2021-03-30 19:49:08 +0530 | [diff] [blame] | 98 | this.$store |
Derick Montague | 71114fe | 2021-05-06 18:17:34 -0500 | [diff] [blame^] | 99 | .dispatch('serverBootSettings/getTpmPolicy') |
Sukanya Pandey | 7f6edb6 | 2021-03-30 19:49:08 +0530 | [diff] [blame] | 100 | .finally(() => |
| 101 | this.$root.$emit('server-power-operations-boot-settings-complete') |
| 102 | ); |
Yoshie Muranaka | c05ff64 | 2020-02-26 14:23:15 -0800 | [diff] [blame] | 103 | }, |
| 104 | methods: { |
| 105 | handleSubmit() { |
Yoshie Muranaka | 5c97797 | 2020-04-30 09:48:23 -0700 | [diff] [blame] | 106 | this.startLoader(); |
Yoshie Muranaka | c05ff64 | 2020-02-26 14:23:15 -0800 | [diff] [blame] | 107 | const bootSettingsChanged = |
| 108 | this.$v.form.bootOption.$dirty || this.$v.form.oneTimeBoot.$dirty; |
| 109 | const tpmPolicyChanged = this.$v.form.tpmPolicyOn.$dirty; |
| 110 | let settings; |
| 111 | let bootSource = null; |
| 112 | let overrideEnabled = null; |
| 113 | let tpmEnabled = null; |
| 114 | |
| 115 | if (bootSettingsChanged) { |
| 116 | // If bootSource or overrideEnabled changed get |
| 117 | // both current values to send with request |
| 118 | bootSource = this.form.bootOption; |
| 119 | overrideEnabled = this.form.oneTimeBoot; |
| 120 | } |
| 121 | if (tpmPolicyChanged) tpmEnabled = this.form.tpmPolicyOn; |
| 122 | settings = { bootSource, overrideEnabled, tpmEnabled }; |
| 123 | |
| 124 | this.$store |
Derick Montague | 71114fe | 2021-05-06 18:17:34 -0500 | [diff] [blame^] | 125 | .dispatch('serverBootSettings/saveSettings', settings) |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 126 | .then((message) => this.successToast(message)) |
Yoshie Muranaka | c05ff64 | 2020-02-26 14:23:15 -0800 | [diff] [blame] | 127 | .catch(({ message }) => this.errorToast(message)) |
| 128 | .finally(() => { |
| 129 | this.$v.form.$reset(); |
Yoshie Muranaka | 5c97797 | 2020-04-30 09:48:23 -0700 | [diff] [blame] | 130 | this.endLoader(); |
Yoshie Muranaka | c05ff64 | 2020-02-26 14:23:15 -0800 | [diff] [blame] | 131 | }); |
| 132 | }, |
| 133 | onChangeSelect(selectedOption) { |
| 134 | this.$v.form.bootOption.$touch(); |
| 135 | // Disable one time boot if selected boot option is 'None' |
| 136 | if (selectedOption === 'None') this.form.oneTimeBoot = false; |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 137 | }, |
| 138 | }, |
Yoshie Muranaka | c05ff64 | 2020-02-26 14:23:15 -0800 | [diff] [blame] | 139 | }; |
| 140 | </script> |