Skip to content

Commit dd2881e

Browse files
[UI] Use GET request method for list API calls
1 parent 86827f8 commit dd2881e

File tree

13 files changed

+58
-39
lines changed

13 files changed

+58
-39
lines changed

ui/src/api/index.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,19 @@ import {
2323
ACCESS_TOKEN
2424
} from '@/store/mutation-types'
2525

26+
const getAPICommandsRegex = /^(get|list|query|find)\w+$/i
27+
const addlGetAPICommandsList = [
28+
'isaccountallowedtocreateofferingswithtags',
29+
'readyforshutdown',
30+
'cloudianisenabled',
31+
'quotabalance',
32+
'quotasummary',
33+
'quotatarifflist',
34+
'quotaisenabled',
35+
'quotastatement',
36+
'verifyoauthcodeandgetuser'
37+
]
38+
2639
export function getAPI (command, args = {}) {
2740
args.command = command
2841
args.response = 'json'
@@ -64,6 +77,12 @@ export function postAPI (command, data = {}) {
6477
})
6578
}
6679

80+
export function callAPI (command, args = {}) {
81+
const isGetAPICommand = getAPICommandsRegex.test(command) || addlGetAPICommandsList.includes(command.toLowerCase())
82+
const call = isGetAPICommand ? getAPI : postAPI
83+
return call(command, args)
84+
}
85+
6786
export function login (arg) {
6887
if (!sourceToken.checkExistSource()) {
6988
sourceToken.init()

ui/src/components/view/ListView.vue

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1230,45 +1230,45 @@ export default {
12301230
this.editableValue = record.value
12311231
},
12321232
getUpdateApi () {
1233-
let apiString = ''
1233+
let apiCommand = ''
12341234
switch (this.$route.name) {
12351235
case 'template':
1236-
apiString = 'updateTemplate'
1236+
apiCommand = 'updateTemplate'
12371237
break
12381238
case 'iso':
1239-
apiString = 'updateIso'
1239+
apiCommand = 'updateIso'
12401240
break
12411241
case 'zone':
1242-
apiString = 'updateZone'
1242+
apiCommand = 'updateZone'
12431243
break
12441244
case 'computeoffering':
12451245
case 'systemoffering':
1246-
apiString = 'updateServiceOffering'
1246+
apiCommand = 'updateServiceOffering'
12471247
break
12481248
case 'diskoffering':
1249-
apiString = 'updateDiskOffering'
1249+
apiCommand = 'updateDiskOffering'
12501250
break
12511251
case 'networkoffering':
1252-
apiString = 'updateNetworkOffering'
1252+
apiCommand = 'updateNetworkOffering'
12531253
break
12541254
case 'vpcoffering':
1255-
apiString = 'updateVPCOffering'
1255+
apiCommand = 'updateVPCOffering'
12561256
break
12571257
case 'guestoscategory':
1258-
apiString = 'updateOsCategory'
1258+
apiCommand = 'updateOsCategory'
12591259
break
12601260
}
1261-
return apiString
1261+
return apiCommand
12621262
},
12631263
isOrderUpdatable () {
12641264
return this.getUpdateApi() in this.$store.getters.apis
12651265
},
12661266
handleUpdateOrder (id, index) {
12671267
this.parentToggleLoading()
1268-
const apiString = this.getUpdateApi()
1268+
const apiCommand = this.getUpdateApi()
12691269
12701270
return new Promise((resolve, reject) => {
1271-
postAPI(apiString, {
1271+
postAPI(apiCommand, {
12721272
id,
12731273
sortKey: index
12741274
}).then((response) => {

ui/src/components/view/TreeView.vue

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@
9292

9393
<script>
9494
import store from '@/store'
95-
import { postAPI } from '@/api'
95+
import { callAPI } from '@/api'
9696
import DetailsTab from '@/components/view/DetailsTab'
9797
import ResourceView from '@/components/view/ResourceView'
9898
import ResourceLayout from '@/layouts/ResourceLayout'
@@ -268,7 +268,7 @@ export default {
268268
}
269269
270270
return new Promise(resolve => {
271-
postAPI(this.apiChildren, params).then(json => {
271+
callAPI(this.apiChildren, params).then(json => {
272272
const dataResponse = this.getResponseJsonData(json)
273273
const dataGenerate = this.generateTreeData(dataResponse)
274274
treeNode.dataRef.children = dataGenerate
@@ -390,7 +390,7 @@ export default {
390390
this.treeViewData = []
391391
this.loadingSearch = true
392392
this.$emit('change-tree-store', {})
393-
postAPI(this.apiList, params).then(json => {
393+
callAPI(this.apiList, params).then(json => {
394394
const listDomains = this.getResponseJsonData(json)
395395
this.treeVerticalData = this.treeVerticalData.concat(listDomains)
396396
@@ -454,7 +454,7 @@ export default {
454454
params.pageSize = 1
455455
456456
this.detailLoading = true
457-
postAPI(apiName, params).then(json => {
457+
callAPI(apiName, params).then(json => {
458458
const jsonResponse = this.getResponseJsonData(json)
459459
resolve(jsonResponse[0])
460460
}).catch(() => {

ui/src/components/widgets/InfiniteScrollSelect.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@
8888
</template>
8989

9090
<script>
91-
import { postAPI } from '@/api'
91+
import { getAPI } from '@/api'
9292
import ResourceIcon from '@/components/view/ResourceIcon'
9393
9494
export default {
@@ -191,7 +191,7 @@ export default {
191191
if (this.showIcon) {
192192
params.showicon = true
193193
}
194-
postAPI(this.api, params).then(json => {
194+
getAPI(this.api, params).then(json => {
195195
const response = json[this.api.toLowerCase() + 'response'] || {}
196196
if (this.totalCount === null) {
197197
this.totalCount = response.count || 0

ui/src/views/AutogenView.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,7 @@
587587
<script>
588588
import { ref, reactive, toRaw, h } from 'vue'
589589
import { Button } from 'ant-design-vue'
590-
import { getAPI, postAPI } from '@/api'
590+
import { getAPI, postAPI, callAPI } from '@/api'
591591
import { mixinDevice } from '@/utils/mixin.js'
592592
import { genericCompare } from '@/utils/sort.js'
593593
import { sourceToken } from '@/utils/request'
@@ -1119,7 +1119,7 @@ export default {
11191119
delete params.listall
11201120
}
11211121
1122-
postAPI(this.apiName, params).then(json => {
1122+
callAPI(this.apiName, params).then(json => {
11231123
var responseName
11241124
var objectName
11251125
for (const key in json) {
@@ -1449,7 +1449,7 @@ export default {
14491449
if (showIcon) {
14501450
params.showicon = true
14511451
}
1452-
postAPI(possibleApi, params).then(json => {
1452+
callAPI(possibleApi, params).then(json => {
14531453
param.loading = false
14541454
for (const obj in json) {
14551455
if (obj.includes('response')) {

ui/src/views/compute/CreateAutoScaleVmGroup.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2896,7 +2896,7 @@ export default {
28962896
const param = this.params.zones
28972897
const args = { showicon: true }
28982898
if (zoneId) args.id = zoneId
2899-
postAPI(param.list, args).then(json => {
2899+
getAPI(param.list, args).then(json => {
29002900
const zoneResponse = (json.listzonesresponse.zone || []).filter(item => item.securitygroupsenabled === false)
29012901
if (listZoneAllow && listZoneAllow.length > 0) {
29022902
zoneResponse.map(zone => {
@@ -2928,7 +2928,7 @@ export default {
29282928
if (!('listall' in options) && !['zones', 'pods', 'clusters', 'hosts', 'dynamicScalingVmConfig', 'hypervisors'].includes(name)) {
29292929
options.listall = true
29302930
}
2931-
postAPI(param.list, options).then((response) => {
2931+
getAPI(param.list, options).then((response) => {
29322932
param.loading = false
29332933
_.map(response, (responseItem, responseKey) => {
29342934
if (Object.keys(responseItem).length === 0) {

ui/src/views/compute/DeployVM.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1812,7 +1812,7 @@ export default {
18121812
}
18131813
if (!apiName) return resolve(zones)
18141814
1815-
postAPI(apiName, params).then(json => {
1815+
getAPI(apiName, params).then(json => {
18161816
let objectName
18171817
const responseName = [apiName.toLowerCase(), 'response'].join('')
18181818
for (const key in json[responseName]) {
@@ -2504,7 +2504,7 @@ export default {
25042504
const param = this.params.zones
25052505
const args = { showicon: true }
25062506
if (zoneId) args.id = zoneId
2507-
postAPI(param.list, args).then(json => {
2507+
getAPI(param.list, args).then(json => {
25082508
const zoneResponse = json.listzonesresponse.zone || []
25092509
if (listZoneAllow && listZoneAllow.length > 0) {
25102510
zoneResponse.map(zone => {
@@ -2536,7 +2536,7 @@ export default {
25362536
if (!('listall' in options) && !['zones', 'pods', 'clusters', 'hosts', 'dynamicScalingVmConfig', 'hypervisors'].includes(name)) {
25372537
options.listall = true
25382538
}
2539-
postAPI(param.list, options).then((response) => {
2539+
getAPI(param.list, options).then((response) => {
25402540
param.loading = false
25412541
_.map(response, (responseItem, responseKey) => {
25422542
if (Object.keys(responseItem).length === 0) {

ui/src/views/compute/DeployVnfAppliance.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1721,7 +1721,7 @@ export default {
17211721
}
17221722
if (!apiName) return resolve(zones)
17231723
1724-
postAPI(apiName, params).then(json => {
1724+
getAPI(apiName, params).then(json => {
17251725
let objectName
17261726
const responseName = [apiName.toLowerCase(), 'response'].join('')
17271727
for (const key in json[responseName]) {
@@ -2447,7 +2447,7 @@ export default {
24472447
const param = this.params.zones
24482448
const args = { showicon: true }
24492449
if (zoneId) args.id = zoneId
2450-
postAPI(param.list, args).then(json => {
2450+
getAPI(param.list, args).then(json => {
24512451
const zoneResponse = json.listzonesresponse.zone || []
24522452
if (listZoneAllow && listZoneAllow.length > 0) {
24532453
zoneResponse.map(zone => {
@@ -2479,7 +2479,7 @@ export default {
24792479
if (!('listall' in options) && !['zones', 'pods', 'clusters', 'hosts', 'dynamicScalingVmConfig', 'hypervisors'].includes(name)) {
24802480
options.listall = true
24812481
}
2482-
postAPI(param.list, options).then((response) => {
2482+
getAPI(param.list, options).then((response) => {
24832483
param.loading = false
24842484
_.map(response, (responseItem, responseKey) => {
24852485
if (Object.keys(responseItem).length === 0) {

ui/src/views/iam/DomainView.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
</template>
7979

8080
<script>
81-
import { getAPI, postAPI } from '@/api'
81+
import { getAPI, callAPI } from '@/api'
8282
import store from '@/store'
8383
import { mixinDevice } from '@/utils/mixin.js'
8484
@@ -274,7 +274,7 @@ export default {
274274
}
275275
param.loading = true
276276
param.opts = []
277-
postAPI(possibleApi, params)
277+
callAPI(possibleApi, params)
278278
.then(json => {
279279
param.loading = false
280280
const responseObj = Object.values(json).find(obj => obj.includes('response'))

ui/src/views/infra/network/providers/ProviderItem.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
</template>
5252

5353
<script>
54-
import { postAPI } from '@/api'
54+
import { getAPI } from '@/api'
5555
import ActionButton from '@/components/view/ActionButton'
5656
import ProviderDetail from '@/views/infra/network/providers/ProviderDetail'
5757
import ProviderListView from '@/views/infra/network/providers/ProviderListView'
@@ -199,7 +199,7 @@ export default {
199199
},
200200
executeApi (apiName, params) {
201201
return new Promise((resolve, reject) => {
202-
postAPI(apiName, params).then(json => {
202+
getAPI(apiName, params).then(json => {
203203
let responseName
204204
let objectName
205205
let itemCount = 0

0 commit comments

Comments
 (0)