Skip to content

Commit 96232b3

Browse files
bernardodemarcodhslove
authored andcommitted
UI: Allow accounts of the User type to add other accounts or users to projects through UI (apache#9927)
1 parent 5c9e02d commit 96232b3

File tree

1 file changed

+60
-35
lines changed

1 file changed

+60
-35
lines changed

ui/src/views/project/AddAccountOrUserToProject.vue

Lines changed: 60 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -31,27 +31,23 @@
3131
<template #label>
3232
<tooltip-label :title="$t('label.account')" :tooltip="apiParams.addAccountToProject.account.description"/>
3333
</template>
34-
<a-select
35-
show-search
34+
<a-auto-complete
3635
v-model:value="form.account"
3736
:placeholder="apiParams.addAccountToProject.account.description"
38-
v-focus="true"
39-
:filterOption="false"
40-
@search="fetchAccounts"
41-
>
42-
<template v-if="load.accounts" #notFoundContent>
43-
<a-spin size="small" />
44-
</template>
45-
<template v-if="!load.accounts">
46-
<a-select-option v-for="account in accounts" :key="account.name" :value="account.name">
47-
<span v-if="account.icon">
48-
<resource-icon :image="account.icon.base64image" size="1x" style="margin-right: 5px"/>
49-
</span>
50-
<block-outlined v-else style="margin-right: 5px" />
51-
{{ account.name }}
52-
</a-select-option>
53-
</template>
54-
</a-select>
37+
:filterOption="filterOption"
38+
:options="accounts"
39+
>
40+
<template v-if="load.accounts" #notFoundContent>
41+
<a-spin size="small" />
42+
</template>
43+
<template v-if="!load.accounts" #option="account">
44+
<span v-if="account.icon">
45+
<resource-icon :image="account.icon.base64image" size="1x" style="margin-right: 5px"/>
46+
</span>
47+
<block-outlined v-else style="margin-right: 5px" />
48+
{{ account.name }}
49+
</template>
50+
</a-auto-complete>
5551
</a-form-item>
5652
<a-form-item name="email" ref="email">
5753
<template #label>
@@ -121,27 +117,23 @@
121117
<template #label>
122118
<tooltip-label :title="$t('label.name')" :tooltip="apiParams.addUserToProject.username.description"/>
123119
</template>
124-
<a-select
125-
show-search
120+
<a-auto-complete
126121
v-model:value="form.username"
127122
:placeholder="apiParams.addUserToProject.username.description"
128-
v-focus="true"
129-
:filterOption="false"
130-
@search="fetchUsers"
123+
:filterOption="filterOption"
124+
:options="users"
131125
>
132126
<template v-if="load.users" #notFoundContent>
133127
<a-spin size="small" />
134128
</template>
135-
<template v-if="!load.users">
136-
<a-select-option v-for="user in users" :key="user.username" :value="user.username">
137-
<span v-if="user.icon">
138-
<resource-icon :image="user.icon.base64image" size="1x" style="margin-right: 5px"/>
139-
</span>
140-
<block-outlined v-else style="margin-right: 5px" />
141-
{{ user.firstname + ' ' + user.lastname + " (" + user.username + ")" }}
142-
</a-select-option>
129+
<template v-if="!load.users" #option="user">
130+
<span v-if="user.icon">
131+
<resource-icon :image="user.icon.base64image" size="1x" style="margin-right: 5px"/>
132+
</span>
133+
<block-outlined v-else style="margin-right: 5px" />
134+
{{ user.firstName + ' ' + user.lastName + " (" + user.username + ")" }}
143135
</template>
144-
</a-select>
136+
</a-auto-complete>
145137
</a-form-item>
146138
<a-form-item name="email" ref="email">
147139
<template #label>
@@ -254,34 +246,67 @@ export default {
254246
this.fetchProjectRoles()
255247
}
256248
},
249+
filterOption (input, option) {
250+
return (
251+
option.value.toUpperCase().indexOf(input.toUpperCase()) >= 0
252+
)
253+
},
257254
fetchUsers (keyword) {
258255
this.load.users = true
259256
const params = { listall: true, showicon: true }
260257
if (keyword) {
261258
params.keyword = keyword
262259
}
263260
api('listUsers', params).then(response => {
264-
this.users = response.listusersresponse.user ? response.listusersresponse.user : []
261+
this.users = this.parseUsers(response?.listusersresponse?.user)
265262
}).catch(error => {
266263
this.$notifyError(error)
267264
}).finally(() => {
268265
this.load.users = false
269266
})
270267
},
268+
parseUsers (users) {
269+
if (!users) {
270+
return []
271+
}
272+
273+
return users.map(user => {
274+
return {
275+
value: user.username,
276+
username: user.username,
277+
firstName: user.firstname,
278+
lastName: user.lastname,
279+
icon: user.icon
280+
}
281+
})
282+
},
271283
fetchAccounts (keyword) {
272284
this.load.accounts = true
273285
const params = { domainid: this.resource.domainid, showicon: true }
274286
if (keyword) {
275287
params.keyword = keyword
276288
}
277289
api('listAccounts', params).then(response => {
278-
this.accounts = response.listaccountsresponse.account || []
290+
this.accounts = this.parseAccounts(response?.listaccountsresponse?.account)
279291
}).catch(error => {
280292
this.$notifyError(error)
281293
}).finally(() => {
282294
this.load.accounts = false
283295
})
284296
},
297+
parseAccounts (accounts) {
298+
if (!accounts) {
299+
return []
300+
}
301+
302+
return accounts.map(account => {
303+
return {
304+
value: account.name,
305+
name: account.name,
306+
icon: account.icon
307+
}
308+
})
309+
},
285310
fetchProjectRoles () {
286311
this.load.projectRoles = true
287312
api('listProjectRoles', {

0 commit comments

Comments
 (0)