blob: a9a575d5a0d64b8ba8483fbc9586b07532944eab [file] [log] [blame]
Mateusz Gapski75100462020-07-30 11:01:29 +02001<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">
11 <b-form-group
12 :label="dev.id"
13 :label-for="dev.id"
14 label-class="bold"
15 >
16 <b-form-file
17 v-show="!dev.isActive"
18 :id="dev.id"
19 v-model="dev.file"
20 />
21 <p v-if="dev.isActive">{{ dev.file.name }}</p>
22 </b-form-group>
23 <b-button
24 v-if="!dev.isActive"
25 variant="primary"
26 :disabled="!dev.file"
27 @click="startVM(dev)"
28 >
29 {{ 'Start' }}
30 </b-button>
31 <b-button
32 v-if="dev.isActive"
33 variant="primary"
34 :disabled="!dev.file"
35 @click="stopVM(dev)"
36 >
37 {{ 'Stop' }}
38 </b-button>
39 </b-col>
40 </b-row>
41 </page-section>
42 </b-col>
43 </b-row>
44 <b-row v-if="loadImageFromExternalServer" class="mb-4">
45 <b-col md="12">
46 <page-section
47 :section-title="$t('pageVirtualMedia.virtualMediaSubTitleSecond')"
48 >
49 <b-row>
50 <b-col
51 v-for="(device, $index) in legacyDevices"
52 :key="$index"
53 md="6"
54 >
55 <b-form-group
56 :label="device.id"
57 :label-for="device.id"
58 label-class="bold"
59 >
60 <b-button variant="primary" @click="configureConnection()">
61 {{ $t('pageVirtualMedia.configureConnection') }}
62 </b-button>
63
64 <b-button
65 variant="primary"
66 class="float-right"
67 :disabled="!device.address"
68 @click="startLegacy(device)"
69 >
70 {{ 'Start' }}
71 </b-button>
72 </b-form-group>
73 </b-col>
74 </b-row>
75 </page-section>
76 </b-col>
77 </b-row>
78 </b-container>
79</template>
80
81<script>
82import PageTitle from '@/components/Global/PageTitle';
83import PageSection from '@/components/Global/PageSection';
84import BVToastMixin from '@/components/Mixins/BVToastMixin';
85import LoadingBarMixin from '@/components/Mixins/LoadingBarMixin';
86import NbdServer from '@/utilities/NBDServer';
87
88export default {
89 name: 'VirtualMedia',
90 components: { PageTitle, PageSection },
91 mixins: [BVToastMixin, LoadingBarMixin],
92 data() {
93 return {
94 loadImageFromExternalServer:
95 process.env.VUE_APP_VIRTUAL_MEDIA_LIST_ENABLED === 'true' ? true : false
96 };
97 },
98 computed: {
99 proxyDevices() {
100 return this.$store.getters['virtualMedia/proxyDevices'];
101 },
102 legacyDevices() {
103 return this.$store.getters['virtualMedia/legacyDevices'];
104 }
105 },
106 created() {
107 if (this.proxyDevices.length > 0 || this.legacyDevices.length > 0) return;
108 this.startLoader();
109 this.$store
110 .dispatch('virtualMedia/getData')
111 .finally(() => this.endLoader());
112 },
113 methods: {
114 startVM(device) {
115 const token = this.$store.getters['authentication/token'];
116 device.nbd = new NbdServer(
117 `wss://${window.location.host}${device.websocket}`,
118 device.file,
119 device.id,
120 token
121 );
122 device.nbd.socketStarted = () =>
123 this.successToast(this.$t('pageVirtualMedia.toast.serverRunning'));
124 device.nbd.errorReadingFile = () =>
125 this.errorToast(this.$t('pageVirtualMedia.toast.errorReadingFile'));
126 device.nbd.socketClosed = code => {
127 if (code === 1000)
128 this.successToast(
129 this.$t('pageVirtualMedia.toast.serverClosedSuccessfully')
130 );
131 else
132 this.errorToast(
133 this.$t('pageVirtualMedia.toast.serverClosedWithErrors')
134 );
135 device.file = null;
136 device.isActive = false;
137 };
138
139 device.nbd.start();
140 device.isActive = true;
141 },
142 stopVM(device) {
143 device.nbd.stop();
144 },
145 startLegacy() {
146 console.log('starting legacy...');
147 },
148 configureConnection() {
149 this.warningToast('This option is unavialable. We are working on it.');
150 }
151 }
152};
153</script>