From dc03c1b25f6c870832f10b973763c48fbc095a12 Mon Sep 17 00:00:00 2001 From: Thomas Cardon Date: Fri, 18 Feb 2022 10:16:55 +0100 Subject: [PATCH 1/5] mis en place admin-page --- src/app/app-routing.module.ts | 2 + src/app/app.module.ts | 7 +- .../admin-page/admin-page.component.html | 98 +++++++++++++++++++ .../admin-page/admin-page.component.scss | 32 ++++++ .../admin-page/admin-page.component.spec.ts | 25 +++++ .../pages/admin-page/admin-page.component.ts | 76 ++++++++++++++ src/app/pages/models/restaurant.ts | 13 +++ src/app/services/api-back.service.ts | 10 +- 8 files changed, 258 insertions(+), 5 deletions(-) create mode 100644 src/app/pages/admin-page/admin-page.component.html create mode 100644 src/app/pages/admin-page/admin-page.component.scss create mode 100644 src/app/pages/admin-page/admin-page.component.spec.ts create mode 100644 src/app/pages/admin-page/admin-page.component.ts create mode 100644 src/app/pages/models/restaurant.ts diff --git a/src/app/app-routing.module.ts b/src/app/app-routing.module.ts index 97ed3a3..d6925dd 100644 --- a/src/app/app-routing.module.ts +++ b/src/app/app-routing.module.ts @@ -7,6 +7,7 @@ import { RestoPageComponent } from './pages/resto-page/resto-page.component'; import { PageNotFoundComponent } from './pages/page-not-found/page-not-found.component'; import { FiltersPageComponent } from './pages/filters-page/filters-page.component'; import { SigninComponent } from './pages/signin/signin.component'; +import { AdminPageComponent } from './pages/admin-page/admin-page.component'; const routes: Routes = [ { path: '', redirectTo: 'home', pathMatch: 'full' }, @@ -18,6 +19,7 @@ const routes: Routes = [ {path: 'restaurants',component: RestoPageComponent}, {path: 'page-not-found',component: PageNotFoundComponent}, {path: 'signin', component: SigninComponent}, + {path: 'admin', component: AdminPageComponent}, {path: '**', redirectTo: 'page-not-found' } ]; diff --git a/src/app/app.module.ts b/src/app/app.module.ts index d7a4ae2..2a0d753 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -1,6 +1,6 @@ import { NgModule } from '@angular/core'; import { BrowserModule } from '@angular/platform-browser'; -import { FormsModule } from '@angular/forms'; +import { FormsModule, ReactiveFormsModule } from '@angular/forms'; import { AppRoutingModule } from './app-routing.module'; import { AppComponent } from './app.component'; import { NavBarComponent } from './header/components/nav-bar/nav-bar.component'; @@ -18,6 +18,7 @@ import { FiltersPageComponent } from './pages/filters-page/filters-page.componen import { AvisBarComponent } from './filters/avis-bar/avis-bar.component'; import { IconComponent } from './filters/icon/icon.component'; import { TemplatePageComponent } from './components/template-page/template-page.component'; +import { AdminPageComponent } from './pages/admin-page/admin-page.component'; @NgModule({ declarations: [ @@ -35,13 +36,15 @@ import { TemplatePageComponent } from './components/template-page/template-page. AvisBarComponent, IconComponent, SigninComponent, - TemplatePageComponent + TemplatePageComponent, + AdminPageComponent ], imports: [ BrowserModule, AppRoutingModule, HttpClientModule, FormsModule, + ReactiveFormsModule ], providers: [], bootstrap: [AppComponent] diff --git a/src/app/pages/admin-page/admin-page.component.html b/src/app/pages/admin-page/admin-page.component.html new file mode 100644 index 0000000..3acef17 --- /dev/null +++ b/src/app/pages/admin-page/admin-page.component.html @@ -0,0 +1,98 @@ +
+
+
+

Enregistrer un restaurant

+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+ +
+ {{errorMessage}} +
+ + + +
+
+
\ No newline at end of file diff --git a/src/app/pages/admin-page/admin-page.component.scss b/src/app/pages/admin-page/admin-page.component.scss new file mode 100644 index 0000000..35aa744 --- /dev/null +++ b/src/app/pages/admin-page/admin-page.component.scss @@ -0,0 +1,32 @@ +.login-form { + height: 100vh; + padding-top: 40px; + background-color: #f5f5f5; +} + +.form-signup { + width: 100%; + max-width: 330px; + padding: 15px; + margin: auto; +} + +.form-signup .checkbox { + font-weight: 400; +} + +.form-signup .form-floating:focus-within { + z-index: 2; +} + +.form-signup input[type="email"] { + margin-bottom: -1px; + border-bottom-right-radius: 0; + border-bottom-left-radius: 0; +} + +.form-signup input[type="password"] { + margin-bottom: 10px; + border-top-left-radius: 0; + border-top-right-radius: 0; +} \ No newline at end of file diff --git a/src/app/pages/admin-page/admin-page.component.spec.ts b/src/app/pages/admin-page/admin-page.component.spec.ts new file mode 100644 index 0000000..9e9cb02 --- /dev/null +++ b/src/app/pages/admin-page/admin-page.component.spec.ts @@ -0,0 +1,25 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; + +import { AdminPageComponent } from './admin-page.component'; + +describe('AdminPageComponent', () => { + let component: AdminPageComponent; + let fixture: ComponentFixture; + + beforeEach(async () => { + await TestBed.configureTestingModule({ + declarations: [ AdminPageComponent ] + }) + .compileComponents(); + }); + + beforeEach(() => { + fixture = TestBed.createComponent(AdminPageComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/pages/admin-page/admin-page.component.ts b/src/app/pages/admin-page/admin-page.component.ts new file mode 100644 index 0000000..1a827fb --- /dev/null +++ b/src/app/pages/admin-page/admin-page.component.ts @@ -0,0 +1,76 @@ +import { Component, OnInit } from '@angular/core'; +import { FormControl, FormGroup, Validators } from '@angular/forms'; +import { Router } from '@angular/router'; +import { ApiBackService } from 'src/app/services/api-back.service'; +import { Restaurant } from '../models/restaurant'; + +@Component({ + selector: 'app-admin-page', + templateUrl: './admin-page.component.html', + styleUrls: ['./admin-page.component.scss'] +}) +export class AdminPageComponent implements OnInit { + + + public signupForm: FormGroup; + public errorMessage ?: string; + + constructor( private router: Router, private apiBackService : ApiBackService) { + this.signupForm = new FormGroup({}); + } + + ngOnInit(): void { + this.signupForm = new FormGroup({ + nomFc : new FormControl('', [Validators.required]), + prixFc : new FormControl(''), + longitudeFc : new FormControl('', [Validators.required,]), // chercher une meilleure regex + latitudeFc : new FormControl('', [Validators.required]), + adresseFc : new FormControl('', [Validators.required]), + telephoneFc : new FormControl(''), + websiteFc : new FormControl(''), + aEmporterFc : new FormControl(''), + }) + } + + public onSubmit(): void { + console.log("value : ", this.signupForm.value); + console.log("form : ", this.signupForm); + const nomFc = this.signupForm.value['nomFc']; + const prixFc = this.signupForm.value['prixFc']; + const longitudeFc = this.signupForm.value['longitudeFc']; + const latitudeFc = this.signupForm.value['latitudeFc']; + const adresseFc = this.signupForm.value['adresseFc']; + const telephoneFc = this.signupForm.value['telephoneFc']; + const websiteFc = this.signupForm.value['websiteFc']; + const aEmporterFc = this.signupForm.value['aEmporterFc']; + // const accesPMRFc = this.signupForm.value['accesPMRFc']; + // const surPlaceFc = this.signupForm.value['surPlaceFc']; + + const restaurant: Restaurant = { + latitude: latitudeFc, + longitude: longitudeFc, + nom : nomFc, + prix: prixFc, + adresse : adresseFc, + telephone : telephoneFc, + website : websiteFc, + aEmporter : aEmporterFc, + // accesPMR : accesPMRFc, + // surPlace : surPlaceFc + } + if( restaurant.latitude !== '' && + restaurant.longitude !== '' && + restaurant.nom !== '' && + restaurant.adresse !== '' ) { + this.apiBackService.addRestaurant(restaurant).subscribe( + resp=> + + this.router.navigate(['restaurants']) + ); + }else{ + this.errorMessage = "Renseigner les champs obligatoires **"; + } + + } + +} diff --git a/src/app/pages/models/restaurant.ts b/src/app/pages/models/restaurant.ts new file mode 100644 index 0000000..272f5e9 --- /dev/null +++ b/src/app/pages/models/restaurant.ts @@ -0,0 +1,13 @@ +export interface Restaurant { + id?:number; + nom: string; + adresse: string; + prix?: number; + latitude: string; + longitude: string; + telephone ?: string; + website ?: string; + aEmporter?: boolean; + accesPMR?: boolean; + surPlace?: boolean; +} diff --git a/src/app/services/api-back.service.ts b/src/app/services/api-back.service.ts index a6ad8f2..696cc0f 100644 --- a/src/app/services/api-back.service.ts +++ b/src/app/services/api-back.service.ts @@ -2,6 +2,7 @@ import { Injectable, Input } from '@angular/core'; import { Observable, of, Subject } from 'rxjs'; import { HttpClient } from '@angular/common/http'; import { environment } from 'src/environments/environment'; +import { Restaurant } from '../pages/models/restaurant'; @Injectable({ providedIn: 'root' @@ -57,7 +58,10 @@ export class ApiBackService { deg2rad(deg : number) { return deg * (Math.PI/180) } - } - - + + addRestaurant( newRestau : Restaurant) : Observable{ + return this.httpClient.post(`${environment.apiUrl}/add-restaurant`, newRestau); + + } +} From d7f423f93caa5e12154f55f6ecd328dacc6ba774 Mon Sep 17 00:00:00 2001 From: Thomas Cardon Date: Fri, 18 Feb 2022 14:21:13 +0100 Subject: [PATCH 2/5] stash merge + card resto --- src/app/card-resto/card-resto.component.html | 8 +- src/app/card-resto/card-resto.component.ts | 8 +- .../admin-page/admin-page.component.html | 117 ++++++++++++++++-- .../admin-page/admin-page.component.scss | 6 +- .../pages/admin-page/admin-page.component.ts | 12 +- 5 files changed, 126 insertions(+), 25 deletions(-) diff --git a/src/app/card-resto/card-resto.component.html b/src/app/card-resto/card-resto.component.html index c92f701..709fc3c 100644 --- a/src/app/card-resto/card-resto.component.html +++ b/src/app/card-resto/card-resto.component.html @@ -41,8 +41,8 @@ - 5-10€ - + +

Site Web @@ -66,8 +66,8 @@ [iconName]="restaurant.surPlace ? 'bi bi-check-square-fill' : 'bi bi-x-square-fill ps-2 pt-1 '" [iconColor]="restaurant.surPlace ? '#4ECB71' : '#ED2F2F'" > - A emporter : - A emporter : + diff --git a/src/app/card-resto/card-resto.component.ts b/src/app/card-resto/card-resto.component.ts index 3abf51e..6bdb9be 100644 --- a/src/app/card-resto/card-resto.component.ts +++ b/src/app/card-resto/card-resto.component.ts @@ -13,6 +13,7 @@ export class CardRestoComponent implements OnInit { @Input() likeResto: any; @Output() clickLike = new EventEmitter(); isLiked : boolean = false; + priceRef = ["Info indisponible"," € 1-10€ "," €€ 11-20€"," €€€ 21-30€"," €€€€ 31-40€"]; constructor(private apiBackService : ApiBackService) { this.distance = 0 ; @@ -20,8 +21,6 @@ export class CardRestoComponent implements OnInit { ngOnInit(): void { - console.log(this.restaurant); - this.distance = Math.round( this.apiBackService.setDistance( 48.86201110271593 , //latitude Simplon @@ -29,10 +28,7 @@ export class CardRestoComponent implements OnInit { this.restaurant.latitude, this.restaurant.longitude) ); - - console.log(this.distance); - - + } onClickLike() { console.log('click'); diff --git a/src/app/pages/admin-page/admin-page.component.html b/src/app/pages/admin-page/admin-page.component.html index 3acef17..1c4213c 100644 --- a/src/app/pages/admin-page/admin-page.component.html +++ b/src/app/pages/admin-page/admin-page.component.html @@ -74,20 +74,117 @@ class="form-control" id="floatingInputWebsite" placeholder="" - name="website" > + name="website" + formControlName="websiteFc" + [ngClass]="{'is-valid' : signupForm.controls['websiteFc'].touched && signupForm.controls['websiteFc'].valid, + 'is-invalid': signupForm.controls['websiteFc'].touched && !signupForm.controls['websiteFc'].valid}">

-
- - + +
+

Sur Place :

+
+ + +
+
+ + +
+
+ + +
+
+ +
+

A Emporter :

+
+ + +
+
+ + +
+
+ + +
-
- {{errorMessage}} +
+

Accès PMR :

+
+ + +
+
+ + +
+
+ + +
+
+ +
+
+ + + \ No newline at end of file diff --git a/src/app/card-resto/card-resto.component.ts b/src/app/card-resto/card-resto.component.ts index 3abf51e..b843623 100644 --- a/src/app/card-resto/card-resto.component.ts +++ b/src/app/card-resto/card-resto.component.ts @@ -13,9 +13,16 @@ export class CardRestoComponent implements OnInit { @Input() likeResto: any; @Output() clickLike = new EventEmitter(); isLiked : boolean = false; + priceRef : object; + constructor(private apiBackService : ApiBackService) { this.distance = 0 ; + this.priceRef = {1 : '€ 1-10€', + 2 : '€€ 11-20€', + 3 : '€€€ 21-30€', + 4 : '€€€€ 31-40€', + } } ngOnInit(): void { diff --git a/src/app/pages/resto-page/resto-page.component.ts b/src/app/pages/resto-page/resto-page.component.ts index 62ec299..4b1aee8 100644 --- a/src/app/pages/resto-page/resto-page.component.ts +++ b/src/app/pages/resto-page/resto-page.component.ts @@ -31,6 +31,9 @@ export class RestoPageComponent implements OnInit { }) } + console.log(this.apiBackService); + + From 19feceeb19f44bd938358555d764ea359b36d4dd Mon Sep 17 00:00:00 2001 From: Thomas Cardon Date: Fri, 18 Feb 2022 15:11:51 +0100 Subject: [PATCH 4/5] admin-page + prix card resto --- src/app/card-resto/card-resto.component.html | 11 +++++++++-- src/app/card-resto/card-resto.component.ts | 2 +- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/app/card-resto/card-resto.component.html b/src/app/card-resto/card-resto.component.html index 709fc3c..eda8112 100644 --- a/src/app/card-resto/card-resto.component.html +++ b/src/app/card-resto/card-resto.component.html @@ -39,9 +39,16 @@ {{distance}}m + + + {{ priceRef[restaurant.prix] }} + - - +

diff --git a/src/app/card-resto/card-resto.component.ts b/src/app/card-resto/card-resto.component.ts index 6bdb9be..005d776 100644 --- a/src/app/card-resto/card-resto.component.ts +++ b/src/app/card-resto/card-resto.component.ts @@ -13,7 +13,7 @@ export class CardRestoComponent implements OnInit { @Input() likeResto: any; @Output() clickLike = new EventEmitter(); isLiked : boolean = false; - priceRef = ["Info indisponible"," € 1-10€ "," €€ 11-20€"," €€€ 21-30€"," €€€€ 31-40€"]; + priceRef = ["Info indisponible","1-10€ ","11-20€","21-30€","31-40€"]; constructor(private apiBackService : ApiBackService) { this.distance = 0 ; From 5524d3c6d9e0b215bfb84aaffcb11cdb96184af3 Mon Sep 17 00:00:00 2001 From: Thomas Cardon Date: Fri, 18 Feb 2022 16:47:23 +0100 Subject: [PATCH 5/5] ajout composant add-restau --- .../add-restau/add-restau.component.html | 195 +++++++++++++++++ .../add-restau/add-restau.component.scss | 36 ++++ .../add-restau/add-restau.component.spec.ts | 25 +++ .../add-restau/add-restau.component.ts | 81 ++++++++ src/app/app.module.ts | 4 +- .../admin-page/admin-page.component.html | 196 +----------------- .../admin-page/admin-page.component.scss | 36 ---- .../pages/admin-page/admin-page.component.ts | 61 +----- 8 files changed, 343 insertions(+), 291 deletions(-) create mode 100644 src/app/admin-component/add-restau/add-restau.component.html create mode 100644 src/app/admin-component/add-restau/add-restau.component.scss create mode 100644 src/app/admin-component/add-restau/add-restau.component.spec.ts create mode 100644 src/app/admin-component/add-restau/add-restau.component.ts diff --git a/src/app/admin-component/add-restau/add-restau.component.html b/src/app/admin-component/add-restau/add-restau.component.html new file mode 100644 index 0000000..1c4213c --- /dev/null +++ b/src/app/admin-component/add-restau/add-restau.component.html @@ -0,0 +1,195 @@ +

\ No newline at end of file diff --git a/src/app/admin-component/add-restau/add-restau.component.scss b/src/app/admin-component/add-restau/add-restau.component.scss new file mode 100644 index 0000000..8778894 --- /dev/null +++ b/src/app/admin-component/add-restau/add-restau.component.scss @@ -0,0 +1,36 @@ +.login-form { + height: 100vh; + padding-top: 40px; + background-color: #f5f5f5; +} + +.form-signup { + width: 100%; + max-width: 350px; + padding: 15px; + margin: auto; +} + +.form-signup .checkbox { + font-weight: 400; +} + +.form-signup .form-floating:focus-within { + z-index: 2; +} + +.form-signup input[type="email"] { + margin-bottom: -1px; + border-bottom-right-radius: 0; + border-bottom-left-radius: 0; +} + +.form-signup input[type="password"] { + margin-bottom: 10px; + border-top-left-radius: 0; + border-top-right-radius: 0; +} + +.text-left{ + text-align: left; +} \ No newline at end of file diff --git a/src/app/admin-component/add-restau/add-restau.component.spec.ts b/src/app/admin-component/add-restau/add-restau.component.spec.ts new file mode 100644 index 0000000..f2d6986 --- /dev/null +++ b/src/app/admin-component/add-restau/add-restau.component.spec.ts @@ -0,0 +1,25 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; + +import { AddRestauComponent } from './add-restau.component'; + +describe('AddRestauComponent', () => { + let component: AddRestauComponent; + let fixture: ComponentFixture; + + beforeEach(async () => { + await TestBed.configureTestingModule({ + declarations: [ AddRestauComponent ] + }) + .compileComponents(); + }); + + beforeEach(() => { + fixture = TestBed.createComponent(AddRestauComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/admin-component/add-restau/add-restau.component.ts b/src/app/admin-component/add-restau/add-restau.component.ts new file mode 100644 index 0000000..bf2df6a --- /dev/null +++ b/src/app/admin-component/add-restau/add-restau.component.ts @@ -0,0 +1,81 @@ + +import { Component, OnInit } from '@angular/core'; +import { FormControl, FormGroup, Validators } from '@angular/forms'; +import { Router } from '@angular/router'; +import { Restaurant } from 'src/app/pages/models/restaurant'; +import { ApiBackService } from 'src/app/services/api-back.service'; + +@Component({ + selector: 'app-add-restau', + templateUrl: './add-restau.component.html', + styleUrls: ['./add-restau.component.scss'] +}) +export class AddRestauComponent implements OnInit { + + + public signupForm: FormGroup; + public errorMessage ?: string; + + constructor( private router: Router, private apiBackService : ApiBackService) { + this.signupForm = new FormGroup({}); + } + + ngOnInit(): void { + this.signupForm = new FormGroup({ + nomFc : new FormControl('', [Validators.required]), + prixFc : new FormControl(''), + longitudeFc : new FormControl('', [Validators.required,]), // chercher une meilleure regex + latitudeFc : new FormControl('', [Validators.required]), + adresseFc : new FormControl('', [Validators.required]), + telephoneFc : new FormControl(''), + websiteFc : new FormControl('',[Validators.pattern("/^(http[s]?:\/\/){0,1}(www\.){0,1}[a-zA-Z0-9\.\-]+\.[a-zA-Z]{2,5}[\.]{0,1}/")]), + surPlaceFc : new FormControl(''), + aEmporterFc : new FormControl(''), + accesPMRFc : new FormControl('') + }) + } + + public onSubmit(): void { + console.log("value : ", this.signupForm.value); + console.log("form : ", this.signupForm); + const nomFc = this.signupForm.value['nomFc']; + const prixFc = this.signupForm.value['prixFc']; + const longitudeFc = this.signupForm.value['longitudeFc']; + const latitudeFc = this.signupForm.value['latitudeFc']; + const adresseFc = this.signupForm.value['adresseFc']; + const telephoneFc = this.signupForm.value['telephoneFc']; + const websiteFc = this.signupForm.value['websiteFc']; + const surPlaceFc = this.signupForm.value['surPlaceFc']; + const aEmporterFc = this.signupForm.value['aEmporterFc']; + const accesPMRFc = this.signupForm.value['accesPMRFc']; + + const restaurant: Restaurant = { + latitude: latitudeFc, + longitude: longitudeFc, + nom : nomFc, + prix: prixFc, + adresse : adresseFc, + telephone : telephoneFc, + website : websiteFc, + surPlace : surPlaceFc, + aEmporter : aEmporterFc, + accesPMR : accesPMRFc + } + if( restaurant.latitude !== '' && + restaurant.longitude !== '' && + restaurant.nom !== '' && + restaurant.adresse !== '' ) { + this.apiBackService.addRestaurant(restaurant).subscribe( + resp=> + + this.router.navigate(['restaurants']) + ); + }else{ + + this.errorMessage = "Renseigner les champs obligatoires **"; + } + + } + +} + diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 2a0d753..1ad877a 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -19,6 +19,7 @@ import { AvisBarComponent } from './filters/avis-bar/avis-bar.component'; import { IconComponent } from './filters/icon/icon.component'; import { TemplatePageComponent } from './components/template-page/template-page.component'; import { AdminPageComponent } from './pages/admin-page/admin-page.component'; +import { AddRestauComponent } from './admin-component/add-restau/add-restau.component'; @NgModule({ declarations: [ @@ -37,7 +38,8 @@ import { AdminPageComponent } from './pages/admin-page/admin-page.component'; IconComponent, SigninComponent, TemplatePageComponent, - AdminPageComponent + AdminPageComponent, + AddRestauComponent ], imports: [ BrowserModule, diff --git a/src/app/pages/admin-page/admin-page.component.html b/src/app/pages/admin-page/admin-page.component.html index 1c4213c..1e715de 100644 --- a/src/app/pages/admin-page/admin-page.component.html +++ b/src/app/pages/admin-page/admin-page.component.html @@ -1,195 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/src/app/pages/admin-page/admin-page.component.scss b/src/app/pages/admin-page/admin-page.component.scss index 8778894..e69de29 100644 --- a/src/app/pages/admin-page/admin-page.component.scss +++ b/src/app/pages/admin-page/admin-page.component.scss @@ -1,36 +0,0 @@ -.login-form { - height: 100vh; - padding-top: 40px; - background-color: #f5f5f5; -} - -.form-signup { - width: 100%; - max-width: 350px; - padding: 15px; - margin: auto; -} - -.form-signup .checkbox { - font-weight: 400; -} - -.form-signup .form-floating:focus-within { - z-index: 2; -} - -.form-signup input[type="email"] { - margin-bottom: -1px; - border-bottom-right-radius: 0; - border-bottom-left-radius: 0; -} - -.form-signup input[type="password"] { - margin-bottom: 10px; - border-top-left-radius: 0; - border-top-right-radius: 0; -} - -.text-left{ - text-align: left; -} \ No newline at end of file diff --git a/src/app/pages/admin-page/admin-page.component.ts b/src/app/pages/admin-page/admin-page.component.ts index fa9fcd8..e431721 100644 --- a/src/app/pages/admin-page/admin-page.component.ts +++ b/src/app/pages/admin-page/admin-page.component.ts @@ -12,69 +12,12 @@ import { Restaurant } from '../models/restaurant'; export class AdminPageComponent implements OnInit { - public signupForm: FormGroup; - public errorMessage ?: string; - - constructor( private router: Router, private apiBackService : ApiBackService) { - this.signupForm = new FormGroup({}); + constructor( ) { + } ngOnInit(): void { - this.signupForm = new FormGroup({ - nomFc : new FormControl('', [Validators.required]), - prixFc : new FormControl(''), - longitudeFc : new FormControl('', [Validators.required,]), // chercher une meilleure regex - latitudeFc : new FormControl('', [Validators.required]), - adresseFc : new FormControl('', [Validators.required]), - telephoneFc : new FormControl(''), - websiteFc : new FormControl(''), - surPlaceFc : new FormControl(''), - aEmporterFc : new FormControl(''), - accesPMRFc : new FormControl('') - }) } - public onSubmit(): void { - console.log("value : ", this.signupForm.value); - console.log("form : ", this.signupForm); - const nomFc = this.signupForm.value['nomFc']; - const prixFc = this.signupForm.value['prixFc']; - const longitudeFc = this.signupForm.value['longitudeFc']; - const latitudeFc = this.signupForm.value['latitudeFc']; - const adresseFc = this.signupForm.value['adresseFc']; - const telephoneFc = this.signupForm.value['telephoneFc']; - const websiteFc = this.signupForm.value['websiteFc']; - const surPlaceFc = this.signupForm.value['surPlaceFc']; - const aEmporterFc = this.signupForm.value['aEmporterFc']; - const accesPMRFc = this.signupForm.value['accesPMRFc']; - - const restaurant: Restaurant = { - latitude: latitudeFc, - longitude: longitudeFc, - nom : nomFc, - prix: prixFc, - adresse : adresseFc, - telephone : telephoneFc, - website : websiteFc, - surPlace : surPlaceFc, - aEmporter : aEmporterFc, - accesPMR : accesPMRFc - } - if( restaurant.latitude !== '' && - restaurant.longitude !== '' && - restaurant.nom !== '' && - restaurant.adresse !== '' ) { - this.apiBackService.addRestaurant(restaurant).subscribe( - resp=> - - this.router.navigate(['restaurants']) - ); - }else{ - console.log("hello"); - - this.errorMessage = "Renseigner les champs obligatoires **"; - } - - } }