From 500c946118f2a3beab764df5e10c5676143664ac Mon Sep 17 00:00:00 2001 From: utchoang Date: Thu, 1 Apr 2021 15:00:06 +0700 Subject: [PATCH 1/6] add multiple management server support --- ui/public/config.json | 7 ++++ ui/src/components/widgets/Console.vue | 14 +++++++- ui/src/main.js | 2 +- ui/src/permission.js | 15 +++++++- ui/src/store/getters.js | 3 +- ui/src/store/modules/app.js | 13 +++++-- ui/src/store/mutation-types.js | 1 + ui/src/views/auth/Login.vue | 49 ++++++++++++++++++++++++++- 8 files changed, 97 insertions(+), 7 deletions(-) diff --git a/ui/public/config.json b/ui/public/config.json index 45cc974ffeba..bb18d2a4228c 100644 --- a/ui/public/config.json +++ b/ui/public/config.json @@ -1,5 +1,12 @@ { "apiBase": "/client/api", + "servers": [ + { + "name": "Local-Server", + "apiHost": "", + "apiBase": "/client/api" + } + ], "docBase": "http://docs.cloudstack.apache.org/en/latest", "appTitle": "CloudStack", "footer": "Licensed under the Apache License, Version 2.0.", diff --git a/ui/src/components/widgets/Console.vue b/ui/src/components/widgets/Console.vue index 3064d8f0def4..b9a5b05536a6 100644 --- a/ui/src/components/widgets/Console.vue +++ b/ui/src/components/widgets/Console.vue @@ -18,7 +18,7 @@ diff --git a/ui/src/main.js b/ui/src/main.js index 064314b98de8..b60080c0d678 100644 --- a/ui/src/main.js +++ b/ui/src/main.js @@ -37,7 +37,7 @@ Vue.use(toLocaleDatePlugin) fetch('config.json').then(response => response.json()).then(config => { Vue.prototype.$config = config - Vue.axios.defaults.baseURL = config.apiBase + Vue.axios.defaults.baseURL = (config.servers[0].apiHost || '') + config.servers[0].apiBase loadLanguageAsync().then(() => { new Vue({ diff --git a/ui/src/permission.js b/ui/src/permission.js index 8e975118611e..d931f5f5a2a8 100644 --- a/ui/src/permission.js +++ b/ui/src/permission.js @@ -26,7 +26,7 @@ import 'nprogress/nprogress.css' // progress bar style import message from 'ant-design-vue/es/message' import notification from 'ant-design-vue/es/notification' import { setDocumentTitle } from '@/utils/domUtil' -import { ACCESS_TOKEN, APIS } from '@/store/mutation-types' +import { ACCESS_TOKEN, APIS, SERVER_MANAGER } from '@/store/mutation-types' NProgress.configure({ showSpinner: false }) // NProgress Configuration @@ -39,6 +39,19 @@ router.beforeEach((to, from, next) => { const title = i18n.t(to.meta.title) + ' - ' + Vue.prototype.$config.appTitle setDocumentTitle(title) } + + const servers = Vue.prototype.$config.servers + const serverStorage = Vue.ls.get(SERVER_MANAGER) + let apiFullPath = '' + if (serverStorage) { + apiFullPath = (serverStorage.apiHost || '') + serverStorage.apiBase + } + const serverFilter = servers.filter(ser => (ser.apiHost || '') + ser.apiBase === apiFullPath) + const server = serverFilter[0] || servers[0] + + Vue.axios.defaults.baseURL = (server.apiHost || '') + server.apiBase + store.dispatch('SetServer', server) + const validLogin = Vue.ls.get(ACCESS_TOKEN) || Cookies.get('userid') || Cookies.get('userid', { path: '/client' }) if (validLogin) { if (to.path === '/user/login') { diff --git a/ui/src/store/getters.js b/ui/src/store/getters.js index 4e2d5eb21a60..1571502b4db0 100644 --- a/ui/src/store/getters.js +++ b/ui/src/store/getters.js @@ -35,7 +35,8 @@ const getters = { cloudian: state => state.user.cloudian, zones: state => state.user.zones, timezoneoffset: state => state.user.timezoneoffset, - usebrowsertimezone: state => state.user.usebrowsertimezone + usebrowsertimezone: state => state.user.usebrowsertimezone, + server: state => state.app.server } export default getters diff --git a/ui/src/store/modules/app.js b/ui/src/store/modules/app.js index a03fc63b2ef4..e512c42f3728 100644 --- a/ui/src/store/modules/app.js +++ b/ui/src/store/modules/app.js @@ -27,7 +27,8 @@ import { DEFAULT_FIXED_HEADER_HIDDEN, DEFAULT_CONTENT_WIDTH_TYPE, DEFAULT_MULTI_TAB, - USE_BROWSER_TIMEZONE + USE_BROWSER_TIMEZONE, + SERVER_MANAGER } from '@/store/mutation-types' const app = { @@ -44,7 +45,8 @@ const app = { color: null, inverted: true, multiTab: true, - metrics: false + metrics: false, + server: '' }, mutations: { SET_SIDEBAR_TYPE: (state, type) => { @@ -100,6 +102,10 @@ const app = { SET_USE_BROWSER_TIMEZONE: (state, bool) => { Vue.ls.set(USE_BROWSER_TIMEZONE, bool) state.usebrowsertimezone = bool + }, + SET_SERVER: (state, server) => { + Vue.ls.set(SERVER_MANAGER, server) + state.server = server } }, actions: { @@ -147,6 +153,9 @@ const app = { }, SetUseBrowserTimezone ({ commit }, bool) { commit('SET_USE_BROWSER_TIMEZONE', bool) + }, + SetServer ({ commit }, server) { + commit('SET_SERVER', server) } } } diff --git a/ui/src/store/mutation-types.js b/ui/src/store/mutation-types.js index 9d735610e072..16d0ac10463c 100644 --- a/ui/src/store/mutation-types.js +++ b/ui/src/store/mutation-types.js @@ -32,6 +32,7 @@ export const ZONES = 'ZONES' export const ASYNC_JOB_IDS = 'ASYNC_JOB_IDS' export const TIMEZONE_OFFSET = 'TIMEZONE_OFFSET' export const USE_BROWSER_TIMEZONE = 'USE_BROWSER_TIMEZONE' +export const SERVER_MANAGER = 'SERVER_MANAGER' export const CONTENT_WIDTH_TYPE = { Fluid: 'Fluid', diff --git a/ui/src/views/auth/Login.vue b/ui/src/views/auth/Login.vue index a3fdf3bb96aa..ccd07477ab2c 100644 --- a/ui/src/views/auth/Login.vue +++ b/ui/src/views/auth/Login.vue @@ -35,6 +35,23 @@ {{ $t('label.login.portal') }} + + + + + {{ item.name }} + + + {{ $t('label.login.single.signon') }} + + + + + {{ item.name }} + + + @@ -110,8 +144,11 @@