Skip to content

Commit 5b9d802

Browse files
sureshanapartidhslove
authored andcommitted
[UI] Use GET request method for list API calls (apache#11354)
* [UI] Use GET request method for list API calls * Updated UI unit tests
1 parent 458a417 commit 5b9d802

File tree

14 files changed

+68
-49
lines changed

14 files changed

+68
-49
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 additionalGetAPICommandsList = [
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) || additionalGetAPICommandsList.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
@@ -1270,45 +1270,45 @@ export default {
12701270
this.editableValue = record.value
12711271
},
12721272
getUpdateApi () {
1273-
let apiString = ''
1273+
let apiCommand = ''
12741274
switch (this.$route.name) {
12751275
case 'template':
1276-
apiString = 'updateTemplate'
1276+
apiCommand = 'updateTemplate'
12771277
break
12781278
case 'iso':
1279-
apiString = 'updateIso'
1279+
apiCommand = 'updateIso'
12801280
break
12811281
case 'zone':
1282-
apiString = 'updateZone'
1282+
apiCommand = 'updateZone'
12831283
break
12841284
case 'computeoffering':
12851285
case 'systemoffering':
1286-
apiString = 'updateServiceOffering'
1286+
apiCommand = 'updateServiceOffering'
12871287
break
12881288
case 'diskoffering':
1289-
apiString = 'updateDiskOffering'
1289+
apiCommand = 'updateDiskOffering'
12901290
break
12911291
case 'networkoffering':
1292-
apiString = 'updateNetworkOffering'
1292+
apiCommand = 'updateNetworkOffering'
12931293
break
12941294
case 'vpcoffering':
1295-
apiString = 'updateVPCOffering'
1295+
apiCommand = 'updateVPCOffering'
12961296
break
12971297
case 'guestoscategory':
1298-
apiString = 'updateOsCategory'
1298+
apiCommand = 'updateOsCategory'
12991299
break
13001300
}
1301-
return apiString
1301+
return apiCommand
13021302
},
13031303
isOrderUpdatable () {
13041304
return this.getUpdateApi() in this.$store.getters.apis
13051305
},
13061306
handleUpdateOrder (id, index) {
13071307
this.parentToggleLoading()
1308-
const apiString = this.getUpdateApi()
1308+
const apiCommand = this.getUpdateApi()
13091309
13101310
return new Promise((resolve, reject) => {
1311-
postAPI(apiString, {
1311+
postAPI(apiCommand, {
13121312
id,
13131313
sortKey: index
13141314
}).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
@@ -820,7 +820,7 @@
820820
<script>
821821
import { ref, reactive, toRaw, h } from 'vue'
822822
import { Button } from 'ant-design-vue'
823-
import { getAPI, postAPI } from '@/api'
823+
import { getAPI, postAPI, callAPI } from '@/api'
824824
import { mixinDevice } from '@/utils/mixin.js'
825825
import { genericCompare } from '@/utils/sort.js'
826826
import { sourceToken } from '@/utils/request'
@@ -1434,7 +1434,7 @@ export default {
14341434
delete params.listall
14351435
}
14361436
1437-
postAPI(this.apiName, params).then(json => {
1437+
callAPI(this.apiName, params).then(json => {
14381438
var responseName
14391439
var objectName
14401440
for (const key in json) {
@@ -1764,7 +1764,7 @@ export default {
17641764
if (showIcon) {
17651765
params.showicon = true
17661766
}
1767-
postAPI(possibleApi, params).then(json => {
1767+
callAPI(possibleApi, params).then(json => {
17681768
param.loading = false
17691769
for (const obj in json) {
17701770
if (obj.includes('response')) {

ui/src/views/compute/CreateAutoScaleVmGroup.vue

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

ui/src/views/compute/DeployVM.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1936,7 +1936,7 @@ export default {
19361936
}
19371937
if (!apiName) return resolve(zones)
19381938
1939-
postAPI(apiName, params).then(json => {
1939+
getAPI(apiName, params).then(json => {
19401940
let objectName
19411941
const responseName = [apiName.toLowerCase(), 'response'].join('')
19421942
for (const key in json[responseName]) {
@@ -2728,7 +2728,7 @@ export default {
27282728
const param = this.params.zones
27292729
const args = { showicon: true }
27302730
if (zoneId) args.id = zoneId
2731-
postAPI(param.list, args).then(json => {
2731+
getAPI(param.list, args).then(json => {
27322732
const zoneResponse = json.listzonesresponse.zone || []
27332733
if (listZoneAllow && listZoneAllow.length > 0) {
27342734
zoneResponse.map(zone => {

ui/src/views/compute/DeployVnfAppliance.vue

Lines changed: 2 additions & 2 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 => {

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)