1<template> 2 <b-container fluid="xl"> 3 <page-title /> 4 <b-row class="mb-4"> 5 <b-col md="8" xl="6"> 6 <page-section 7 :section-title="$t('pageServerPowerOperations.currentStatus')" 8 > 9 <b-row> 10 <b-col> 11 <dl> 12 <dt>{{ $t('pageServerPowerOperations.serverStatus') }}</dt> 13 <dd 14 v-if="serverStatus === 'on'" 15 data-test-id="powerServerOps-text-hostStatus" 16 > 17 {{ $t('global.status.on') }} 18 </dd> 19 <dd 20 v-else-if="serverStatus === 'off'" 21 data-test-id="powerServerOps-text-hostStatus" 22 > 23 {{ $t('global.status.off') }} 24 </dd> 25 <dd v-else> 26 {{ $t('global.status.notAvailable') }} 27 </dd> 28 </dl> 29 </b-col> 30 </b-row> 31 <b-row> 32 <b-col> 33 <dl> 34 <dt> 35 {{ $t('pageServerPowerOperations.lastPowerOperation') }} 36 </dt> 37 <dd 38 v-if="lastPowerOperationTime" 39 data-test-id="powerServerOps-text-lastPowerOp" 40 > 41 {{ lastPowerOperationTime | formatDate }} 42 {{ lastPowerOperationTime | formatTime }} 43 </dd> 44 <dd v-else>--</dd> 45 </dl> 46 </b-col> 47 </b-row> 48 </page-section> 49 </b-col> 50 </b-row> 51 <b-row> 52 <b-col v-if="hasBootSourceOptions" sm="8" md="6" xl="4"> 53 <page-section 54 :section-title="$t('pageServerPowerOperations.serverBootSettings')" 55 > 56 <boot-settings /> 57 </page-section> 58 </b-col> 59 <b-col sm="8" md="6" xl="7"> 60 <page-section 61 :section-title="$t('pageServerPowerOperations.operations')" 62 > 63 <alert :show="oneTimeBootEnabled" variant="warning"> 64 {{ $t('pageServerPowerOperations.oneTimeBootWarning') }} 65 </alert> 66 <template v-if="isOperationInProgress"> 67 <alert variant="info"> 68 {{ $t('pageServerPowerOperations.operationInProgress') }} 69 </alert> 70 </template> 71 <template v-else-if="serverStatus === 'off'"> 72 <b-button 73 variant="primary" 74 data-test-id="serverPowerOperations-button-powerOn" 75 @click="powerOn" 76 > 77 {{ $t('pageServerPowerOperations.powerOn') }} 78 </b-button> 79 </template> 80 <template v-else> 81 <!-- Reboot server options --> 82 <b-form novalidate class="mb-5" @submit.prevent="rebootServer"> 83 <b-form-group 84 :label="$t('pageServerPowerOperations.rebootServer')" 85 > 86 <b-form-radio 87 v-model="form.rebootOption" 88 name="reboot-option" 89 data-test-id="serverPowerOperations-radio-rebootOrderly" 90 value="orderly" 91 > 92 {{ $t('pageServerPowerOperations.orderlyReboot') }} 93 </b-form-radio> 94 <b-form-radio 95 v-model="form.rebootOption" 96 name="reboot-option" 97 data-test-id="serverPowerOperations-radio-rebootImmediate" 98 value="immediate" 99 > 100 {{ $t('pageServerPowerOperations.immediateReboot') }} 101 </b-form-radio> 102 </b-form-group> 103 <b-button 104 variant="primary" 105 type="submit" 106 data-test-id="serverPowerOperations-button-reboot" 107 > 108 {{ $t('pageServerPowerOperations.reboot') }} 109 </b-button> 110 </b-form> 111 <!-- Shutdown server options --> 112 <b-form novalidate @submit.prevent="shutdownServer"> 113 <b-form-group 114 :label="$t('pageServerPowerOperations.shutdownServer')" 115 > 116 <b-form-radio 117 v-model="form.shutdownOption" 118 name="shutdown-option" 119 data-test-id="serverPowerOperations-radio-shutdownOrderly" 120 value="orderly" 121 > 122 {{ $t('pageServerPowerOperations.orderlyShutdown') }} 123 </b-form-radio> 124 <b-form-radio 125 v-model="form.shutdownOption" 126 name="shutdown-option" 127 data-test-id="serverPowerOperations-radio-shutdownImmediate" 128 value="immediate" 129 > 130 {{ $t('pageServerPowerOperations.immediateShutdown') }} 131 </b-form-radio> 132 </b-form-group> 133 <b-button 134 variant="primary" 135 type="submit" 136 data-test-id="serverPowerOperations-button-shutDown" 137 > 138 {{ $t('pageServerPowerOperations.shutDown') }} 139 </b-button> 140 </b-form> 141 </template> 142 </page-section> 143 </b-col> 144 </b-row> 145 </b-container> 146</template> 147 148<script> 149import PageTitle from '@/components/Global/PageTitle'; 150import PageSection from '@/components/Global/PageSection'; 151import BVToastMixin from '@/components/Mixins/BVToastMixin'; 152import BootSettings from './BootSettings'; 153import LoadingBarMixin from '@/components/Mixins/LoadingBarMixin'; 154import Alert from '@/components/Global/Alert'; 155 156export default { 157 name: 'ServerPowerOperations', 158 components: { PageTitle, PageSection, BootSettings, Alert }, 159 mixins: [BVToastMixin, LoadingBarMixin], 160 beforeRouteLeave(to, from, next) { 161 this.hideLoader(); 162 next(); 163 }, 164 data() { 165 return { 166 form: { 167 rebootOption: 'orderly', 168 shutdownOption: 'orderly', 169 }, 170 }; 171 }, 172 computed: { 173 serverStatus() { 174 return this.$store.getters['global/serverStatus']; 175 }, 176 isOperationInProgress() { 177 return this.$store.getters['controls/isOperationInProgress']; 178 }, 179 lastPowerOperationTime() { 180 return this.$store.getters['controls/lastPowerOperationTime']; 181 }, 182 oneTimeBootEnabled() { 183 return this.$store.getters['serverBootSettings/overrideEnabled']; 184 }, 185 hasBootSourceOptions() { 186 let bootOptions = this.$store.getters[ 187 'serverBootSettings/bootSourceOptions' 188 ]; 189 return bootOptions.length !== 0; 190 }, 191 }, 192 created() { 193 this.startLoader(); 194 const bootSettingsPromise = new Promise((resolve) => { 195 this.$root.$on('server-power-operations-boot-settings-complete', () => 196 resolve() 197 ); 198 }); 199 Promise.all([ 200 this.$store.dispatch('serverBootSettings/getBootSettings'), 201 this.$store.dispatch('controls/getLastPowerOperationTime'), 202 bootSettingsPromise, 203 ]).finally(() => this.endLoader()); 204 }, 205 methods: { 206 powerOn() { 207 this.$store.dispatch('controls/serverPowerOn'); 208 }, 209 rebootServer() { 210 const modalMessage = this.$t( 211 'pageServerPowerOperations.modal.confirmRebootMessage' 212 ); 213 const modalOptions = { 214 title: this.$t('pageServerPowerOperations.modal.confirmRebootTitle'), 215 okTitle: this.$t('global.action.confirm'), 216 cancelTitle: this.$t('global.action.cancel'), 217 }; 218 219 if (this.form.rebootOption === 'orderly') { 220 this.$bvModal 221 .msgBoxConfirm(modalMessage, modalOptions) 222 .then((confirmed) => { 223 if (confirmed) this.$store.dispatch('controls/serverSoftReboot'); 224 }); 225 } else if (this.form.rebootOption === 'immediate') { 226 this.$bvModal 227 .msgBoxConfirm(modalMessage, modalOptions) 228 .then((confirmed) => { 229 if (confirmed) this.$store.dispatch('controls/serverHardReboot'); 230 }); 231 } 232 }, 233 shutdownServer() { 234 const modalMessage = this.$t( 235 'pageServerPowerOperations.modal.confirmShutdownMessage' 236 ); 237 const modalOptions = { 238 title: this.$t('pageServerPowerOperations.modal.confirmShutdownTitle'), 239 okTitle: this.$t('global.action.confirm'), 240 cancelTitle: this.$t('global.action.cancel'), 241 }; 242 243 if (this.form.shutdownOption === 'orderly') { 244 this.$bvModal 245 .msgBoxConfirm(modalMessage, modalOptions) 246 .then((confirmed) => { 247 if (confirmed) this.$store.dispatch('controls/serverSoftPowerOff'); 248 }); 249 } 250 if (this.form.shutdownOption === 'immediate') { 251 this.$bvModal 252 .msgBoxConfirm(modalMessage, modalOptions) 253 .then((confirmed) => { 254 if (confirmed) this.$store.dispatch('controls/serverHardPowerOff'); 255 }); 256 } 257 }, 258 }, 259}; 260</script> 261