mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
UI fix api in project view (#11191)
* Add project id for post requests as well in the params * Replace leftover api calls to getAPI calls * ui: don't remove values from request if the value is null or empty string * Address comments * Apply suggestions from code review * Apply suggestions from code review Co-authored-by: Suresh Kumar Anaparti <sureshkumar.anaparti@gmail.com> * fixup * Return null if guiTheme requests fails --------- Co-authored-by: Suresh Kumar Anaparti <sureshkumar.anaparti@gmail.com>
This commit is contained in:
parent
e8ab0ae70a
commit
f52e05863e
@ -47,7 +47,7 @@ export function postAPI (command, data = {}) {
|
|||||||
params.append('response', 'json')
|
params.append('response', 'json')
|
||||||
if (data) {
|
if (data) {
|
||||||
Object.entries(data).forEach(([key, value]) => {
|
Object.entries(data).forEach(([key, value]) => {
|
||||||
if (value !== undefined && value !== null && value !== '') {
|
if (value !== undefined && value !== null) {
|
||||||
params.append(key, value)
|
params.append(key, value)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@ -41,7 +41,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { api } from '@/api'
|
import { getAPI } from '@/api'
|
||||||
import ResourceIcon from '@/components/view/ResourceIcon'
|
import ResourceIcon from '@/components/view/ResourceIcon'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
@ -100,7 +100,7 @@ export default {
|
|||||||
this.itemCount = 0
|
this.itemCount = 0
|
||||||
this.fetchLoading = true
|
this.fetchLoading = true
|
||||||
this.zones = []
|
this.zones = []
|
||||||
api(this.imageApi, params).then(json => {
|
getAPI(this.imageApi, params).then(json => {
|
||||||
const imageResponse = json?.[this.imageApi.toLowerCase() + 'response']?.[this.$route.meta.name] || []
|
const imageResponse = json?.[this.imageApi.toLowerCase() + 'response']?.[this.$route.meta.name] || []
|
||||||
this.zones = imageResponse.map(i => ({
|
this.zones = imageResponse.map(i => ({
|
||||||
id: i.zoneid,
|
id: i.zoneid,
|
||||||
@ -122,7 +122,7 @@ export default {
|
|||||||
}
|
}
|
||||||
const zoneids = this.zones.map(z => z.id)
|
const zoneids = this.zones.map(z => z.id)
|
||||||
this.loading = true
|
this.loading = true
|
||||||
api('listZones', { showicon: true, ids: zoneids.join(',') }).then(json => {
|
getAPI('listZones', { showicon: true, ids: zoneids.join(',') }).then(json => {
|
||||||
this.zones = json.listzonesresponse.zone || []
|
this.zones = json.listzonesresponse.zone || []
|
||||||
}).finally(() => {
|
}).finally(() => {
|
||||||
this.loading = false
|
this.loading = false
|
||||||
|
|||||||
@ -44,7 +44,7 @@ import {
|
|||||||
import { VueAxios } from './utils/request'
|
import { VueAxios } from './utils/request'
|
||||||
import directives from './utils/directives'
|
import directives from './utils/directives'
|
||||||
import Cookies from 'js-cookie'
|
import Cookies from 'js-cookie'
|
||||||
import { api } from '@/api'
|
import { getAPI } from '@/api'
|
||||||
import { applyCustomGuiTheme } from './utils/guiTheme'
|
import { applyCustomGuiTheme } from './utils/guiTheme'
|
||||||
|
|
||||||
vueApp.use(VueAxios, router)
|
vueApp.use(VueAxios, router)
|
||||||
@ -106,7 +106,7 @@ fetch('config.json?ts=' + Date.now())
|
|||||||
let domainid = null
|
let domainid = null
|
||||||
|
|
||||||
if (userid !== undefined && Cookies.get('sessionkey')) {
|
if (userid !== undefined && Cookies.get('sessionkey')) {
|
||||||
await api('listUsers', { userid: userid }).then(response => {
|
await getAPI('listUsers', { userid: userid }).then(response => {
|
||||||
accountid = response.listusersresponse.user[0].accountid
|
accountid = response.listusersresponse.user[0].accountid
|
||||||
domainid = response.listusersresponse.user[0].domainid
|
domainid = response.listusersresponse.user[0].domainid
|
||||||
})
|
})
|
||||||
|
|||||||
@ -16,7 +16,7 @@
|
|||||||
// under the License.
|
// under the License.
|
||||||
|
|
||||||
import { vueProps } from '@/vue-app'
|
import { vueProps } from '@/vue-app'
|
||||||
import { api } from '@/api'
|
import { getAPI } from '@/api'
|
||||||
|
|
||||||
export async function applyCustomGuiTheme (accountid, domainid) {
|
export async function applyCustomGuiTheme (accountid, domainid) {
|
||||||
await fetch('config.json').then(response => response.json()).then(config => {
|
await fetch('config.json').then(response => response.json()).then(config => {
|
||||||
@ -45,10 +45,13 @@ export async function applyCustomGuiTheme (accountid, domainid) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function fetchGuiTheme (params) {
|
async function fetchGuiTheme (params) {
|
||||||
return await api('listGuiThemes', params).then(response => {
|
return await getAPI('listGuiThemes', params).then(response => {
|
||||||
if (response.listguithemesresponse.guiThemes) {
|
if (response.listguithemesresponse.guiThemes) {
|
||||||
return response.listguithemesresponse.guiThemes[0]
|
return response.listguithemesresponse.guiThemes[0]
|
||||||
}
|
}
|
||||||
|
}).catch(error => {
|
||||||
|
console.error('Error fetching GUI theme:', error)
|
||||||
|
return null
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -149,6 +149,15 @@ const err = (error) => {
|
|||||||
service.interceptors.request.use(config => {
|
service.interceptors.request.use(config => {
|
||||||
source = sourceToken.getSource()
|
source = sourceToken.getSource()
|
||||||
config.cancelToken = source.token
|
config.cancelToken = source.token
|
||||||
|
|
||||||
|
handleGetRequestParams(config)
|
||||||
|
|
||||||
|
handlePostRequestParams(config)
|
||||||
|
|
||||||
|
return config
|
||||||
|
}, err)
|
||||||
|
|
||||||
|
function handleGetRequestParams (config) {
|
||||||
if (config && config.params) {
|
if (config && config.params) {
|
||||||
config.params.response = 'json'
|
config.params.response = 'json'
|
||||||
const project = vueProps.$localStorage.get(CURRENT_PROJECT)
|
const project = vueProps.$localStorage.get(CURRENT_PROJECT)
|
||||||
@ -160,11 +169,30 @@ service.interceptors.request.use(config => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (config.params.ignoreproject !== undefined) {
|
if (config.params.ignoreproject !== undefined) {
|
||||||
config.params.ignoreproject = null
|
delete config.params.ignoreproject
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return config
|
}
|
||||||
}, err)
|
|
||||||
|
function handlePostRequestParams (config) {
|
||||||
|
if (config && config.data && config.data instanceof URLSearchParams) {
|
||||||
|
const project = vueProps.$localStorage.get(CURRENT_PROJECT)
|
||||||
|
const command = config.data.get('command')
|
||||||
|
const hasProjectId = config.data.has('projectid')
|
||||||
|
const ignoreProject = config.data.has('ignoreproject')
|
||||||
|
|
||||||
|
if (!hasProjectId && !ignoreProject && project && project.id) {
|
||||||
|
if (command === 'listTags') {
|
||||||
|
config.data.append('projectid', '-1')
|
||||||
|
} else if (command !== 'assignVirtualMachine') {
|
||||||
|
config.data.append('projectid', project.id)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (config.data.has('ignoreproject')) {
|
||||||
|
config.data.delete('ignoreproject')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// response interceptor
|
// response interceptor
|
||||||
service.interceptors.response.use((response) => {
|
service.interceptors.response.use((response) => {
|
||||||
|
|||||||
@ -66,7 +66,7 @@
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { ref, reactive, toRaw } from 'vue'
|
import { ref, reactive, toRaw } from 'vue'
|
||||||
import { api } from '@/api'
|
import { getAPI, postAPI } from '@/api'
|
||||||
import TooltipLabel from '@/components/widgets/TooltipLabel'
|
import TooltipLabel from '@/components/widgets/TooltipLabel'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
@ -112,7 +112,7 @@ export default {
|
|||||||
callListVms (accountId, domainId) {
|
callListVms (accountId, domainId) {
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
this.volumes = []
|
this.volumes = []
|
||||||
api('listVirtualMachines', {
|
getAPI('listVirtualMachines', {
|
||||||
accountId: accountId,
|
accountId: accountId,
|
||||||
domainId: domainId,
|
domainId: domainId,
|
||||||
details: 'min',
|
details: 'min',
|
||||||
@ -172,7 +172,7 @@ export default {
|
|||||||
},
|
},
|
||||||
addNodesToKubernetesCluster (params) {
|
addNodesToKubernetesCluster (params) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
api('addNodesToKubernetesCluster', params).then(json => {
|
postAPI('addNodesToKubernetesCluster', params).then(json => {
|
||||||
const jobId = json.addnodestokubernetesclusterresponse.jobid
|
const jobId = json.addnodestokubernetesclusterresponse.jobid
|
||||||
return resolve(jobId)
|
return resolve(jobId)
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
|
|||||||
@ -54,7 +54,7 @@
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { ref, reactive, toRaw } from 'vue'
|
import { ref, reactive, toRaw } from 'vue'
|
||||||
import { api } from '@/api'
|
import { postAPI } from '@/api'
|
||||||
import TooltipLabel from '@/components/widgets/TooltipLabel'
|
import TooltipLabel from '@/components/widgets/TooltipLabel'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
@ -137,7 +137,7 @@ export default {
|
|||||||
},
|
},
|
||||||
removeNodesFromKubernetesCluster (params) {
|
removeNodesFromKubernetesCluster (params) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
api('removeNodesFromKubernetesCluster', params).then(json => {
|
postAPI('removeNodesFromKubernetesCluster', params).then(json => {
|
||||||
const jobId = json.removenodesfromkubernetesclusterresponse.jobid
|
const jobId = json.removenodesfromkubernetesclusterresponse.jobid
|
||||||
return resolve(jobId)
|
return resolve(jobId)
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user