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