Skip to content

Commit

Permalink
feat: Allow setting project type during creation
Browse files Browse the repository at this point in the history
Closes #1961
  • Loading branch information
zusorio committed Nov 7, 2024
1 parent e8cb5e1 commit 9f7bb85
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 15 deletions.
1 change: 1 addition & 0 deletions backend/capellacollab/projects/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ class PostProjectRequest(core_pydantic.BaseModel):
name: str
description: str | None = None
visibility: Visibility = Visibility.PRIVATE
type: ProjectType = ProjectType.GENERAL


class DatabaseProject(database.Base):
Expand Down
1 change: 1 addition & 0 deletions backend/capellacollab/projects/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ def create_project(
post_project.name,
post_project.description or "",
post_project.visibility,
post_project.type,
)

if user.role != users_models.Role.ADMIN:
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/app/openapi/model/post-project-request.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,33 @@ <h3 class="flex justify-center sm:hidden">Create new project</h3>
formControlName="visibility"
class="flex flex-col"
>
<mat-radio-button
*ngFor="
let visibility of projectService.getAvailableVisibilities()
"
[value]="visibility"
>
{{
projectService.getProjectVisibilityDescription(visibility)
}}
</mat-radio-button>
@for (
visibility of projectService.getAvailableVisibilities();
track visibility
) {
<mat-radio-button [value]="visibility">
{{
projectService.getProjectVisibilityDescription(
visibility
)
}}
</mat-radio-button>
}
</mat-radio-group>
</div>
</fieldset>
<fieldset>
<div class="flex flex-col">
<legend>Project type</legend>
<mat-radio-group formControlName="type" class="flex flex-col">
@for (
type of projectService.getAvailableProjectTypes();
track type
) {
<mat-radio-button [value]="type">
{{ projectService.getProjectTypeDescription(type) }}
</mat-radio-button>
}
</mat-radio-group>
</div>
</fieldset>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* SPDX-FileCopyrightText: Copyright DB InfraGO AG and contributors
* SPDX-License-Identifier: Apache-2.0
*/
import { NgFor, AsyncPipe } from '@angular/common';
import { AsyncPipe } from '@angular/common';
import { Component, OnDestroy, OnInit, ViewChild } from '@angular/core';
import {
FormControl,
Expand All @@ -18,7 +18,7 @@ import { MatInput } from '@angular/material/input';
import { MatRadioGroup, MatRadioButton } from '@angular/material/radio';
import { MatStepper, MatStep, MatStepLabel } from '@angular/material/stepper';
import { RouterLink } from '@angular/router';
import { Visibility } from 'src/app/openapi';
import { ProjectType, Visibility } from 'src/app/openapi';
import {
CreateModelComponent,
CreateModelStep,
Expand All @@ -44,7 +44,6 @@ import { ProjectWrapperService } from '../service/project.service';
MatInput,
MatError,
MatRadioGroup,
NgFor,
MatRadioButton,
MatButton,
MatIcon,
Expand Down Expand Up @@ -73,6 +72,7 @@ export class CreateProjectComponent implements OnInit, OnDestroy {
}),
description: new FormControl(''),
visibility: new FormControl('private'),
type: new FormControl('general'),
});

ngOnInit(): void {
Expand All @@ -90,6 +90,7 @@ export class CreateProjectComponent implements OnInit, OnDestroy {
name: this.form.value.name!,
description: this.form.value.description!,
visibility: this.form.value.visibility! as Visibility,
type: this.form.value.type! as ProjectType,
})
.subscribe((project) => {
this.toastService.showSuccess(
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/app/projects/service/project.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,6 @@ export const ProjectVisibilityDescriptions = {
};

export const ProjectTypeDescriptions = {
general: 'General (a project that contains multiple related models)',
general: 'General (a project that contains related models)',
training: 'Training (special project containing training material)',
};
11 changes: 10 additions & 1 deletion frontend/src/storybook/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
*/
import { AsyncValidatorFn, ValidationErrors } from '@angular/forms';
import { BehaviorSubject, Observable, of } from 'rxjs';
import { Project, Visibility } from 'src/app/openapi';
import { Project, ProjectType, Visibility } from 'src/app/openapi';
import {
ProjectTypeDescriptions,
ProjectVisibilityDescriptions,
ProjectWrapperService,
} from 'src/app/projects/service/project.service';
Expand Down Expand Up @@ -51,6 +52,14 @@ export class MockProjectWrapperService
getAvailableVisibilities(): Visibility[] {
return Object.keys(ProjectVisibilityDescriptions) as Visibility[];
}

getProjectTypeDescription(type: ProjectType): string {
return ProjectTypeDescriptions[type];
}

getAvailableProjectTypes(): ProjectType[] {
return Object.keys(ProjectTypeDescriptions) as ProjectType[];
}
createProject(project: Project): Observable<Project> {
return of(project);
}
Expand Down

0 comments on commit 9f7bb85

Please sign in to comment.