mirror of https://github.com/rancher/dashboard.git
Making use of the rancher/norman api to create/update projects
rancher/dashboard#3090
This commit is contained in:
parent
579a562839
commit
49106dec3b
|
|
@ -18,6 +18,7 @@ export const NORMAN = {
|
|||
CLUSTER_ROLE_TEMPLATE_BINDING: 'clusterRoleTemplateBinding',
|
||||
GROUP: 'group',
|
||||
PRINCIPAL: 'principal',
|
||||
PROJECT: 'project',
|
||||
SPOOFED: { GROUP_PRINCIPAL: 'group.principal' },
|
||||
TOKEN: 'token',
|
||||
USER: 'user',
|
||||
|
|
|
|||
|
|
@ -7,21 +7,67 @@ import ResourceQuota from '@/components/form/ResourceQuota';
|
|||
import Tab from '@/components/Tabbed/Tab';
|
||||
import Tabbed from '@/components/Tabbed';
|
||||
import NameNsDescription from '@/components/form/NameNsDescription';
|
||||
import { NORMAN } from '@/config/types';
|
||||
|
||||
export default {
|
||||
components: {
|
||||
ContainerResourceLimit, CruResource, Labels, NameNsDescription, ResourceQuota, Tabbed, Tab
|
||||
},
|
||||
mixins: [CreateEditView],
|
||||
computed: {
|
||||
doneLocationOverride() {
|
||||
return this.value.listLocation;
|
||||
}
|
||||
},
|
||||
mixins: [CreateEditView],
|
||||
created() {
|
||||
this.$set(this.value.metadata, 'namespace', this.$store.getters['currentCluster'].id);
|
||||
this.$set(this.value, 'spec', this.value.spec || {});
|
||||
this.$set(this.value.spec, 'containerDefaultResourceLimit', this.value.spec.containerDefaultResourceLimit || {});
|
||||
},
|
||||
methods: {
|
||||
async save(saveCb) {
|
||||
try {
|
||||
const normanProject = this.isCreate ? await this.createProject() : await this.editProject();
|
||||
|
||||
await normanProject.save();
|
||||
saveCb(true);
|
||||
this.$router.replace(this.value.listLocation);
|
||||
} catch (ex) {
|
||||
saveCb(false);
|
||||
}
|
||||
},
|
||||
|
||||
async createProject() {
|
||||
const normanProject = await this.$store.dispatch('rancher/create', {
|
||||
type: NORMAN.PROJECT,
|
||||
name: this.value.spec.displayName,
|
||||
description: this.value.spec.description,
|
||||
annotations: this.value.metadata.annotations,
|
||||
labels: this.value.metadata.labels,
|
||||
clusterId: this.$store.getters['currentCluster'].id,
|
||||
creatorId: this.$store.getters['auth/principalId'],
|
||||
containerDefaultResourceLimit: this.value.spec.containerDefaultResourceLimit,
|
||||
namespaceDefaultResourceQuota: this.value.spec.namespaceDefaultResourceQuota,
|
||||
resourceQuota: this.value.spec.resourceQuota,
|
||||
});
|
||||
|
||||
// The backend seemingly required both labels/annotation and metadata.labels/annotations or it doesn't save the labels and annotations
|
||||
normanProject.setAnnotations(this.value.metadata.annotations);
|
||||
normanProject.setLabels(this.value.metadata.labels);
|
||||
|
||||
return normanProject;
|
||||
},
|
||||
|
||||
async editProject() {
|
||||
const normanProject = await this.$store.dispatch('rancher/find', {
|
||||
type: NORMAN.PROJECT,
|
||||
id: this.value.id.replace('/', ':'),
|
||||
});
|
||||
|
||||
normanProject.setAnnotations(this.value.metadata.annotations);
|
||||
normanProject.setLabels(this.value.metadata.labels);
|
||||
normanProject.description = this.value.spec.description;
|
||||
normanProject.containerDefaultResourceLimit = this.value.spec.containerDefaultResourceLimit;
|
||||
normanProject.namespaceDefaultResourceQuota = this.value.spec.namespaceDefaultResourceQuota;
|
||||
normanProject.resourceQuota = this.value.spec.resourceQuota;
|
||||
|
||||
return normanProject;
|
||||
}
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
|
@ -38,7 +84,7 @@ export default {
|
|||
@finish="save"
|
||||
@cancel="done"
|
||||
>
|
||||
<NameNsDescription v-model="value" :mode="mode" :namespaced="false" description-key="spec.description" />
|
||||
<NameNsDescription v-model="value" :mode="mode" :namespaced="false" description-key="spec.description" name-key="spec.displayName" />
|
||||
<Tabbed :side-tabs="true">
|
||||
<Tab name="resource-quotas" :label="t('project.resourceQuotas')" :weight="9">
|
||||
<ResourceQuota v-model="value" :mode="mode" />
|
||||
|
|
|
|||
Loading…
Reference in New Issue