Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ui/src/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export function postAPI (command, data = {}) {
params.append('response', 'json')
if (data) {
Object.entries(data).forEach(([key, value]) => {
if (value !== undefined && value !== null && value !== '') {
if (value !== undefined && value !== null) {
params.append(key, value)
}
})
Expand Down
6 changes: 3 additions & 3 deletions ui/src/components/view/ImageDeployInstanceButton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
</template>

<script>
import { api } from '@/api'
import { getAPI } from '@/api'
import ResourceIcon from '@/components/view/ResourceIcon'

export default {
Expand Down Expand Up @@ -100,7 +100,7 @@ export default {
this.itemCount = 0
this.fetchLoading = true
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] || []
this.zones = imageResponse.map(i => ({
id: i.zoneid,
Expand All @@ -122,7 +122,7 @@ export default {
}
const zoneids = this.zones.map(z => z.id)
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 || []
}).finally(() => {
this.loading = false
Expand Down
4 changes: 2 additions & 2 deletions ui/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ import {
import { VueAxios } from './utils/request'
import directives from './utils/directives'
import Cookies from 'js-cookie'
import { api } from '@/api'
import { getAPI } from '@/api'
import { applyCustomGuiTheme } from './utils/guiTheme'

vueApp.use(VueAxios, router)
Expand Down Expand Up @@ -106,7 +106,7 @@ fetch('config.json?ts=' + Date.now())
let domainid = null

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
domainid = response.listusersresponse.user[0].domainid
})
Expand Down
7 changes: 5 additions & 2 deletions ui/src/utils/guiTheme.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
// under the License.

import { vueProps } from '@/vue-app'
import { api } from '@/api'
import { getAPI } from '@/api'

export async function applyCustomGuiTheme (accountid, domainid) {
await fetch('config.json').then(response => response.json()).then(config => {
Expand Down Expand Up @@ -45,10 +45,13 @@ export async function applyCustomGuiTheme (accountid, domainid) {
}

async function fetchGuiTheme (params) {
return await api('listGuiThemes', params).then(response => {
return await getAPI('listGuiThemes', params).then(response => {
if (response.listguithemesresponse.guiThemes) {
return response.listguithemesresponse.guiThemes[0]
}
}).catch(error => {
console.error('Error fetching GUI theme:', error)
return null
})
}

Expand Down
34 changes: 31 additions & 3 deletions ui/src/utils/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,15 @@ const err = (error) => {
service.interceptors.request.use(config => {
source = sourceToken.getSource()
config.cancelToken = source.token

handleGetRequestParams(config)

handlePostRequestParams(config)

return config
}, err)

function handleGetRequestParams (config) {
if (config && config.params) {
config.params.response = 'json'
const project = vueProps.$localStorage.get(CURRENT_PROJECT)
Expand All @@ -160,11 +169,30 @@ service.interceptors.request.use(config => {
}
}
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') {
Comment on lines +185 to +187
Copy link

Copilot AI Jul 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Hardcoding command names like 'listTags' and 'assignVirtualMachine' can be brittle. Consider centralizing these exceptions into a configuration constant or lookup table to improve maintainability.

Suggested change
if (command === 'listTags') {
config.data.append('projectid', '-1')
} else if (command !== 'assignVirtualMachine') {
if (command === COMMANDS.LIST_TAGS) {
config.data.append('projectid', '-1')
} else if (command !== COMMANDS.ASSIGN_VM) {

Copilot uses AI. Check for mistakes.
config.data.append('projectid', project.id)
}
}
if (config.data.has('ignoreproject')) {
config.data.delete('ignoreproject')
}
}
}

// response interceptor
service.interceptors.response.use((response) => {
Expand Down
6 changes: 3 additions & 3 deletions ui/src/views/compute/KubernetesAddNodes.vue
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@

<script>
import { ref, reactive, toRaw } from 'vue'
import { api } from '@/api'
import { getAPI, postAPI } from '@/api'
import TooltipLabel from '@/components/widgets/TooltipLabel'

export default {
Expand Down Expand Up @@ -112,7 +112,7 @@ export default {
callListVms (accountId, domainId) {
return new Promise((resolve) => {
this.volumes = []
api('listVirtualMachines', {
getAPI('listVirtualMachines', {
accountId: accountId,
domainId: domainId,
details: 'min',
Expand Down Expand Up @@ -172,7 +172,7 @@ export default {
},
addNodesToKubernetesCluster (params) {
return new Promise((resolve, reject) => {
api('addNodesToKubernetesCluster', params).then(json => {
postAPI('addNodesToKubernetesCluster', params).then(json => {
Copy link

Copilot AI Jul 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can simplify this method by returning postAPI(...).then(json => json.addnodestokubernetesclusterresponse.jobid) directly, removing the explicit new Promise wrapper and reducing boilerplate.

Copilot uses AI. Check for mistakes.
const jobId = json.addnodestokubernetesclusterresponse.jobid
return resolve(jobId)
}).catch(error => {
Expand Down
4 changes: 2 additions & 2 deletions ui/src/views/compute/KubernetesRemoveNodes.vue
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@

<script>
import { ref, reactive, toRaw } from 'vue'
import { api } from '@/api'
import { postAPI } from '@/api'
import TooltipLabel from '@/components/widgets/TooltipLabel'

export default {
Expand Down Expand Up @@ -137,7 +137,7 @@ export default {
},
removeNodesFromKubernetesCluster (params) {
return new Promise((resolve, reject) => {
api('removeNodesFromKubernetesCluster', params).then(json => {
postAPI('removeNodesFromKubernetesCluster', params).then(json => {
Copy link

Copilot AI Jul 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid wrapping postAPI in a new Promise. Instead, return the promise directly and chain .then() to extract the job ID, which simplifies the code and ensures errors propagate correctly.

Copilot uses AI. Check for mistakes.
const jobId = json.removenodesfromkubernetesclusterresponse.jobid
return resolve(jobId)
}).catch(error => {
Expand Down
Loading