From dc03c1b25f6c870832f10b973763c48fbc095a12 Mon Sep 17 00:00:00 2001 From: Thomas Cardon Date: Fri, 18 Feb 2022 10:16:55 +0100 Subject: [PATCH] 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); + + } +}