From 4cc9058887b05699a26de5699d6388cef5d6dec9 Mon Sep 17 00:00:00 2001 From: MiharyR Date: Wed, 5 Jan 2022 20:37:31 +0100 Subject: [PATCH] =?UTF-8?q?frontend=20avec=20donn=C3=A9es=20fictif=20pr?= =?UTF-8?q?=C3=AAt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../page-user-list.component.html | 110 +++++++++-------- .../page-user-list.component.scss | 5 + .../page-user-list.component.ts | 43 ++++--- .../popup-create-person.component.html | 11 +- .../popup-create-person.component.ts | 13 +- .../popup-delete-person.component.html | 8 -- .../popup-delete-person.component.ts | 17 --- .../popup-update-person-admin.component.html | 68 ++++++++++ .../popup-update-person-admin.component.scss} | 0 ...opup-update-person-admin.component.spec.ts | 25 ++++ .../popup-update-person-admin.component.ts | 116 ++++++++++++++++++ frontend/src/app/app-routing.module.ts | 7 +- frontend/src/app/app.module.ts | 14 ++- .../components/navbar/navbar.component.html | 15 ++- .../components/navbar/navbar.component.ts | 1 - .../page-profil/page-profil.component.html | 53 ++++++++ .../page-profil/page-profil.component.scss | 0 .../page-profil/page-profil.component.spec.ts | 0 .../page-profil/page-profil.component.ts | 44 ++++++- .../popup-delete-profil.component.html | 14 +++ .../popup-delete-profil.component.scss} | 0 .../popup-delete-profil.component.spec.ts} | 12 +- .../popup-delete-profil.component.ts | 28 +++++ .../popup-update-profil.component.html | 4 +- .../popup-update-profil.component.scss | 37 ++++++ .../popup-update-profil.component.spec.ts | 0 .../popup-update-profil.component.ts | 17 ++- .../page-profil/page-profil.component.html | 38 ------ frontend/src/app/common/interfaces/Person.ts | 9 -- .../fictitious-datas.service.ts | 22 ++-- .../services/profil/profil.service.spec.ts | 16 +++ .../common/services/profil/profil.service.ts | 9 ++ .../page-login/page-login.component.html | 2 +- .../login/page-login/page-login.component.ts | 4 +- .../page-register.component.html | 4 +- .../page-register/page-register.component.ts | 11 +- .../app/user/{ => myProfil}/commentary.txt | 4 +- .../page-registry.component.html | 45 +++++++ .../page-registry.component.scss | 9 ++ .../page-registry.component.spec.ts | 25 ++++ .../page-registry/page-registry.component.ts | 50 ++++++++ 41 files changed, 697 insertions(+), 213 deletions(-) delete mode 100644 frontend/src/app/admin/userList/popup-delete-person/popup-delete-person.component.html delete mode 100644 frontend/src/app/admin/userList/popup-delete-person/popup-delete-person.component.ts create mode 100644 frontend/src/app/admin/userList/popup-update-person-admin/popup-update-person-admin.component.html rename frontend/src/app/{common/components/profil/popup-update-profil/popup-update-profil.component.scss => admin/userList/popup-update-person-admin/popup-update-person-admin.component.scss} (100%) create mode 100644 frontend/src/app/admin/userList/popup-update-person-admin/popup-update-person-admin.component.spec.ts create mode 100644 frontend/src/app/admin/userList/popup-update-person-admin/popup-update-person-admin.component.ts create mode 100644 frontend/src/app/common/components/page-profil/page-profil.component.html rename frontend/src/app/common/components/{profil => }/page-profil/page-profil.component.scss (100%) rename frontend/src/app/common/components/{profil => }/page-profil/page-profil.component.spec.ts (100%) rename frontend/src/app/common/components/{profil => }/page-profil/page-profil.component.ts (63%) create mode 100644 frontend/src/app/common/components/popup-delete-profil/popup-delete-profil.component.html rename frontend/src/app/{admin/userList/popup-delete-person/popup-delete-person.component.scss => common/components/popup-delete-profil/popup-delete-profil.component.scss} (100%) rename frontend/src/app/{admin/userList/popup-delete-person/popup-delete-person.component.spec.ts => common/components/popup-delete-profil/popup-delete-profil.component.spec.ts} (50%) create mode 100644 frontend/src/app/common/components/popup-delete-profil/popup-delete-profil.component.ts rename frontend/src/app/common/components/{profil => }/popup-update-profil/popup-update-profil.component.html (97%) create mode 100644 frontend/src/app/common/components/popup-update-profil/popup-update-profil.component.scss rename frontend/src/app/common/components/{profil => }/popup-update-profil/popup-update-profil.component.spec.ts (100%) rename frontend/src/app/common/components/{profil => }/popup-update-profil/popup-update-profil.component.ts (84%) delete mode 100644 frontend/src/app/common/components/profil/page-profil/page-profil.component.html delete mode 100644 frontend/src/app/common/interfaces/Person.ts create mode 100644 frontend/src/app/common/services/profil/profil.service.spec.ts create mode 100644 frontend/src/app/common/services/profil/profil.service.ts rename frontend/src/app/user/{ => myProfil}/commentary.txt (65%) create mode 100644 frontend/src/app/user/page-registry/page-registry.component.html create mode 100644 frontend/src/app/user/page-registry/page-registry.component.scss create mode 100644 frontend/src/app/user/page-registry/page-registry.component.spec.ts create mode 100644 frontend/src/app/user/page-registry/page-registry.component.ts diff --git a/frontend/src/app/admin/userList/page-user-list/page-user-list.component.html b/frontend/src/app/admin/userList/page-user-list/page-user-list.component.html index f33c7ad..81abaa9 100644 --- a/frontend/src/app/admin/userList/page-user-list/page-user-list.component.html +++ b/frontend/src/app/admin/userList/page-user-list/page-user-list.component.html @@ -3,61 +3,65 @@ -
- -
- -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Pseudo{{person.login}}Email{{person.email}}Rôle - utilisateur - admin - Actions - - -
- - - +
+
+
+ + Filter + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Pseudo{{person.nickname}}Email{{person.email}}Rôle{{person.role}}Actions + + +
+ + + + +


diff --git a/frontend/src/app/admin/userList/page-user-list/page-user-list.component.scss b/frontend/src/app/admin/userList/page-user-list/page-user-list.component.scss index 1a60697..78b21a9 100644 --- a/frontend/src/app/admin/userList/page-user-list/page-user-list.component.scss +++ b/frontend/src/app/admin/userList/page-user-list/page-user-list.component.scss @@ -11,3 +11,8 @@ mat-paginator, table { .btnAjouter { border: solid 1px black; } + +.filtre { + text-align: center; + width: 33%; +} diff --git a/frontend/src/app/admin/userList/page-user-list/page-user-list.component.ts b/frontend/src/app/admin/userList/page-user-list/page-user-list.component.ts index 5e97438..dcb2dc8 100644 --- a/frontend/src/app/admin/userList/page-user-list/page-user-list.component.ts +++ b/frontend/src/app/admin/userList/page-user-list/page-user-list.component.ts @@ -1,14 +1,13 @@ import {AfterViewInit, Component, ViewChild} from '@angular/core'; import {MatTableDataSource} from "@angular/material/table"; -import {Person} from "../../../common/interfaces/Person"; import {FictitiousDatasService} from "../../../common/services/fictitiousDatas/fictitious-datas.service"; import {MatSort} from "@angular/material/sort"; import {MatPaginator} from "@angular/material/paginator"; import {MatDialog} from "@angular/material/dialog"; import {PopupCreatePersonComponent} from "../popup-create-person/popup-create-person.component"; import {MatSnackBar} from "@angular/material/snack-bar"; -import {PopupUpdateProfilComponent} from "../../../common/components/profil/popup-update-profil/popup-update-profil.component"; -import {PopupDeletePersonComponent} from "../popup-delete-person/popup-delete-person.component"; +import {PopupUpdatePersonAdminComponent} from "../popup-update-person-admin/popup-update-person-admin.component"; +import {PopupDeleteProfilComponent} from "../../../common/components/popup-delete-profil/popup-delete-profil.component"; @@ -19,33 +18,40 @@ import {PopupDeletePersonComponent} from "../popup-delete-person/popup-delete-pe }) export class PageUserListComponent implements AfterViewInit { - displayedColumns: string[] = [ "login", "email", "role", "actions" ]; - dataSource: MatTableDataSource; + displayedColumns: string[] = [ "nickname", "email", "role", "actions" ]; + dataSource: MatTableDataSource = new MatTableDataSource(); @ViewChild(MatSort) sort: MatSort; @ViewChild(MatPaginator) paginator: MatPaginator; configSnackBar = { duration: 2000, panelClass: "custom-class" }; - constructor( private fictitiousDatasService: FictitiousDatasService, public dialog: MatDialog, private snackBar: MatSnackBar) { } - ngAfterViewInit(): void { // Faux code - const tabPerson = this.fictitiousDatasService.getTabPerson(5); + let tabPerson = this.fictitiousDatasService.getTabPerson(5); // Vrai code ... - + tabPerson = tabPerson.map( person => { + if(!person.is_admin) return Object.assign(person, {role: "utilisateur"}); + else return Object.assign(person, {role: "admin"}); + }); this.dataSource = new MatTableDataSource(tabPerson); this.dataSource.sort = this.sort; this.dataSource.paginator = this.paginator; } + applyFilter(event: Event) + { + const filterValue = (event.target as HTMLInputElement).value; + this.dataSource.filter = filterValue.trim().toLowerCase(); + } + // Appuie sur le bouton "add" onAdd(): void @@ -62,24 +68,22 @@ export class PageUserListComponent implements AfterViewInit else { this.dataSource.data.push(person); this.dataSource.data = this.dataSource.data; - this.dataSource = this.dataSource + this.dataSource = this.dataSource; this.snackBar.open( "L'utilisateur a bien été créé ✔", "", this.configSnackBar); } - }); } - // Appuie sur le bouton "edit" - onUpdate(personToUpdate: Person): void + onUpdate(personToUpdate: any): void { const config = { width: '50%', data: { person: personToUpdate } }; this.dialog - .open(PopupUpdateProfilComponent, config) + .open(PopupUpdatePersonAdminComponent, config) .afterClosed() .subscribe( personUpdated => { @@ -98,15 +102,18 @@ export class PageUserListComponent implements AfterViewInit } - // Appuie sur le bouton "delete" - onDelete(personToDelete: Person): void + onDelete(personToDelete: any): void { const config = { - data: { person: personToDelete } + data: { + id: personToDelete.id, + email: personToDelete.email, + me: false, + } }; this.dialog - .open(PopupDeletePersonComponent, config) + .open(PopupDeleteProfilComponent, config) .afterClosed() .subscribe( personUpdated => { diff --git a/frontend/src/app/admin/userList/popup-create-person/popup-create-person.component.html b/frontend/src/app/admin/userList/popup-create-person/popup-create-person.component.html index 00c24ba..9f648d7 100644 --- a/frontend/src/app/admin/userList/popup-create-person/popup-create-person.component.html +++ b/frontend/src/app/admin/userList/popup-create-person/popup-create-person.component.html @@ -4,10 +4,10 @@ - + Pseudo - +
@@ -29,10 +29,9 @@
- - - Utilisateur   - Admin + + Utilisateur   + Admin

diff --git a/frontend/src/app/admin/userList/popup-create-person/popup-create-person.component.ts b/frontend/src/app/admin/userList/popup-create-person/popup-create-person.component.ts index 53e6aae..48db16b 100644 --- a/frontend/src/app/admin/userList/popup-create-person/popup-create-person.component.ts +++ b/frontend/src/app/admin/userList/popup-create-person/popup-create-person.component.ts @@ -2,7 +2,6 @@ import {Component, Inject} from '@angular/core'; import {MAT_DIALOG_DATA, MatDialogRef} from "@angular/material/dialog"; import {CheckEmailService} from "../../../common/services/checkEmail/check-email.service"; import {HashageService} from "../../../common/services/hashage/hashage.service"; -import {Person} from "../../../common/interfaces/Person"; @@ -13,12 +12,12 @@ import {Person} from "../../../common/interfaces/Person"; }) export class PopupCreatePersonComponent { - person: Person = { + person = { id: "", - login: "", + nickname: "", email: "", - hashPass: "", - role: "user" + hash_pass: "", + is_admin: false, }; password: string = ""; confirmPassword: string = "" ; @@ -39,7 +38,7 @@ export class PopupCreatePersonComponent this.checkField(); if(!this.hasError) { - if(this.changePassword) this.person.hashPass = this.hashageService.run(this.password); + if(this.changePassword) this.person.hash_pass = this.hashageService.run(this.password); const data = { user: this.person }; // ... @@ -67,7 +66,7 @@ export class PopupCreatePersonComponent // Check les champs saisis par l'utilisateur checkField(): void { - if(this.person.login.length === 0) { + if(this.person.nickname.length === 0) { this.errorMessage = "Veuillez remplir le champ 'pseudo'."; this.hasError = true; } diff --git a/frontend/src/app/admin/userList/popup-delete-person/popup-delete-person.component.html b/frontend/src/app/admin/userList/popup-delete-person/popup-delete-person.component.html deleted file mode 100644 index a182917..0000000 --- a/frontend/src/app/admin/userList/popup-delete-person/popup-delete-person.component.html +++ /dev/null @@ -1,8 +0,0 @@ - - Êtes-vous sûr de vouloir supprimer {{data.person.login}} ? - - - - - - diff --git a/frontend/src/app/admin/userList/popup-delete-person/popup-delete-person.component.ts b/frontend/src/app/admin/userList/popup-delete-person/popup-delete-person.component.ts deleted file mode 100644 index 7c20091..0000000 --- a/frontend/src/app/admin/userList/popup-delete-person/popup-delete-person.component.ts +++ /dev/null @@ -1,17 +0,0 @@ -import {Component, Inject} from '@angular/core'; -import {MAT_DIALOG_DATA, MatDialogRef} from "@angular/material/dialog"; - - - -@Component({ - selector: 'app-popup-delete-person', - templateUrl: './popup-delete-person.component.html', - styleUrls: ['./popup-delete-person.component.scss'] -}) -export class PopupDeletePersonComponent -{ - - constructor( public dialogRef: MatDialogRef, - @Inject(MAT_DIALOG_DATA) public data: any ) { } - -} diff --git a/frontend/src/app/admin/userList/popup-update-person-admin/popup-update-person-admin.component.html b/frontend/src/app/admin/userList/popup-update-person-admin/popup-update-person-admin.component.html new file mode 100644 index 0000000..77f59bc --- /dev/null +++ b/frontend/src/app/admin/userList/popup-update-person-admin/popup-update-person-admin.component.html @@ -0,0 +1,68 @@ +
+
+ +

Modifier

+ + +

+ + + + Pseudo + +
+ + +
+ + + + Utilisateur   + Admin +

+ + +
+ + +
+ Modifier mot de passe: + +
+ + +
+ + + Nouveau mot de passe + + +
+ + + Confirmation nouveau mot de passe + + +
+

+ + +
+ + +
+ {{errorMessage}} +
+ + +
+ + +
+ +
+
diff --git a/frontend/src/app/common/components/profil/popup-update-profil/popup-update-profil.component.scss b/frontend/src/app/admin/userList/popup-update-person-admin/popup-update-person-admin.component.scss similarity index 100% rename from frontend/src/app/common/components/profil/popup-update-profil/popup-update-profil.component.scss rename to frontend/src/app/admin/userList/popup-update-person-admin/popup-update-person-admin.component.scss diff --git a/frontend/src/app/admin/userList/popup-update-person-admin/popup-update-person-admin.component.spec.ts b/frontend/src/app/admin/userList/popup-update-person-admin/popup-update-person-admin.component.spec.ts new file mode 100644 index 0000000..431857c --- /dev/null +++ b/frontend/src/app/admin/userList/popup-update-person-admin/popup-update-person-admin.component.spec.ts @@ -0,0 +1,25 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; + +import { PopupUpdatePersonAdminComponent } from './popup-update-person-admin.component'; + +describe('PopupUpdatePersonAdminComponent', () => { + let component: PopupUpdatePersonAdminComponent; + let fixture: ComponentFixture; + + beforeEach(async () => { + await TestBed.configureTestingModule({ + declarations: [ PopupUpdatePersonAdminComponent ] + }) + .compileComponents(); + }); + + beforeEach(() => { + fixture = TestBed.createComponent(PopupUpdatePersonAdminComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/frontend/src/app/admin/userList/popup-update-person-admin/popup-update-person-admin.component.ts b/frontend/src/app/admin/userList/popup-update-person-admin/popup-update-person-admin.component.ts new file mode 100644 index 0000000..22e2eef --- /dev/null +++ b/frontend/src/app/admin/userList/popup-update-person-admin/popup-update-person-admin.component.ts @@ -0,0 +1,116 @@ +import {Component, Inject, OnInit} from '@angular/core'; +import {MAT_DIALOG_DATA, MatDialogRef} from "@angular/material/dialog"; +import {CheckEmailService} from "../../../common/services/checkEmail/check-email.service"; +import {HashageService} from "../../../common/services/hashage/hashage.service"; + + + +@Component({ + selector: 'app-popup-update-person-admin', + templateUrl: './popup-update-person-admin.component.html', + styleUrls: ['./popup-update-person-admin.component.scss'] +}) +export class PopupUpdatePersonAdminComponent implements OnInit +{ + personCopy: any = { + id: "", + nickname: "", + email: "", + hash_pass: "", + is_admin: true, + role: "utilisateur" + }; + newPassword: string = ""; + confirmNewPassword: string = "" ; + changePassword: boolean = false ; + hasError: boolean = false; + errorMessage: string = "" ; + + + constructor( public dialogRef: MatDialogRef, + @Inject(MAT_DIALOG_DATA) public data: any, + private checkEmailService: CheckEmailService, + private hashageService: HashageService ) { } + + + ngOnInit(): void + { + const person = this.data.person; + this.personCopy = { + id: person.id, + nickname: person.nickname, + email: person.email, + hash_pass: person.hash_pass, + is_admin: person.is_admin, + role: person.role, + }; + console.log("ngOnInit") + console.log(this.personCopy); + } + + + // Appuie sur le bouton "valider" + onValider(): void + { + console.log("onValider") + console.log(this.personCopy); + + this.checkField(); + if(!this.hasError) + { + if(this.changePassword) this.personCopy.hash_pass = this.hashageService.run(this.newPassword); + const data = { user: this.personCopy }; + + // ... + + // Faux code + this.onValiderCallback({ status: "success"}); + } + } + + + // Callback de 'onValider' + onValiderCallback(retour: any) + { + if(retour.status === 'error') + { + console.log(retour); + this.dialogRef.close(null); + } + else + { + this.dialogRef.close(this.personCopy); + } + } + + + // Check les champs saisis par l'utilisateur + checkField(): void + { + if(this.personCopy.nickname.length === 0) { + this.errorMessage = "Veuillez remplir le champ 'pseudo'" ; + this.hasError = true; + } + else if(this.personCopy.email.length === 0) { + this.errorMessage = "Veuillez remplir le champ 'email'" ; + this.hasError = true; + } + else if(!this.checkEmailService.isValidEmail(this.personCopy.email)) { + this.errorMessage = "Email invalide" ; + this.hasError = true; + } + else if((this.changePassword) && (this.newPassword.length === 0)) { + this.errorMessage = "Veuillez remplir le champ 'mot de passe'"; + this.hasError = true; + } + else if((this.changePassword) && (this.newPassword !== this.confirmNewPassword)) { + this.errorMessage = "Le mot de passe est différent de sa confirmation"; + this.hasError = true; + } + else { + this.errorMessage = "" ; + this.hasError = false; + } + } + +} diff --git a/frontend/src/app/app-routing.module.ts b/frontend/src/app/app-routing.module.ts index e6af829..5373cfb 100644 --- a/frontend/src/app/app-routing.module.ts +++ b/frontend/src/app/app-routing.module.ts @@ -2,8 +2,9 @@ import { NgModule } from '@angular/core'; import { RouterModule, Routes } from '@angular/router'; import {PageLoginComponent} from "./login/page-login/page-login.component"; import {PageRegisterComponent} from "./register/page-register/page-register.component"; -import {PageProfilComponent} from "./common/components/profil/page-profil/page-profil.component"; +import {PageProfilComponent} from "./common/components/page-profil/page-profil.component"; import {PageUserListComponent} from "./admin/userList/page-user-list/page-user-list.component"; +import {PageRegistryComponent} from "./user/page-registry/page-registry.component"; const routes: Routes = [ @@ -12,7 +13,9 @@ const routes: Routes = [ { path: "register", component: PageRegisterComponent }, - { path: "user", component: PageProfilComponent }, + { path: "user", component: PageRegistryComponent }, + { path: "user/registry", component: PageRegistryComponent }, + { path: "user/myProfil", component: PageProfilComponent }, { path: "admin", component: PageUserListComponent }, { path: "admin/userList", component: PageUserListComponent }, diff --git a/frontend/src/app/app.module.ts b/frontend/src/app/app.module.ts index 835ee6a..c87f35c 100644 --- a/frontend/src/app/app.module.ts +++ b/frontend/src/app/app.module.ts @@ -11,8 +11,8 @@ import {MatInputModule} from "@angular/material/input"; import {PageLoginComponent} from "./login/page-login/page-login.component"; import { NavbarComponent } from './common/components/navbar/navbar.component'; import {MatButtonModule} from "@angular/material/button"; -import { PageProfilComponent } from './common/components/profil/page-profil/page-profil.component'; -import { PopupUpdateProfilComponent } from './common/components/profil/popup-update-profil/popup-update-profil.component'; +import { PageProfilComponent } from './common/components/page-profil/page-profil.component'; +import { PopupUpdateProfilComponent } from './common/components/popup-update-profil/popup-update-profil.component'; import {MatDividerModule} from "@angular/material/divider"; import {MatCheckboxModule} from "@angular/material/checkbox"; import {MatDialogModule} from "@angular/material/dialog"; @@ -22,9 +22,12 @@ import { PopupCreatePersonComponent } from './admin/userList/popup-create-person import {MatTableModule} from "@angular/material/table"; import {MatPaginatorModule} from "@angular/material/paginator"; import { PopupConfirmRegisterComponent } from './register/popup-confirm-register/popup-confirm-register.component'; -import { PopupDeletePersonComponent } from './admin/userList/popup-delete-person/popup-delete-person.component'; import {MatIconModule} from "@angular/material/icon"; import {MatRadioModule} from "@angular/material/radio"; +import { PageRegistryComponent } from './user/page-registry/page-registry.component'; +import { PopupDeleteProfilComponent } from './common/components/popup-delete-profil/popup-delete-profil.component'; +import {MatSortModule} from "@angular/material/sort"; +import { PopupUpdatePersonAdminComponent } from './admin/userList/popup-update-person-admin/popup-update-person-admin.component'; @@ -39,7 +42,9 @@ import {MatRadioModule} from "@angular/material/radio"; PageUserListComponent, PopupCreatePersonComponent, PopupConfirmRegisterComponent, - PopupDeletePersonComponent + PageRegistryComponent, + PopupDeleteProfilComponent, + PopupUpdatePersonAdminComponent ], imports: [ BrowserModule, @@ -55,6 +60,7 @@ import {MatRadioModule} from "@angular/material/radio"; MatSnackBarModule, MatTableModule, MatPaginatorModule, + MatSortModule, MatIconModule, MatRadioModule ], diff --git a/frontend/src/app/common/components/navbar/navbar.component.html b/frontend/src/app/common/components/navbar/navbar.component.html index c8b6f59..4c06dd1 100644 --- a/frontend/src/app/common/components/navbar/navbar.component.html +++ b/frontend/src/app/common/components/navbar/navbar.component.html @@ -1,5 +1,5 @@ -
+
+
+ +
+
+ +
+
+ + + + + + diff --git a/frontend/src/app/common/components/profil/page-profil/page-profil.component.scss b/frontend/src/app/common/components/page-profil/page-profil.component.scss similarity index 100% rename from frontend/src/app/common/components/profil/page-profil/page-profil.component.scss rename to frontend/src/app/common/components/page-profil/page-profil.component.scss diff --git a/frontend/src/app/common/components/profil/page-profil/page-profil.component.spec.ts b/frontend/src/app/common/components/page-profil/page-profil.component.spec.ts similarity index 100% rename from frontend/src/app/common/components/profil/page-profil/page-profil.component.spec.ts rename to frontend/src/app/common/components/page-profil/page-profil.component.spec.ts diff --git a/frontend/src/app/common/components/profil/page-profil/page-profil.component.ts b/frontend/src/app/common/components/page-profil/page-profil.component.ts similarity index 63% rename from frontend/src/app/common/components/profil/page-profil/page-profil.component.ts rename to frontend/src/app/common/components/page-profil/page-profil.component.ts index b4dce60..90f67bd 100644 --- a/frontend/src/app/common/components/profil/page-profil/page-profil.component.ts +++ b/frontend/src/app/common/components/page-profil/page-profil.component.ts @@ -1,10 +1,10 @@ import { Component, OnInit } from '@angular/core'; -import {Person} from "../../../interfaces/Person"; import {MatDialog} from "@angular/material/dialog"; import {MatSnackBar} from "@angular/material/snack-bar"; import {PopupUpdateProfilComponent} from "../popup-update-profil/popup-update-profil.component"; -import {FictitiousDatasService} from "../../../services/fictitiousDatas/fictitious-datas.service"; +import {FictitiousDatasService} from "../../services/fictitiousDatas/fictitious-datas.service"; import {Router} from "@angular/router"; +import {PopupDeleteProfilComponent} from "../popup-delete-profil/popup-delete-profil.component"; @@ -15,12 +15,12 @@ import {Router} from "@angular/router"; }) export class PageProfilComponent implements OnInit { - person: Person = { + person = { id: "", - login: "", + nickname: "", email: "", - hashPass: "", - role: "user", + hash_pass: "", + is_admin: false, }; from: string = "" ; @@ -75,4 +75,36 @@ export class PageProfilComponent implements OnInit } } + + // Appuie sur le bouton supprimer + onSupprimer(): void + { + const config = { + data: { + id: this.person.id, + email: this.person.email, + me: true, + } + }; + this.dialog + .open(PopupDeleteProfilComponent, config) + .afterClosed() + .subscribe(retour => this.onSupprimerCallback(retour)); + } + + + // Callback de onSupprimer + onSupprimerCallback(retour: any): void + { + if((retour === null) || (retour === undefined)) + { + const config = { duration: 1000, panelClass: "custom-class" }; + this.snackBar.open( "Opération annulé", "", config); + } + else + { + this.router.navigateByUrl("/login"); + } + } + } diff --git a/frontend/src/app/common/components/popup-delete-profil/popup-delete-profil.component.html b/frontend/src/app/common/components/popup-delete-profil/popup-delete-profil.component.html new file mode 100644 index 0000000..9118e3b --- /dev/null +++ b/frontend/src/app/common/components/popup-delete-profil/popup-delete-profil.component.html @@ -0,0 +1,14 @@ + + Êtes-vous sûr de vouloir supprimer votre compte ? + + + + + Êtes-vous sûr de vouloir supprimer {{email}} ? + + + + + + + diff --git a/frontend/src/app/admin/userList/popup-delete-person/popup-delete-person.component.scss b/frontend/src/app/common/components/popup-delete-profil/popup-delete-profil.component.scss similarity index 100% rename from frontend/src/app/admin/userList/popup-delete-person/popup-delete-person.component.scss rename to frontend/src/app/common/components/popup-delete-profil/popup-delete-profil.component.scss diff --git a/frontend/src/app/admin/userList/popup-delete-person/popup-delete-person.component.spec.ts b/frontend/src/app/common/components/popup-delete-profil/popup-delete-profil.component.spec.ts similarity index 50% rename from frontend/src/app/admin/userList/popup-delete-person/popup-delete-person.component.spec.ts rename to frontend/src/app/common/components/popup-delete-profil/popup-delete-profil.component.spec.ts index f45d4a1..8743fad 100644 --- a/frontend/src/app/admin/userList/popup-delete-person/popup-delete-person.component.spec.ts +++ b/frontend/src/app/common/components/popup-delete-profil/popup-delete-profil.component.spec.ts @@ -1,20 +1,20 @@ import { ComponentFixture, TestBed } from '@angular/core/testing'; -import { PopupDeletePersonComponent } from './popup-delete-person.component'; +import { PopupDeleteProfilComponent } from './popup-delete-profil.component'; -describe('PopupDeletePersonComponent', () => { - let component: PopupDeletePersonComponent; - let fixture: ComponentFixture; +describe('PopupDeleteProfilComponent', () => { + let component: PopupDeleteProfilComponent; + let fixture: ComponentFixture; beforeEach(async () => { await TestBed.configureTestingModule({ - declarations: [ PopupDeletePersonComponent ] + declarations: [ PopupDeleteProfilComponent ] }) .compileComponents(); }); beforeEach(() => { - fixture = TestBed.createComponent(PopupDeletePersonComponent); + fixture = TestBed.createComponent(PopupDeleteProfilComponent); component = fixture.componentInstance; fixture.detectChanges(); }); diff --git a/frontend/src/app/common/components/popup-delete-profil/popup-delete-profil.component.ts b/frontend/src/app/common/components/popup-delete-profil/popup-delete-profil.component.ts new file mode 100644 index 0000000..e5efad8 --- /dev/null +++ b/frontend/src/app/common/components/popup-delete-profil/popup-delete-profil.component.ts @@ -0,0 +1,28 @@ +import {Component, Inject, OnInit} from '@angular/core'; +import {MAT_DIALOG_DATA, MatDialogRef} from "@angular/material/dialog"; + + + +@Component({ + selector: 'app-popup-delete-profil', + templateUrl: './popup-delete-profil.component.html', + styleUrls: ['./popup-delete-profil.component.scss'] +}) +export class PopupDeleteProfilComponent implements OnInit +{ + me: boolean = false; // on se supprime soi-même + email: string = ""; + + constructor( public dialogRef: MatDialogRef, + @Inject(MAT_DIALOG_DATA) public data: any ) { } + + ngOnInit(): void { + this.me = this.data.me; + this.email = this.data.email; + } + + onValider(): void { + this.dialogRef.close(true); + } + +} diff --git a/frontend/src/app/common/components/profil/popup-update-profil/popup-update-profil.component.html b/frontend/src/app/common/components/popup-update-profil/popup-update-profil.component.html similarity index 97% rename from frontend/src/app/common/components/profil/popup-update-profil/popup-update-profil.component.html rename to frontend/src/app/common/components/popup-update-profil/popup-update-profil.component.html index 036c8b7..c28fe07 100644 --- a/frontend/src/app/common/components/profil/popup-update-profil/popup-update-profil.component.html +++ b/frontend/src/app/common/components/popup-update-profil/popup-update-profil.component.html @@ -6,10 +6,10 @@

- + Pseudo - +
diff --git a/frontend/src/app/common/components/popup-update-profil/popup-update-profil.component.scss b/frontend/src/app/common/components/popup-update-profil/popup-update-profil.component.scss new file mode 100644 index 0000000..1317c7a --- /dev/null +++ b/frontend/src/app/common/components/popup-update-profil/popup-update-profil.component.scss @@ -0,0 +1,37 @@ +.boite { + font-size: small; +} + +h3 { + text-align: center; +} + +button { + font-size: small; +} + +img { + margin: 0px 0px 10px 0px; + width: 5vw; + height: 5vw; + border: solid 2px black; + border-radius: 50%; + font-size: xxx-large; +} + +// ------------------------------------------------------------------------- + +// aura +::ng-deep .mat-checkbox-ripple .mat-ripple-element { + background-color: grey !important; +} + +// contenu coche +::ng-deep .mat-checkbox-checked.mat-accent .mat-checkbox-background { + background-color: black !important; +} + +// indeterminate +::ng-deep .mat-checkbox .mat-checkbox-frame { + background-color: white !important; +} diff --git a/frontend/src/app/common/components/profil/popup-update-profil/popup-update-profil.component.spec.ts b/frontend/src/app/common/components/popup-update-profil/popup-update-profil.component.spec.ts similarity index 100% rename from frontend/src/app/common/components/profil/popup-update-profil/popup-update-profil.component.spec.ts rename to frontend/src/app/common/components/popup-update-profil/popup-update-profil.component.spec.ts diff --git a/frontend/src/app/common/components/profil/popup-update-profil/popup-update-profil.component.ts b/frontend/src/app/common/components/popup-update-profil/popup-update-profil.component.ts similarity index 84% rename from frontend/src/app/common/components/profil/popup-update-profil/popup-update-profil.component.ts rename to frontend/src/app/common/components/popup-update-profil/popup-update-profil.component.ts index f792fec..9753ac7 100644 --- a/frontend/src/app/common/components/profil/popup-update-profil/popup-update-profil.component.ts +++ b/frontend/src/app/common/components/popup-update-profil/popup-update-profil.component.ts @@ -1,8 +1,7 @@ import {Component, Inject, OnInit} from '@angular/core'; import {MAT_DIALOG_DATA, MatDialogRef} from "@angular/material/dialog"; -import {Person} from "../../../interfaces/Person"; -import {CheckEmailService} from "../../../services/checkEmail/check-email.service"; -import {HashageService} from "../../../services/hashage/hashage.service"; +import {CheckEmailService} from "../../services/checkEmail/check-email.service"; +import {HashageService} from "../../services/hashage/hashage.service"; @@ -13,7 +12,7 @@ import {HashageService} from "../../../services/hashage/hashage.service"; }) export class PopupUpdateProfilComponent implements OnInit { - personCopy: Person; + personCopy: any; newPassword: string = ""; confirmNewPassword: string = "" ; changePassword: boolean = false ; @@ -32,10 +31,10 @@ export class PopupUpdateProfilComponent implements OnInit const person = this.data.person; this.personCopy = { id: person.id, - login: person.login, + nickname: person.nickname, email: person.email, - hashPass: person.hashPass, - role: person.role + hash_pass: person.hash_pass, + is_admin: person.is_admin }; } @@ -46,7 +45,7 @@ export class PopupUpdateProfilComponent implements OnInit this.checkField(); if(!this.hasError) { - if(this.changePassword) this.personCopy.hashPass = this.hashageService.run(this.newPassword); + if(this.changePassword) this.personCopy.hash_pass = this.hashageService.run(this.newPassword); const data = { user: this.personCopy }; // ... @@ -75,7 +74,7 @@ export class PopupUpdateProfilComponent implements OnInit // Check les champs saisis par l'utilisateur checkField(): void { - if(this.personCopy.login.length === 0) { + if(this.personCopy.nickname.length === 0) { this.errorMessage = "Veuillez remplir le champ 'pseudo'" ; this.hasError = true; } diff --git a/frontend/src/app/common/components/profil/page-profil/page-profil.component.html b/frontend/src/app/common/components/profil/page-profil/page-profil.component.html deleted file mode 100644 index 6767c47..0000000 --- a/frontend/src/app/common/components/profil/page-profil/page-profil.component.html +++ /dev/null @@ -1,38 +0,0 @@ -
- - - - - - -
- - -
-
Pseudo:
-
{{person.login}}
-
- - -
-
Mail:
-
{{person.email}}
-
- - -
-
Rôle:
-
- utilisateur - admin -
- - -
- -
- -
- - -
diff --git a/frontend/src/app/common/interfaces/Person.ts b/frontend/src/app/common/interfaces/Person.ts deleted file mode 100644 index ab25968..0000000 --- a/frontend/src/app/common/interfaces/Person.ts +++ /dev/null @@ -1,9 +0,0 @@ -// user or admin -export interface Person -{ - id: string, - login: string, - email: string, - hashPass: string, - role: string, -} diff --git a/frontend/src/app/common/services/fictitiousDatas/fictitious-datas.service.ts b/frontend/src/app/common/services/fictitiousDatas/fictitious-datas.service.ts index 4cb751e..e4eb760 100644 --- a/frontend/src/app/common/services/fictitiousDatas/fictitious-datas.service.ts +++ b/frontend/src/app/common/services/fictitiousDatas/fictitious-datas.service.ts @@ -1,5 +1,5 @@ import { Injectable } from '@angular/core'; -import {Person} from "../../interfaces/Person"; + @Injectable({ providedIn: 'root' @@ -7,33 +7,33 @@ import {Person} from "../../interfaces/Person"; export class FictitiousDatasService { - getUser(): Person + getUser() { const id = (Math.floor(Math.random()*100000)).toString() return { id: id, - login: "Riri"+id, + nickname: "Riri"+id, email: "riri"+id+"@gmail.com", - hashPass: "blablabla", - role: "user", + hash_pass: "blablabla", + is_admin: false, } } - getAdmin(): Person + getAdmin() { const id = (Math.floor(Math.random()*100000)).toString() return { id: id, - login: "Fifi"+id, + nickname: "Fifi"+id, email: "fifi"+id+"@gmail.com", - hashPass: "blablabla", - role: "admin", + hash_pass: "blablabla", + is_admin: true, } } - getTabPerson(n: number): Person[] + getTabPerson(n: number) { - let tab: Person[] = []; + let tab = []; for(let i=0 ; i { + let service: ProfilService; + + beforeEach(() => { + TestBed.configureTestingModule({}); + service = TestBed.inject(ProfilService); + }); + + it('should be created', () => { + expect(service).toBeTruthy(); + }); +}); diff --git a/frontend/src/app/common/services/profil/profil.service.ts b/frontend/src/app/common/services/profil/profil.service.ts new file mode 100644 index 0000000..213c1f3 --- /dev/null +++ b/frontend/src/app/common/services/profil/profil.service.ts @@ -0,0 +1,9 @@ +import { Injectable } from '@angular/core'; + +@Injectable({ + providedIn: 'root' +}) +export class ProfilService { + + constructor() { } +} diff --git a/frontend/src/app/login/page-login/page-login.component.html b/frontend/src/app/login/page-login/page-login.component.html index 8510729..493e7b7 100644 --- a/frontend/src/app/login/page-login/page-login.component.html +++ b/frontend/src/app/login/page-login/page-login.component.html @@ -3,7 +3,7 @@ - + diff --git a/frontend/src/app/login/page-login/page-login.component.ts b/frontend/src/app/login/page-login/page-login.component.ts index 8caff6f..0076521 100644 --- a/frontend/src/app/login/page-login/page-login.component.ts +++ b/frontend/src/app/login/page-login/page-login.component.ts @@ -6,7 +6,7 @@ import {HashageService} from "../../common/services/hashage/hashage.service"; @Component({ - selector: 'app-page-login', + selector: 'app-page-nickname', templateUrl: './page-login.component.html', styleUrls: ['./page-login.component.scss'] }) @@ -31,7 +31,7 @@ export class PageLoginComponent { let data = { email: this.email, - hashPass: this.hashageService.run(this.password) + hash_pass: this.hashageService.run(this.password) }; console.log(data); /* diff --git a/frontend/src/app/register/page-register/page-register.component.html b/frontend/src/app/register/page-register/page-register.component.html index 0f08b14..b2ca879 100644 --- a/frontend/src/app/register/page-register/page-register.component.html +++ b/frontend/src/app/register/page-register/page-register.component.html @@ -8,10 +8,10 @@
- + Pseudo - +
diff --git a/frontend/src/app/register/page-register/page-register.component.ts b/frontend/src/app/register/page-register/page-register.component.ts index 22b376e..d3ccf85 100644 --- a/frontend/src/app/register/page-register/page-register.component.ts +++ b/frontend/src/app/register/page-register/page-register.component.ts @@ -1,5 +1,4 @@ import { Component } from '@angular/core'; -import {Person} from "../../common/interfaces/Person"; import {HashageService} from "../../common/services/hashage/hashage.service"; import {Router} from "@angular/router"; import {CheckEmailService} from "../../common/services/checkEmail/check-email.service"; @@ -15,11 +14,11 @@ import {PopupConfirmRegisterComponent} from "../popup-confirm-register/popup-con }) export class PageRegisterComponent { - person: Person = { + person = { id: "", - login: "", + nickname: "", email: "", - hashPass: "", + hash_pass: "", role: "user" }; password: string = ""; @@ -40,7 +39,7 @@ export class PageRegisterComponent this.checkField(); if(!this.hasError) { - this.person.hashPass = this.hashageService.run(this.password); + this.person.hash_pass = this.hashageService.run(this.password); // FAUX CODE const retour = { status: "succes", data: {} }; @@ -76,7 +75,7 @@ export class PageRegisterComponent // Check les champs saisis par l'utilisateur checkField(): void { - if(this.person.login.length === 0) { + if(this.person.nickname.length === 0) { this.errorMessage = "Veuillez remplir le champ 'pseudo'."; this.hasError = true; } diff --git a/frontend/src/app/user/commentary.txt b/frontend/src/app/user/myProfil/commentary.txt similarity index 65% rename from frontend/src/app/user/commentary.txt rename to frontend/src/app/user/myProfil/commentary.txt index f1df163..902847e 100644 --- a/frontend/src/app/user/commentary.txt +++ b/frontend/src/app/user/myProfil/commentary.txt @@ -1,7 +1,7 @@ -La partie utilisateur est composé uniquement d'une page contenant: +La page "admin/myProfil" contient: - les informations de l'utilisateur (composant "page-profil") - un bouton "modifier profil" pour modifier les informations de l'utilisateur (composant "popup-update-profil") -Cette page est la même que la page "Mon Profil" de la partie admin. +Cette page est la même que la page de la partie admin. Ainsi, on a rangé cette page dans le dossier "common/components/profil". diff --git a/frontend/src/app/user/page-registry/page-registry.component.html b/frontend/src/app/user/page-registry/page-registry.component.html new file mode 100644 index 0000000..6c7f471 --- /dev/null +++ b/frontend/src/app/user/page-registry/page-registry.component.html @@ -0,0 +1,45 @@ +
+ +

+ + +
+ + Filter + + +
+ + + + + + + + + + + + + + + + + + + + + + + + +
Pseudo{{person.nickname}}Email{{person.email}}Rôle{{person.role}}
+ + + + +
+

diff --git a/frontend/src/app/user/page-registry/page-registry.component.scss b/frontend/src/app/user/page-registry/page-registry.component.scss new file mode 100644 index 0000000..7440dcb --- /dev/null +++ b/frontend/src/app/user/page-registry/page-registry.component.scss @@ -0,0 +1,9 @@ +mat-paginator, table { + width: 80%; + margin: auto 10%; +} + +.filtre { + text-align: center; + width: 33%; +} diff --git a/frontend/src/app/user/page-registry/page-registry.component.spec.ts b/frontend/src/app/user/page-registry/page-registry.component.spec.ts new file mode 100644 index 0000000..1851010 --- /dev/null +++ b/frontend/src/app/user/page-registry/page-registry.component.spec.ts @@ -0,0 +1,25 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; + +import { PageRegistryComponent } from './page-registry.component'; + +describe('RegistryComponent', () => { + let component: PageRegistryComponent; + let fixture: ComponentFixture; + + beforeEach(async () => { + await TestBed.configureTestingModule({ + declarations: [ PageRegistryComponent ] + }) + .compileComponents(); + }); + + beforeEach(() => { + fixture = TestBed.createComponent(PageRegistryComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/frontend/src/app/user/page-registry/page-registry.component.ts b/frontend/src/app/user/page-registry/page-registry.component.ts new file mode 100644 index 0000000..6d0e1b9 --- /dev/null +++ b/frontend/src/app/user/page-registry/page-registry.component.ts @@ -0,0 +1,50 @@ +import {AfterViewInit, Component, ViewChild} from '@angular/core'; +import {MatTableDataSource} from "@angular/material/table"; +import {MatSort} from "@angular/material/sort"; +import {MatPaginator} from "@angular/material/paginator"; +import {FictitiousDatasService} from "../../common/services/fictitiousDatas/fictitious-datas.service"; +import {MatDialog} from "@angular/material/dialog"; + + + +@Component({ + selector: 'app-page-registry', + templateUrl: './page-registry.component.html', + styleUrls: ['./page-registry.component.scss'] +}) +export class PageRegistryComponent implements AfterViewInit +{ + displayedColumns: string[] = [ "nickname", "email", "role" ]; + dataSource: MatTableDataSource; + @ViewChild(MatSort) sort: MatSort; + @ViewChild(MatPaginator) paginator: MatPaginator; + + + constructor( private fictitiousDatasService: FictitiousDatasService, + public dialog: MatDialog ) { } + + + ngAfterViewInit(): void + { + // Faux code + let tabPerson = this.fictitiousDatasService.getTabPerson(5); + + // Vrai code ... + + tabPerson = tabPerson.map( person => { + if(!person.is_admin) return Object.assign(person, {role: "utilisateur"}); + else return Object.assign(person, {role: "admin"}); + }); + this.dataSource = new MatTableDataSource(tabPerson); + this.dataSource.sort = this.sort; + this.dataSource.paginator = this.paginator; + } + + + applyFilter(event: Event) + { + const filterValue = (event.target as HTMLInputElement).value; + this.dataSource.filter = filterValue.trim().toLowerCase(); + } + +}