| Mateusz Gapski | 7510046 | 2020-07-30 11:01:29 +0200 | [diff] [blame] | 1 | <template> |
| 2 | <b-container fluid="xl"> |
| 3 | <page-title /> |
| 4 | <b-row class="mb-4"> |
| 5 | <b-col md="12"> |
| 6 | <page-section |
| 7 | :section-title="$t('pageVirtualMedia.virtualMediaSubTitleFirst')" |
| 8 | > |
| 9 | <b-row> |
| 10 | <b-col v-for="(dev, $index) in proxyDevices" :key="$index" md="6"> |
| SurenNeware | 978807d | 2020-09-03 18:35:21 +0530 | [diff] [blame] | 11 | <b-form-group :label="dev.id" label-class="bold"> |
| 12 | <form-file |
| 13 | v-if="!dev.isActive" |
| 14 | :id="concatId(dev.id)" |
| Mateusz Gapski | 7510046 | 2020-07-30 11:01:29 +0200 | [diff] [blame] | 15 | v-model="dev.file" |
| SurenNeware | 978807d | 2020-09-03 18:35:21 +0530 | [diff] [blame] | 16 | > |
| 17 | <template #invalid> |
| 18 | <b-form-invalid-feedback role="alert"> |
| Derick Montague | d1ff01e | 2021-01-04 11:56:23 -0600 | [diff] [blame] | 19 | {{ $t('global.form.required') }} |
| SurenNeware | 978807d | 2020-09-03 18:35:21 +0530 | [diff] [blame] | 20 | </b-form-invalid-feedback> |
| 21 | </template> |
| 22 | </form-file> |
| Mateusz Gapski | 7510046 | 2020-07-30 11:01:29 +0200 | [diff] [blame] | 23 | </b-form-group> |
| 24 | <b-button |
| 25 | v-if="!dev.isActive" |
| 26 | variant="primary" |
| 27 | :disabled="!dev.file" |
| 28 | @click="startVM(dev)" |
| 29 | > |
| Mateusz Gapski | 2224ece | 2020-09-02 17:00:06 +0200 | [diff] [blame] | 30 | {{ $t('pageVirtualMedia.start') }} |
| Mateusz Gapski | 7510046 | 2020-07-30 11:01:29 +0200 | [diff] [blame] | 31 | </b-button> |
| 32 | <b-button |
| 33 | v-if="dev.isActive" |
| 34 | variant="primary" |
| 35 | :disabled="!dev.file" |
| 36 | @click="stopVM(dev)" |
| 37 | > |
| Mateusz Gapski | 2224ece | 2020-09-02 17:00:06 +0200 | [diff] [blame] | 38 | {{ $t('pageVirtualMedia.stop') }} |
| Mateusz Gapski | 7510046 | 2020-07-30 11:01:29 +0200 | [diff] [blame] | 39 | </b-button> |
| 40 | </b-col> |
| 41 | </b-row> |
| 42 | </page-section> |
| 43 | </b-col> |
| 44 | </b-row> |
| 45 | <b-row v-if="loadImageFromExternalServer" class="mb-4"> |
| 46 | <b-col md="12"> |
| 47 | <page-section |
| 48 | :section-title="$t('pageVirtualMedia.virtualMediaSubTitleSecond')" |
| 49 | > |
| 50 | <b-row> |
| 51 | <b-col |
| 52 | v-for="(device, $index) in legacyDevices" |
| 53 | :key="$index" |
| 54 | md="6" |
| 55 | > |
| 56 | <b-form-group |
| 57 | :label="device.id" |
| 58 | :label-for="device.id" |
| 59 | label-class="bold" |
| 60 | > |
| Mateusz Gapski | 2224ece | 2020-09-02 17:00:06 +0200 | [diff] [blame] | 61 | <b-button |
| 62 | variant="primary" |
| 63 | :disabled="device.isActive" |
| 64 | @click="configureConnection(device)" |
| 65 | > |
| Mateusz Gapski | 7510046 | 2020-07-30 11:01:29 +0200 | [diff] [blame] | 66 | {{ $t('pageVirtualMedia.configureConnection') }} |
| 67 | </b-button> |
| 68 | |
| 69 | <b-button |
| Mateusz Gapski | 2224ece | 2020-09-02 17:00:06 +0200 | [diff] [blame] | 70 | v-if="!device.isActive" |
| Mateusz Gapski | 7510046 | 2020-07-30 11:01:29 +0200 | [diff] [blame] | 71 | variant="primary" |
| jason westover | d36ac8a | 2025-11-03 20:58:59 -0600 | [diff] [blame^] | 72 | class="float-end" |
| Mateusz Gapski | 2224ece | 2020-09-02 17:00:06 +0200 | [diff] [blame] | 73 | :disabled="!device.serverUri" |
| Mateusz Gapski | 7510046 | 2020-07-30 11:01:29 +0200 | [diff] [blame] | 74 | @click="startLegacy(device)" |
| 75 | > |
| Mateusz Gapski | 2224ece | 2020-09-02 17:00:06 +0200 | [diff] [blame] | 76 | {{ $t('pageVirtualMedia.start') }} |
| 77 | </b-button> |
| 78 | <b-button |
| 79 | v-if="device.isActive" |
| 80 | variant="primary" |
| jason westover | d36ac8a | 2025-11-03 20:58:59 -0600 | [diff] [blame^] | 81 | class="float-end" |
| Mateusz Gapski | 2224ece | 2020-09-02 17:00:06 +0200 | [diff] [blame] | 82 | @click="stopLegacy(device)" |
| 83 | > |
| 84 | {{ $t('pageVirtualMedia.stop') }} |
| Mateusz Gapski | 7510046 | 2020-07-30 11:01:29 +0200 | [diff] [blame] | 85 | </b-button> |
| 86 | </b-form-group> |
| 87 | </b-col> |
| 88 | </b-row> |
| 89 | </page-section> |
| 90 | </b-col> |
| 91 | </b-row> |
| Mateusz Gapski | 2224ece | 2020-09-02 17:00:06 +0200 | [diff] [blame] | 92 | <modal-configure-connection |
| jason westover | d36ac8a | 2025-11-03 20:58:59 -0600 | [diff] [blame^] | 93 | v-model="showConfigureConnectionModal" |
| Mateusz Gapski | 2224ece | 2020-09-02 17:00:06 +0200 | [diff] [blame] | 94 | :connection="modalConfigureConnection" |
| 95 | @ok="saveConnection" |
| 96 | /> |
| Mateusz Gapski | 7510046 | 2020-07-30 11:01:29 +0200 | [diff] [blame] | 97 | </b-container> |
| 98 | </template> |
| 99 | |
| 100 | <script> |
| 101 | import PageTitle from '@/components/Global/PageTitle'; |
| 102 | import PageSection from '@/components/Global/PageSection'; |
| 103 | import BVToastMixin from '@/components/Mixins/BVToastMixin'; |
| 104 | import LoadingBarMixin from '@/components/Mixins/LoadingBarMixin'; |
| Mateusz Gapski | 2224ece | 2020-09-02 17:00:06 +0200 | [diff] [blame] | 105 | import ModalConfigureConnection from './ModalConfigureConnection'; |
| Mateusz Gapski | 7510046 | 2020-07-30 11:01:29 +0200 | [diff] [blame] | 106 | import NbdServer from '@/utilities/NBDServer'; |
| SurenNeware | 978807d | 2020-09-03 18:35:21 +0530 | [diff] [blame] | 107 | import FormFile from '@/components/Global/FormFile'; |
| Surya V | de23ea2 | 2024-07-11 15:19:46 +0530 | [diff] [blame] | 108 | import { useI18n } from 'vue-i18n'; |
| 109 | import i18n from '@/i18n'; |
| jason westover | d36ac8a | 2025-11-03 20:58:59 -0600 | [diff] [blame^] | 110 | import { useModal } from 'bootstrap-vue-next'; |
| Mateusz Gapski | 7510046 | 2020-07-30 11:01:29 +0200 | [diff] [blame] | 111 | |
| 112 | export default { |
| 113 | name: 'VirtualMedia', |
| SurenNeware | 978807d | 2020-09-03 18:35:21 +0530 | [diff] [blame] | 114 | components: { PageTitle, PageSection, ModalConfigureConnection, FormFile }, |
| Mateusz Gapski | 7510046 | 2020-07-30 11:01:29 +0200 | [diff] [blame] | 115 | mixins: [BVToastMixin, LoadingBarMixin], |
| jason westover | d36ac8a | 2025-11-03 20:58:59 -0600 | [diff] [blame^] | 116 | setup() { |
| 117 | const bvModal = useModal(); |
| 118 | return { bvModal }; |
| 119 | }, |
| Mateusz Gapski | 7510046 | 2020-07-30 11:01:29 +0200 | [diff] [blame] | 120 | data() { |
| 121 | return { |
| Surya V | de23ea2 | 2024-07-11 15:19:46 +0530 | [diff] [blame] | 122 | $t: useI18n().t, |
| Mateusz Gapski | 2224ece | 2020-09-02 17:00:06 +0200 | [diff] [blame] | 123 | modalConfigureConnection: null, |
| jason westover | d36ac8a | 2025-11-03 20:58:59 -0600 | [diff] [blame^] | 124 | showConfigureConnectionModal: false, |
| Mateusz Gapski | 7510046 | 2020-07-30 11:01:29 +0200 | [diff] [blame] | 125 | loadImageFromExternalServer: |
| Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 126 | process.env.VUE_APP_VIRTUAL_MEDIA_LIST_ENABLED === 'true' |
| 127 | ? true |
| 128 | : false, |
| Mateusz Gapski | 7510046 | 2020-07-30 11:01:29 +0200 | [diff] [blame] | 129 | }; |
| 130 | }, |
| 131 | computed: { |
| 132 | proxyDevices() { |
| 133 | return this.$store.getters['virtualMedia/proxyDevices']; |
| 134 | }, |
| 135 | legacyDevices() { |
| 136 | return this.$store.getters['virtualMedia/legacyDevices']; |
| Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 137 | }, |
| Mateusz Gapski | 7510046 | 2020-07-30 11:01:29 +0200 | [diff] [blame] | 138 | }, |
| 139 | created() { |
| kirankumarb07 | e78d10b | 2023-03-03 12:10:29 +0530 | [diff] [blame] | 140 | this.$store.dispatch('global/getSystemInfo'); |
| Mateusz Gapski | 7510046 | 2020-07-30 11:01:29 +0200 | [diff] [blame] | 141 | if (this.proxyDevices.length > 0 || this.legacyDevices.length > 0) return; |
| 142 | this.startLoader(); |
| 143 | this.$store |
| 144 | .dispatch('virtualMedia/getData') |
| 145 | .finally(() => this.endLoader()); |
| 146 | }, |
| 147 | methods: { |
| 148 | startVM(device) { |
| 149 | const token = this.$store.getters['authentication/token']; |
| 150 | device.nbd = new NbdServer( |
| 151 | `wss://${window.location.host}${device.websocket}`, |
| 152 | device.file, |
| 153 | device.id, |
| Ed Tanous | 8132399 | 2024-02-27 11:26:24 -0800 | [diff] [blame] | 154 | token, |
| Mateusz Gapski | 7510046 | 2020-07-30 11:01:29 +0200 | [diff] [blame] | 155 | ); |
| 156 | device.nbd.socketStarted = () => |
| Surya V | de23ea2 | 2024-07-11 15:19:46 +0530 | [diff] [blame] | 157 | this.successToast( |
| 158 | i18n.global.t('pageVirtualMedia.toast.serverRunning'), |
| 159 | ); |
| Mateusz Gapski | 7510046 | 2020-07-30 11:01:29 +0200 | [diff] [blame] | 160 | device.nbd.errorReadingFile = () => |
| Surya V | de23ea2 | 2024-07-11 15:19:46 +0530 | [diff] [blame] | 161 | this.errorToast( |
| 162 | i18n.global.t('pageVirtualMedia.toast.errorReadingFile'), |
| 163 | ); |
| Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 164 | device.nbd.socketClosed = (code) => { |
| Mateusz Gapski | 7510046 | 2020-07-30 11:01:29 +0200 | [diff] [blame] | 165 | if (code === 1000) |
| 166 | this.successToast( |
| Surya V | de23ea2 | 2024-07-11 15:19:46 +0530 | [diff] [blame] | 167 | i18n.global.t('pageVirtualMedia.toast.serverClosedSuccessfully'), |
| Mateusz Gapski | 7510046 | 2020-07-30 11:01:29 +0200 | [diff] [blame] | 168 | ); |
| 169 | else |
| 170 | this.errorToast( |
| Surya V | de23ea2 | 2024-07-11 15:19:46 +0530 | [diff] [blame] | 171 | i18n.global.t('pageVirtualMedia.toast.serverClosedWithErrors'), |
| Mateusz Gapski | 7510046 | 2020-07-30 11:01:29 +0200 | [diff] [blame] | 172 | ); |
| 173 | device.file = null; |
| 174 | device.isActive = false; |
| 175 | }; |
| 176 | |
| 177 | device.nbd.start(); |
| 178 | device.isActive = true; |
| 179 | }, |
| 180 | stopVM(device) { |
| 181 | device.nbd.stop(); |
| 182 | }, |
| Mateusz Gapski | 2224ece | 2020-09-02 17:00:06 +0200 | [diff] [blame] | 183 | startLegacy(connectionData) { |
| 184 | var data = {}; |
| 185 | data.Image = connectionData.serverUri; |
| 186 | data.UserName = connectionData.username; |
| 187 | data.Password = connectionData.password; |
| MichalX Szopinski | f3022e5 | 2021-03-28 19:08:09 +0200 | [diff] [blame] | 188 | data.WriteProtected = !connectionData.isRW; |
| Mateusz Gapski | 2224ece | 2020-09-02 17:00:06 +0200 | [diff] [blame] | 189 | this.startLoader(); |
| 190 | this.$store |
| 191 | .dispatch('virtualMedia/mountImage', { |
| 192 | id: connectionData.id, |
| Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 193 | data: data, |
| Mateusz Gapski | 2224ece | 2020-09-02 17:00:06 +0200 | [diff] [blame] | 194 | }) |
| 195 | .then(() => { |
| 196 | this.successToast( |
| Surya V | de23ea2 | 2024-07-11 15:19:46 +0530 | [diff] [blame] | 197 | i18n.global.t('pageVirtualMedia.toast.serverConnectionEstablished'), |
| Mateusz Gapski | 2224ece | 2020-09-02 17:00:06 +0200 | [diff] [blame] | 198 | ); |
| 199 | connectionData.isActive = true; |
| 200 | }) |
| 201 | .catch(() => { |
| Surya V | de23ea2 | 2024-07-11 15:19:46 +0530 | [diff] [blame] | 202 | this.errorToast( |
| 203 | i18n.global.t('pageVirtualMedia.toast.errorMounting'), |
| 204 | ); |
| Mateusz Gapski | 2224ece | 2020-09-02 17:00:06 +0200 | [diff] [blame] | 205 | this.isActive = false; |
| 206 | }) |
| 207 | .finally(() => this.endLoader()); |
| Mateusz Gapski | 7510046 | 2020-07-30 11:01:29 +0200 | [diff] [blame] | 208 | }, |
| Mateusz Gapski | 2224ece | 2020-09-02 17:00:06 +0200 | [diff] [blame] | 209 | stopLegacy(connectionData) { |
| 210 | this.$store |
| 211 | .dispatch('virtualMedia/unmountImage', connectionData.id) |
| 212 | .then(() => { |
| 213 | this.successToast( |
| Surya V | de23ea2 | 2024-07-11 15:19:46 +0530 | [diff] [blame] | 214 | i18n.global.t('pageVirtualMedia.toast.serverClosedSuccessfully'), |
| Mateusz Gapski | 2224ece | 2020-09-02 17:00:06 +0200 | [diff] [blame] | 215 | ); |
| 216 | connectionData.isActive = false; |
| 217 | }) |
| 218 | .catch(() => |
| Surya V | de23ea2 | 2024-07-11 15:19:46 +0530 | [diff] [blame] | 219 | this.errorToast( |
| 220 | i18n.global.t('pageVirtualMedia.toast.errorUnmounting'), |
| 221 | ), |
| Mateusz Gapski | 2224ece | 2020-09-02 17:00:06 +0200 | [diff] [blame] | 222 | ) |
| 223 | .finally(() => this.endLoader()); |
| 224 | }, |
| 225 | saveConnection(connectionData) { |
| 226 | this.modalConfigureConnection.serverUri = connectionData.serverUri; |
| 227 | this.modalConfigureConnection.username = connectionData.username; |
| 228 | this.modalConfigureConnection.password = connectionData.password; |
| 229 | this.modalConfigureConnection.isRW = connectionData.isRW; |
| 230 | }, |
| 231 | configureConnection(connectionData) { |
| 232 | this.modalConfigureConnection = connectionData; |
| jason westover | d36ac8a | 2025-11-03 20:58:59 -0600 | [diff] [blame^] | 233 | this.showConfigureConnectionModal = true; |
| Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 234 | }, |
| SurenNeware | 978807d | 2020-09-03 18:35:21 +0530 | [diff] [blame] | 235 | concatId(val) { |
| 236 | return val.split(' ').join('_').toLowerCase(); |
| 237 | }, |
| Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 238 | }, |
| Mateusz Gapski | 7510046 | 2020-07-30 11:01:29 +0200 | [diff] [blame] | 239 | }; |
| 240 | </script> |