Skip to content

Commit 1fc61a4

Browse files
committed
ui: Fetching all records in list* API
1 parent 450de92 commit 1fc61a4

File tree

1 file changed

+68
-9
lines changed

1 file changed

+68
-9
lines changed

ui/src/api/index.js

Lines changed: 68 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
import { axios } from '@/utils/request'
1919

20-
export function api (command, args = {}, method = 'GET', data = {}) {
20+
export async function api (command, args = {}, method = 'GET', data = {}) {
2121
let params = {}
2222
args.command = command
2323
args.response = 'json'
@@ -29,14 +29,73 @@ export function api (command, args = {}, method = 'GET', data = {}) {
2929
})
3030
}
3131

32-
return axios({
33-
params: {
34-
...args
35-
},
36-
url: '/',
37-
method,
38-
data: params || {}
39-
})
32+
const exemptedAPIs = ['listLdapConfigurations', 'listCapabilities', 'listIdps', 'listApis', 'listInfrastructure', 'listAndSwitchSamlAccount']
33+
34+
if ('page' in args || exemptedAPIs.includes(command) || !command.startsWith('list')) {
35+
return axios({
36+
params: {
37+
...args
38+
},
39+
url: '/',
40+
method,
41+
data: params || {}
42+
})
43+
}
44+
45+
const pagesize = 10
46+
let page = 1
47+
let items = []
48+
let done = false
49+
let response = null
50+
51+
while (!done) {
52+
args.page = page
53+
args.pagesize = pagesize
54+
await axios({
55+
params: {
56+
...args
57+
},
58+
url: '/',
59+
method,
60+
data: params || {}
61+
}).then(json => {
62+
var responseName
63+
var objectName
64+
for (const key in json) {
65+
if (key.includes('response')) {
66+
responseName = key
67+
break
68+
}
69+
}
70+
for (const key in json[responseName]) {
71+
if (key === 'count') {
72+
continue
73+
}
74+
objectName = key
75+
break
76+
}
77+
if (json[responseName][objectName]) {
78+
items = items.concat(json[responseName][objectName])
79+
console.log(command, page, responseName, objectName, items.length, json[responseName].count, 'WIP')
80+
}
81+
if (!json[responseName].count || json[responseName].count === items.length || !json[responseName][objectName]) {
82+
console.log(command, page, responseName, objectName, items.length, json[responseName].count, 'DONE')
83+
done = true
84+
json[responseName][objectName] = items
85+
console.log(json)
86+
response = new Promise((resolve) => {
87+
resolve(json)
88+
})
89+
return
90+
}
91+
page++
92+
}).catch(error => {
93+
response = new Promise((resolve, reject) => {
94+
reject(error)
95+
})
96+
})
97+
}
98+
return response
4099
}
41100

42101
export function login (arg) {

0 commit comments

Comments
 (0)