feat: Ajout de projet
This commit is contained in:
@@ -8,4 +8,13 @@ export class ProjectService extends BaseService {
|
|||||||
public getProjects(): Observable<Project[]> {
|
public getProjects(): Observable<Project[]> {
|
||||||
return this.get<Project[]>("project");
|
return this.get<Project[]>("project");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public addProject(name: string): Observable<Project> {
|
||||||
|
let body: Project = {
|
||||||
|
name_project: name,
|
||||||
|
id_project: 0
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.post<Project>("project/add", body);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -67,6 +67,17 @@
|
|||||||
{{ project.name_project }}
|
{{ project.name_project }}
|
||||||
</p>
|
</p>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
<button (click)="toggleProjectForm()">Ajouter un projet</button>
|
||||||
|
|
||||||
|
@if (showProjectForm){
|
||||||
|
<form [formGroup]="newProjectForm" (ngSubmit)="submitProject()">
|
||||||
|
<label for="name-project">Nom </label>
|
||||||
|
<input id="name-project" type="text" formControlName="name" />
|
||||||
|
|
||||||
|
<button type="submit" [disabled]="!newProjectForm.valid">Valider</button>
|
||||||
|
</form>
|
||||||
|
}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<router-outlet />
|
<router-outlet />
|
||||||
|
|||||||
@@ -39,6 +39,13 @@ export class Home {
|
|||||||
});
|
});
|
||||||
|
|
||||||
showGroupForm: boolean = false;
|
showGroupForm: boolean = false;
|
||||||
|
|
||||||
|
newProjectForm = new FormGroup({
|
||||||
|
name: new FormControl('', Validators.required),
|
||||||
|
});
|
||||||
|
|
||||||
|
showProjectForm: boolean = false;
|
||||||
|
|
||||||
//#endregion
|
//#endregion
|
||||||
|
|
||||||
public ngOnInit(): void {
|
public ngOnInit(): void {
|
||||||
@@ -92,4 +99,20 @@ export class Home {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public toggleProjectForm(): void {
|
||||||
|
this.showProjectForm = !this.showProjectForm;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* submitProject
|
||||||
|
*/
|
||||||
|
public submitProject() {
|
||||||
|
let response: Observable<Project> = this.projectService.addProject(this.newProjectForm.controls.name.value!);
|
||||||
|
|
||||||
|
response.subscribe(response => {
|
||||||
|
this.projects.update(values => {
|
||||||
|
return [...values, response];
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user