diff --git a/src/model/Group.ts b/src/model/Group.ts index 1c5566d..69c15d6 100644 --- a/src/model/Group.ts +++ b/src/model/Group.ts @@ -1,5 +1,5 @@ export interface Group{ id_group: number; - id_project: number; + id_project?: number; name_group: string; } diff --git a/src/services/group.service.ts b/src/services/group.service.ts index 82afbcb..cd8fb65 100644 --- a/src/services/group.service.ts +++ b/src/services/group.service.ts @@ -7,4 +7,13 @@ export class GroupService extends BaseService { public getGroups(): Observable { return this.get("group"); } + + public addGroup(name:string):Observable{ + let body:Group = { + id_group:0, + name_group:name, + }; + + return this.post("group/add",body); + } } diff --git a/src/view/pages/home/home.component.html b/src/view/pages/home/home.component.html index 4ca957d..d26d23d 100644 --- a/src/view/pages/home/home.component.html +++ b/src/view/pages/home/home.component.html @@ -12,7 +12,7 @@

} - @@ -44,6 +44,18 @@ {{ group.name_group }}

} + + + + + @if (showGroupForm){ +
+ + + + +
+ }

diff --git a/src/view/pages/home/home.component.ts b/src/view/pages/home/home.component.ts index 97992fc..56b21e5 100644 --- a/src/view/pages/home/home.component.ts +++ b/src/view/pages/home/home.component.ts @@ -16,6 +16,7 @@ import { Observable } from 'rxjs'; templateUrl: './home.component.html', }) export class Home { + //#region Attributs private taskService: TaskService = inject(TaskService); private groupService: GroupService = inject(GroupService); private projectService: ProjectService = inject(ProjectService); @@ -33,6 +34,13 @@ export class Home { showTaskForm: boolean = false; + newGroupForm = new FormGroup({ + name: new FormControl('', Validators.required), + }); + + showGroupForm: boolean = false; + //#endregion + public ngOnInit(): void { this.taskService.getTasks().subscribe((response: Task[]): void => { this.tasks.set(response); @@ -47,7 +55,7 @@ export class Home { }) } - public toggleForm(): void { + public toggleTaskForm(): void { this.showTaskForm = !this.showTaskForm; } @@ -66,4 +74,22 @@ export class Home { }); }); } + + public toggleGroupForm(): void { + this.showGroupForm = !this.showGroupForm; + } + + /** + * submitGroup + */ + public submitGroup() { + let response: Observable = this.groupService.addGroup(this.newGroupForm.controls.name.value!); + + response.subscribe(response => { + this.groups.update(values => { + return [...values, response]; + }); + }); + } + }