From cf3c596c7b257bffc6c4264f2cb9b4c2aa69283a Mon Sep 17 00:00:00 2001 From: MiharyR Date: Sat, 11 Dec 2021 14:17:10 +0100 Subject: [PATCH 1/3] =?UTF-8?q?partie=20'beforeConnexion'=20entierement=20?= =?UTF-8?q?connect=C3=A9e=20avec=20le=20back?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../input-interests-register.component.ts | 22 ++++++++++++++----- .../page-register.component.html | 4 ++-- .../page-register/page-register.component.ts | 14 +++++++----- src/app/utils/interfaces/user.ts | 14 +++++++++++- 4 files changed, 39 insertions(+), 15 deletions(-) diff --git a/src/app/beforeConnexion/register/input-interests-register/input-interests-register.component.ts b/src/app/beforeConnexion/register/input-interests-register/input-interests-register.component.ts index baf610c..131c2f9 100644 --- a/src/app/beforeConnexion/register/input-interests-register/input-interests-register.component.ts +++ b/src/app/beforeConnexion/register/input-interests-register/input-interests-register.component.ts @@ -6,7 +6,8 @@ import {MessageService} from "../../../utils/services/message/message.service"; import {map, startWith} from "rxjs/operators"; import {MatChipInputEvent} from "@angular/material/chips"; import {MatAutocompleteSelectedEvent} from "@angular/material/autocomplete"; -import {FictitiousUtilsService} from "../../../utils/services/fictitiousDatas/fictitiousUtils/fictitious-utils.service"; + + @Component({ selector: 'app-input-interests-register', @@ -26,8 +27,7 @@ export class InputInterestsRegisterComponent implements OnInit @ViewChild('tagInput') tagInput: ElementRef; - constructor( private fictitiousUtilsService: FictitiousUtilsService, - private messageService: MessageService ) {} + constructor( private messageService: MessageService ) {} ngOnInit(): void @@ -36,9 +36,19 @@ export class InputInterestsRegisterComponent implements OnInit startWith(null), map((fruit: string | null) => fruit ? this._filter(fruit) : this.allInterests.slice())); - // --- FAUX CODE --- - this.allInterests = this.fictitiousUtilsService.getTags(); - this.allInterests.sort(); + this.messageService + .get("misc/getInterests", {}) + .subscribe( retour => { + + if(retour.status !== "success") { + console.log(retour); + } + else { + this.allInterests = []; + for(let elt of retour.data) this.allInterests.push(elt.interest); + this.allInterests.sort(); + } + }); } diff --git a/src/app/beforeConnexion/register/page-register/page-register.component.html b/src/app/beforeConnexion/register/page-register/page-register.component.html index dc6d23c..4d7b629 100644 --- a/src/app/beforeConnexion/register/page-register/page-register.component.html +++ b/src/app/beforeConnexion/register/page-register/page-register.component.html @@ -109,9 +109,9 @@ - + (eventEmitter)="onEventInputInterests($event)"> diff --git a/src/app/beforeConnexion/register/page-register/page-register.component.ts b/src/app/beforeConnexion/register/page-register/page-register.component.ts index 5eaf743..f24a4f7 100644 --- a/src/app/beforeConnexion/register/page-register/page-register.component.ts +++ b/src/app/beforeConnexion/register/page-register/page-register.component.ts @@ -53,21 +53,23 @@ export class PageRegisterComponent this.checkField(); if(!this.hasError) { - if(this.user.role.name === "user") this.user.role.permission = 0; - else this.user.role.permission = 5; - this.user.hashPass = this.password; + let data: any = Object.assign({}, this.user); + if(this.user.role.name === "user") data.role = "user" ; + else data.role = "advertiser"; + data.hashPass = this.password; this.messageService - .post('user/create', this.user) + .post('user/create', data) .subscribe(retour => this.onEnregistrerCallback(retour), err => this.onEnregistrerCallback(err)); } } - // Gestion de la réponde du backend + // Gestion de la réponse du backend onEnregistrerCallback(retour): void { + console.log(retour); if(retour.status !== "success") { - console.log(retour); + } else { diff --git a/src/app/utils/interfaces/user.ts b/src/app/utils/interfaces/user.ts index 9732a08..b8c2752 100644 --- a/src/app/utils/interfaces/user.ts +++ b/src/app/utils/interfaces/user.ts @@ -11,7 +11,7 @@ export interface User profileImageUrl: string, dateOfBirth: Date, gender: string, - interests: string[], + interests: any[], company: string, isActive: boolean, isAccepted: boolean, @@ -19,3 +19,15 @@ export interface User createdAt: Date, updatedAt: Date } + + +interface VideoCategorie +{ + id: number + interest: string + categories: { + id: string + name: string + source: string + } +} From 7f6d089f1d0b9e3a7ef7b86264683bb60bf0c1bf Mon Sep 17 00:00:00 2001 From: MiharyR Date: Sat, 11 Dec 2021 21:22:27 +0100 Subject: [PATCH 2/3] commencement de la connexion avec le back de 'user/myProfil' et de 'user/myPlaylists' --- .../navbar-admin/navbar-admin.component.ts | 2 +- .../navbar-advertiser.component.ts | 2 +- src/app/app.module.ts | 4 +- .../login/page-login/page-login.component.ts | 1 + .../input-interests-register.component.ts | 2 +- .../page-register/page-register.component.ts | 3 +- .../playlist-list.component.html | 6 +- .../playlist-list/playlist-list.component.ts | 71 ++++++++++++-- ...-create-or-update-playlist.component.html} | 5 +- ...-create-or-update-playlist.component.scss} | 0 ...eate-or-update-playlist.component.spec.ts} | 10 +- ...pup-create-or-update-playlist.component.ts | 92 ++++++++++++++++++ .../popup-create-playlist.component.ts | 95 ------------------- .../popup-delete-playlist.component.ts | 15 ++- .../input-interests-profil.component.ts | 20 ++-- .../page-profil-user.component.ts | 45 ++++++++- .../popup-update-user.component.ts | 44 +++++---- .../navbar-user/navbar-user.component.ts | 2 +- .../utils/services/message/message.service.ts | 8 +- .../utils/services/profil/profil.service.ts | 1 + 20 files changed, 279 insertions(+), 149 deletions(-) rename src/app/user/myPlaylists/{popup-create-playlist/popup-create-playlist.component.html => popup-create-or-update-playlist/popup-create-or-update-playlist.component.html} (74%) rename src/app/user/myPlaylists/{popup-create-playlist/popup-create-playlist.component.scss => popup-create-or-update-playlist/popup-create-or-update-playlist.component.scss} (100%) rename src/app/user/myPlaylists/{popup-create-playlist/popup-create-playlist.component.spec.ts => popup-create-or-update-playlist/popup-create-or-update-playlist.component.spec.ts} (52%) create mode 100644 src/app/user/myPlaylists/popup-create-or-update-playlist/popup-create-or-update-playlist.component.ts delete mode 100644 src/app/user/myPlaylists/popup-create-playlist/popup-create-playlist.component.ts diff --git a/src/app/admin/utils/navbar-admin/navbar-admin.component.ts b/src/app/admin/utils/navbar-admin/navbar-admin.component.ts index e23ae05..dd4f436 100644 --- a/src/app/admin/utils/navbar-admin/navbar-admin.component.ts +++ b/src/app/admin/utils/navbar-admin/navbar-admin.component.ts @@ -28,7 +28,7 @@ export class NavbarAdminComponent onDeconnexion(): void { this.messageService - .delete('user/logout', {}) + .delete('user/logout') .subscribe(retour => this.onDeconnexionCallback(retour), err => this.onDeconnexionCallback(err)); } diff --git a/src/app/advertiser/utils/navbar-advertiser/navbar-advertiser.component.ts b/src/app/advertiser/utils/navbar-advertiser/navbar-advertiser.component.ts index a0e5181..9bd8e1e 100644 --- a/src/app/advertiser/utils/navbar-advertiser/navbar-advertiser.component.ts +++ b/src/app/advertiser/utils/navbar-advertiser/navbar-advertiser.component.ts @@ -29,7 +29,7 @@ export class NavbarAdvertiserComponent onDeconnexion(): void { this.messageService - .delete('user/logout', {}) + .delete('user/logout') .subscribe(retour => this.onDeconnexionCallback(retour), err => this.onDeconnexionCallback(err)); } diff --git a/src/app/app.module.ts b/src/app/app.module.ts index dc121e6..133f928 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -26,7 +26,7 @@ import {MatGridListModule} from "@angular/material/grid-list"; import { PageMyPlaylistsComponent } from './user/myPlaylists/page-my-playlists/page-my-playlists.component'; import { PlaylistListComponent } from './user/myPlaylists/playlist-list/playlist-list.component'; import {VideoListComponent} from "./user/myPlaylists/video-list/video-list.component"; -import { PopupCreatePlaylistComponent } from './user/myPlaylists/popup-create-playlist/popup-create-playlist.component'; +import { PopupCreateOrUpdatePlaylistComponent } from './user/myPlaylists/popup-create-or-update-playlist/popup-create-or-update-playlist.component'; import { PageHistoryUserComponent } from './user/history/page-history-user/page-history-user.component'; import {MatTableModule} from '@angular/material/table'; import { NgbModule } from '@ng-bootstrap/ng-bootstrap'; @@ -87,7 +87,7 @@ import { PopupForgottenPasswordComponent } from './beforeConnexion/login/popup-f VideoListComponent, PlaylistListComponent, VideoListComponent, - PopupCreatePlaylistComponent, + PopupCreateOrUpdatePlaylistComponent, PageHistoryUserComponent, PageAdListAdvertiserComponent, PopupDeleteAdAdvertiserComponent, diff --git a/src/app/beforeConnexion/login/page-login/page-login.component.ts b/src/app/beforeConnexion/login/page-login/page-login.component.ts index d53bf46..ad2f03b 100644 --- a/src/app/beforeConnexion/login/page-login/page-login.component.ts +++ b/src/app/beforeConnexion/login/page-login/page-login.component.ts @@ -58,6 +58,7 @@ export class PageLoginComponent implements OnInit this.hasError = true; } else { + this.profilService.id = retour.data.id; this.profilService.profileImageUrl = retour.data.profileImageUrl; if(retour.data.role.name === "user") this.router.navigateByUrl( '/user/search'); else if(retour.data.role.name === "advertiser") this.router.navigateByUrl( '/advertiser/adList'); diff --git a/src/app/beforeConnexion/register/input-interests-register/input-interests-register.component.ts b/src/app/beforeConnexion/register/input-interests-register/input-interests-register.component.ts index 131c2f9..6f8301b 100644 --- a/src/app/beforeConnexion/register/input-interests-register/input-interests-register.component.ts +++ b/src/app/beforeConnexion/register/input-interests-register/input-interests-register.component.ts @@ -37,7 +37,7 @@ export class InputInterestsRegisterComponent implements OnInit map((fruit: string | null) => fruit ? this._filter(fruit) : this.allInterests.slice())); this.messageService - .get("misc/getInterests", {}) + .get("misc/getInterests") .subscribe( retour => { if(retour.status !== "success") { diff --git a/src/app/beforeConnexion/register/page-register/page-register.component.ts b/src/app/beforeConnexion/register/page-register/page-register.component.ts index f24a4f7..8632fe8 100644 --- a/src/app/beforeConnexion/register/page-register/page-register.component.ts +++ b/src/app/beforeConnexion/register/page-register/page-register.component.ts @@ -67,9 +67,8 @@ export class PageRegisterComponent // Gestion de la réponse du backend onEnregistrerCallback(retour): void { - console.log(retour); if(retour.status !== "success") { - + console.log(retour); } else { diff --git a/src/app/user/myPlaylists/playlist-list/playlist-list.component.html b/src/app/user/myPlaylists/playlist-list/playlist-list.component.html index a1c5285..4ab952a 100644 --- a/src/app/user/myPlaylists/playlist-list/playlist-list.component.html +++ b/src/app/user/myPlaylists/playlist-list/playlist-list.component.html @@ -16,7 +16,11 @@
-
+
+ +
{{playlist.name}}
{{playlist.videoIds.length}} vidéo diff --git a/src/app/user/myPlaylists/playlist-list/playlist-list.component.ts b/src/app/user/myPlaylists/playlist-list/playlist-list.component.ts index 1a95744..84a78f4 100644 --- a/src/app/user/myPlaylists/playlist-list/playlist-list.component.ts +++ b/src/app/user/myPlaylists/playlist-list/playlist-list.component.ts @@ -3,9 +3,10 @@ import {ThemeService} from "../../../utils/services/theme/theme.service"; import {PlaylistDB} from "../../../utils/interfaces/playlist"; import {MatDialog} from "@angular/material/dialog"; import {MatSnackBar} from "@angular/material/snack-bar"; -import {PopupCreatePlaylistComponent} from "../popup-create-playlist/popup-create-playlist.component"; +import {PopupCreateOrUpdatePlaylistComponent} from "../popup-create-or-update-playlist/popup-create-or-update-playlist.component"; import {FictitiousVideosService} from "../../../utils/services/fictitiousDatas/fictitiousVideos/fictitious-videos.service"; import {PopupDeletePlaylistComponent} from "../popup-delete-playlist/popup-delete-playlist.component"; +import {MessageService} from "../../../utils/services/message/message.service"; @@ -26,13 +27,30 @@ export class PlaylistListComponent implements OnInit constructor( public themeService: ThemeService, public dialog: MatDialog, public snackBar: MatSnackBar, - private fictitiousVideosService: FictitiousVideosService ) { } + private fictitiousVideosService: FictitiousVideosService, + private messageService: MessageService ) { } ngOnInit(): void { - this.allPlaylists = this.fictitiousVideosService.getNoRandomTabPlaylistDB(10); - this.tabPlaylist = [].concat(this.allPlaylists); + this.messageService + .get("playlist/findAll") + .subscribe( retour => this.ngOnInitCallback(retour), err => this.ngOnInitCallback(err) ); + } + + + ngOnInitCallback(retour: any): void + { + if(retour.status !== "success") { + console.log(retour); + } else { + const aux = retour.data.filter( x => x.isActive === true); + this.allPlaylists = aux.map(x => { + x["_id"] = x.id ; + return x; + }); + this.tabPlaylist = [].concat(this.allPlaylists); + } } @@ -50,9 +68,14 @@ export class PlaylistListComponent implements OnInit // click sur créer playlist onCreatePlaylist(): void { - const config = { data: this.tabPlaylist }; + const config = { + data: { + action: "create", + tabPlaylist: this.tabPlaylist, + } + }; this.dialog - .open(PopupCreatePlaylistComponent, config ) + .open(PopupCreateOrUpdatePlaylistComponent, config ) .afterClosed() .subscribe(playlist => { @@ -61,6 +84,7 @@ export class PlaylistListComponent implements OnInit this.snackBar.open("Opération annulée", "", config); } else { + playlist["_id"] = playlist.id; this.allPlaylists.push(playlist); this.tabPlaylist.push(playlist); this.snackBar.open(`La playlist '${playlist.name}' a bien été créée ✔`, "", config); @@ -69,6 +93,41 @@ export class PlaylistListComponent implements OnInit } + // click sur update playlist + onUpdatePlaylist(playlistToUpdate: PlaylistDB): void + { + console.log(playlistToUpdate); + + const config = { + data: { + action: "update", + tabPlaylist: this.tabPlaylist, + playlistName: playlistToUpdate.name, + playlistId: playlistToUpdate._id + } + }; + this.dialog + .open(PopupCreateOrUpdatePlaylistComponent, config) + .afterClosed() + .subscribe(newName => { + + console.log("nn:" + newName); + + const config = { duration: 1500, panelClass: "custom-class" }; + if((newName === null) || (newName === undefined)) { + this.snackBar.open("Opération annulée", "", config); + } + else { + let index = this.allPlaylists.findIndex( elt => (elt._id === playlistToUpdate._id)); + this.allPlaylists[index].name = newName; + index = this.tabPlaylist.findIndex( elt => (elt._id === playlistToUpdate._id)); + this.tabPlaylist[index].name = newName; + this.snackBar.open(`La playlist '${playlistToUpdate.name}' a bien été mise à jour ✔`, "", config); + } + }); + } + + // click sur supprimer playlist onDeletePlaylist(playlist: PlaylistDB): void { diff --git a/src/app/user/myPlaylists/popup-create-playlist/popup-create-playlist.component.html b/src/app/user/myPlaylists/popup-create-or-update-playlist/popup-create-or-update-playlist.component.html similarity index 74% rename from src/app/user/myPlaylists/popup-create-playlist/popup-create-playlist.component.html rename to src/app/user/myPlaylists/popup-create-or-update-playlist/popup-create-or-update-playlist.component.html index 49ebbf3..c366837 100644 --- a/src/app/user/myPlaylists/popup-create-playlist/popup-create-playlist.component.html +++ b/src/app/user/myPlaylists/popup-create-or-update-playlist/popup-create-or-update-playlist.component.html @@ -10,7 +10,10 @@
- +
diff --git a/src/app/user/myPlaylists/popup-create-playlist/popup-create-playlist.component.scss b/src/app/user/myPlaylists/popup-create-or-update-playlist/popup-create-or-update-playlist.component.scss similarity index 100% rename from src/app/user/myPlaylists/popup-create-playlist/popup-create-playlist.component.scss rename to src/app/user/myPlaylists/popup-create-or-update-playlist/popup-create-or-update-playlist.component.scss diff --git a/src/app/user/myPlaylists/popup-create-playlist/popup-create-playlist.component.spec.ts b/src/app/user/myPlaylists/popup-create-or-update-playlist/popup-create-or-update-playlist.component.spec.ts similarity index 52% rename from src/app/user/myPlaylists/popup-create-playlist/popup-create-playlist.component.spec.ts rename to src/app/user/myPlaylists/popup-create-or-update-playlist/popup-create-or-update-playlist.component.spec.ts index a4853cb..640bdbc 100644 --- a/src/app/user/myPlaylists/popup-create-playlist/popup-create-playlist.component.spec.ts +++ b/src/app/user/myPlaylists/popup-create-or-update-playlist/popup-create-or-update-playlist.component.spec.ts @@ -1,20 +1,20 @@ import { ComponentFixture, TestBed } from '@angular/core/testing'; -import { PopupCreatePlaylistComponent } from './popup-create-playlist.component'; +import { PopupCreateOrUpdatePlaylistComponent } from './popup-create-or-update-playlist.component'; describe('PopupCreatePlaylistComponent', () => { - let component: PopupCreatePlaylistComponent; - let fixture: ComponentFixture; + let component: PopupCreateOrUpdatePlaylistComponent; + let fixture: ComponentFixture; beforeEach(async () => { await TestBed.configureTestingModule({ - declarations: [ PopupCreatePlaylistComponent ] + declarations: [ PopupCreateOrUpdatePlaylistComponent ] }) .compileComponents(); }); beforeEach(() => { - fixture = TestBed.createComponent(PopupCreatePlaylistComponent); + fixture = TestBed.createComponent(PopupCreateOrUpdatePlaylistComponent); component = fixture.componentInstance; fixture.detectChanges(); }); diff --git a/src/app/user/myPlaylists/popup-create-or-update-playlist/popup-create-or-update-playlist.component.ts b/src/app/user/myPlaylists/popup-create-or-update-playlist/popup-create-or-update-playlist.component.ts new file mode 100644 index 0000000..a6ce4b6 --- /dev/null +++ b/src/app/user/myPlaylists/popup-create-or-update-playlist/popup-create-or-update-playlist.component.ts @@ -0,0 +1,92 @@ +import {Component, Inject, OnInit} from '@angular/core'; +import {MAT_DIALOG_DATA, MatDialogRef} from "@angular/material/dialog"; +import {MessageService} from "../../../utils/services/message/message.service"; +import {PlaylistDB} from "../../../utils/interfaces/playlist"; + + + +@Component({ + selector: 'app-popup-create-or-update-playlist', + templateUrl: './popup-create-or-update-playlist.component.html', + styleUrls: ['./popup-create-or-update-playlist.component.scss'] +}) +export class PopupCreateOrUpdatePlaylistComponent implements OnInit +{ + name: string = "" ; + hasError: boolean = false; + tabNomPlaylist: string[] = []; + errorMessage: string = "" ; + action: string = ""; + + + + constructor( public dialogRef: MatDialogRef, + @Inject(MAT_DIALOG_DATA) public data, + private messageService: MessageService) { } + + + ngOnInit(): void + { + this.action = this.data.action; + this.tabNomPlaylist = this.data.tabPlaylist.map( playlist0 => playlist0.name ); + if(this.action === "update") this.name = this.data.playlistName; + } + + + onValider(): void + { + this.checkError(); + if(!this.hasError) + { + if(this.action === "create") + { + this.messageService + .post("playlist/create", {name: this.name}) + .subscribe(retour => this.onValiderCallback(retour), err => this.onValiderCallback(err)); + } + else if(this.action === "update") + { + this.messageService + .put("playlist/update/"+this.data.playlistId, {name: this.name}) + .subscribe(retour => this.onValiderCallback(retour), err => this.onValiderCallback(err)); + } + } + } + + + onValiderCallback(retour): void + { + if(retour.status !== "success") { + console.log(retour); + this.dialogRef.close(null); + } + else { + if(this.action === "create") this.dialogRef.close(retour.data); + else if(this.action === "update") this.dialogRef.close(this.name); + } + } + + + checkError(): void + { + if(this.name === "") { + this.errorMessage = "Le nom ne peut pas être vide" ; + this.hasError = true; + } + else if(this.tabNomPlaylist.includes(this.name)){ + this.errorMessage = "Ce nom est déjà utilisé" ; + this.hasError = true; + } + else { + this.hasError = false; + this.errorMessage = "" ; + } + } + + + onAnnuler(): void + { + this.dialogRef.close(null); + } + +} diff --git a/src/app/user/myPlaylists/popup-create-playlist/popup-create-playlist.component.ts b/src/app/user/myPlaylists/popup-create-playlist/popup-create-playlist.component.ts deleted file mode 100644 index b9ecbbb..0000000 --- a/src/app/user/myPlaylists/popup-create-playlist/popup-create-playlist.component.ts +++ /dev/null @@ -1,95 +0,0 @@ -import {Component, Inject, OnInit} from '@angular/core'; -import {MAT_DIALOG_DATA, MatDialogRef} from "@angular/material/dialog"; -import {MessageService} from "../../../utils/services/message/message.service"; -import {PlaylistDB} from "../../../utils/interfaces/playlist"; - - - -@Component({ - selector: 'app-popup-create-playlist', - templateUrl: './popup-create-playlist.component.html', - styleUrls: ['./popup-create-playlist.component.scss'] -}) -export class PopupCreatePlaylistComponent implements OnInit -{ - name: string = "" ; - hasError: boolean = false; - tabNomPlaylist: string[] = []; - errorMessage: string = "" ; - - - constructor( public dialogRef: MatDialogRef, - @Inject(MAT_DIALOG_DATA) public data, - private messageService: MessageService) { } - - - ngOnInit(): void - { - this.tabNomPlaylist = this.data.map( playlist0 => playlist0.name ); - } - - - onValider(): void - { - // --- FAUX CODE --- - // - this.checkError(); - if(!this.hasError) - { - const playlist: PlaylistDB = { - _id: "", - userId: "userId", - name: this.name, - videoIds: [], - isActive: true, - createdAt: new Date(), - updatedAt: new Date(), - }; - this.dialogRef.close(playlist); - } - - // --- VRAI CODE --- - /* - this.checkError(); - if(!this.hasError) - { - this.messageService - .sendMessage("user/create/playlist", {title: this.data.title}) - .subscribe(retour => { - - if (retour.status === "error") { - console.log(retour); - this.dialogRef.close(null); - } else { - this.dialogRef.close(retour.data.playlist); - } - }); - } - */ - } - - - checkError(): void - { - if(this.name === "") { - this.errorMessage = "Le nom ne peut pas être vide" ; - this.hasError = true; - } - else if(this.tabNomPlaylist.includes(this.name)){ - this.errorMessage = "Ce nom est déjà utilisé" ; - this.hasError = true; - } - else { - this.hasError = false; - this.errorMessage = "" ; - } - console.log("em:" + this.errorMessage); - } - - - onAnnuler(): void - { - this.dialogRef.close(null); - } - -} diff --git a/src/app/user/myPlaylists/popup-delete-playlist/popup-delete-playlist.component.ts b/src/app/user/myPlaylists/popup-delete-playlist/popup-delete-playlist.component.ts index 0160eb6..2cc06ec 100644 --- a/src/app/user/myPlaylists/popup-delete-playlist/popup-delete-playlist.component.ts +++ b/src/app/user/myPlaylists/popup-delete-playlist/popup-delete-playlist.component.ts @@ -22,7 +22,20 @@ export class PopupDeletePlaylistComponent implements OnInit onValidate(): void { - this.dialogRef.close(true); + this.messageService + .delete("playlist/delete/"+this.playlist._id) + .subscribe( retour => this.onValidateCallback(retour), err => this.onValidateCallback(err)); + } + + onValidateCallback(retour: any): void + { + if(retour.status !== "success") { + console.log(retour); + this.dialogRef.close(null); + } + else { + this.dialogRef.close(true); + } } } diff --git a/src/app/user/myProfil/input-interests-profil/input-interests-profil.component.ts b/src/app/user/myProfil/input-interests-profil/input-interests-profil.component.ts index cb7bc9e..70c60da 100644 --- a/src/app/user/myProfil/input-interests-profil/input-interests-profil.component.ts +++ b/src/app/user/myProfil/input-interests-profil/input-interests-profil.component.ts @@ -6,7 +6,6 @@ import {MessageService} from "../../../utils/services/message/message.service"; import {map, startWith} from "rxjs/operators"; import {MatChipInputEvent} from "@angular/material/chips"; import {MatAutocompleteSelectedEvent} from "@angular/material/autocomplete"; -import {FictitiousUtilsService} from "../../../utils/services/fictitiousDatas/fictitiousUtils/fictitious-utils.service"; @@ -28,8 +27,7 @@ export class InputInterestsProfilComponent implements OnInit @ViewChild('tagInput') tagInput: ElementRef; - constructor( private fictitiousUtilsService: FictitiousUtilsService, - private messageService: MessageService ) {} + constructor( private messageService: MessageService ) {} ngOnInit(): void @@ -38,9 +36,19 @@ export class InputInterestsProfilComponent implements OnInit startWith(null), map((fruit: string | null) => fruit ? this._filter(fruit) : this.allInterests.slice())); - // --- FAUX CODE --- - this.allInterests = this.fictitiousUtilsService.getTags(); - this.allInterests.sort(); + this.messageService + .get("misc/getInterests") + .subscribe( retour => { + + if(retour.status !== "success") { + console.log(retour); + } + else { + this.allInterests = []; + for(let elt of retour.data) this.allInterests.push(elt.interest); + this.allInterests.sort(); + } + }); } diff --git a/src/app/user/myProfil/page-profil-user/page-profil-user.component.ts b/src/app/user/myProfil/page-profil-user/page-profil-user.component.ts index 7544482..1967c8d 100644 --- a/src/app/user/myProfil/page-profil-user/page-profil-user.component.ts +++ b/src/app/user/myProfil/page-profil-user/page-profil-user.component.ts @@ -4,7 +4,8 @@ import {User} from "../../../utils/interfaces/user"; import {MatDialog} from "@angular/material/dialog"; import {MatSnackBar} from "@angular/material/snack-bar"; import {PopupUpdateUserComponent} from "../popup-update-user/popup-update-user.component"; -import {FictitiousUsersService} from "../../../utils/services/fictitiousDatas/fictitiousUsers/fictitious-users.service"; +import {MessageService} from "../../../utils/services/message/message.service"; +import {ProfilService} from "../../../utils/services/profil/profil.service"; @@ -15,18 +16,52 @@ import {FictitiousUsersService} from "../../../utils/services/fictitiousDatas/fi }) export class PageProfilUserComponent implements OnInit { - user: User; + user: User = { + _id: "", + login: "", + hashPass: "", + email: "", + role: { + name: "user", + permission: 0, + }, + profileImageUrl: "", + dateOfBirth: null, + gender: "man", + interests: [], + company: "", + isActive: false, + isAccepted: false, + createdAt: new Date(), + updatedAt: new Date(), + lastConnexion: null + }; constructor( public themeService: ThemeService, - private fictitiousUsersService: FictitiousUsersService, public dialog: MatDialog, - private snackBar: MatSnackBar ) { } + private snackBar: MatSnackBar, + private messageService: MessageService, + private profilService: ProfilService ) { } ngOnInit(): void { - this.user = this.fictitiousUsersService.getUser(); + this.messageService + .get( "user/findOne/"+this.profilService.id) + .subscribe( retour => this.ngOnInitCallback(retour), err => this.ngOnInitCallback(err) ) + } + + + ngOnInitCallback(retour: any) + { + if(retour.status !== "success") { + console.log(retour); + } + else { + this.user = retour.data; + this.profilService.id = retour.data.id; + } } diff --git a/src/app/user/myProfil/popup-update-user/popup-update-user.component.ts b/src/app/user/myProfil/popup-update-user/popup-update-user.component.ts index 5424dca..a4202ad 100644 --- a/src/app/user/myProfil/popup-update-user/popup-update-user.component.ts +++ b/src/app/user/myProfil/popup-update-user/popup-update-user.component.ts @@ -1,6 +1,8 @@ import {Component, Inject, OnInit} from '@angular/core'; import {MAT_DIALOG_DATA, MatDialogRef} from "@angular/material/dialog"; import {User} from "../../../utils/interfaces/user"; +import {MessageService} from "../../../utils/services/message/message.service"; +import {ProfilService} from "../../../utils/services/profil/profil.service"; @@ -20,7 +22,9 @@ export class PopupUpdateUserComponent implements OnInit constructor( public dialogRef: MatDialogRef, - @Inject(MAT_DIALOG_DATA) public data) { } + @Inject(MAT_DIALOG_DATA) public data, + private messageService: MessageService, + private profilService: ProfilService ) { } ngOnInit(): void @@ -55,11 +59,30 @@ export class PopupUpdateUserComponent implements OnInit this.checkField(); if(!this.hasError) { - if(this.changePassword) this.userCopy.hashPass = this.hashage(this.newPassword); - const data = { user: this.userCopy }; + if(this.changePassword) this.userCopy.hashPass = this.newPassword; + const data = { + login: this.userCopy.login, + hashPass: this.userCopy.hashPass, + email: this.userCopy.email, + profileImageUrl: this.userCopy.profileImageUrl, + dateOfBirth: this.userCopy.dateOfBirth, + gender: this.userCopy.gender, + interests: this.userCopy.interests, + }; + this.messageService + .put("user/update/"+this.profilService.id, data) + .subscribe( ret => this.onValiderCallback(ret), err => this.onValiderCallback(err) ); + } + } - // VRAI CODE: envoie au back ... + onValiderCallback(retour: any) + { + if(retour.status !== "success") { + console.log(retour); + this.dialogRef.close(null); + } + else { this.dialogRef.close(this.userCopy); } } @@ -106,17 +129,4 @@ export class PopupUpdateUserComponent implements OnInit this.userCopy.interests = myInterets; } - - // Fonction de hashage (faible) - hashage(input: string): string - { - let hash = 0; - for (let i = 0; i < input.length; i++) { - let ch = input.charCodeAt(i); - hash = ((hash << 5) - hash) + ch; - hash = hash & hash; - } - return hash.toString(); - } - } diff --git a/src/app/user/utils/components/navbar-user/navbar-user.component.ts b/src/app/user/utils/components/navbar-user/navbar-user.component.ts index ce92706..bb2e345 100644 --- a/src/app/user/utils/components/navbar-user/navbar-user.component.ts +++ b/src/app/user/utils/components/navbar-user/navbar-user.component.ts @@ -29,7 +29,7 @@ export class NavbarUserComponent onDeconnexion(): void { this.messageService - .delete('user/logout', {}) + .delete('user/logout') .subscribe(retour => this.onDeconnexionCallback(retour), err => this.onDeconnexionCallback(err)); } diff --git a/src/app/utils/services/message/message.service.ts b/src/app/utils/services/message/message.service.ts index 22b7450..086b447 100644 --- a/src/app/utils/services/message/message.service.ts +++ b/src/app/utils/services/message/message.service.ts @@ -19,10 +19,10 @@ export class MessageService return this.http.post(urlComplete, data, {withCredentials: true}); } - get(url: string, data: any): Observable + get(url: string): Observable { const urlComplete = environment.debutUrl + url ; - return this.http.get(urlComplete, data); + return this.http.get(urlComplete,{withCredentials: true}); } put(url: string, data: any): Observable @@ -31,10 +31,10 @@ export class MessageService return this.http.put(urlComplete, data, {withCredentials: true}); } - delete(url: string, data: any): Observable + delete(url: string): Observable { const urlComplete = environment.debutUrl + url ; - return this.http.delete(urlComplete, data); + return this.http.delete(urlComplete,{withCredentials: true}); } } diff --git a/src/app/utils/services/profil/profil.service.ts b/src/app/utils/services/profil/profil.service.ts index f32dac8..e4d2e2b 100644 --- a/src/app/utils/services/profil/profil.service.ts +++ b/src/app/utils/services/profil/profil.service.ts @@ -5,5 +5,6 @@ import { Injectable } from '@angular/core'; }) export class ProfilService { + public id: string = "" ; public profileImageUrl: string = ""; } From 526e5fbbbff3fabcad4e1daa341cf21a3cbb2d5c Mon Sep 17 00:00:00 2001 From: MiharyR Date: Sat, 11 Dec 2021 21:59:15 +0100 Subject: [PATCH 3/3] connexion avec le back de toutes les pages 'myProfil' --- .../page-profil-admin.component.ts | 46 ++++++++++++++++--- .../popup-update-admin.component.ts | 41 ++++++++++------- .../page-ad-list-advertiser.component.ts | 1 - .../page-profil-advertiser.component.ts | 45 ++++++++++++++++-- .../popup-update-advertiser.component.ts | 41 ++++++++++------- .../login/page-login/page-login.component.ts | 13 ------ 6 files changed, 129 insertions(+), 58 deletions(-) diff --git a/src/app/admin/myProfil/page-profil-admin/page-profil-admin.component.ts b/src/app/admin/myProfil/page-profil-admin/page-profil-admin.component.ts index 33998a6..f6199c9 100644 --- a/src/app/admin/myProfil/page-profil-admin/page-profil-admin.component.ts +++ b/src/app/admin/myProfil/page-profil-admin/page-profil-admin.component.ts @@ -4,7 +4,8 @@ import {ThemeService} from "../../../utils/services/theme/theme.service"; import {MatDialog} from "@angular/material/dialog"; import {MatSnackBar} from "@angular/material/snack-bar"; import {PopupUpdateAdminComponent} from "../popup-update-admin/popup-update-admin.component"; -import {FictitiousUsersService} from "../../../utils/services/fictitiousDatas/fictitiousUsers/fictitious-users.service"; +import {MessageService} from "../../../utils/services/message/message.service"; +import {ProfilService} from "../../../utils/services/profil/profil.service"; @@ -15,19 +16,52 @@ import {FictitiousUsersService} from "../../../utils/services/fictitiousDatas/fi }) export class PageProfilAdminComponent implements OnInit { - - admin: User; + admin: User = { + _id: "", + login: "", + hashPass: "", + email: "", + role: { + name: "admin", + permission: 10, + }, + profileImageUrl: "", + dateOfBirth: null, + gender: "man", + interests: [], + company: "", + isActive: false, + isAccepted: false, + createdAt: new Date(), + updatedAt: new Date(), + lastConnexion: null + }; constructor( public themeService: ThemeService, - private fictitiousUsersService: FictitiousUsersService, public dialog: MatDialog, - private snackBar: MatSnackBar ) { } + private snackBar: MatSnackBar, + private messageService: MessageService, + private profilService: ProfilService ) { } ngOnInit(): void { - this.admin = this.fictitiousUsersService.getAdmin(); + this.messageService + .get( "user/findOne/"+this.profilService.id) + .subscribe( retour => this.ngOnInitCallback(retour), err => this.ngOnInitCallback(err) ) + } + + + ngOnInitCallback(retour: any) + { + if(retour.status !== "success") { + console.log(retour); + } + else { + this.admin = retour.data; + this.profilService.id = retour.data.id; + } } diff --git a/src/app/admin/myProfil/popup-update-admin/popup-update-admin.component.ts b/src/app/admin/myProfil/popup-update-admin/popup-update-admin.component.ts index 3ae595b..8ca8996 100644 --- a/src/app/admin/myProfil/popup-update-admin/popup-update-admin.component.ts +++ b/src/app/admin/myProfil/popup-update-admin/popup-update-admin.component.ts @@ -1,6 +1,8 @@ import {Component, Inject, OnInit} from '@angular/core'; import {User} from "../../../utils/interfaces/user"; import {MAT_DIALOG_DATA, MatDialogRef} from "@angular/material/dialog"; +import {MessageService} from "../../../utils/services/message/message.service"; +import {ProfilService} from "../../../utils/services/profil/profil.service"; @@ -20,7 +22,9 @@ export class PopupUpdateAdminComponent implements OnInit constructor( public dialogRef: MatDialogRef, - @Inject(MAT_DIALOG_DATA) public data) { } + @Inject(MAT_DIALOG_DATA) public data, + private messageService: MessageService, + private profilService: ProfilService ) { } ngOnInit(): void @@ -55,11 +59,27 @@ export class PopupUpdateAdminComponent implements OnInit this.checkField(); if(!this.hasError) { - if(this.changePassword) this.adminCopy.hashPass = this.hashage(this.newPassword); - const data = { user: this.adminCopy }; + if(this.changePassword) this.adminCopy.hashPass = this.newPassword; + const data = { + login: this.adminCopy.login, + hashPass: this.adminCopy.hashPass, + email: this.adminCopy.email, + profileImageUrl: this.adminCopy.profileImageUrl, + }; + this.messageService + .put("user/update/"+this.profilService.id, data) + .subscribe( ret => this.onValiderCallback(ret), err => this.onValiderCallback(err) ); + } + } - // VRAI CODE: envoie au back ... + onValiderCallback(retour: any) + { + if(retour.status !== "success") { + console.log(retour); + this.dialogRef.close(null); + } + else { this.dialogRef.close(this.adminCopy); } } @@ -100,17 +120,4 @@ export class PopupUpdateAdminComponent implements OnInit return re.test(email); } - - // Fonction de hashage (faible) - hashage(input: string): string - { - let hash = 0; - for (let i = 0; i < input.length; i++) { - let ch = input.charCodeAt(i); - hash = ((hash << 5) - hash) + ch; - hash = hash & hash; - } - return hash.toString(); - } - } diff --git a/src/app/advertiser/adList/page-ad-list-advertiser/page-ad-list-advertiser.component.ts b/src/app/advertiser/adList/page-ad-list-advertiser/page-ad-list-advertiser.component.ts index 6b3306b..37ff560 100644 --- a/src/app/advertiser/adList/page-ad-list-advertiser/page-ad-list-advertiser.component.ts +++ b/src/app/advertiser/adList/page-ad-list-advertiser/page-ad-list-advertiser.component.ts @@ -168,7 +168,6 @@ export class PageAdListAdvertiserComponent implements AfterViewInit onFilter(): void { - console.log("b:" + this.formControlInterests.value); this.dataSource.data = []; for(let advert of this.tabAdvertWithCountViews) { diff --git a/src/app/advertiser/myProfil/page-profil-advertiser/page-profil-advertiser.component.ts b/src/app/advertiser/myProfil/page-profil-advertiser/page-profil-advertiser.component.ts index 671ce53..1213210 100644 --- a/src/app/advertiser/myProfil/page-profil-advertiser/page-profil-advertiser.component.ts +++ b/src/app/advertiser/myProfil/page-profil-advertiser/page-profil-advertiser.component.ts @@ -4,7 +4,8 @@ import {ThemeService} from "../../../utils/services/theme/theme.service"; import {MatDialog} from "@angular/material/dialog"; import {MatSnackBar} from "@angular/material/snack-bar"; import {PopupUpdateAdvertiserComponent} from "../popup-update-advertiser/popup-update-advertiser.component"; -import {FictitiousUsersService} from "../../../utils/services/fictitiousDatas/fictitiousUsers/fictitious-users.service"; +import {MessageService} from "../../../utils/services/message/message.service"; +import {ProfilService} from "../../../utils/services/profil/profil.service"; @@ -15,18 +16,52 @@ import {FictitiousUsersService} from "../../../utils/services/fictitiousDatas/fi }) export class PageProfilAdvertiserComponent implements OnInit { - advertiser: User; + advertiser: User = { + _id: "", + login: "", + hashPass: "", + email: "", + role: { + name: "advertiser", + permission: 5, + }, + profileImageUrl: "", + dateOfBirth: null, + gender: "man", + interests: [], + company: "", + isActive: false, + isAccepted: false, + createdAt: new Date(), + updatedAt: new Date(), + lastConnexion: null + }; constructor( public themeService: ThemeService, - private fictitiousUsersService: FictitiousUsersService, public dialog: MatDialog, - private snackBar: MatSnackBar ) { } + private snackBar: MatSnackBar, + private messageService: MessageService, + private profilService: ProfilService ) { } ngOnInit(): void { - this.advertiser = this.fictitiousUsersService.getAdvertiser(); + this.messageService + .get( "user/findOne/"+this.profilService.id) + .subscribe( retour => this.ngOnInitCallback(retour), err => this.ngOnInitCallback(err) ) + } + + + ngOnInitCallback(retour: any) + { + if(retour.status !== "success") { + console.log(retour); + } + else { + this.advertiser = retour.data; + this.profilService.id = retour.data.id; + } } diff --git a/src/app/advertiser/myProfil/popup-update-advertiser/popup-update-advertiser.component.ts b/src/app/advertiser/myProfil/popup-update-advertiser/popup-update-advertiser.component.ts index b224472..e32bbc7 100644 --- a/src/app/advertiser/myProfil/popup-update-advertiser/popup-update-advertiser.component.ts +++ b/src/app/advertiser/myProfil/popup-update-advertiser/popup-update-advertiser.component.ts @@ -1,6 +1,8 @@ import {Component, Inject, OnInit} from '@angular/core'; import {User} from "../../../utils/interfaces/user"; import {MAT_DIALOG_DATA, MatDialogRef} from "@angular/material/dialog"; +import {MessageService} from "../../../utils/services/message/message.service"; +import {ProfilService} from "../../../utils/services/profil/profil.service"; @@ -20,7 +22,9 @@ export class PopupUpdateAdvertiserComponent implements OnInit constructor( public dialogRef: MatDialogRef, - @Inject(MAT_DIALOG_DATA) public data) { } + @Inject(MAT_DIALOG_DATA) public data, + private messageService: MessageService, + private profilService: ProfilService ) { } ngOnInit(): void @@ -55,11 +59,28 @@ export class PopupUpdateAdvertiserComponent implements OnInit this.checkField(); if(!this.hasError) { - if(this.changePassword) this.advertiserCopy.hashPass = this.hashage(this.newPassword); - const data = { user: this.advertiserCopy }; + if(this.changePassword) this.advertiserCopy.hashPass = this.newPassword; + const data = { + login: this.advertiserCopy.login, + hashPass: this.advertiserCopy.hashPass, + email: this.advertiserCopy.email, + profileImageUrl: this.advertiserCopy.profileImageUrl, + company: this.advertiserCopy.company + }; + this.messageService + .put("user/update/"+this.profilService.id, data) + .subscribe( ret => this.onValiderCallback(ret), err => this.onValiderCallback(err) ); + } + } - // VRAI CODE: envoie au back ... + onValiderCallback(retour: any) + { + if(retour.status !== "success") { + console.log(retour); + this.dialogRef.close(null); + } + else { this.dialogRef.close(this.advertiserCopy); } } @@ -100,16 +121,4 @@ export class PopupUpdateAdvertiserComponent implements OnInit return re.test(email); } - - // Fonction de hashage (faible) - hashage(input: string): string - { - let hash = 0; - for (let i = 0; i < input.length; i++) { - let ch = input.charCodeAt(i); - hash = ((hash << 5) - hash) + ch; - hash = hash & hash; - } - return hash.toString(); - } } diff --git a/src/app/beforeConnexion/login/page-login/page-login.component.ts b/src/app/beforeConnexion/login/page-login/page-login.component.ts index ad2f03b..f864ee6 100644 --- a/src/app/beforeConnexion/login/page-login/page-login.component.ts +++ b/src/app/beforeConnexion/login/page-login/page-login.component.ts @@ -98,17 +98,4 @@ export class PageLoginComponent implements OnInit } } - - // Fonction de hashage (faible) - hashage(input: string): string - { - let hash = 0; - for (let i = 0; i < input.length; i++) { - let ch = input.charCodeAt(i); - hash = ((hash << 5) - hash) + ch; - hash = hash & hash; - } - return hash.toString(); - } - }