From 48dedea6652a1f927de9ec8772c8a2c48cb737b0 Mon Sep 17 00:00:00 2001 From: Hedi MJID Date: Fri, 4 Mar 2022 15:54:34 +0100 Subject: [PATCH] calendrier : ajout du formulaire d'ajout de evenement --- src/app/app-routing.module.ts | 2 + src/app/app.module.ts | 4 +- .../page-agenda/page-agenda.component.html | 2 +- .../page-ajout-evenements.component.html | 48 +++++++++++++ .../page-ajout-evenements.component.scss | 0 .../page-ajout-evenements.component.spec.ts | 25 +++++++ .../page-ajout-evenements.component.ts | 67 +++++++++++++++++++ 7 files changed, 146 insertions(+), 2 deletions(-) create mode 100644 src/app/pages/page-ajout-evenements/page-ajout-evenements.component.html create mode 100644 src/app/pages/page-ajout-evenements/page-ajout-evenements.component.scss create mode 100644 src/app/pages/page-ajout-evenements/page-ajout-evenements.component.spec.ts create mode 100644 src/app/pages/page-ajout-evenements/page-ajout-evenements.component.ts diff --git a/src/app/app-routing.module.ts b/src/app/app-routing.module.ts index d43e8ef..0b80815 100644 --- a/src/app/app-routing.module.ts +++ b/src/app/app-routing.module.ts @@ -22,6 +22,7 @@ import { PageUpdateMemberComponent } from './pages/page-update-member/page-updat import { PageSupportComponent } from './pages/page-support/page-support.component'; import { FooterComponent } from './components/footer/footer.component'; import { AuthGuard } from './auth.guard'; +import { PageAjoutEvenementsComponent } from './pages/page-ajout-evenements/page-ajout-evenements.component'; const routes: Routes = [ { path: '', redirectTo: 'accueil', pathMatch: 'full' }, @@ -45,6 +46,7 @@ const routes: Routes = [ { path: 'ajouter-contact', canActivate: [AuthGuard], component: PageAjoutContactComponent }, { path: 'creation-team', canActivate: [AuthGuard], component: PageCreationTeamComponent }, { path: 'footer', component: FooterComponent}, + { path: 'ajout-evenement', canActivate: [AuthGuard], component: PageAjoutEvenementsComponent }, { path: '**', component: PageNotFoundComponent }, ]; diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 2ea2f43..960f483 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -44,6 +44,7 @@ import { CardAvatarComponent } from './components/card-avatar/card-avatar.compon import { HumeurComponent } from './components/humeur/humeur.component'; import { DeconnexionComponent } from './components/deconnexion/deconnexion.component'; import { AlertComponent } from './components/alert/alert.component'; +import { PageAjoutEvenementsComponent } from './pages/page-ajout-evenements/page-ajout-evenements.component'; registerLocaleData(localeFr) @NgModule({ @@ -84,7 +85,8 @@ registerLocaleData(localeFr) CardAvatarComponent, DeconnexionComponent, HumeurComponent, - AlertComponent + AlertComponent, + PageAjoutEvenementsComponent ], imports: [ BrowserModule, diff --git a/src/app/pages/page-agenda/page-agenda.component.html b/src/app/pages/page-agenda/page-agenda.component.html index f71faf6..bd42f5a 100644 --- a/src/app/pages/page-agenda/page-agenda.component.html +++ b/src/app/pages/page-agenda/page-agenda.component.html @@ -66,7 +66,7 @@ Ajouter un évènement + +
+
+ +
+
+

Ajouter un évènement à l'agenda

+
+
+
+
+ + +
+
+ + +
+
+ + +
+ + +
+
+
+
+
+ \ No newline at end of file diff --git a/src/app/pages/page-ajout-evenements/page-ajout-evenements.component.scss b/src/app/pages/page-ajout-evenements/page-ajout-evenements.component.scss new file mode 100644 index 0000000..e69de29 diff --git a/src/app/pages/page-ajout-evenements/page-ajout-evenements.component.spec.ts b/src/app/pages/page-ajout-evenements/page-ajout-evenements.component.spec.ts new file mode 100644 index 0000000..e28926a --- /dev/null +++ b/src/app/pages/page-ajout-evenements/page-ajout-evenements.component.spec.ts @@ -0,0 +1,25 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; + +import { PageAjoutEvenementsComponent } from './page-ajout-evenements.component'; + +describe('PageAjoutEvenementsComponent', () => { + let component: PageAjoutEvenementsComponent; + let fixture: ComponentFixture; + + beforeEach(async () => { + await TestBed.configureTestingModule({ + declarations: [ PageAjoutEvenementsComponent ] + }) + .compileComponents(); + }); + + beforeEach(() => { + fixture = TestBed.createComponent(PageAjoutEvenementsComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/pages/page-ajout-evenements/page-ajout-evenements.component.ts b/src/app/pages/page-ajout-evenements/page-ajout-evenements.component.ts new file mode 100644 index 0000000..68d53a1 --- /dev/null +++ b/src/app/pages/page-ajout-evenements/page-ajout-evenements.component.ts @@ -0,0 +1,67 @@ +import { Component, OnInit } from '@angular/core'; +import { FormControl, FormGroup, Validators } from '@angular/forms'; +import { Router } from '@angular/router'; +import { EvenementService } from 'src/app/services/evenement.service'; +import { TokenService } from 'src/app/services/token.service'; + +@Component({ + selector: 'app-page-ajout-evenements', + templateUrl: './page-ajout-evenements.component.html', + styleUrls: ['./page-ajout-evenements.component.scss'] +}) +export class PageAjoutEvenementsComponent implements OnInit { + public eventForm: FormGroup; + public userId : any; + public teamId : any; + public isShow: boolean; + public alert:any; + + constructor(private evenementService:EvenementService, private tokenService: TokenService, private router: Router,) { + this.eventForm = new FormGroup({}); + this.isShow = false; + this.alert = ""; + } + + ngOnInit(): void { + this.userId = this.tokenService.getCurrentMembreId(); + this.teamId = this.tokenService.getCurrentTeamId(); + + this.eventForm = new FormGroup({ + startFc : new FormControl(''), + endFc : new FormControl(''), + textFc : new FormControl('', [ Validators.required]) + }) + } + + public onSubmit(): void { + const startValue = this.eventForm.value['startFc']; + const endValue = this.eventForm.value['endFc']; + const textValue = this.eventForm.value['textFc']; + + const event = { + start: startValue, + end: endValue, + text: textValue, + id:"", + membre: {id:this.userId}, + team: {id:this.teamId} + } + + this.evenementService.addEvenements(event).subscribe({ + next: result => { + this.alert={"type":"success", "content":"L'évènement à été correctement ajouté au calendrier"}; + this.isShow = true; + }, + error: err => { + this.alert={"type":"danger", "content":"Problème lors de l'ajout de l'évenment"}; + this.isShow = true; + }, + complete: () => { + console.log('DONE!'); + this.router.navigate(['agenda']); + } + }); + + } + +}