initial
This commit is contained in:
commit
73897ea5b4
94 changed files with 32679 additions and 0 deletions
16
.browserslistrc
Normal file
16
.browserslistrc
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
# This file is used by the build system to adjust CSS and JS output to support the specified browsers below.
|
||||||
|
# For additional information regarding the format and rule options, please see:
|
||||||
|
# https://github.com/browserslist/browserslist#queries
|
||||||
|
|
||||||
|
# For the full list of supported browsers by the Angular framework, please see:
|
||||||
|
# https://angular.io/guide/browser-support
|
||||||
|
|
||||||
|
# You can see what browsers were selected by your queries by running:
|
||||||
|
# npx browserslist
|
||||||
|
|
||||||
|
last 1 Chrome version
|
||||||
|
last 1 Firefox version
|
||||||
|
last 2 Edge major versions
|
||||||
|
last 2 Safari major versions
|
||||||
|
last 2 iOS major versions
|
||||||
|
Firefox ESR
|
16
.editorconfig
Normal file
16
.editorconfig
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
# Editor configuration, see https://editorconfig.org
|
||||||
|
root = true
|
||||||
|
|
||||||
|
[*]
|
||||||
|
charset = utf-8
|
||||||
|
indent_style = space
|
||||||
|
indent_size = 2
|
||||||
|
insert_final_newline = true
|
||||||
|
trim_trailing_whitespace = true
|
||||||
|
|
||||||
|
[*.ts]
|
||||||
|
quote_type = single
|
||||||
|
|
||||||
|
[*.md]
|
||||||
|
max_line_length = off
|
||||||
|
trim_trailing_whitespace = false
|
46
.gitignore
vendored
Normal file
46
.gitignore
vendored
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
# See http://help.github.com/ignore-files/ for more about ignoring files.
|
||||||
|
|
||||||
|
# compiled output
|
||||||
|
/dist
|
||||||
|
/tmp
|
||||||
|
/out-tsc
|
||||||
|
# Only exists if Bazel was run
|
||||||
|
/bazel-out
|
||||||
|
|
||||||
|
# dependencies
|
||||||
|
/node_modules
|
||||||
|
|
||||||
|
# profiling files
|
||||||
|
chrome-profiler-events*.json
|
||||||
|
|
||||||
|
# IDEs and editors
|
||||||
|
/.idea
|
||||||
|
.project
|
||||||
|
.classpath
|
||||||
|
.c9/
|
||||||
|
*.launch
|
||||||
|
.settings/
|
||||||
|
*.sublime-workspace
|
||||||
|
|
||||||
|
# IDE - VSCode
|
||||||
|
.vscode/*
|
||||||
|
!.vscode/settings.json
|
||||||
|
!.vscode/tasks.json
|
||||||
|
!.vscode/launch.json
|
||||||
|
!.vscode/extensions.json
|
||||||
|
.history/*
|
||||||
|
|
||||||
|
# misc
|
||||||
|
/.angular/cache
|
||||||
|
/.sass-cache
|
||||||
|
/connect.lock
|
||||||
|
/coverage
|
||||||
|
/libpeerconnection.log
|
||||||
|
npm-debug.log
|
||||||
|
yarn-error.log
|
||||||
|
testem.log
|
||||||
|
/typings
|
||||||
|
|
||||||
|
# System Files
|
||||||
|
.DS_Store
|
||||||
|
Thumbs.db
|
29
README.md
Normal file
29
README.md
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
# LaBellePlante
|
||||||
|
|
||||||
|
This project was generated with [Angular CLI](https://github.com/angular/angular-cli) version 13.0.3.
|
||||||
|
|
||||||
|
## Development server
|
||||||
|
|
||||||
|
Run `ng serve` for a dev server. Navigate to `http://localhost:4200/`. The app will automatically reload if you change any of the source files.
|
||||||
|
|
||||||
|
Run `npm run api` for the api server. Reach to `http://localhost:3000/`
|
||||||
|
|
||||||
|
## Code scaffolding
|
||||||
|
|
||||||
|
Run `ng generate component component-name` to generate a new component. You can also use `ng generate directive|pipe|service|class|guard|interface|enum|module`.
|
||||||
|
|
||||||
|
## Build
|
||||||
|
|
||||||
|
Run `ng build` to build the project. The build artifacts will be stored in the `dist/` directory.
|
||||||
|
|
||||||
|
## Running unit tests
|
||||||
|
|
||||||
|
Run `ng test` to execute the unit tests via [Karma](https://karma-runner.github.io).
|
||||||
|
|
||||||
|
## Running end-to-end tests
|
||||||
|
|
||||||
|
Run `ng e2e` to execute the end-to-end tests via a platform of your choice. To use this command, you need to first add a package that implements end-to-end testing capabilities.
|
||||||
|
|
||||||
|
## Further help
|
||||||
|
|
||||||
|
To get more help on the Angular CLI use `ng help` or go check out the [Angular CLI Overview and Command Reference](https://angular.io/cli) page.
|
113
angular.json
Normal file
113
angular.json
Normal file
|
@ -0,0 +1,113 @@
|
||||||
|
{
|
||||||
|
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
|
||||||
|
"version": 1,
|
||||||
|
"newProjectRoot": "projects",
|
||||||
|
"projects": {
|
||||||
|
"la-belle-plante": {
|
||||||
|
"projectType": "application",
|
||||||
|
"schematics": {
|
||||||
|
"@schematics/angular:component": {
|
||||||
|
"style": "scss"
|
||||||
|
},
|
||||||
|
"@schematics/angular:application": {
|
||||||
|
"strict": true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"root": "",
|
||||||
|
"sourceRoot": "src",
|
||||||
|
"prefix": "app",
|
||||||
|
"architect": {
|
||||||
|
"build": {
|
||||||
|
"builder": "@angular-devkit/build-angular:browser",
|
||||||
|
"options": {
|
||||||
|
"outputPath": "dist/la-belle-plante",
|
||||||
|
"index": "src/index.html",
|
||||||
|
"main": "src/main.ts",
|
||||||
|
"polyfills": "src/polyfills.ts",
|
||||||
|
"tsConfig": "tsconfig.app.json",
|
||||||
|
"inlineStyleLanguage": "scss",
|
||||||
|
"assets": [
|
||||||
|
"src/favicon.ico",
|
||||||
|
"src/assets"
|
||||||
|
],
|
||||||
|
"styles": [
|
||||||
|
"src/styles.scss"
|
||||||
|
],
|
||||||
|
"scripts": [
|
||||||
|
"node_modules/bootstrap/dist/js/bootstrap.bundle.min.js"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"configurations": {
|
||||||
|
"production": {
|
||||||
|
"budgets": [
|
||||||
|
{
|
||||||
|
"type": "initial",
|
||||||
|
"maximumWarning": "500kb",
|
||||||
|
"maximumError": "1mb"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "anyComponentStyle",
|
||||||
|
"maximumWarning": "2kb",
|
||||||
|
"maximumError": "4kb"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"fileReplacements": [
|
||||||
|
{
|
||||||
|
"replace": "src/environments/environment.ts",
|
||||||
|
"with": "src/environments/environment.prod.ts"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"outputHashing": "all"
|
||||||
|
},
|
||||||
|
"development": {
|
||||||
|
"buildOptimizer": false,
|
||||||
|
"optimization": false,
|
||||||
|
"vendorChunk": true,
|
||||||
|
"extractLicenses": false,
|
||||||
|
"sourceMap": true,
|
||||||
|
"namedChunks": true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"defaultConfiguration": "production"
|
||||||
|
},
|
||||||
|
"serve": {
|
||||||
|
"builder": "@angular-devkit/build-angular:dev-server",
|
||||||
|
"configurations": {
|
||||||
|
"production": {
|
||||||
|
"browserTarget": "la-belle-plante:build:production"
|
||||||
|
},
|
||||||
|
"development": {
|
||||||
|
"browserTarget": "la-belle-plante:build:development"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"defaultConfiguration": "development"
|
||||||
|
},
|
||||||
|
"extract-i18n": {
|
||||||
|
"builder": "@angular-devkit/build-angular:extract-i18n",
|
||||||
|
"options": {
|
||||||
|
"browserTarget": "la-belle-plante:build"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"test": {
|
||||||
|
"builder": "@angular-devkit/build-angular:karma",
|
||||||
|
"options": {
|
||||||
|
"main": "src/test.ts",
|
||||||
|
"polyfills": "src/polyfills.ts",
|
||||||
|
"tsConfig": "tsconfig.spec.json",
|
||||||
|
"karmaConfig": "karma.conf.js",
|
||||||
|
"inlineStyleLanguage": "scss",
|
||||||
|
"assets": [
|
||||||
|
"src/favicon.ico",
|
||||||
|
"src/assets"
|
||||||
|
],
|
||||||
|
"styles": [
|
||||||
|
"src/styles.scss"
|
||||||
|
],
|
||||||
|
"scripts": []
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"defaultProject": "la-belle-plante"
|
||||||
|
}
|
44
karma.conf.js
Normal file
44
karma.conf.js
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
// Karma configuration file, see link for more information
|
||||||
|
// https://karma-runner.github.io/1.0/config/configuration-file.html
|
||||||
|
|
||||||
|
module.exports = function (config) {
|
||||||
|
config.set({
|
||||||
|
basePath: '',
|
||||||
|
frameworks: ['jasmine', '@angular-devkit/build-angular'],
|
||||||
|
plugins: [
|
||||||
|
require('karma-jasmine'),
|
||||||
|
require('karma-chrome-launcher'),
|
||||||
|
require('karma-jasmine-html-reporter'),
|
||||||
|
require('karma-coverage'),
|
||||||
|
require('@angular-devkit/build-angular/plugins/karma')
|
||||||
|
],
|
||||||
|
client: {
|
||||||
|
jasmine: {
|
||||||
|
// you can add configuration options for Jasmine here
|
||||||
|
// the possible options are listed at https://jasmine.github.io/api/edge/Configuration.html
|
||||||
|
// for example, you can disable the random execution with `random: false`
|
||||||
|
// or set a specific seed with `seed: 4321`
|
||||||
|
},
|
||||||
|
clearContext: false // leave Jasmine Spec Runner output visible in browser
|
||||||
|
},
|
||||||
|
jasmineHtmlReporter: {
|
||||||
|
suppressAll: true // removes the duplicated traces
|
||||||
|
},
|
||||||
|
coverageReporter: {
|
||||||
|
dir: require('path').join(__dirname, './coverage/la-belle-plante'),
|
||||||
|
subdir: '.',
|
||||||
|
reporters: [
|
||||||
|
{ type: 'html' },
|
||||||
|
{ type: 'text-summary' }
|
||||||
|
]
|
||||||
|
},
|
||||||
|
reporters: ['progress', 'kjhtml'],
|
||||||
|
port: 9876,
|
||||||
|
colors: true,
|
||||||
|
logLevel: config.LOG_INFO,
|
||||||
|
autoWatch: true,
|
||||||
|
browsers: ['Chrome'],
|
||||||
|
singleRun: false,
|
||||||
|
restartOnFileChange: true
|
||||||
|
});
|
||||||
|
};
|
24645
package-lock.json
generated
Normal file
24645
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load diff
45
package.json
Normal file
45
package.json
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
{
|
||||||
|
"name": "la-belle-plante",
|
||||||
|
"version": "0.0.0",
|
||||||
|
"scripts": {
|
||||||
|
"ng": "ng",
|
||||||
|
"start": "ng serve",
|
||||||
|
"build": "ng build",
|
||||||
|
"watch": "ng build --watch --configuration development",
|
||||||
|
"test": "ng test",
|
||||||
|
"api": "json-server-auth db.json"
|
||||||
|
},
|
||||||
|
"private": true,
|
||||||
|
"dependencies": {
|
||||||
|
"@angular/animations": "~13.0.0",
|
||||||
|
"@angular/common": "~13.0.0",
|
||||||
|
"@angular/compiler": "~13.0.0",
|
||||||
|
"@angular/core": "~13.0.0",
|
||||||
|
"@angular/forms": "~13.0.0",
|
||||||
|
"@angular/platform-browser": "~13.0.0",
|
||||||
|
"@angular/platform-browser-dynamic": "~13.0.0",
|
||||||
|
"@angular/router": "~13.0.0",
|
||||||
|
"bootstrap": "^5.1.3",
|
||||||
|
"jwt-decode": "^3.1.2",
|
||||||
|
"rxjs": "~7.4.0",
|
||||||
|
"tslib": "^2.3.0",
|
||||||
|
"underscore": "^1.13.1",
|
||||||
|
"zone.js": "~0.11.4"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@angular-devkit/build-angular": "~13.0.3",
|
||||||
|
"@angular/cli": "~13.0.3",
|
||||||
|
"@angular/compiler-cli": "~13.0.0",
|
||||||
|
"@types/jasmine": "~3.10.0",
|
||||||
|
"@types/node": "^12.11.1",
|
||||||
|
"@types/underscore": "^1.11.4",
|
||||||
|
"jasmine-core": "~3.10.0",
|
||||||
|
"json-server-auth": "^2.1.0",
|
||||||
|
"karma": "~6.3.0",
|
||||||
|
"karma-chrome-launcher": "~3.1.0",
|
||||||
|
"karma-coverage": "~2.0.3",
|
||||||
|
"karma-jasmine": "~4.0.0",
|
||||||
|
"karma-jasmine-html-reporter": "~1.7.0",
|
||||||
|
"typescript": "~4.4.3"
|
||||||
|
}
|
||||||
|
}
|
24
src/app/app-routing.module.ts
Normal file
24
src/app/app-routing.module.ts
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
import { NgModule } from '@angular/core';
|
||||||
|
import { RouterModule, Routes } from '@angular/router';
|
||||||
|
import { PageAccueilComponent } from './pages/page-accueil/page-accueil.component';
|
||||||
|
import { PageDetailsComponent } from './pages/page-details/page-details.component';
|
||||||
|
import { PageNotFoundComponent } from './pages/page-not-found/page-not-found.component';
|
||||||
|
|
||||||
|
//Lazy Loading du module account à implémenter dans ce fichier
|
||||||
|
|
||||||
|
const routes: Routes = [
|
||||||
|
{ path: '', redirectTo: 'home', pathMatch: 'full' },
|
||||||
|
{ path: 'home', component: PageAccueilComponent },
|
||||||
|
{ path: 'details', component: PageDetailsComponent },
|
||||||
|
{ path: 'account',
|
||||||
|
loadChildren: () => import('./modules/account/account.module')
|
||||||
|
.then(m => m.AccountModule)
|
||||||
|
},
|
||||||
|
{ path: '**', component: PageNotFoundComponent }
|
||||||
|
];
|
||||||
|
|
||||||
|
@NgModule({
|
||||||
|
imports: [RouterModule.forRoot(routes)],
|
||||||
|
exports: [RouterModule]
|
||||||
|
})
|
||||||
|
export class AppRoutingModule { }
|
2
src/app/app.component.html
Normal file
2
src/app/app.component.html
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
<app-nav-bar></app-nav-bar>
|
||||||
|
<router-outlet></router-outlet>
|
0
src/app/app.component.scss
Normal file
0
src/app/app.component.scss
Normal file
35
src/app/app.component.spec.ts
Normal file
35
src/app/app.component.spec.ts
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
import { TestBed } from '@angular/core/testing';
|
||||||
|
import { RouterTestingModule } from '@angular/router/testing';
|
||||||
|
import { AppComponent } from './app.component';
|
||||||
|
|
||||||
|
describe('AppComponent', () => {
|
||||||
|
beforeEach(async () => {
|
||||||
|
await TestBed.configureTestingModule({
|
||||||
|
imports: [
|
||||||
|
RouterTestingModule
|
||||||
|
],
|
||||||
|
declarations: [
|
||||||
|
AppComponent
|
||||||
|
],
|
||||||
|
}).compileComponents();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should create the app', () => {
|
||||||
|
const fixture = TestBed.createComponent(AppComponent);
|
||||||
|
const app = fixture.componentInstance;
|
||||||
|
expect(app).toBeTruthy();
|
||||||
|
});
|
||||||
|
|
||||||
|
it(`should have as title 'la-belle-plante'`, () => {
|
||||||
|
const fixture = TestBed.createComponent(AppComponent);
|
||||||
|
const app = fixture.componentInstance;
|
||||||
|
expect(app.title).toEqual('la-belle-plante');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should render title', () => {
|
||||||
|
const fixture = TestBed.createComponent(AppComponent);
|
||||||
|
fixture.detectChanges();
|
||||||
|
const compiled = fixture.nativeElement as HTMLElement;
|
||||||
|
expect(compiled.querySelector('.content span')?.textContent).toContain('la-belle-plante app is running!');
|
||||||
|
});
|
||||||
|
});
|
10
src/app/app.component.ts
Normal file
10
src/app/app.component.ts
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
import { Component } from '@angular/core';
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'app-root',
|
||||||
|
templateUrl: './app.component.html',
|
||||||
|
styleUrls: ['./app.component.scss']
|
||||||
|
})
|
||||||
|
export class AppComponent {
|
||||||
|
title = 'la-belle-plante';
|
||||||
|
}
|
39
src/app/app.module.ts
Normal file
39
src/app/app.module.ts
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
import { NgModule } from '@angular/core';
|
||||||
|
import { BrowserModule } from '@angular/platform-browser';
|
||||||
|
|
||||||
|
import { AppRoutingModule } from './app-routing.module';
|
||||||
|
import { AppComponent } from './app.component';
|
||||||
|
import { NavBarComponent } from './components/nav-bar/nav-bar.component';
|
||||||
|
import { PageAccueilComponent } from './pages/page-accueil/page-accueil.component';
|
||||||
|
import { PageDetailsComponent } from './pages/page-details/page-details.component';
|
||||||
|
import { PageNotFoundComponent } from './pages/page-not-found/page-not-found.component';
|
||||||
|
import { FilterSideBarComponent } from './components/filter-side-bar/filter-side-bar.component';
|
||||||
|
import { CardPlanteComponent } from './components/card-plante/card-plante.component';
|
||||||
|
import { HttpClientModule, HTTP_INTERCEPTORS } from '@angular/common/http';
|
||||||
|
import { IconComponent } from './components/icon/icon.component';
|
||||||
|
import { AvisBarComponent } from './components/avis-bar/avis-bar.component';
|
||||||
|
import { AuthInterceptor } from './services/auth.interceptor';
|
||||||
|
|
||||||
|
@NgModule({
|
||||||
|
declarations: [
|
||||||
|
AppComponent,
|
||||||
|
NavBarComponent,
|
||||||
|
PageAccueilComponent,
|
||||||
|
PageDetailsComponent,
|
||||||
|
PageNotFoundComponent,
|
||||||
|
FilterSideBarComponent,
|
||||||
|
CardPlanteComponent,
|
||||||
|
IconComponent,
|
||||||
|
AvisBarComponent
|
||||||
|
],
|
||||||
|
imports: [
|
||||||
|
BrowserModule,
|
||||||
|
AppRoutingModule,
|
||||||
|
HttpClientModule
|
||||||
|
],
|
||||||
|
providers: [
|
||||||
|
{ provide: HTTP_INTERCEPTORS, useClass: AuthInterceptor, multi: true }
|
||||||
|
],
|
||||||
|
bootstrap: [AppComponent]
|
||||||
|
})
|
||||||
|
export class AppModule { }
|
9
src/app/components/avis-bar/avis-bar.component.html
Normal file
9
src/app/components/avis-bar/avis-bar.component.html
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
<div (mouseleave)="onMouseLeave()">
|
||||||
|
<app-icon *ngFor="let star of starStates; let starIndex = index"
|
||||||
|
[iconName]="star.stateHoverUser ? 'star-fill' : 'star'"
|
||||||
|
[iconSize]="1.2"
|
||||||
|
[iconColor]="'#ffbf00'"
|
||||||
|
(mouseover)="onMouseOver(starIndex)"
|
||||||
|
(click)="onClickStar(starIndex)"
|
||||||
|
></app-icon>
|
||||||
|
</div>
|
0
src/app/components/avis-bar/avis-bar.component.scss
Normal file
0
src/app/components/avis-bar/avis-bar.component.scss
Normal file
25
src/app/components/avis-bar/avis-bar.component.spec.ts
Normal file
25
src/app/components/avis-bar/avis-bar.component.spec.ts
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||||
|
|
||||||
|
import { AvisBarComponent } from './avis-bar.component';
|
||||||
|
|
||||||
|
describe('AvisBarComponent', () => {
|
||||||
|
let component: AvisBarComponent;
|
||||||
|
let fixture: ComponentFixture<AvisBarComponent>;
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
await TestBed.configureTestingModule({
|
||||||
|
declarations: [ AvisBarComponent ]
|
||||||
|
})
|
||||||
|
.compileComponents();
|
||||||
|
});
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
fixture = TestBed.createComponent(AvisBarComponent);
|
||||||
|
component = fixture.componentInstance;
|
||||||
|
fixture.detectChanges();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should create', () => {
|
||||||
|
expect(component).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
62
src/app/components/avis-bar/avis-bar.component.ts
Normal file
62
src/app/components/avis-bar/avis-bar.component.ts
Normal file
|
@ -0,0 +1,62 @@
|
||||||
|
import { Component, OnInit } from '@angular/core';
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'app-avis-bar',
|
||||||
|
templateUrl: './avis-bar.component.html',
|
||||||
|
styleUrls: ['./avis-bar.component.scss']
|
||||||
|
})
|
||||||
|
export class AvisBarComponent implements OnInit {
|
||||||
|
starStates: {stateSelectedUser : boolean, stateHoverUser : boolean}[];
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
this.starStates = [];
|
||||||
|
|
||||||
|
for (let index = 0; index < 5; index++) {
|
||||||
|
this.starStates.push(
|
||||||
|
{
|
||||||
|
stateSelectedUser : false,
|
||||||
|
stateHoverUser : false
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ngOnInit(): void {
|
||||||
|
}
|
||||||
|
|
||||||
|
onMouseOver(index: number) {
|
||||||
|
console.log("star over", index);
|
||||||
|
for (let i = 0; i < this.starStates.length ; i++) {
|
||||||
|
if(i <= index) {
|
||||||
|
this.starStates[i].stateHoverUser = true;
|
||||||
|
} else {
|
||||||
|
this.starStates[i].stateHoverUser = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onMouseLeave() {
|
||||||
|
// this.starState = ['star', 'star', 'star', 'star', 'star'];
|
||||||
|
const tempTab = [];
|
||||||
|
for (let index = 0; index < this.starStates.length; index++) {
|
||||||
|
tempTab.push(
|
||||||
|
{
|
||||||
|
stateSelectedUser : this.starStates[index].stateSelectedUser,
|
||||||
|
stateHoverUser : this.starStates[index].stateSelectedUser
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
this.starStates = [...tempTab];
|
||||||
|
}
|
||||||
|
|
||||||
|
onClickStar(starIndex: number) {
|
||||||
|
for (let i = 0; i < this.starStates.length ; i++) {
|
||||||
|
if(i <= starIndex) {
|
||||||
|
this.starStates[i].stateSelectedUser = true;
|
||||||
|
} else {
|
||||||
|
this.starStates[i].stateSelectedUser = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
20
src/app/components/card-plante/card-plante.component.html
Normal file
20
src/app/components/card-plante/card-plante.component.html
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
<div class="plant card mb-4" style="width: 14rem;">
|
||||||
|
<app-icon class="like"
|
||||||
|
[iconName]="plant.plantLike ? 'heart-fill' : 'heart'"
|
||||||
|
[iconColor]="'#e35d6a'"
|
||||||
|
(click)="onClickLike()"></app-icon>
|
||||||
|
<img src="{{plant.product_url_picture}}" class="card-img-top" alt="Image de {{ plant.product_name }}">
|
||||||
|
<div class="card-body">
|
||||||
|
<h6 class="card-title">{{ plant.product_name }}</h6>
|
||||||
|
<div class="card-content">
|
||||||
|
<app-avis-bar></app-avis-bar>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="d-flex flex-row align-items-end justify-content-between">
|
||||||
|
<div class="card-content">
|
||||||
|
{{ plant.product_unitprice_ati }} €
|
||||||
|
</div>
|
||||||
|
<a href="#" class="btn btn-success">Pour moi !</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
14
src/app/components/card-plante/card-plante.component.scss
Normal file
14
src/app/components/card-plante/card-plante.component.scss
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
.plant {
|
||||||
|
min-height: 22rem;
|
||||||
|
.card-body {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
justify-content: space-between;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.like {
|
||||||
|
position: absolute;
|
||||||
|
right: 0.7rem;
|
||||||
|
top: 0.5rem;
|
||||||
|
}
|
25
src/app/components/card-plante/card-plante.component.spec.ts
Normal file
25
src/app/components/card-plante/card-plante.component.spec.ts
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||||
|
|
||||||
|
import { CardPlanteComponent } from './card-plante.component';
|
||||||
|
|
||||||
|
describe('CardPlanteComponent', () => {
|
||||||
|
let component: CardPlanteComponent;
|
||||||
|
let fixture: ComponentFixture<CardPlanteComponent>;
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
await TestBed.configureTestingModule({
|
||||||
|
declarations: [ CardPlanteComponent ]
|
||||||
|
})
|
||||||
|
.compileComponents();
|
||||||
|
});
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
fixture = TestBed.createComponent(CardPlanteComponent);
|
||||||
|
component = fixture.componentInstance;
|
||||||
|
fixture.detectChanges();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should create', () => {
|
||||||
|
expect(component).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
22
src/app/components/card-plante/card-plante.component.ts
Normal file
22
src/app/components/card-plante/card-plante.component.ts
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
|
||||||
|
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'app-card-plante',
|
||||||
|
templateUrl: './card-plante.component.html',
|
||||||
|
styleUrls: ['./card-plante.component.scss']
|
||||||
|
})
|
||||||
|
export class CardPlanteComponent implements OnInit {
|
||||||
|
@Input() plant: any;
|
||||||
|
@Output() clickLike = new EventEmitter();
|
||||||
|
constructor() { }
|
||||||
|
|
||||||
|
ngOnInit(): void {
|
||||||
|
}
|
||||||
|
|
||||||
|
onClickLike() {
|
||||||
|
console.log('click');
|
||||||
|
this.clickLike.emit();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,27 @@
|
||||||
|
<div class="custom-side-bar flex-shrink-0 bg-white border-end">
|
||||||
|
<div class="p-3">
|
||||||
|
<span class="fs-5 fw-semibold">Filtres</span>
|
||||||
|
</div>
|
||||||
|
<ul class="list-unstyled ps-0 border-top">
|
||||||
|
<div class="p-3">
|
||||||
|
<p class="mb-1 fs-5 fw-semibold">Catégories</p>
|
||||||
|
<div
|
||||||
|
*ngFor="let category of listCategories; let indexCat = index"
|
||||||
|
class="form-check">
|
||||||
|
|
||||||
|
<input
|
||||||
|
class="form-check-input"
|
||||||
|
type="checkbox"
|
||||||
|
value="testcategory"
|
||||||
|
id="checkBoxCategory{{indexCat}}">
|
||||||
|
|
||||||
|
<label class="form-check-label" for="checkBoxCategory{{indexCat}}">
|
||||||
|
{{ category }}
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
<div *ngIf="listCategories.length == 0 ">
|
||||||
|
Aucune catégorie disponible
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</ul>
|
||||||
|
</div>
|
|
@ -0,0 +1,5 @@
|
||||||
|
.custom-side-bar {
|
||||||
|
min-height: calc(100vh - 54px);
|
||||||
|
width: 280px;
|
||||||
|
height: 100%;
|
||||||
|
}
|
|
@ -0,0 +1,25 @@
|
||||||
|
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||||
|
|
||||||
|
import { FilterSideBarComponent } from './filter-side-bar.component';
|
||||||
|
|
||||||
|
describe('FilterSideBarComponent', () => {
|
||||||
|
let component: FilterSideBarComponent;
|
||||||
|
let fixture: ComponentFixture<FilterSideBarComponent>;
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
await TestBed.configureTestingModule({
|
||||||
|
declarations: [ FilterSideBarComponent ]
|
||||||
|
})
|
||||||
|
.compileComponents();
|
||||||
|
});
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
fixture = TestBed.createComponent(FilterSideBarComponent);
|
||||||
|
component = fixture.componentInstance;
|
||||||
|
fixture.detectChanges();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should create', () => {
|
||||||
|
expect(component).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
|
@ -0,0 +1,18 @@
|
||||||
|
import { Component, Input, OnInit } from '@angular/core';
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'app-filter-side-bar',
|
||||||
|
templateUrl: './filter-side-bar.component.html',
|
||||||
|
styleUrls: ['./filter-side-bar.component.scss']
|
||||||
|
})
|
||||||
|
export class FilterSideBarComponent implements OnInit {
|
||||||
|
@Input() listCategories: string[];
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
this.listCategories = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
ngOnInit(): void {
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
2
src/app/components/icon/icon.component.html
Normal file
2
src/app/components/icon/icon.component.html
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
<i class="bi-{{iconName}}"
|
||||||
|
[ngStyle]="{'font-size.rem': iconSize, 'color': iconColor}"></i>
|
3
src/app/components/icon/icon.component.scss
Normal file
3
src/app/components/icon/icon.component.scss
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
i {
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
25
src/app/components/icon/icon.component.spec.ts
Normal file
25
src/app/components/icon/icon.component.spec.ts
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||||
|
|
||||||
|
import { IconComponent } from './icon.component';
|
||||||
|
|
||||||
|
describe('IconComponent', () => {
|
||||||
|
let component: IconComponent;
|
||||||
|
let fixture: ComponentFixture<IconComponent>;
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
await TestBed.configureTestingModule({
|
||||||
|
declarations: [ IconComponent ]
|
||||||
|
})
|
||||||
|
.compileComponents();
|
||||||
|
});
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
fixture = TestBed.createComponent(IconComponent);
|
||||||
|
component = fixture.componentInstance;
|
||||||
|
fixture.detectChanges();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should create', () => {
|
||||||
|
expect(component).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
17
src/app/components/icon/icon.component.ts
Normal file
17
src/app/components/icon/icon.component.ts
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
import { Component, Input, OnInit } from '@angular/core';
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'app-icon',
|
||||||
|
templateUrl: './icon.component.html',
|
||||||
|
styleUrls: ['./icon.component.scss']
|
||||||
|
})
|
||||||
|
export class IconComponent implements OnInit {
|
||||||
|
@Input() iconName!: string;
|
||||||
|
@Input() iconSize!: number;
|
||||||
|
@Input() iconColor!: string;
|
||||||
|
constructor() { }
|
||||||
|
|
||||||
|
ngOnInit(): void {
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
27
src/app/components/nav-bar/nav-bar.component.html
Normal file
27
src/app/components/nav-bar/nav-bar.component.html
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
<nav class="navbar sticky-top navbar-expand-lg navbar-light bg-light shadow ">
|
||||||
|
<div class="container-fluid">
|
||||||
|
<a class="navbar-brand" href="#">🪴 La Belle Plante</a>
|
||||||
|
<button class="navbar-toggler"
|
||||||
|
type="button"
|
||||||
|
data-bs-toggle="collapse"
|
||||||
|
data-bs-target="#navbarNavAltMarkup"
|
||||||
|
aria-controls="navbarNavAltMarkup"
|
||||||
|
aria-expanded="false"
|
||||||
|
aria-label="Toggle navigation">
|
||||||
|
<span class="navbar-toggler-icon"></span>
|
||||||
|
</button>
|
||||||
|
<div class="collapse navbar-collapse" id="navbarNavAltMarkup">
|
||||||
|
<div class="navbar-nav">
|
||||||
|
<a routerLink="home" routerLinkActive="active-custom" class="nav-link">Accueil</a>
|
||||||
|
<a routerLink="details" routerLinkActive="active-custom" class="nav-link">Details</a>
|
||||||
|
<a routerLink="account/signin" routerLinkActive="active-custom" class="nav-link">Se connecter</a>
|
||||||
|
<a routerLink="account/user" routerLinkActive="active-custom" class="nav-link">Mon compte</a>
|
||||||
|
<a class="nav-link">Panier</a>
|
||||||
|
<a class="nav-link disabled">Plus d'option bientôt</a>
|
||||||
|
<a class="nav-link disabled" *ngIf="likeCounter == 0"> Pas de plante likée</a>
|
||||||
|
<a class="nav-link disabled" *ngIf="likeCounter == 1">Plante likée : {{ likeCounter }}</a>
|
||||||
|
<a class="nav-link disabled" *ngIf="likeCounter > 1">Plantes likées : {{ likeCounter }}</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</nav>
|
3
src/app/components/nav-bar/nav-bar.component.scss
Normal file
3
src/app/components/nav-bar/nav-bar.component.scss
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
.active-custom {
|
||||||
|
color: green !important;
|
||||||
|
}
|
25
src/app/components/nav-bar/nav-bar.component.spec.ts
Normal file
25
src/app/components/nav-bar/nav-bar.component.spec.ts
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||||
|
|
||||||
|
import { NavBarComponent } from './nav-bar.component';
|
||||||
|
|
||||||
|
describe('NavBarComponent', () => {
|
||||||
|
let component: NavBarComponent;
|
||||||
|
let fixture: ComponentFixture<NavBarComponent>;
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
await TestBed.configureTestingModule({
|
||||||
|
declarations: [ NavBarComponent ]
|
||||||
|
})
|
||||||
|
.compileComponents();
|
||||||
|
});
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
fixture = TestBed.createComponent(NavBarComponent);
|
||||||
|
component = fixture.componentInstance;
|
||||||
|
fixture.detectChanges();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should create', () => {
|
||||||
|
expect(component).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
31
src/app/components/nav-bar/nav-bar.component.ts
Normal file
31
src/app/components/nav-bar/nav-bar.component.ts
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
import { Component, OnDestroy, OnInit } from '@angular/core';
|
||||||
|
import { Subscription } from 'rxjs';
|
||||||
|
import { PlantouneService } from 'src/app/services/plantoune.service';
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'app-nav-bar',
|
||||||
|
templateUrl: './nav-bar.component.html',
|
||||||
|
styleUrls: ['./nav-bar.component.scss']
|
||||||
|
})
|
||||||
|
export class NavBarComponent implements OnInit, OnDestroy {
|
||||||
|
likeCounter: number;
|
||||||
|
subPlantLiked!: Subscription;
|
||||||
|
|
||||||
|
constructor(private plantouneService: PlantouneService) {
|
||||||
|
this.likeCounter = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
ngOnInit(): void {
|
||||||
|
this.subPlantLiked = this.plantouneService.plantLiked$.subscribe(
|
||||||
|
() => {
|
||||||
|
console.log('Get new event from Subject');
|
||||||
|
this.likeCounter ++;
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
ngOnDestroy(): void {
|
||||||
|
this.subPlantLiked.unsubscribe();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
24
src/app/modules/account/account-routing.module.ts
Normal file
24
src/app/modules/account/account-routing.module.ts
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
import { NgModule } from '@angular/core';
|
||||||
|
import { RouterModule, Routes } from '@angular/router';
|
||||||
|
import { AuthGuard } from './auth.guard';
|
||||||
|
import { PageAccountComponent } from './pages/page-account/page-account.component';
|
||||||
|
import { PageForgotPasswordComponent } from './pages/page-forgot-password/page-forgot-password.component';
|
||||||
|
import { PageResetPasswordComponent } from './pages/page-reset-password/page-reset-password.component';
|
||||||
|
import { PageSigninComponent } from './pages/page-signin/page-signin.component';
|
||||||
|
import { PageSignupComponent } from './pages/page-signup/page-signup.component';
|
||||||
|
|
||||||
|
const routes: Routes = [
|
||||||
|
{ path: '', redirectTo: 'signin', pathMatch: 'full'}, // account -> account/signin
|
||||||
|
{ path: 'signin', component: PageSigninComponent }, // account/signin
|
||||||
|
{ path: 'signup', component: PageSignupComponent },// account/signup
|
||||||
|
{ path: 'forgot-password', component: PageForgotPasswordComponent },
|
||||||
|
{ path: 'reset-password', component: PageResetPasswordComponent },
|
||||||
|
{ path: 'user', canActivate: [AuthGuard], component: PageAccountComponent }
|
||||||
|
|
||||||
|
];
|
||||||
|
|
||||||
|
@NgModule({
|
||||||
|
imports: [RouterModule.forChild(routes)],
|
||||||
|
exports: [RouterModule]
|
||||||
|
})
|
||||||
|
export class AccountRoutingModule { }
|
28
src/app/modules/account/account.module.ts
Normal file
28
src/app/modules/account/account.module.ts
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
import { NgModule } from '@angular/core';
|
||||||
|
import { CommonModule } from '@angular/common';
|
||||||
|
|
||||||
|
import { AccountRoutingModule } from './account-routing.module';
|
||||||
|
import { PageSigninComponent } from './pages/page-signin/page-signin.component';
|
||||||
|
import { PageSignupComponent } from './pages/page-signup/page-signup.component';
|
||||||
|
import { PageForgotPasswordComponent } from './pages/page-forgot-password/page-forgot-password.component';
|
||||||
|
import { PageResetPasswordComponent } from './pages/page-reset-password/page-reset-password.component';
|
||||||
|
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
|
||||||
|
import { PageAccountComponent } from './pages/page-account/page-account.component';
|
||||||
|
|
||||||
|
|
||||||
|
@NgModule({
|
||||||
|
declarations: [
|
||||||
|
PageSigninComponent,
|
||||||
|
PageSignupComponent,
|
||||||
|
PageForgotPasswordComponent,
|
||||||
|
PageResetPasswordComponent,
|
||||||
|
PageAccountComponent
|
||||||
|
],
|
||||||
|
imports: [
|
||||||
|
CommonModule,
|
||||||
|
AccountRoutingModule,
|
||||||
|
FormsModule,
|
||||||
|
ReactiveFormsModule
|
||||||
|
]
|
||||||
|
})
|
||||||
|
export class AccountModule { }
|
16
src/app/modules/account/auth.guard.spec.ts
Normal file
16
src/app/modules/account/auth.guard.spec.ts
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
import { TestBed } from '@angular/core/testing';
|
||||||
|
|
||||||
|
import { AuthGuard } from './auth.guard';
|
||||||
|
|
||||||
|
describe('AuthGuard', () => {
|
||||||
|
let guard: AuthGuard;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
TestBed.configureTestingModule({});
|
||||||
|
guard = TestBed.inject(AuthGuard);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should be created', () => {
|
||||||
|
expect(guard).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
46
src/app/modules/account/auth.guard.ts
Normal file
46
src/app/modules/account/auth.guard.ts
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
import { Injectable } from '@angular/core';
|
||||||
|
import { ActivatedRouteSnapshot, CanActivate, Router, RouterStateSnapshot, UrlTree } from '@angular/router';
|
||||||
|
import { Observable } from 'rxjs';
|
||||||
|
import { environment } from 'src/environments/environment';
|
||||||
|
import jwt_decode from 'jwt-decode';
|
||||||
|
|
||||||
|
@Injectable({
|
||||||
|
providedIn: 'root'
|
||||||
|
})
|
||||||
|
export class AuthGuard implements CanActivate {
|
||||||
|
private tokenKey: string;
|
||||||
|
constructor(private router: Router){
|
||||||
|
this.tokenKey = environment.tokenKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
canActivate(
|
||||||
|
route: ActivatedRouteSnapshot,
|
||||||
|
state: RouterStateSnapshot): Observable<boolean | UrlTree> | Promise<boolean | UrlTree> | boolean | UrlTree {
|
||||||
|
|
||||||
|
const token = localStorage.getItem(this.tokenKey);
|
||||||
|
|
||||||
|
if(token) {
|
||||||
|
const decodedToken = jwt_decode<any>(token);
|
||||||
|
|
||||||
|
console.log('decodedToken : ', decodedToken);
|
||||||
|
|
||||||
|
if(decodedToken.exp) {
|
||||||
|
console.log('Date d\'exp decodedToken : ', decodedToken.exp);
|
||||||
|
const dateExp = new Date(decodedToken.exp * 1000);
|
||||||
|
if(new Date() >= dateExp) {
|
||||||
|
// le token a expiré, je n'autorise pas l'accès
|
||||||
|
this.router.navigate(['account/signin']);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log("C'est ok ! ")
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
console.log("You shall not pass !!!!")
|
||||||
|
this.router.navigate(['account/signin']); // redirection de notre utilisateur vers une url de notre application (dans notre code TS)
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
7
src/app/modules/account/models/user.ts
Normal file
7
src/app/modules/account/models/user.ts
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
export interface User {
|
||||||
|
id?:number;
|
||||||
|
firstName: string;
|
||||||
|
lastName: string;
|
||||||
|
email: string;
|
||||||
|
password?: string;
|
||||||
|
}
|
|
@ -0,0 +1,16 @@
|
||||||
|
<div class="container mt-5">
|
||||||
|
<form class="row g-2" [formGroup]="userInfo">
|
||||||
|
<div class="col-md-6">
|
||||||
|
<label for="inputFirstName" class="form-label">Prénom</label>
|
||||||
|
<input type="text" class="form-control" id="inputFirstName" formControlName="firstName">
|
||||||
|
</div>
|
||||||
|
<div class="col-md-6">
|
||||||
|
<label for="inputLastName" class="form-label">Nom</label>
|
||||||
|
<input type="text" class="form-control" id="inputLastName" formControlName="lastName">
|
||||||
|
</div>
|
||||||
|
<div class="col-md-12">
|
||||||
|
<label for="inputEmail" class="form-label">Email</label>
|
||||||
|
<input type="email" class="form-control" id="inputEmail" formControlName="email">
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
|
@ -0,0 +1,25 @@
|
||||||
|
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||||
|
|
||||||
|
import { PageAccountComponent } from './page-account.component';
|
||||||
|
|
||||||
|
describe('PageAccountComponent', () => {
|
||||||
|
let component: PageAccountComponent;
|
||||||
|
let fixture: ComponentFixture<PageAccountComponent>;
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
await TestBed.configureTestingModule({
|
||||||
|
declarations: [ PageAccountComponent ]
|
||||||
|
})
|
||||||
|
.compileComponents();
|
||||||
|
});
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
fixture = TestBed.createComponent(PageAccountComponent);
|
||||||
|
component = fixture.componentInstance;
|
||||||
|
fixture.detectChanges();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should create', () => {
|
||||||
|
expect(component).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
|
@ -0,0 +1,46 @@
|
||||||
|
import { Component, OnInit } from '@angular/core';
|
||||||
|
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
|
||||||
|
import { User } from '../../models/user';
|
||||||
|
import { AuthService } from '../../services/auth.service';
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'app-page-account',
|
||||||
|
templateUrl: './page-account.component.html',
|
||||||
|
styleUrls: ['./page-account.component.scss']
|
||||||
|
})
|
||||||
|
export class PageAccountComponent implements OnInit {
|
||||||
|
public userInfo: FormGroup;
|
||||||
|
|
||||||
|
constructor(private fb: FormBuilder, private authService: AuthService) {
|
||||||
|
this.userInfo = this.initForm();
|
||||||
|
|
||||||
|
this.authService.getConnectedUserInfo()?.subscribe(
|
||||||
|
(user: User) => {
|
||||||
|
this.userInfo = this.initForm(user);
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
ngOnInit(): void {
|
||||||
|
}
|
||||||
|
|
||||||
|
private initForm(user?: User): FormGroup {
|
||||||
|
return this.fb.group({
|
||||||
|
firstName: [user ? user.firstName : ''],
|
||||||
|
lastName: [user ? user.lastName : ''],
|
||||||
|
email: [user ? user.email : '']
|
||||||
|
})
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
user !== '' ? user.firstName : ''
|
||||||
|
|
||||||
|
if(user) {
|
||||||
|
return user.firstName;
|
||||||
|
} else {
|
||||||
|
return ''
|
||||||
|
}
|
||||||
|
|
||||||
|
//`${token ? user.name : 'Se Connecter'}`
|
||||||
|
*/
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1 @@
|
||||||
|
<p>page-forgot-password works!</p>
|
|
@ -0,0 +1,25 @@
|
||||||
|
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||||
|
|
||||||
|
import { PageForgotPasswordComponent } from './page-forgot-password.component';
|
||||||
|
|
||||||
|
describe('PageForgotPasswordComponent', () => {
|
||||||
|
let component: PageForgotPasswordComponent;
|
||||||
|
let fixture: ComponentFixture<PageForgotPasswordComponent>;
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
await TestBed.configureTestingModule({
|
||||||
|
declarations: [ PageForgotPasswordComponent ]
|
||||||
|
})
|
||||||
|
.compileComponents();
|
||||||
|
});
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
fixture = TestBed.createComponent(PageForgotPasswordComponent);
|
||||||
|
component = fixture.componentInstance;
|
||||||
|
fixture.detectChanges();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should create', () => {
|
||||||
|
expect(component).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
|
@ -0,0 +1,15 @@
|
||||||
|
import { Component, OnInit } from '@angular/core';
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'app-page-forgot-password',
|
||||||
|
templateUrl: './page-forgot-password.component.html',
|
||||||
|
styleUrls: ['./page-forgot-password.component.scss']
|
||||||
|
})
|
||||||
|
export class PageForgotPasswordComponent implements OnInit {
|
||||||
|
|
||||||
|
constructor() { }
|
||||||
|
|
||||||
|
ngOnInit(): void {
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1 @@
|
||||||
|
<p>page-reset-password works!</p>
|
|
@ -0,0 +1,25 @@
|
||||||
|
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||||
|
|
||||||
|
import { PageResetPasswordComponent } from './page-reset-password.component';
|
||||||
|
|
||||||
|
describe('PageResetPasswordComponent', () => {
|
||||||
|
let component: PageResetPasswordComponent;
|
||||||
|
let fixture: ComponentFixture<PageResetPasswordComponent>;
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
await TestBed.configureTestingModule({
|
||||||
|
declarations: [ PageResetPasswordComponent ]
|
||||||
|
})
|
||||||
|
.compileComponents();
|
||||||
|
});
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
fixture = TestBed.createComponent(PageResetPasswordComponent);
|
||||||
|
component = fixture.componentInstance;
|
||||||
|
fixture.detectChanges();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should create', () => {
|
||||||
|
expect(component).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
|
@ -0,0 +1,15 @@
|
||||||
|
import { Component, OnInit } from '@angular/core';
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'app-page-reset-password',
|
||||||
|
templateUrl: './page-reset-password.component.html',
|
||||||
|
styleUrls: ['./page-reset-password.component.scss']
|
||||||
|
})
|
||||||
|
export class PageResetPasswordComponent implements OnInit {
|
||||||
|
|
||||||
|
constructor() { }
|
||||||
|
|
||||||
|
ngOnInit(): void {
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,52 @@
|
||||||
|
<!--**********************************
|
||||||
|
Formulaire Signin :
|
||||||
|
- champ email et password obligatoire
|
||||||
|
- bouton submit disable si le formulaire est invalid
|
||||||
|
- doit envoyer les données vers l'url /login
|
||||||
|
|
||||||
|
**********************************-->
|
||||||
|
<div class="signin-form text-center">
|
||||||
|
<main class="form-signin">
|
||||||
|
<form (ngSubmit)="onSubmit(signinForm)" #signinForm="ngForm">
|
||||||
|
<h1>Merci de vous connecter</h1>
|
||||||
|
<div class="form-floating">
|
||||||
|
<input type="email"
|
||||||
|
class="form-control"
|
||||||
|
id="floatingInput"
|
||||||
|
placeholder=""
|
||||||
|
name="email"
|
||||||
|
ngModel
|
||||||
|
required
|
||||||
|
[ngClass]="{'is-valid': signinForm.form.touched && signinForm.form.value['email'] != '' ,
|
||||||
|
'is-invalid': signinForm.form.touched && signinForm.form.value['email'] == ''}">
|
||||||
|
<label for="floatingInput">Adresse email</label>
|
||||||
|
</div>
|
||||||
|
<div class="form-floating">
|
||||||
|
<input type="password"
|
||||||
|
class="form-control"
|
||||||
|
id="floatingPassword"
|
||||||
|
placeholder=""
|
||||||
|
name="password"
|
||||||
|
ngModel
|
||||||
|
required
|
||||||
|
[ngClass]="{'is-valid': signinForm.form.touched && signinForm.form.value['password'] != '' ,
|
||||||
|
'is-invalid': signinForm.form.touched && signinForm.form.value['password'] == ''}">
|
||||||
|
<label for="floatingPassword">Mot de passe</label>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<button class="w-100 btn btn-lg btn-success"
|
||||||
|
type="submit"
|
||||||
|
[disabled]="signinForm.invalid">Je me connecte !</button>
|
||||||
|
<p>
|
||||||
|
Form is dirty : {{ signinForm.form.dirty }}
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
Form is touched : {{ signinForm.form.touched }}
|
||||||
|
</p>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<div *ngIf="errorForm">
|
||||||
|
<p class="text-danger">Il manque des informations dans le formulaire...</p>
|
||||||
|
</div>
|
||||||
|
</main>
|
||||||
|
</div>
|
|
@ -0,0 +1,31 @@
|
||||||
|
.signin-form {
|
||||||
|
height: 100vh;
|
||||||
|
padding-top: 40px;
|
||||||
|
background-color: #f5f5f5;
|
||||||
|
}
|
||||||
|
|
||||||
|
.form-signin {
|
||||||
|
width: 100%;
|
||||||
|
max-width: 330px;
|
||||||
|
padding: 15px;
|
||||||
|
margin: auto;
|
||||||
|
.checkbox {
|
||||||
|
font-weight: 400;
|
||||||
|
}
|
||||||
|
|
||||||
|
.form-floating:focus-within {
|
||||||
|
z-index: 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
input[type="email"] {
|
||||||
|
margin-bottom: -1px;
|
||||||
|
border-bottom-right-radius: 0;
|
||||||
|
border-bottom-left-radius: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
input[type="password"] {
|
||||||
|
margin-bottom: 10px;
|
||||||
|
border-top-left-radius: 0;
|
||||||
|
border-top-right-radius: 0;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,25 @@
|
||||||
|
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||||
|
|
||||||
|
import { PageSigninComponent } from './page-signin.component';
|
||||||
|
|
||||||
|
describe('PageSigninComponent', () => {
|
||||||
|
let component: PageSigninComponent;
|
||||||
|
let fixture: ComponentFixture<PageSigninComponent>;
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
await TestBed.configureTestingModule({
|
||||||
|
declarations: [ PageSigninComponent ]
|
||||||
|
})
|
||||||
|
.compileComponents();
|
||||||
|
});
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
fixture = TestBed.createComponent(PageSigninComponent);
|
||||||
|
component = fixture.componentInstance;
|
||||||
|
fixture.detectChanges();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should create', () => {
|
||||||
|
expect(component).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
|
@ -0,0 +1,36 @@
|
||||||
|
import { Component, OnInit } from '@angular/core';
|
||||||
|
import { Router } from '@angular/router';
|
||||||
|
import { AuthService } from '../../services/auth.service';
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'app-page-signin',
|
||||||
|
templateUrl: './page-signin.component.html',
|
||||||
|
styleUrls: ['./page-signin.component.scss']
|
||||||
|
})
|
||||||
|
export class PageSigninComponent implements OnInit {
|
||||||
|
public errorForm: boolean;
|
||||||
|
constructor(private authService: AuthService, private router: Router) {
|
||||||
|
this.errorForm = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
ngOnInit(): void {
|
||||||
|
}
|
||||||
|
|
||||||
|
public onSubmit(submittedForm: any): void {
|
||||||
|
console.log(submittedForm.form.value);
|
||||||
|
const email = submittedForm.form.value['email'];
|
||||||
|
const password = submittedForm.form.value['password'];
|
||||||
|
if(email !== '' && password !== '') {
|
||||||
|
this.authService.signin(email, password).subscribe(
|
||||||
|
resp => {
|
||||||
|
console.log('Component Page Signin: ', resp);
|
||||||
|
this.router.navigate(['account/user']);
|
||||||
|
}
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
// afficher une erreur à l'utilisateur
|
||||||
|
this.errorForm = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,62 @@
|
||||||
|
<div class="signup-form text-center">
|
||||||
|
<main class="form-signup">
|
||||||
|
<form (ngSubmit)="onSubmit()" [formGroup]="signupForm">
|
||||||
|
<h1>Merci de vous inscrire</h1>
|
||||||
|
<div class="form-floating">
|
||||||
|
<input type="text"
|
||||||
|
class="form-control"
|
||||||
|
id="floatingInputfirstName"
|
||||||
|
placeholder=""
|
||||||
|
name="firstName"
|
||||||
|
formControlName="firstNameFc"
|
||||||
|
[ngClass]="{'is-valid' : signupForm.controls['firstNameFc'].touched && signupForm.controls['firstNameFc'].valid,
|
||||||
|
'is-invalid': signupForm.controls['firstNameFc'].touched && !signupForm.controls['firstNameFc'].valid}">
|
||||||
|
<label for="floatingInputfirstName">Prénom</label>
|
||||||
|
</div>
|
||||||
|
<div class="form-floating">
|
||||||
|
<input type="text"
|
||||||
|
class="form-control"
|
||||||
|
id="floatingInputlastName"
|
||||||
|
placeholder=""
|
||||||
|
name="lastName"
|
||||||
|
formControlName="lastNameFc"
|
||||||
|
[ngClass]="{'is-valid' : signupForm.controls['lastNameFc'].touched && signupForm.controls['lastNameFc'].valid,
|
||||||
|
'is-invalid': signupForm.controls['lastNameFc'].touched && !signupForm.controls['lastNameFc'].valid}">
|
||||||
|
<label for="floatingInputlastName">Nom</label>
|
||||||
|
</div>
|
||||||
|
<div class="form-floating">
|
||||||
|
<input type="email"
|
||||||
|
class="form-control"
|
||||||
|
id="floatingInput"
|
||||||
|
placeholder=""
|
||||||
|
name="email"
|
||||||
|
formControlName="emailFc"
|
||||||
|
[ngClass]="{'is-valid' : signupForm.controls['emailFc'].touched && signupForm.controls['emailFc'].valid,
|
||||||
|
'is-invalid': signupForm.controls['emailFc'].touched && !signupForm.controls['emailFc'].valid}">
|
||||||
|
<label for="floatingInput">Adresse email</label>
|
||||||
|
</div>
|
||||||
|
<div class="form-floating">
|
||||||
|
<input type="password"
|
||||||
|
class="form-control"
|
||||||
|
id="floatingPassword"
|
||||||
|
placeholder=""
|
||||||
|
name="password"
|
||||||
|
formControlName="passwordFc"
|
||||||
|
[ngClass]="{'is-valid' : signupForm.controls['passwordFc'].touched && signupForm.controls['passwordFc'].valid,
|
||||||
|
'is-invalid': signupForm.controls['passwordFc'].touched && !signupForm.controls['passwordFc'].valid}">
|
||||||
|
<label for="floatingPassword">Mot de passe</label>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<button class="w-100 btn btn-lg btn-success"
|
||||||
|
type="submit"
|
||||||
|
[disabled]="signupForm.invalid">Je m'inscris !</button>
|
||||||
|
<p>
|
||||||
|
Value : {{ signupForm.value | json }}
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
Form valid : {{ signupForm.valid }}
|
||||||
|
</p>
|
||||||
|
|
||||||
|
</form>
|
||||||
|
</main>
|
||||||
|
</div>
|
|
@ -0,0 +1,32 @@
|
||||||
|
.signup-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;
|
||||||
|
}
|
|
@ -0,0 +1,25 @@
|
||||||
|
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||||
|
|
||||||
|
import { PageSignupComponent } from './page-signup.component';
|
||||||
|
|
||||||
|
describe('PageSignupComponent', () => {
|
||||||
|
let component: PageSignupComponent;
|
||||||
|
let fixture: ComponentFixture<PageSignupComponent>;
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
await TestBed.configureTestingModule({
|
||||||
|
declarations: [ PageSignupComponent ]
|
||||||
|
})
|
||||||
|
.compileComponents();
|
||||||
|
});
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
fixture = TestBed.createComponent(PageSignupComponent);
|
||||||
|
component = fixture.componentInstance;
|
||||||
|
fixture.detectChanges();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should create', () => {
|
||||||
|
expect(component).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
|
@ -0,0 +1,56 @@
|
||||||
|
import { Component, OnInit } from '@angular/core';
|
||||||
|
import { FormControl, FormGroup, Validators } from '@angular/forms';
|
||||||
|
import { Router } from '@angular/router';
|
||||||
|
import { User } from '../../models/user';
|
||||||
|
import { AuthService } from '../../services/auth.service';
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'app-page-signup',
|
||||||
|
templateUrl: './page-signup.component.html',
|
||||||
|
styleUrls: ['./page-signup.component.scss']
|
||||||
|
})
|
||||||
|
export class PageSignupComponent implements OnInit {
|
||||||
|
public signupForm: FormGroup;
|
||||||
|
|
||||||
|
constructor(private authService: AuthService, private router: Router) {
|
||||||
|
this.signupForm = new FormGroup({});
|
||||||
|
}
|
||||||
|
|
||||||
|
ngOnInit(): void {
|
||||||
|
// FormGroupe => Group de champs de saisie (notre objet)
|
||||||
|
// FormControl => Les champs de saisie (nos propriétés)
|
||||||
|
this.signupForm = new FormGroup({
|
||||||
|
firstNameFc : new FormControl(''),
|
||||||
|
lastNameFc : new FormControl(''),
|
||||||
|
emailFc : new FormControl('', [Validators.email, Validators.required, Validators.pattern(/^([\w\.\-_]+)?\w+@[\w-_]+(\.\w+){1,}/igm)]), // chercher une meilleure regex
|
||||||
|
passwordFc : new FormControl('', [Validators.minLength(8), Validators.required])
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
public onSubmit(): void {
|
||||||
|
console.log("value : ", this.signupForm.value);
|
||||||
|
console.log("form : ", this.signupForm);
|
||||||
|
const firstNameValue = this.signupForm.value['firstNameFc'];
|
||||||
|
const lastNameValue = this.signupForm.value['lastNameFc'];
|
||||||
|
const emailValue = this.signupForm.value['emailFc'];
|
||||||
|
const passwordValue = this.signupForm.value['passwordFc'];
|
||||||
|
|
||||||
|
const user: User = {
|
||||||
|
firstName: firstNameValue,
|
||||||
|
lastName: lastNameValue,
|
||||||
|
email: emailValue,
|
||||||
|
password: passwordValue
|
||||||
|
}
|
||||||
|
|
||||||
|
if(user.email !== '' && user.password !== '') {
|
||||||
|
this.authService.signup(user).subscribe(
|
||||||
|
resp => {
|
||||||
|
this.router.navigate(['account/signin'])
|
||||||
|
}
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
// affichage erreur
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
16
src/app/modules/account/services/auth.service.spec.ts
Normal file
16
src/app/modules/account/services/auth.service.spec.ts
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
import { TestBed } from '@angular/core/testing';
|
||||||
|
|
||||||
|
import { AuthService } from './auth.service';
|
||||||
|
|
||||||
|
describe('AuthService', () => {
|
||||||
|
let service: AuthService;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
TestBed.configureTestingModule({});
|
||||||
|
service = TestBed.inject(AuthService);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should be created', () => {
|
||||||
|
expect(service).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
80
src/app/modules/account/services/auth.service.ts
Normal file
80
src/app/modules/account/services/auth.service.ts
Normal file
|
@ -0,0 +1,80 @@
|
||||||
|
import { HttpClient } from '@angular/common/http';
|
||||||
|
import { Injectable } from '@angular/core';
|
||||||
|
import { map, Observable } from 'rxjs';
|
||||||
|
import { environment } from 'src/environments/environment';
|
||||||
|
import { User } from '../models/user';
|
||||||
|
import jwt_decode from 'jwt-decode';
|
||||||
|
import { Router } from '@angular/router';
|
||||||
|
|
||||||
|
|
||||||
|
@Injectable({
|
||||||
|
providedIn: 'root'
|
||||||
|
})
|
||||||
|
export class AuthService {
|
||||||
|
private apiUrl: string;
|
||||||
|
private tokenKey: string;
|
||||||
|
|
||||||
|
constructor(private http: HttpClient, private router: Router) {
|
||||||
|
// On se sert des variables d'environnement de notre application
|
||||||
|
this.apiUrl = environment.apiUrl;
|
||||||
|
this.tokenKey = environment.tokenKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
signup(newUser: User): Observable<any> {
|
||||||
|
// const body = {
|
||||||
|
// firstName: firstName,
|
||||||
|
// lastName: lastName,
|
||||||
|
// email: email,
|
||||||
|
// password: password
|
||||||
|
// };
|
||||||
|
|
||||||
|
console.log("Mon nouvel utilisateur : ", newUser);
|
||||||
|
|
||||||
|
return this.http.post(`${this.apiUrl}/register`, newUser);
|
||||||
|
}
|
||||||
|
|
||||||
|
signin(email: string, password: string): Observable<any> {
|
||||||
|
const body = {
|
||||||
|
email: email,
|
||||||
|
password: password
|
||||||
|
};
|
||||||
|
|
||||||
|
console.log("Mon body : ", body);
|
||||||
|
|
||||||
|
// Modifier cette partie ci-dessous :
|
||||||
|
// - pour pouvoir stocker dans le localstorage notre accesstoken
|
||||||
|
// - Sous la clé "TOKEN-LBP"
|
||||||
|
|
||||||
|
return this.http.post(`${this.apiUrl}/login`, body).pipe(
|
||||||
|
map((x: any) => {
|
||||||
|
console.log('Service : ', x.accessToken);
|
||||||
|
// Modification à faire ici
|
||||||
|
localStorage.setItem(this.tokenKey, x.accessToken);
|
||||||
|
return x; // permet de renvoyer la réponse à l'initiateur (page Signin) après le traitement du map
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
forgotPassword(email: string, password: string): Observable<any> {
|
||||||
|
const body = {
|
||||||
|
email: email,
|
||||||
|
password: password
|
||||||
|
};
|
||||||
|
|
||||||
|
console.log("Mon body : ", body);
|
||||||
|
|
||||||
|
return this.http.post(`${this.apiUrl}/forgot-psw`, body);
|
||||||
|
}
|
||||||
|
|
||||||
|
getConnectedUserInfo(): Observable<User> | void {
|
||||||
|
const token = localStorage.getItem(this.tokenKey);
|
||||||
|
if(token) {
|
||||||
|
const decodedToken = jwt_decode<any>(token);
|
||||||
|
const userId = decodedToken.sub;
|
||||||
|
return this.http.get<User>(`${this.apiUrl}/users/${userId}`);
|
||||||
|
} else {
|
||||||
|
this.router.navigate(['account/signin']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
26
src/app/pages/page-accueil/page-accueil.component.html
Normal file
26
src/app/pages/page-accueil/page-accueil.component.html
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
<div class="d-flex align-items-stretch">
|
||||||
|
<app-filter-side-bar [listCategories]="listCategoriesFilter"></app-filter-side-bar>
|
||||||
|
|
||||||
|
<div class="custom-main container p-3">
|
||||||
|
<input class="form-control"
|
||||||
|
type="text"
|
||||||
|
placeholder="Recherche ta belle plante"
|
||||||
|
aria-label="Input Recherche ta belle plante">
|
||||||
|
|
||||||
|
<div class="py-3">
|
||||||
|
Trier par :
|
||||||
|
<button class="btn btn-outline-success btn-sm me-2">Prix</button>
|
||||||
|
<button class="btn btn-outline-success btn-sm me-2">Ordre Alpha</button>
|
||||||
|
<button class="btn btn-outline-success btn-sm me-2">Avis</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
<div class="col" *ngFor="let product of listData">
|
||||||
|
<app-card-plante [plant]="product"
|
||||||
|
(clickLike)="onEventLike()">
|
||||||
|
</app-card-plante>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
0
src/app/pages/page-accueil/page-accueil.component.scss
Normal file
0
src/app/pages/page-accueil/page-accueil.component.scss
Normal file
25
src/app/pages/page-accueil/page-accueil.component.spec.ts
Normal file
25
src/app/pages/page-accueil/page-accueil.component.spec.ts
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||||
|
|
||||||
|
import { PageAccueilComponent } from './page-accueil.component';
|
||||||
|
|
||||||
|
describe('PageAccueilComponent', () => {
|
||||||
|
let component: PageAccueilComponent;
|
||||||
|
let fixture: ComponentFixture<PageAccueilComponent>;
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
await TestBed.configureTestingModule({
|
||||||
|
declarations: [ PageAccueilComponent ]
|
||||||
|
})
|
||||||
|
.compileComponents();
|
||||||
|
});
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
fixture = TestBed.createComponent(PageAccueilComponent);
|
||||||
|
component = fixture.componentInstance;
|
||||||
|
fixture.detectChanges();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should create', () => {
|
||||||
|
expect(component).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
126
src/app/pages/page-accueil/page-accueil.component.ts
Normal file
126
src/app/pages/page-accueil/page-accueil.component.ts
Normal file
|
@ -0,0 +1,126 @@
|
||||||
|
import { Component, OnInit } from '@angular/core';
|
||||||
|
import { PlantouneService } from 'src/app/services/plantoune.service';
|
||||||
|
import { environment } from 'src/environments/environment';
|
||||||
|
import * as _ from 'underscore';
|
||||||
|
import jwt_token from 'jwt-decode';
|
||||||
|
import { forkJoin } from 'rxjs';
|
||||||
|
import { TokenService } from 'src/app/services/token.service';
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'app-page-accueil',
|
||||||
|
templateUrl: './page-accueil.component.html',
|
||||||
|
styleUrls: ['./page-accueil.component.scss']
|
||||||
|
})
|
||||||
|
export class PageAccueilComponent implements OnInit {
|
||||||
|
public listData: any[];
|
||||||
|
public listCategoriesFilter: string[];
|
||||||
|
|
||||||
|
constructor(private plantouneService: PlantouneService, private tokenService: TokenService) {
|
||||||
|
this.listData = [];
|
||||||
|
this.listCategoriesFilter = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* equivalent de la ligne du dessus
|
||||||
|
*
|
||||||
|
* plantouneService;
|
||||||
|
*
|
||||||
|
* constructor(plantouneService: PlantouneService) {
|
||||||
|
* this.plantouneService = plantouneService;
|
||||||
|
* }
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
ngOnInit(): void {
|
||||||
|
const userId = this.tokenService.getCurrentUserId();
|
||||||
|
|
||||||
|
if(userId) {
|
||||||
|
|
||||||
|
const listObservable = [this.plantouneService.getData(), this.plantouneService.getPlantFav(userId)]
|
||||||
|
forkJoin(listObservable).subscribe((listResp: any[]) => {
|
||||||
|
console.log("Reponse forkjoin list plant : ", listResp[0])
|
||||||
|
console.log("Reponse forkjoin list plant fav : ", listResp[1]);
|
||||||
|
})
|
||||||
|
|
||||||
|
forkJoin({
|
||||||
|
listPlant: this.plantouneService.getData(),
|
||||||
|
listPlantFav: this.plantouneService.getPlantFav(userId)
|
||||||
|
}).subscribe(({listPlant, listPlantFav}) => {
|
||||||
|
console.log("plant liké : ", listPlantFav);
|
||||||
|
|
||||||
|
// j'ai accès à la réponse qui contient ma liste de plante
|
||||||
|
// j'ai accès à la réponse qui contient mes plant favorites/likées
|
||||||
|
this.listCategoriesFilter = this.buildListCategory(listPlant);
|
||||||
|
|
||||||
|
// toutes les plantes mises en favorites par l'utilsateur connecté => leur ajouter une propriété => plantlikée
|
||||||
|
this.listData = listPlant;
|
||||||
|
|
||||||
|
// extraction des plantId
|
||||||
|
const listPlantIdLike = listPlantFav.map((x: any) => x.plantId);
|
||||||
|
|
||||||
|
// ajout de la propriété plantLike à true sur les plantes likées si elles sont dans le tableau de plante likées
|
||||||
|
this.listData.forEach((plant: any) => {
|
||||||
|
if(listPlantIdLike.includes(plant.product_id))
|
||||||
|
plant.plantLike = true;
|
||||||
|
});
|
||||||
|
|
||||||
|
this.listData.length = 9;
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
// faire un call api pour récupérer nos plantes
|
||||||
|
// this.plantouneService.getData().subscribe(
|
||||||
|
// (listPlant: any[]) => {
|
||||||
|
// this.plantouneService.getPlantFav(userId).subscribe(
|
||||||
|
// (data: any) => {
|
||||||
|
// console.log("plant liké : ", data);
|
||||||
|
|
||||||
|
// // j'ai accès à la réponse qui contient ma liste de plante
|
||||||
|
// // j'ai accès à la réponse qui contient mes plant favorites/likées
|
||||||
|
// this.listCategoriesFilter = this.buildListCategory(listPlant);
|
||||||
|
|
||||||
|
// // toutes les plantes mises en favorites par l'utilsateur connecté => leur ajouter une propriété => plantlikée
|
||||||
|
// this.listData = listPlant;
|
||||||
|
|
||||||
|
// // extraction des plantId
|
||||||
|
// const listPlantIdLike = data.map((x: any) => x.plantId);
|
||||||
|
|
||||||
|
// // ajout de la propriété plantLike à true sur les plantes likées si elles sont dans le tableau de plante likées
|
||||||
|
// this.listData.forEach((plant: any) => {
|
||||||
|
// if(listPlantIdLike.includes(plant.product_id))
|
||||||
|
// plant.plantLike = true;
|
||||||
|
// });
|
||||||
|
|
||||||
|
// this.listData.length = 9;
|
||||||
|
// }
|
||||||
|
// )
|
||||||
|
|
||||||
|
// }
|
||||||
|
// )
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
this.plantouneService.getData().subscribe(
|
||||||
|
(listPlant: any[]) => {
|
||||||
|
this.listCategoriesFilter = this.buildListCategory(listPlant);
|
||||||
|
// listPlant.forEach(x => {x.plantLike = true})
|
||||||
|
this.listData = listPlant;
|
||||||
|
this.listData.length = 9;
|
||||||
|
}
|
||||||
|
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private buildListCategory(listPlant: any[]): string[] {
|
||||||
|
const listAllCategories = listPlant.map(product => product.product_breadcrumb_label);
|
||||||
|
const listUniqCategories = _.uniq(listAllCategories)
|
||||||
|
return listUniqCategories;
|
||||||
|
}
|
||||||
|
|
||||||
|
onEventLike() {
|
||||||
|
this.plantouneService.plantLiked$.next('')
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
1
src/app/pages/page-details/page-details.component.html
Normal file
1
src/app/pages/page-details/page-details.component.html
Normal file
|
@ -0,0 +1 @@
|
||||||
|
<p>page-details works!</p>
|
0
src/app/pages/page-details/page-details.component.scss
Normal file
0
src/app/pages/page-details/page-details.component.scss
Normal file
25
src/app/pages/page-details/page-details.component.spec.ts
Normal file
25
src/app/pages/page-details/page-details.component.spec.ts
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||||
|
|
||||||
|
import { PageDetailsComponent } from './page-details.component';
|
||||||
|
|
||||||
|
describe('PageDetailsComponent', () => {
|
||||||
|
let component: PageDetailsComponent;
|
||||||
|
let fixture: ComponentFixture<PageDetailsComponent>;
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
await TestBed.configureTestingModule({
|
||||||
|
declarations: [ PageDetailsComponent ]
|
||||||
|
})
|
||||||
|
.compileComponents();
|
||||||
|
});
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
fixture = TestBed.createComponent(PageDetailsComponent);
|
||||||
|
component = fixture.componentInstance;
|
||||||
|
fixture.detectChanges();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should create', () => {
|
||||||
|
expect(component).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
15
src/app/pages/page-details/page-details.component.ts
Normal file
15
src/app/pages/page-details/page-details.component.ts
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
import { Component, OnInit } from '@angular/core';
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'app-page-details',
|
||||||
|
templateUrl: './page-details.component.html',
|
||||||
|
styleUrls: ['./page-details.component.scss']
|
||||||
|
})
|
||||||
|
export class PageDetailsComponent implements OnInit {
|
||||||
|
|
||||||
|
constructor() { }
|
||||||
|
|
||||||
|
ngOnInit(): void {
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1 @@
|
||||||
|
<p>page-not-found works!</p>
|
|
@ -0,0 +1,25 @@
|
||||||
|
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||||
|
|
||||||
|
import { PageNotFoundComponent } from './page-not-found.component';
|
||||||
|
|
||||||
|
describe('PageNotFoundComponent', () => {
|
||||||
|
let component: PageNotFoundComponent;
|
||||||
|
let fixture: ComponentFixture<PageNotFoundComponent>;
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
await TestBed.configureTestingModule({
|
||||||
|
declarations: [ PageNotFoundComponent ]
|
||||||
|
})
|
||||||
|
.compileComponents();
|
||||||
|
});
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
fixture = TestBed.createComponent(PageNotFoundComponent);
|
||||||
|
component = fixture.componentInstance;
|
||||||
|
fixture.detectChanges();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should create', () => {
|
||||||
|
expect(component).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
15
src/app/pages/page-not-found/page-not-found.component.ts
Normal file
15
src/app/pages/page-not-found/page-not-found.component.ts
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
import { Component, OnInit } from '@angular/core';
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'app-page-not-found',
|
||||||
|
templateUrl: './page-not-found.component.html',
|
||||||
|
styleUrls: ['./page-not-found.component.scss']
|
||||||
|
})
|
||||||
|
export class PageNotFoundComponent implements OnInit {
|
||||||
|
|
||||||
|
constructor() { }
|
||||||
|
|
||||||
|
ngOnInit(): void {
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
16
src/app/services/auth.interceptor.spec.ts
Normal file
16
src/app/services/auth.interceptor.spec.ts
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
import { TestBed } from '@angular/core/testing';
|
||||||
|
|
||||||
|
import { AuthInterceptor } from './auth.interceptor';
|
||||||
|
|
||||||
|
describe('AuthInterceptor', () => {
|
||||||
|
beforeEach(() => TestBed.configureTestingModule({
|
||||||
|
providers: [
|
||||||
|
AuthInterceptor
|
||||||
|
]
|
||||||
|
}));
|
||||||
|
|
||||||
|
it('should be created', () => {
|
||||||
|
const interceptor: AuthInterceptor = TestBed.inject(AuthInterceptor);
|
||||||
|
expect(interceptor).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
31
src/app/services/auth.interceptor.ts
Normal file
31
src/app/services/auth.interceptor.ts
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
import { Injectable } from '@angular/core';
|
||||||
|
import {
|
||||||
|
HttpRequest,
|
||||||
|
HttpHandler,
|
||||||
|
HttpEvent,
|
||||||
|
HttpInterceptor
|
||||||
|
} from '@angular/common/http';
|
||||||
|
import { Observable } from 'rxjs';
|
||||||
|
import { TokenService } from './token.service';
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class AuthInterceptor implements HttpInterceptor {
|
||||||
|
|
||||||
|
constructor(private tokenService: TokenService) {}
|
||||||
|
|
||||||
|
intercept(request: HttpRequest<unknown>, next: HttpHandler): Observable<HttpEvent<unknown>> {
|
||||||
|
console.log('Coucou je suis le videur ! ');
|
||||||
|
const token = this.tokenService.getToken();
|
||||||
|
if(token) {
|
||||||
|
|
||||||
|
const authReq = request.clone(
|
||||||
|
{
|
||||||
|
headers : request.headers.set('Authorization', `Bearer ${token}`)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
return next.handle(authReq);
|
||||||
|
} else {
|
||||||
|
return next.handle(request);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
16
src/app/services/plantoune.service.spec.ts
Normal file
16
src/app/services/plantoune.service.spec.ts
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
import { TestBed } from '@angular/core/testing';
|
||||||
|
|
||||||
|
import { PlantouneService } from './plantoune.service';
|
||||||
|
|
||||||
|
describe('PlantouneService', () => {
|
||||||
|
let service: PlantouneService;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
TestBed.configureTestingModule({});
|
||||||
|
service = TestBed.inject(PlantouneService);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should be created', () => {
|
||||||
|
expect(service).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
24
src/app/services/plantoune.service.ts
Normal file
24
src/app/services/plantoune.service.ts
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
import { Injectable } from '@angular/core';
|
||||||
|
import { Observable, Subject } from 'rxjs';
|
||||||
|
import { HttpClient } from '@angular/common/http';
|
||||||
|
import { environment } from 'src/environments/environment';
|
||||||
|
|
||||||
|
@Injectable({
|
||||||
|
providedIn: 'root'
|
||||||
|
})
|
||||||
|
export class PlantouneService {
|
||||||
|
plantLiked$ = new Subject<any>();
|
||||||
|
apiUrl: string;
|
||||||
|
|
||||||
|
constructor(private httpClient: HttpClient) {
|
||||||
|
this.apiUrl = environment.apiUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
getData(): Observable<any[]> {
|
||||||
|
return this.httpClient.get<any[]>(`${this.apiUrl}/list_products`);
|
||||||
|
}
|
||||||
|
|
||||||
|
getPlantFav(userId: number): Observable<any[]> {
|
||||||
|
return this.httpClient.get<any[]>(`${this.apiUrl}/favPlant?userId=${userId}`)
|
||||||
|
}
|
||||||
|
}
|
16
src/app/services/token.service.spec.ts
Normal file
16
src/app/services/token.service.spec.ts
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
import { TestBed } from '@angular/core/testing';
|
||||||
|
|
||||||
|
import { TokenService } from './token.service';
|
||||||
|
|
||||||
|
describe('TokenService', () => {
|
||||||
|
let service: TokenService;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
TestBed.configureTestingModule({});
|
||||||
|
service = TestBed.inject(TokenService);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should be created', () => {
|
||||||
|
expect(service).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
32
src/app/services/token.service.ts
Normal file
32
src/app/services/token.service.ts
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
import { Injectable } from '@angular/core';
|
||||||
|
import { environment } from 'src/environments/environment';
|
||||||
|
import jwt_decode from 'jwt-decode';
|
||||||
|
|
||||||
|
@Injectable({
|
||||||
|
providedIn: 'root'
|
||||||
|
})
|
||||||
|
export class TokenService {
|
||||||
|
tokenKey = environment.tokenKey;
|
||||||
|
|
||||||
|
constructor() { }
|
||||||
|
|
||||||
|
public getToken(): string | null {
|
||||||
|
const token = localStorage.getItem(this.tokenKey);
|
||||||
|
if(token) {
|
||||||
|
return token;
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public getCurrentUserId(): number | null {
|
||||||
|
const token = this.getToken();
|
||||||
|
if(token) {
|
||||||
|
const decodedToken = jwt_decode<any>(token);
|
||||||
|
const userId = decodedToken.sub;
|
||||||
|
return userId;
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
0
src/assets/.gitkeep
Normal file
0
src/assets/.gitkeep
Normal file
5
src/environments/environment.prod.ts
Normal file
5
src/environments/environment.prod.ts
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
export const environment = {
|
||||||
|
production: true,
|
||||||
|
apiUrl: "",
|
||||||
|
tokenKey: ""
|
||||||
|
};
|
18
src/environments/environment.ts
Normal file
18
src/environments/environment.ts
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
// This file can be replaced during build by using the `fileReplacements` array.
|
||||||
|
// `ng build` replaces `environment.ts` with `environment.prod.ts`.
|
||||||
|
// The list of file replacements can be found in `angular.json`.
|
||||||
|
|
||||||
|
export const environment = {
|
||||||
|
production: false,
|
||||||
|
apiUrl: "http://localhost:3000",
|
||||||
|
tokenKey: "TOKEN-LBP"
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* For easier debugging in development mode, you can import the following file
|
||||||
|
* to ignore zone related error stack frames such as `zone.run`, `zoneDelegate.invokeTask`.
|
||||||
|
*
|
||||||
|
* This import should be commented out in production mode because it will have a negative impact
|
||||||
|
* on performance if an error is thrown.
|
||||||
|
*/
|
||||||
|
// import 'zone.js/plugins/zone-error'; // Included with Angular CLI.
|
BIN
src/favicon.ico
Normal file
BIN
src/favicon.ico
Normal file
Binary file not shown.
After Width: | Height: | Size: 948 B |
14
src/index.html
Normal file
14
src/index.html
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
<!doctype html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<title>LaBellePlante</title>
|
||||||
|
<base href="/">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
|
<link rel="icon" type="image/x-icon" href="favicon.ico">
|
||||||
|
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.7.2/font/bootstrap-icons.css">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<app-root></app-root>
|
||||||
|
</body>
|
||||||
|
</html>
|
12
src/main.ts
Normal file
12
src/main.ts
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
import { enableProdMode } from '@angular/core';
|
||||||
|
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
|
||||||
|
|
||||||
|
import { AppModule } from './app/app.module';
|
||||||
|
import { environment } from './environments/environment';
|
||||||
|
|
||||||
|
if (environment.production) {
|
||||||
|
enableProdMode();
|
||||||
|
}
|
||||||
|
|
||||||
|
platformBrowserDynamic().bootstrapModule(AppModule)
|
||||||
|
.catch(err => console.error(err));
|
46
src/page-account.component.ts
Normal file
46
src/page-account.component.ts
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
import { Component, OnInit } from '@angular/core';
|
||||||
|
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
|
||||||
|
import { User } from '../../models/user';
|
||||||
|
import { AuthService } from '../../services/auth.service';
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'app-page-account',
|
||||||
|
templateUrl: './page-account.component.html',
|
||||||
|
styleUrls: ['./page-account.component.scss']
|
||||||
|
})
|
||||||
|
export class PageAccountComponent implements OnInit {
|
||||||
|
public userInfo: FormGroup;
|
||||||
|
|
||||||
|
constructor(private fb: FormBuilder, private authService: AuthService) {
|
||||||
|
this.userInfo = this.initForm();
|
||||||
|
|
||||||
|
this.authService.getConnectedUserInfo()?.subscribe(
|
||||||
|
(user: User) => {
|
||||||
|
this.userInfo = this.initForm(user);
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
ngOnInit(): void {
|
||||||
|
}
|
||||||
|
|
||||||
|
private initForm(user?: User): FormGroup {
|
||||||
|
return this.fb.group({
|
||||||
|
firstName: [user ? user.firstName : ''],
|
||||||
|
lastName: [user ? user.lastName : ''],
|
||||||
|
email: [user ? user.email : '']
|
||||||
|
})
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
user !== '' ? user.firstName : ''
|
||||||
|
|
||||||
|
if(user) {
|
||||||
|
return user.firstName;
|
||||||
|
} else {
|
||||||
|
return ''
|
||||||
|
}
|
||||||
|
|
||||||
|
//`${token ? user.name : 'Se Connecter'}`
|
||||||
|
*/
|
||||||
|
|
||||||
|
}
|
56
src/page-signup.component.ts
Normal file
56
src/page-signup.component.ts
Normal file
|
@ -0,0 +1,56 @@
|
||||||
|
import { Component, OnInit } from '@angular/core';
|
||||||
|
import { FormControl, FormGroup, Validators } from '@angular/forms';
|
||||||
|
import { Router } from '@angular/router';
|
||||||
|
import { User } from '../../models/user';
|
||||||
|
import { AuthService } from '../../services/auth.service';
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'app-page-signup',
|
||||||
|
templateUrl: './page-signup.component.html',
|
||||||
|
styleUrls: ['./page-signup.component.scss']
|
||||||
|
})
|
||||||
|
export class PageSignupComponent implements OnInit {
|
||||||
|
public signupForm: FormGroup;
|
||||||
|
|
||||||
|
constructor(private authService: AuthService, private router: Router) {
|
||||||
|
this.signupForm = new FormGroup({});
|
||||||
|
}
|
||||||
|
|
||||||
|
ngOnInit(): void {
|
||||||
|
// FormGroupe => Group de champs de saisie (notre objet)
|
||||||
|
// FormControl => Les champs de saisie (nos propriétés)
|
||||||
|
this.signupForm = new FormGroup({
|
||||||
|
firstNameFc : new FormControl(''),
|
||||||
|
lastNameFc : new FormControl(''),
|
||||||
|
emailFc : new FormControl('', [Validators.email, Validators.required, Validators.pattern(/^([\w\.\-_]+)?\w+@[\w-_]+(\.\w+){1,}/igm)]), // chercher une meilleure regex
|
||||||
|
passwordFc : new FormControl('', [Validators.minLength(8), Validators.required])
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
public onSubmit(): void {
|
||||||
|
console.log("value : ", this.signupForm.value);
|
||||||
|
console.log("form : ", this.signupForm);
|
||||||
|
const firstNameValue = this.signupForm.value['firstNameFc'];
|
||||||
|
const lastNameValue = this.signupForm.value['lastNameFc'];
|
||||||
|
const emailValue = this.signupForm.value['emailFc'];
|
||||||
|
const passwordValue = this.signupForm.value['passwordFc'];
|
||||||
|
|
||||||
|
const user: User = {
|
||||||
|
firstName: firstNameValue,
|
||||||
|
lastName: lastNameValue,
|
||||||
|
email: emailValue,
|
||||||
|
password: passwordValue
|
||||||
|
}
|
||||||
|
|
||||||
|
if(user.email !== '' && user.password !== '') {
|
||||||
|
this.authService.signup(user).subscribe(
|
||||||
|
resp => {
|
||||||
|
this.router.navigate(['account/signin'])
|
||||||
|
}
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
// affichage erreur
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
53
src/polyfills.ts
Normal file
53
src/polyfills.ts
Normal file
|
@ -0,0 +1,53 @@
|
||||||
|
/**
|
||||||
|
* This file includes polyfills needed by Angular and is loaded before the app.
|
||||||
|
* You can add your own extra polyfills to this file.
|
||||||
|
*
|
||||||
|
* This file is divided into 2 sections:
|
||||||
|
* 1. Browser polyfills. These are applied before loading ZoneJS and are sorted by browsers.
|
||||||
|
* 2. Application imports. Files imported after ZoneJS that should be loaded before your main
|
||||||
|
* file.
|
||||||
|
*
|
||||||
|
* The current setup is for so-called "evergreen" browsers; the last versions of browsers that
|
||||||
|
* automatically update themselves. This includes recent versions of Safari, Chrome (including
|
||||||
|
* Opera), Edge on the desktop, and iOS and Chrome on mobile.
|
||||||
|
*
|
||||||
|
* Learn more in https://angular.io/guide/browser-support
|
||||||
|
*/
|
||||||
|
|
||||||
|
/***************************************************************************************************
|
||||||
|
* BROWSER POLYFILLS
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* By default, zone.js will patch all possible macroTask and DomEvents
|
||||||
|
* user can disable parts of macroTask/DomEvents patch by setting following flags
|
||||||
|
* because those flags need to be set before `zone.js` being loaded, and webpack
|
||||||
|
* will put import in the top of bundle, so user need to create a separate file
|
||||||
|
* in this directory (for example: zone-flags.ts), and put the following flags
|
||||||
|
* into that file, and then add the following code before importing zone.js.
|
||||||
|
* import './zone-flags';
|
||||||
|
*
|
||||||
|
* The flags allowed in zone-flags.ts are listed here.
|
||||||
|
*
|
||||||
|
* The following flags will work for all browsers.
|
||||||
|
*
|
||||||
|
* (window as any).__Zone_disable_requestAnimationFrame = true; // disable patch requestAnimationFrame
|
||||||
|
* (window as any).__Zone_disable_on_property = true; // disable patch onProperty such as onclick
|
||||||
|
* (window as any).__zone_symbol__UNPATCHED_EVENTS = ['scroll', 'mousemove']; // disable patch specified eventNames
|
||||||
|
*
|
||||||
|
* in IE/Edge developer tools, the addEventListener will also be wrapped by zone.js
|
||||||
|
* with the following flag, it will bypass `zone.js` patch for IE/Edge
|
||||||
|
*
|
||||||
|
* (window as any).__Zone_enable_cross_context_check = true;
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
/***************************************************************************************************
|
||||||
|
* Zone JS is required by default for Angular itself.
|
||||||
|
*/
|
||||||
|
import 'zone.js'; // Included with Angular CLI.
|
||||||
|
|
||||||
|
|
||||||
|
/***************************************************************************************************
|
||||||
|
* APPLICATION IMPORTS
|
||||||
|
*/
|
3
src/styles.scss
Normal file
3
src/styles.scss
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
/* You can add global styles to this file, and also import other style files */
|
||||||
|
@import '~bootstrap/scss/bootstrap.scss';
|
||||||
|
// le tilde agit comme un raccourci vers le node_modules
|
26
src/test.ts
Normal file
26
src/test.ts
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
// This file is required by karma.conf.js and loads recursively all the .spec and framework files
|
||||||
|
|
||||||
|
import 'zone.js/testing';
|
||||||
|
import { getTestBed } from '@angular/core/testing';
|
||||||
|
import {
|
||||||
|
BrowserDynamicTestingModule,
|
||||||
|
platformBrowserDynamicTesting
|
||||||
|
} from '@angular/platform-browser-dynamic/testing';
|
||||||
|
|
||||||
|
declare const require: {
|
||||||
|
context(path: string, deep?: boolean, filter?: RegExp): {
|
||||||
|
keys(): string[];
|
||||||
|
<T>(id: string): T;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
// First, initialize the Angular testing environment.
|
||||||
|
getTestBed().initTestEnvironment(
|
||||||
|
BrowserDynamicTestingModule,
|
||||||
|
platformBrowserDynamicTesting(),
|
||||||
|
);
|
||||||
|
|
||||||
|
// Then we find all the tests.
|
||||||
|
const context = require.context('./', true, /\.spec\.ts$/);
|
||||||
|
// And load the modules.
|
||||||
|
context.keys().map(context);
|
15
tsconfig.app.json
Normal file
15
tsconfig.app.json
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
/* To learn more about this file see: https://angular.io/config/tsconfig. */
|
||||||
|
{
|
||||||
|
"extends": "./tsconfig.json",
|
||||||
|
"compilerOptions": {
|
||||||
|
"outDir": "./out-tsc/app",
|
||||||
|
"types": []
|
||||||
|
},
|
||||||
|
"files": [
|
||||||
|
"src/main.ts",
|
||||||
|
"src/polyfills.ts"
|
||||||
|
],
|
||||||
|
"include": [
|
||||||
|
"src/**/*.d.ts"
|
||||||
|
]
|
||||||
|
}
|
32
tsconfig.json
Normal file
32
tsconfig.json
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
/* To learn more about this file see: https://angular.io/config/tsconfig. */
|
||||||
|
{
|
||||||
|
"compileOnSave": false,
|
||||||
|
"compilerOptions": {
|
||||||
|
"baseUrl": "./",
|
||||||
|
"outDir": "./dist/out-tsc",
|
||||||
|
"forceConsistentCasingInFileNames": true,
|
||||||
|
"strict": true,
|
||||||
|
"noImplicitOverride": true,
|
||||||
|
"noPropertyAccessFromIndexSignature": true,
|
||||||
|
"noImplicitReturns": true,
|
||||||
|
"noFallthroughCasesInSwitch": true,
|
||||||
|
"sourceMap": true,
|
||||||
|
"declaration": false,
|
||||||
|
"downlevelIteration": true,
|
||||||
|
"experimentalDecorators": true,
|
||||||
|
"moduleResolution": "node",
|
||||||
|
"importHelpers": true,
|
||||||
|
"target": "es2017",
|
||||||
|
"module": "es2020",
|
||||||
|
"lib": [
|
||||||
|
"es2020",
|
||||||
|
"dom"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"angularCompilerOptions": {
|
||||||
|
"enableI18nLegacyMessageIdFormat": false,
|
||||||
|
"strictInjectionParameters": true,
|
||||||
|
"strictInputAccessModifiers": true,
|
||||||
|
"strictTemplates": true
|
||||||
|
}
|
||||||
|
}
|
18
tsconfig.spec.json
Normal file
18
tsconfig.spec.json
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
/* To learn more about this file see: https://angular.io/config/tsconfig. */
|
||||||
|
{
|
||||||
|
"extends": "./tsconfig.json",
|
||||||
|
"compilerOptions": {
|
||||||
|
"outDir": "./out-tsc/spec",
|
||||||
|
"types": [
|
||||||
|
"jasmine"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"files": [
|
||||||
|
"src/test.ts",
|
||||||
|
"src/polyfills.ts"
|
||||||
|
],
|
||||||
|
"include": [
|
||||||
|
"src/**/*.spec.ts",
|
||||||
|
"src/**/*.d.ts"
|
||||||
|
]
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue