Skip to content

Commit 84f3cfa

Browse files
committed
Refactoring of the project creation component to enable domain, account, and user specification
1 parent 9ae696d commit 84f3cfa

File tree

5 files changed

+164
-3
lines changed

5 files changed

+164
-3
lines changed

ui/public/locales/en.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1764,6 +1764,8 @@
17641764
"label.project": "Project",
17651765
"label.project.invitation": "Project Invitations",
17661766
"label.project.name": "Project name",
1767+
"label.project.description.tooltip": "The description of the project. If not informed, defaults to the project's name.",
1768+
"label.project.user.tooltip": "The account's user that will be set as the project Admin. If not informed, defaults to the current account.",
17671769
"label.project.owner": "Project owner(s)",
17681770
"label.project.role": "Project role",
17691771
"label.project.roles": "Project roles",
@@ -3149,6 +3151,7 @@
31493151
"message.error.password": "Enter your password",
31503152
"message.error.path": "Please enter path",
31513153
"message.error.provide.setting": "Must provide a valid key and value for setting",
3154+
"message.error.required.project.name" : "The project's name is required.",
31523155
"message.error.rados.monitor": "Please enter RADOS monitor",
31533156
"message.error.rados.pool": "Please enter RADOS pool",
31543157
"message.error.rados.secret": "Please enter RADOS secret",
@@ -3567,6 +3570,7 @@
35673570
"message.success.migrating": "Migration completed successfully for",
35683571
"message.success.migration": "Migration completed successfully",
35693572
"message.success.move.acl.order": "Successfully moved ACL rule",
3573+
"message.success.project.creation": "Project created successfully",
35703574
"message.success.recurring.snapshot": "Successfully recurring Snapshots",
35713575
"message.success.register.iso": "Successfully registered ISO",
35723576
"message.success.register.keypair": "Successfully registered SSH key pair",

ui/public/locales/pt_BR.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1234,7 +1234,9 @@
12341234
"label.profilename": "Perfil",
12351235
"label.project": "Projeto",
12361236
"label.project.invitation": "Convites do projeto",
1237-
"label.project.name": "Nome de projeto",
1237+
"label.project.name": "Nome do projeto",
1238+
"label.project.description.tooltip": "A descri\u00e7\u00e3o do projeto. Se n\u00e3o informada, o nome do projeto \u00e9 utilizado.",
1239+
"label.project.user.tooltip": "O usu\u00e1rio da conta que ser\u00e1 Admin do projeto. Se n\u00e3o informada, a conta atual \u00e9 atribu\u00edda como Admin.",
12381240
"label.project.owner": "Dono(s) do projeto",
12391241
"label.project.role": "Fun\u00e7\u00e3o do projeto",
12401242
"label.project.roles": "Fun\u00e7\u00f5es do projeto",
@@ -2154,6 +2156,7 @@
21542156
"message.error.password": "Insira a sua senha",
21552157
"message.error.path": "Por favor, insira o path",
21562158
"message.error.provide.setting": "Deve fornecer uma chave v\u00e1lida e um valor para a configura\u00e7\u00e3o",
2159+
"message.error.required.project.name": "\u00C9 necess\u00e1rio informar um nome para o projeto.",
21572160
"message.error.rados.monitor": "Por favor, digite o monitor RADOS",
21582161
"message.error.rados.pool": "Por favor, digite o RADOS pool",
21592162
"message.error.rados.secret": "Por favor, digite o RADOS secret",
@@ -2418,6 +2421,7 @@
24182421
"message.success.migrate.volume": "Volume migrado com sucesso",
24192422
"message.success.migrating": "Migra\u00e7\u00e3o conclu\u00edda com sucesso para",
24202423
"message.success.move.acl.order": "Regra de ACL movida com sucesso",
2424+
"message.success.project.creation": "Projeto criado com sucesso",
24212425
"message.success.recurring.snapshot": "Snapshots recorrentes habilitado com sucesso",
24222426
"message.success.register.iso": "ISO registrado com sucesso",
24232427
"message.success.register.keypair": "Par de chaves SSH registrado com sucesso",

ui/src/config/section/project.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ export default {
6969
label: 'label.new.project',
7070
docHelp: 'adminguide/projects.html#creating-a-new-project',
7171
listView: true,
72-
args: ['name', 'displaytext']
72+
popup: true,
73+
component: shallowRef(defineAsyncComponent(() => import('@/views/project/CreateProject.vue')))
7374
},
7475
{
7576
api: 'updateProjectInvitation',

ui/src/views/compute/wizard/OwnershipSelection.vue

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
<template>
1919
<a-form layout="vertical" >
20-
<a-form-item :label="$t('label.owner.type')">
20+
<a-form-item :label="$t('label.owner.type')" v-if="$props.showOwnerTypeField === true">
2121
<a-select
2222
@change="changeAccountTypeOrDomain"
2323
v-model:value="selectedAccountType"
@@ -151,6 +151,10 @@ export default {
151151
props: {
152152
override: {
153153
type: Object
154+
},
155+
showOwnerTypeField: {
156+
type: Boolean,
157+
default: true
154158
}
155159
},
156160
created () {
Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
<template>
19+
<a-spin :spinning="loading">
20+
<a-form
21+
class="form"
22+
layout="vertical"
23+
:ref="formRef"
24+
:model="form"
25+
:rules="rules"
26+
>
27+
<a-form-item ref="name" name="name">
28+
<template #label>
29+
<tooltip-label :title="$t('label.name')"/>
30+
</template>
31+
<a-input
32+
v-focus="true"
33+
v-model:value="form.name"
34+
:placeholder="$t('label.project.name')" />
35+
</a-form-item>
36+
<a-form-item>
37+
<template #label>
38+
<tooltip-label :title="$t('label.description')" :tooltip="$t('label.project.description.tooltip')"/>
39+
</template>
40+
<a-input
41+
v-model:value="form.displaytext"
42+
:placeholder="$t('label.description')"/>
43+
</a-form-item>
44+
<ownership-selection v-if="isAdminOrDomainAdmin()" @fetch-owner="fetchOwner" :show-owner-type-field="false" />
45+
<a-form-item v-if="Object.keys(this.selectedAccount).length !== 0" ref="userid" name="userid">
46+
<template #label>
47+
<tooltip-label :title="$t('label.user')" :tooltip="$t('label.project.user.tooltip')"/>
48+
</template>
49+
<a-select
50+
v-model:value="form.userid"
51+
:loading="loading"
52+
showSearch
53+
:placeholder="this.$t('label.user')"
54+
>
55+
<a-select-option v-for="user in selectedAccount.user" :value="user.id" :key="user.id">
56+
{{ user.username }}
57+
</a-select-option>
58+
</a-select>
59+
</a-form-item>
60+
<div :span="24" class="action-button">
61+
<a-button @click="closeAction">{{ $t('label.cancel') }}</a-button>
62+
<a-button :loading="loading" ref="submit" type="primary" @click="handleSubmit">{{ $t('label.ok') }}</a-button>
63+
</div>
64+
</a-form>
65+
</a-spin>
66+
</template>
67+
68+
<script>
69+
70+
import { reactive, ref, toRaw } from 'vue'
71+
import { api } from '@/api'
72+
import TooltipLabel from '@/components/widgets/TooltipLabel.vue'
73+
import ResourceIcon from '@/components/view/ResourceIcon.vue'
74+
import OwnershipSelection from '@/views/compute/wizard/OwnershipSelection.vue'
75+
import { isAdminOrDomainAdmin } from '@/role'
76+
77+
export default {
78+
name: 'CreateProject',
79+
components: { OwnershipSelection, ResourceIcon, TooltipLabel },
80+
data () {
81+
return {
82+
loading: false,
83+
selectedAccount: {}
84+
}
85+
},
86+
created () {
87+
this.initForm()
88+
},
89+
methods: {
90+
initForm () {
91+
this.formRef = ref()
92+
this.form = reactive({})
93+
this.rules = reactive({
94+
name: [{ required: true, message: this.$t('message.error.required.project.name') }]
95+
})
96+
},
97+
fetchOwner (ownerData) {
98+
if (ownerData.selectedAccountType === 'Account') {
99+
if (!ownerData.selectedAccount) {
100+
this.selectedAccount = {}
101+
return
102+
}
103+
104+
this.selectedAccount = ownerData.accounts.find(acc => acc.name === ownerData.selectedAccount)
105+
this.form.account = ownerData.selectedAccount
106+
this.form.domainId = ownerData.selectedDomain
107+
}
108+
},
109+
isAdminOrDomainAdmin () {
110+
return isAdminOrDomainAdmin()
111+
},
112+
handleSubmit (e) {
113+
e.preventDefault()
114+
if (this.loading) return
115+
116+
this.formRef.value.validate().then(() => {
117+
this.loading = true
118+
const params = toRaw(this.form)
119+
120+
if (isAdminOrDomainAdmin()) {
121+
params.accountid = this.selectedAccount.id
122+
}
123+
124+
api('createProject', {}, 'POST', params).then(() => {
125+
this.$message.success(this.$t('message.success.project.creation'))
126+
this.closeAction()
127+
this.$emit('refresh-data')
128+
}).catch(error => {
129+
this.$notifyError(error)
130+
}).finally(() => {
131+
this.loading = false
132+
})
133+
})
134+
},
135+
closeAction () {
136+
this.$emit('close-action')
137+
}
138+
}
139+
}
140+
141+
</script>
142+
143+
<style lang="less" scoped>
144+
.form {
145+
width: 20vw;
146+
147+
}
148+
</style>

0 commit comments

Comments
 (0)