From fb6c6de90cba53dff84d687d6b3f2b07b822b1dc Mon Sep 17 00:00:00 2001 From: Konstantin Date: Wed, 14 Jun 2023 17:23:14 +0300 Subject: Fix kvm session and add event bus Bug description: Before this commit KVM window wasn't being closed after logging out Test: Step1. Launch webui on browser and see KVM page on /#/operations/kvm. Step2. Open additional window using 'Open in new tab'. Step3. Navigate to another page. For example, /#/operations/key-clear. Step4. Logout. Window is still open. Change-Id: Ife79ebca41eb4d588c0b8f4fae06135420eda155 Signed-off-by: Konstantin Maskov --- src/components/AppHeader/AppHeader.vue | 5 +++++ src/eventBus.js | 5 +++++ src/main.js | 2 ++ src/views/Operations/Kvm/KvmConsole.vue | 20 ++++++-------------- 4 files changed, 18 insertions(+), 14 deletions(-) create mode 100644 src/eventBus.js diff --git a/src/components/AppHeader/AppHeader.vue b/src/components/AppHeader/AppHeader.vue index a1984953..859a47f7 100644 --- a/src/components/AppHeader/AppHeader.vue +++ b/src/components/AppHeader/AppHeader.vue @@ -115,6 +115,7 @@ import IconMenu from '@carbon/icons-vue/es/menu/20'; import IconRenew from '@carbon/icons-vue/es/renew/20'; import StatusIcon from '@/components/Global/StatusIcon'; import LoadingBar from '@/components/Global/LoadingBar'; +import { mapState } from 'vuex'; export default { name: 'AppHeader', @@ -140,6 +141,7 @@ export default { }; }, computed: { + ...mapState('authentication', ['consoleWindow']), isNavTagPresent() { return this.assetTag || this.modelType || this.serialNumber; }, @@ -194,6 +196,9 @@ export default { }, }, watch: { + consoleWindow() { + if (this.consoleWindow === false) this.$eventBus.$consoleWindow.close(); + }, isAuthorized(value) { if (value === false) { this.errorToast(this.$t('global.toast.unAuthDescription'), { diff --git a/src/eventBus.js b/src/eventBus.js new file mode 100644 index 00000000..c31c98a5 --- /dev/null +++ b/src/eventBus.js @@ -0,0 +1,5 @@ +import Vue from 'vue'; + +const eventBus = new Vue(); + +export default eventBus; diff --git a/src/main.js b/src/main.js index 0aae716f..43d09b8c 100644 --- a/src/main.js +++ b/src/main.js @@ -6,6 +6,7 @@ import router from './router'; //Exact match alias set to support //dotenv customizations. import store from './store'; +import eventBus from './eventBus'; import { AlertPlugin, @@ -135,3 +136,4 @@ new Vue({ i18n, render: (h) => h(App), }).$mount('#app'); +Vue.prototype.$eventBus = eventBus; diff --git a/src/views/Operations/Kvm/KvmConsole.vue b/src/views/Operations/Kvm/KvmConsole.vue index 212514d1..8483c4f3 100644 --- a/src/views/Operations/Kvm/KvmConsole.vue +++ b/src/views/Operations/Kvm/KvmConsole.vue @@ -46,7 +46,6 @@ import StatusIcon from '@/components/Global/StatusIcon'; import IconLaunch from '@carbon/icons-vue/es/launch/20'; import IconArrowDown from '@carbon/icons-vue/es/arrow--down/16'; import { throttle } from 'lodash'; -import { mapState } from 'vuex'; const Connecting = 0; const Connected = 1; @@ -63,7 +62,6 @@ export default { }, data() { return { - isConsoleWindow: null, rfb: null, isConnected: false, terminalClass: this.isFullWindow ? 'full-window' : '', @@ -74,7 +72,6 @@ export default { }; }, computed: { - ...mapState('authentication', ['consoleWindow']), serverStatusIcon() { if (this.status === Connected) { return 'success'; @@ -92,11 +89,6 @@ export default { return this.$t('pageKvm.connecting'); }, }, - watch: { - consoleWindow() { - if (this.consoleWindow == false) this.isConsoleWindow.close(); - }, - }, created() { this.$store.dispatch('global/getSystemInfo'); }, @@ -154,24 +146,24 @@ export default { } }, openConsoleWindow() { - // If isConsoleWindow is not null + // If consoleWindow is not null // Check the newly opened window is closed or not - if (this.isConsoleWindow) { + if (this.$eventBus.$consoleWindow) { // If window is not closed set focus to new window // If window is closed, do open new window - if (!this.isConsoleWindow.closed) { - this.isConsoleWindow.focus(); + if (!this.$eventBus.$consoleWindow.closed) { + this.$eventBus.$consoleWindow.focus(); return; } else { this.openNewWindow(); } } else { - // If isConsoleWindow is null, open new window + // If consoleWindow is null, open new window this.openNewWindow(); } }, openNewWindow() { - this.isConsoleWindow = window.open( + this.$eventBus.$consoleWindow = window.open( '#/console/kvm', 'kvmConsoleWindow', 'directories=no,titlebar=no,toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=yes,width=700,height=550' -- cgit v1.2.3