[go: nahoru, domu]

Skip to content

Commit

Permalink
Merge branch '4.16' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
sureshanaparti committed Jan 13, 2022
2 parents 42a941c + c86b98e commit a6271b8
Show file tree
Hide file tree
Showing 7 changed files with 193 additions and 55 deletions.
8 changes: 7 additions & 1 deletion ui/src/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
// specific language governing permissions and limitations
// under the License.

import { axios } from '@/utils/request'
import { axios, sourceToken } from '@/utils/request'
import { message, notification } from 'ant-design-vue'

export function api (command, args = {}, method = 'GET', data = {}) {
let params = {}
Expand All @@ -40,6 +41,8 @@ export function api (command, args = {}, method = 'GET', data = {}) {
}

export function login (arg) {
sourceToken.init()

const params = new URLSearchParams()
params.append('command', 'login')
params.append('username', arg.username || arg.email)
Expand All @@ -57,5 +60,8 @@ export function login (arg) {
}

export function logout () {
sourceToken.cancel()
message.destroy()
notification.destroy()
return api('logout')
}
2 changes: 1 addition & 1 deletion ui/src/config/section/account.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export default {
},
{
name: 'limits',
show: (record, route, user) => { return ['Admin'].includes(user.roletype) },
show: (record, route, user) => { return ['Admin', 'DomainAdmin'].includes(user.roletype) },
component: () => import('@/components/view/ResourceLimitTab.vue')
},
{
Expand Down
31 changes: 17 additions & 14 deletions ui/src/utils/plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { api } from '@/api'
import { message, notification } from 'ant-design-vue'
import eventBus from '@/config/eventBus'
import store from '@/store'
import { sourceToken } from '@/utils/request'

export const pollJobPlugin = {
install (Vue) {
Expand Down Expand Up @@ -177,20 +178,22 @@ export const pollJobPlugin = {
}
}).catch(e => {
console.error(`${catchMessage} - ${e}`)
let countNotify = store.getters.countNotify
countNotify++
store.commit('SET_COUNT_NOTIFY', countNotify)
notification.error({
top: '65px',
message: i18n.t('label.error'),
description: catchMessage,
duration: 0,
onClose: () => {
let countNotify = store.getters.countNotify
countNotify > 0 ? countNotify-- : countNotify = 0
store.commit('SET_COUNT_NOTIFY', countNotify)
}
})
if (!sourceToken.isCancel(e)) {
let countNotify = store.getters.countNotify
countNotify++
store.commit('SET_COUNT_NOTIFY', countNotify)
notification.error({
top: '65px',
message: i18n.t('label.error'),
description: catchMessage,
duration: 0,
onClose: () => {
let countNotify = store.getters.countNotify
countNotify > 0 ? countNotify-- : countNotify = 0
store.commit('SET_COUNT_NOTIFY', countNotify)
}
})
}
catchMethod && catchMethod()
})
}
Expand Down
21 changes: 20 additions & 1 deletion ui/src/utils/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { CURRENT_PROJECT } from '@/store/mutation-types'
import { i18n } from '@/locales'
import store from '@/store'

let source
const service = axios.create({
timeout: 600000
})
Expand Down Expand Up @@ -128,6 +129,8 @@ const err = (error) => {

// request interceptor
service.interceptors.request.use(config => {
source = sourceToken.getSource()
config.cancelToken = source.token
if (config && config.params) {
config.params.response = 'json'
const project = Vue.ls.get(CURRENT_PROJECT)
Expand All @@ -154,7 +157,23 @@ const installer = {
}
}

const sourceToken = {
init: () => { source = axios.CancelToken.source() },
isCancel: (e) => {
return axios.isCancel(e)
},
getSource: () => {
if (!source) sourceToken.init()
return source
},
cancel: () => {
if (!source) sourceToken.init()
source.cancel()
}
}

export {
installer as VueAxios,
service as axios
service as axios,
sourceToken
}
18 changes: 17 additions & 1 deletion ui/src/views/AutogenView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -976,7 +976,23 @@ export default {
this.form = this.$form.createForm(this)
this.formModel = {}
if (action.component && action.api && !action.popup) {
this.$router.push({ name: action.api })
const query = {}
if (this.$route.path.startsWith('/vm')) {
switch (true) {
case ('templateid' in this.$route.query):
query.templateid = this.$route.query.templateid
break
case ('isoid' in this.$route.query):
query.isoid = this.$route.query.isoid
break
case ('networkid' in this.$route.query):
query.networkid = this.$route.query.networkid
break
default:
break
}
}
this.$router.push({ name: action.api, query })
return
}
this.currentAction = action
Expand Down
Loading

0 comments on commit a6271b8

Please sign in to comment.