| Yoshie Muranaka | c05ff64 | 2020-02-26 14:23:15 -0800 | [diff] [blame] | 1 | <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> | 
|  | 61 | import { mapState } from 'vuex'; | 
|  | 62 | import BVToastMixin from '../../../components/Mixins/BVToastMixin'; | 
| Yoshie Muranaka | 5c97797 | 2020-04-30 09:48:23 -0700 | [diff] [blame] | 63 | import LoadingBarMixin from '@/components/Mixins/LoadingBarMixin'; | 
| Yoshie Muranaka | c05ff64 | 2020-02-26 14:23:15 -0800 | [diff] [blame] | 64 |  | 
|  | 65 | export default { | 
|  | 66 | name: 'BootSettings', | 
| Yoshie Muranaka | 5c97797 | 2020-04-30 09:48:23 -0700 | [diff] [blame] | 67 | mixins: [BVToastMixin, LoadingBarMixin], | 
| Yoshie Muranaka | c05ff64 | 2020-02-26 14:23:15 -0800 | [diff] [blame] | 68 | 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 Muranaka | 5c97797 | 2020-04-30 09:48:23 -0700 | [diff] [blame] | 106 | Promise.all([ | 
|  | 107 | this.$store.dispatch('hostBootSettings/getBootSettings'), | 
|  | 108 | this.$store.dispatch('hostBootSettings/getTpmPolicy') | 
|  | 109 | ]).finally(() => this.endLoader()); | 
| Yoshie Muranaka | c05ff64 | 2020-02-26 14:23:15 -0800 | [diff] [blame] | 110 | }, | 
|  | 111 | methods: { | 
|  | 112 | handleSubmit() { | 
| Yoshie Muranaka | 5c97797 | 2020-04-30 09:48:23 -0700 | [diff] [blame] | 113 | this.startLoader(); | 
| Yoshie Muranaka | c05ff64 | 2020-02-26 14:23:15 -0800 | [diff] [blame] | 114 | 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 Muranaka | 5c97797 | 2020-04-30 09:48:23 -0700 | [diff] [blame] | 137 | this.endLoader(); | 
| Yoshie Muranaka | c05ff64 | 2020-02-26 14:23:15 -0800 | [diff] [blame] | 138 | }); | 
|  | 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 Montague | 4086572 | 2020-04-13 17:01:19 -0500 | [diff] [blame] | 150 | @import 'src/assets/styles/helpers'; | 
|  | 151 |  | 
| Yoshie Muranaka | c05ff64 | 2020-02-26 14:23:15 -0800 | [diff] [blame] | 152 | .boot-settings { | 
| Derick Montague | 4086572 | 2020-04-13 17:01:19 -0500 | [diff] [blame] | 153 | background-color: gray('200'); | 
| Yoshie Muranaka | c05ff64 | 2020-02-26 14:23:15 -0800 | [diff] [blame] | 154 | } | 
|  | 155 | </style> |