Skip to content

Commit aa48ec9

Browse files
sureshanapartiKevin Li
andcommitted
UI changes to use POST requests for state changing APIs
Co-authored-by: Kevin Li <[email protected]>
1 parent 9afef77 commit aa48ec9

File tree

207 files changed

+1221
-1244
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

207 files changed

+1221
-1244
lines changed

ui/src/api/index.js

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

26-
export function api (command, args = {}, method = 'GET', data = {}) {
27-
let params = {}
26+
export function getAPI (command, args = {}) {
2827
args.command = command
2928
args.response = 'json'
3029

31-
if (data) {
32-
params = new URLSearchParams()
33-
Object.entries(data).forEach(([key, value]) => {
34-
params.append(key, value)
35-
})
36-
}
37-
3830
const sessionkey = vueProps.$localStorage.get(ACCESS_TOKEN) || Cookies.get('sessionkey')
3931
if (sessionkey) {
4032
args.sessionkey = sessionkey
@@ -45,8 +37,30 @@ export function api (command, args = {}, method = 'GET', data = {}) {
4537
...args
4638
},
4739
url: '/',
48-
method,
49-
data: params || {}
40+
method: 'GET'
41+
})
42+
}
43+
44+
export function postAPI (command, data = {}) {
45+
const params = new URLSearchParams()
46+
params.append('command', command)
47+
params.append('response', 'json')
48+
if (data) {
49+
Object.entries(data).forEach(([key, value]) => {
50+
if (value !== undefined && value !== null && value !== '') {
51+
params.append(key, value)
52+
}
53+
})
54+
}
55+
56+
const sessionkey = vueProps.$localStorage.get(ACCESS_TOKEN) || Cookies.get('sessionkey')
57+
if (sessionkey) {
58+
params.append('sessionkey', sessionkey)
59+
}
60+
return axios({
61+
url: '/',
62+
method: 'POST',
63+
data: params
5064
})
5165
}
5266

@@ -56,7 +70,7 @@ export function login (arg) {
5670
}
5771

5872
// Logout before login is called to purge any duplicate sessionkey cookies
59-
api('logout')
73+
postAPI('logout')
6074

6175
const params = new URLSearchParams()
6276
params.append('command', 'login')
@@ -66,7 +80,7 @@ export function login (arg) {
6680
params.append('response', 'json')
6781
return axios({
6882
url: '/',
69-
method: 'post',
83+
method: 'POST',
7084
data: params,
7185
headers: {
7286
'content-type': 'application/x-www-form-urlencoded'
@@ -77,7 +91,7 @@ export function login (arg) {
7791
export function logout () {
7892
message.destroy()
7993
notification.destroy()
80-
return api('logout')
94+
return postAPI('logout')
8195
}
8296

8397
export function oauthlogin (arg) {
@@ -86,7 +100,7 @@ export function oauthlogin (arg) {
86100
}
87101

88102
// Logout before login is called to purge any duplicate sessionkey cookies
89-
api('logout')
103+
postAPI('logout')
90104

91105
const params = new URLSearchParams()
92106
params.append('command', 'oauthlogin')

ui/src/components/header/SamlDomainSwitcher.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151

5252
<script>
5353
import store from '@/store'
54-
import { api } from '@/api'
54+
import { postAPI } from '@/api'
5555
import _ from 'lodash'
5656
5757
export default {
@@ -73,7 +73,7 @@ export default {
7373
const samlAccounts = []
7474
const getNextPage = () => {
7575
this.loading = true
76-
api('listAndSwitchSamlAccount', { details: 'min', page: page, pageSize: 500 }).then(json => {
76+
postAPI('listAndSwitchSamlAccount', { details: 'min', page: page, pageSize: 500 }).then(json => {
7777
if (json && json.listandswitchsamlaccountresponse && json.listandswitchsamlaccountresponse.samluseraccount) {
7878
samlAccounts.push(...json.listandswitchsamlaccountresponse.samluseraccount)
7979
}
@@ -102,7 +102,7 @@ export default {
102102
},
103103
changeAccount (index) {
104104
const account = this.samlAccounts[index]
105-
api('listAndSwitchSamlAccount', {}, 'POST', {
105+
postAPI('listAndSwitchSamlAccount', {}, 'POST', {
106106
userid: account.userId,
107107
domainid: account.domainId
108108
}).then(response => {

ui/src/components/header/UserMenu.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
</template>
7272

7373
<script>
74-
import { api } from '@/api'
74+
import { getAPI } from '@/api'
7575
import CreateMenu from './CreateMenu'
7676
import ExternalLink from './ExternalLink'
7777
import HeaderNotice from './HeaderNotice'
@@ -143,7 +143,7 @@ export default {
143143
this.image = this.$store.getters.avatar
144144
resolve(this.image)
145145
}
146-
api('listUsers', {
146+
getAPI('listUsers', {
147147
id: id,
148148
showicon: true
149149
}).then(json => {

ui/src/components/page/GlobalLayout.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ import { triggerWindowResizeEvent } from '@/utils/util'
128128
import { mapState, mapActions } from 'vuex'
129129
import { mixin, mixinDevice } from '@/utils/mixin.js'
130130
import { isAdmin } from '@/role'
131-
import { api } from '@/api'
131+
import { getAPI } from '@/api'
132132
import Drawer from '@/components/widgets/Drawer'
133133
import Setting from '@/components/view/Setting.vue'
134134
@@ -260,7 +260,7 @@ export default {
260260
this.$store.commit('SET_COUNT_NOTIFY', 0)
261261
},
262262
checkShutdown () {
263-
api('readyForShutdown', { managementserverid: this.$store.getters.msId }).then(json => {
263+
getAPI('readyForShutdown', { managementserverid: this.$store.getters.msId }).then(json => {
264264
this.$store.dispatch('SetShutdownTriggered', json.readyforshutdownresponse.readyforshutdown.shutdowntriggered || false)
265265
this.$store.dispatch('SetMaintenanceInitiated', json.readyforshutdownresponse.readyforshutdown.maintenanceinitiated || false)
266266
})

ui/src/components/view/ActionButton.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@
101101
</template>
102102

103103
<script>
104-
import { api } from '@/api'
104+
import { postAPI } from '@/api'
105105
import Console from '@/components/widgets/Console'
106106
107107
export default {
@@ -194,7 +194,7 @@ export default {
194194
const action = actionBadge[i]
195195
196196
arrAsync.push(new Promise((resolve, reject) => {
197-
api(action.api, action.param).then(json => {
197+
postAPI(action.api, action.param).then(json => {
198198
let responseJsonName
199199
const response = {}
200200

ui/src/components/view/AnnotationsTab.vue

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@
119119

120120
<script>
121121
122-
import { api } from '@/api'
122+
import { getAPI, postAPI } from '@/api'
123123
124124
export default {
125125
name: 'AnnotationsTab',
@@ -217,7 +217,7 @@ export default {
217217
}
218218
this.loadingAnnotations = true
219219
this.notes = []
220-
api('listAnnotations', { entityid: this.resource.id, entitytype: this.annotationType, annotationfilter: 'all', page: this.page, pagesize: this.pageSize }).then(json => {
220+
getAPI('listAnnotations', { entityid: this.resource.id, entitytype: this.annotationType, annotationfilter: 'all', page: this.page, pagesize: this.pageSize }).then(json => {
221221
if (json.listannotationsresponse && json.listannotationsresponse.annotation) {
222222
this.notes = json.listannotationsresponse.annotation
223223
this.itemCount = json.listannotationsresponse.count
@@ -246,7 +246,7 @@ export default {
246246
args.entitytype = this.annotationType
247247
args.annotation = this.annotation
248248
args.adminsonly = this.annotationAdminsOnly
249-
api('addAnnotation', args).catch(error => {
249+
postAPI('addAnnotation', args).catch(error => {
250250
this.$notifyError(error)
251251
}).finally(e => {
252252
this.getAnnotations()
@@ -258,7 +258,7 @@ export default {
258258
this.loadingAnnotations = true
259259
const args = {}
260260
args.id = annotation.id
261-
api('removeAnnotation', args).catch(error => {
261+
postAPI('removeAnnotation', args).catch(error => {
262262
this.$notifyError(error)
263263
}).finally(e => {
264264
this.getAnnotations()
@@ -270,7 +270,7 @@ export default {
270270
id: annotation.id,
271271
adminsonly: !annotation.adminsonly
272272
}
273-
api('updateAnnotationVisibility', args).catch(error => {
273+
postAPI('updateAnnotationVisibility', args).catch(error => {
274274
this.$notifyError(error)
275275
}).finally(e => {
276276
this.getAnnotations()

ui/src/components/view/DedicateData.vue

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
</template>
5454

5555
<script>
56-
import { api } from '@/api'
56+
import { getAPI, postAPI } from '@/api'
5757
import DedicateModal from './DedicateModal'
5858
5959
export default {
@@ -124,7 +124,7 @@ export default {
124124
}
125125
},
126126
fetchDedicatedZones () {
127-
api('listDedicatedZones', {
127+
getAPI('listDedicatedZones', {
128128
zoneid: this.resource.id
129129
}).then(response => {
130130
if (response?.listdedicatedzonesresponse?.dedicatedzone?.length > 0) {
@@ -136,7 +136,7 @@ export default {
136136
})
137137
},
138138
fetchDedicatedPods () {
139-
api('listDedicatedPods', {
139+
getAPI('listDedicatedPods', {
140140
podid: this.resource.id
141141
}).then(response => {
142142
if (response?.listdedicatedpodsresponse?.dedicatedpod?.length > 0) {
@@ -148,7 +148,7 @@ export default {
148148
})
149149
},
150150
fetchDedicatedClusters () {
151-
api('listDedicatedClusters', {
151+
getAPI('listDedicatedClusters', {
152152
clusterid: this.resource.id
153153
}).then(response => {
154154
if (response?.listdedicatedclustersresponse?.dedicatedcluster?.length > 0) {
@@ -160,7 +160,7 @@ export default {
160160
})
161161
},
162162
fetchDedicatedHosts () {
163-
api('listDedicatedHosts', {
163+
getAPI('listDedicatedHosts', {
164164
hostid: this.resource.id
165165
}).then(response => {
166166
if (response?.listdedicatedhostsresponse?.dedicatedhost?.length > 0) {
@@ -172,7 +172,7 @@ export default {
172172
})
173173
},
174174
releaseDedidcatedZone () {
175-
api('releaseDedicatedZone', {
175+
postAPI('releaseDedicatedZone', {
176176
zoneid: this.resource.id
177177
}).then(response => {
178178
this.$pollJob({
@@ -195,7 +195,7 @@ export default {
195195
})
196196
},
197197
releaseDedidcatedPod () {
198-
api('releaseDedicatedPod', {
198+
postAPI('releaseDedicatedPod', {
199199
podid: this.resource.id
200200
}).then(response => {
201201
this.$pollJob({
@@ -218,7 +218,7 @@ export default {
218218
})
219219
},
220220
releaseDedidcatedCluster () {
221-
api('releaseDedicatedCluster', {
221+
postAPI('releaseDedicatedCluster', {
222222
clusterid: this.resource.id
223223
}).then(response => {
224224
this.$pollJob({
@@ -241,7 +241,7 @@ export default {
241241
})
242242
},
243243
releaseDedidcatedHost () {
244-
api('releaseDedicatedHost', {
244+
postAPI('releaseDedicatedHost', {
245245
hostid: this.resource.id
246246
}).then(response => {
247247
this.$pollJob({

ui/src/components/view/DedicateDomain.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
</template>
6161

6262
<script>
63-
import { api } from '@/api'
63+
import { getAPI } from '@/api'
6464
6565
export default {
6666
name: 'DedicateDomain',
@@ -90,7 +90,7 @@ export default {
9090
methods: {
9191
fetchData () {
9292
this.domainsLoading = true
93-
api('listDomains', {
93+
getAPI('listDomains', {
9494
listAll: true,
9595
details: 'min'
9696
}).then(response => {
@@ -107,7 +107,7 @@ export default {
107107
})
108108
},
109109
fetchAccounts () {
110-
api('listAccounts', {
110+
getAPI('listAccounts', {
111111
domainid: this.domainId
112112
}).then(response => {
113113
this.accountsList = response.listaccountsresponse.account || []

ui/src/components/view/DedicateModal.vue

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
</template>
3838

3939
<script>
40-
import { api } from '@/api'
40+
import { postAPI } from '@/api'
4141
import DedicateDomain from './DedicateDomain'
4242
4343
export default {
@@ -92,7 +92,7 @@ export default {
9292
this.domainError = true
9393
return
9494
}
95-
api('dedicateZone', {
95+
postAPI('dedicateZone', {
9696
zoneId: this.resource.id,
9797
domainId: this.domainId,
9898
account: this.dedicatedAccount
@@ -134,7 +134,7 @@ export default {
134134
this.domainError = true
135135
return
136136
}
137-
api('dedicatePod', {
137+
postAPI('dedicatePod', {
138138
podId: this.resource.id,
139139
domainId: this.domainId,
140140
account: this.dedicatedAccount
@@ -176,7 +176,7 @@ export default {
176176
this.domainError = true
177177
return
178178
}
179-
api('dedicateCluster', {
179+
postAPI('dedicateCluster', {
180180
clusterId: this.resource.id,
181181
domainId: this.domainId,
182182
account: this.dedicatedAccount
@@ -218,7 +218,7 @@ export default {
218218
this.domainError = true
219219
return
220220
}
221-
api('dedicateHost', {
221+
postAPI('dedicateHost', {
222222
hostId: this.resource.id,
223223
domainId: this.domainId,
224224
account: this.dedicatedAccount

ui/src/components/view/DetailSettings.vue

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@
128128
</template>
129129

130130
<script>
131-
import { api } from '@/api'
131+
import { getAPI, postAPI } from '@/api'
132132
import TooltipButton from '@/components/widgets/TooltipButton'
133133
134134
export default {
@@ -209,11 +209,11 @@ export default {
209209
return { name: k, value: resource.details[k], edit: false }
210210
})
211211
}
212-
api('listDetailOptions', { resourcetype: this.resourceType, resourceid: resource.id }).then(json => {
212+
getAPI('listDetailOptions', { resourcetype: this.resourceType, resourceid: resource.id }).then(json => {
213213
this.detailOptions = json.listdetailoptionsresponse.detailoptions.details
214214
})
215215
this.disableSettings = (this.$route.meta.name === 'vm' && resource.state !== 'Stopped')
216-
api('listTemplates', { templatefilter: 'all', id: resource.templateid }).then(json => {
216+
getAPI('listTemplates', { templatefilter: 'all', id: resource.templateid }).then(json => {
217217
this.deployasistemplate = json.listtemplatesresponse.template[0].deployasis
218218
})
219219
},
@@ -291,7 +291,7 @@ export default {
291291
var params = { id: this.resource.id }
292292
params = Object.assign(params, this.getDetailsParam(this.details))
293293
this.loading = true
294-
api(apiName, params).then(json => {
294+
postAPI(apiName, params).then(json => {
295295
var details = {}
296296
if (this.resourceType === 'UserVm' && json.updatevirtualmachineresponse.virtualmachine.details) {
297297
details = json.updatevirtualmachineresponse.virtualmachine.details

0 commit comments

Comments
 (0)