commencement de la connexion avec le back de 'user/myProfil' et de 'user/myPlaylists'
This commit is contained in:
parent
cf3c596c7b
commit
7f6d089f1d
20 changed files with 279 additions and 149 deletions
|
|
@ -28,7 +28,7 @@ export class NavbarAdminComponent
|
||||||
onDeconnexion(): void
|
onDeconnexion(): void
|
||||||
{
|
{
|
||||||
this.messageService
|
this.messageService
|
||||||
.delete('user/logout', {})
|
.delete('user/logout')
|
||||||
.subscribe(retour => this.onDeconnexionCallback(retour), err => this.onDeconnexionCallback(err));
|
.subscribe(retour => this.onDeconnexionCallback(retour), err => this.onDeconnexionCallback(err));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,7 @@ export class NavbarAdvertiserComponent
|
||||||
onDeconnexion(): void
|
onDeconnexion(): void
|
||||||
{
|
{
|
||||||
this.messageService
|
this.messageService
|
||||||
.delete('user/logout', {})
|
.delete('user/logout')
|
||||||
.subscribe(retour => this.onDeconnexionCallback(retour), err => this.onDeconnexionCallback(err));
|
.subscribe(retour => this.onDeconnexionCallback(retour), err => this.onDeconnexionCallback(err));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ import {MatGridListModule} from "@angular/material/grid-list";
|
||||||
import { PageMyPlaylistsComponent } from './user/myPlaylists/page-my-playlists/page-my-playlists.component';
|
import { PageMyPlaylistsComponent } from './user/myPlaylists/page-my-playlists/page-my-playlists.component';
|
||||||
import { PlaylistListComponent } from './user/myPlaylists/playlist-list/playlist-list.component';
|
import { PlaylistListComponent } from './user/myPlaylists/playlist-list/playlist-list.component';
|
||||||
import {VideoListComponent} from "./user/myPlaylists/video-list/video-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 { PageHistoryUserComponent } from './user/history/page-history-user/page-history-user.component';
|
||||||
import {MatTableModule} from '@angular/material/table';
|
import {MatTableModule} from '@angular/material/table';
|
||||||
import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
|
import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
|
||||||
|
|
@ -87,7 +87,7 @@ import { PopupForgottenPasswordComponent } from './beforeConnexion/login/popup-f
|
||||||
VideoListComponent,
|
VideoListComponent,
|
||||||
PlaylistListComponent,
|
PlaylistListComponent,
|
||||||
VideoListComponent,
|
VideoListComponent,
|
||||||
PopupCreatePlaylistComponent,
|
PopupCreateOrUpdatePlaylistComponent,
|
||||||
PageHistoryUserComponent,
|
PageHistoryUserComponent,
|
||||||
PageAdListAdvertiserComponent,
|
PageAdListAdvertiserComponent,
|
||||||
PopupDeleteAdAdvertiserComponent,
|
PopupDeleteAdAdvertiserComponent,
|
||||||
|
|
|
||||||
|
|
@ -58,6 +58,7 @@ export class PageLoginComponent implements OnInit
|
||||||
this.hasError = true;
|
this.hasError = true;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
this.profilService.id = retour.data.id;
|
||||||
this.profilService.profileImageUrl = retour.data.profileImageUrl;
|
this.profilService.profileImageUrl = retour.data.profileImageUrl;
|
||||||
if(retour.data.role.name === "user") this.router.navigateByUrl( '/user/search');
|
if(retour.data.role.name === "user") this.router.navigateByUrl( '/user/search');
|
||||||
else if(retour.data.role.name === "advertiser") this.router.navigateByUrl( '/advertiser/adList');
|
else if(retour.data.role.name === "advertiser") this.router.navigateByUrl( '/advertiser/adList');
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,7 @@ export class InputInterestsRegisterComponent implements OnInit
|
||||||
map((fruit: string | null) => fruit ? this._filter(fruit) : this.allInterests.slice()));
|
map((fruit: string | null) => fruit ? this._filter(fruit) : this.allInterests.slice()));
|
||||||
|
|
||||||
this.messageService
|
this.messageService
|
||||||
.get("misc/getInterests", {})
|
.get("misc/getInterests")
|
||||||
.subscribe( retour => {
|
.subscribe( retour => {
|
||||||
|
|
||||||
if(retour.status !== "success") {
|
if(retour.status !== "success") {
|
||||||
|
|
|
||||||
|
|
@ -67,9 +67,8 @@ export class PageRegisterComponent
|
||||||
// Gestion de la réponse du backend
|
// Gestion de la réponse du backend
|
||||||
onEnregistrerCallback(retour): void
|
onEnregistrerCallback(retour): void
|
||||||
{
|
{
|
||||||
console.log(retour);
|
|
||||||
if(retour.status !== "success") {
|
if(retour.status !== "success") {
|
||||||
|
console.log(retour);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,11 @@
|
||||||
<div *ngFor="let playlist of tabPlaylist" class="playlistContainer">
|
<div *ngFor="let playlist of tabPlaylist" class="playlistContainer">
|
||||||
|
|
||||||
<div [class]="getClassOfPlaylistContainer(playlist)" (click)="eventEmitter.emit(playlist); playlistFocusedOn = playlist">
|
<div [class]="getClassOfPlaylistContainer(playlist)" (click)="eventEmitter.emit(playlist); playlistFocusedOn = playlist">
|
||||||
<div class="col-2"></div>
|
<div class="col-2" style="text-align: left">
|
||||||
|
<button mat-icon-button (click)="onUpdatePlaylist(playlist)">
|
||||||
|
<mat-icon>edit</mat-icon>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
<div class="col-8" style="text-align: center">
|
<div class="col-8" style="text-align: center">
|
||||||
<span class="playlistName"> {{playlist.name}} </span><br>
|
<span class="playlistName"> {{playlist.name}} </span><br>
|
||||||
<span class="playListCount" *ngIf="playlist.videoIds.length <= 1"> {{playlist.videoIds.length}} vidéo </span>
|
<span class="playListCount" *ngIf="playlist.videoIds.length <= 1"> {{playlist.videoIds.length}} vidéo </span>
|
||||||
|
|
|
||||||
|
|
@ -3,9 +3,10 @@ import {ThemeService} from "../../../utils/services/theme/theme.service";
|
||||||
import {PlaylistDB} from "../../../utils/interfaces/playlist";
|
import {PlaylistDB} from "../../../utils/interfaces/playlist";
|
||||||
import {MatDialog} from "@angular/material/dialog";
|
import {MatDialog} from "@angular/material/dialog";
|
||||||
import {MatSnackBar} from "@angular/material/snack-bar";
|
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 {FictitiousVideosService} from "../../../utils/services/fictitiousDatas/fictitiousVideos/fictitious-videos.service";
|
||||||
import {PopupDeletePlaylistComponent} from "../popup-delete-playlist/popup-delete-playlist.component";
|
import {PopupDeletePlaylistComponent} from "../popup-delete-playlist/popup-delete-playlist.component";
|
||||||
|
import {MessageService} from "../../../utils/services/message/message.service";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -26,14 +27,31 @@ export class PlaylistListComponent implements OnInit
|
||||||
constructor( public themeService: ThemeService,
|
constructor( public themeService: ThemeService,
|
||||||
public dialog: MatDialog,
|
public dialog: MatDialog,
|
||||||
public snackBar: MatSnackBar,
|
public snackBar: MatSnackBar,
|
||||||
private fictitiousVideosService: FictitiousVideosService ) { }
|
private fictitiousVideosService: FictitiousVideosService,
|
||||||
|
private messageService: MessageService ) { }
|
||||||
|
|
||||||
|
|
||||||
ngOnInit(): void
|
ngOnInit(): void
|
||||||
{
|
{
|
||||||
this.allPlaylists = this.fictitiousVideosService.getNoRandomTabPlaylistDB(10);
|
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);
|
this.tabPlaylist = [].concat(this.allPlaylists);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// s'execute lorsqu'on écrit sur la barre de recherche
|
// s'execute lorsqu'on écrit sur la barre de recherche
|
||||||
|
|
@ -50,9 +68,14 @@ export class PlaylistListComponent implements OnInit
|
||||||
// click sur créer playlist
|
// click sur créer playlist
|
||||||
onCreatePlaylist(): void
|
onCreatePlaylist(): void
|
||||||
{
|
{
|
||||||
const config = { data: this.tabPlaylist };
|
const config = {
|
||||||
|
data: {
|
||||||
|
action: "create",
|
||||||
|
tabPlaylist: this.tabPlaylist,
|
||||||
|
}
|
||||||
|
};
|
||||||
this.dialog
|
this.dialog
|
||||||
.open(PopupCreatePlaylistComponent, config )
|
.open(PopupCreateOrUpdatePlaylistComponent, config )
|
||||||
.afterClosed()
|
.afterClosed()
|
||||||
.subscribe(playlist => {
|
.subscribe(playlist => {
|
||||||
|
|
||||||
|
|
@ -61,6 +84,7 @@ export class PlaylistListComponent implements OnInit
|
||||||
this.snackBar.open("Opération annulée", "", config);
|
this.snackBar.open("Opération annulée", "", config);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
playlist["_id"] = playlist.id;
|
||||||
this.allPlaylists.push(playlist);
|
this.allPlaylists.push(playlist);
|
||||||
this.tabPlaylist.push(playlist);
|
this.tabPlaylist.push(playlist);
|
||||||
this.snackBar.open(`La playlist '${playlist.name}' a bien été créée ✔`, "", config);
|
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
|
// click sur supprimer playlist
|
||||||
onDeletePlaylist(playlist: PlaylistDB): void
|
onDeletePlaylist(playlist: PlaylistDB): void
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,10 @@
|
||||||
|
|
||||||
<div style="text-align: right ; margin: 0px; padding: 0px">
|
<div style="text-align: right ; margin: 0px; padding: 0px">
|
||||||
<button mat-button (click)="onAnnuler()">Annuler</button>
|
<button mat-button (click)="onAnnuler()">Annuler</button>
|
||||||
<button mat-button (click)="onValider()">Creer</button>
|
<button mat-button (click)="onValider()">
|
||||||
|
<span *ngIf="action === 'create'"> Creer </span>
|
||||||
|
<span *ngIf="action === 'update'"> Modifier </span>
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -1,20 +1,20 @@
|
||||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
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', () => {
|
describe('PopupCreatePlaylistComponent', () => {
|
||||||
let component: PopupCreatePlaylistComponent;
|
let component: PopupCreateOrUpdatePlaylistComponent;
|
||||||
let fixture: ComponentFixture<PopupCreatePlaylistComponent>;
|
let fixture: ComponentFixture<PopupCreateOrUpdatePlaylistComponent>;
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
await TestBed.configureTestingModule({
|
await TestBed.configureTestingModule({
|
||||||
declarations: [ PopupCreatePlaylistComponent ]
|
declarations: [ PopupCreateOrUpdatePlaylistComponent ]
|
||||||
})
|
})
|
||||||
.compileComponents();
|
.compileComponents();
|
||||||
});
|
});
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
fixture = TestBed.createComponent(PopupCreatePlaylistComponent);
|
fixture = TestBed.createComponent(PopupCreateOrUpdatePlaylistComponent);
|
||||||
component = fixture.componentInstance;
|
component = fixture.componentInstance;
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
});
|
});
|
||||||
|
|
@ -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<PopupCreateOrUpdatePlaylistComponent>,
|
||||||
|
@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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -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<PopupCreatePlaylistComponent>,
|
|
||||||
@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);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -22,7 +22,20 @@ export class PopupDeletePlaylistComponent implements OnInit
|
||||||
|
|
||||||
onValidate(): void
|
onValidate(): void
|
||||||
{
|
{
|
||||||
|
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);
|
this.dialogRef.close(true);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,6 @@ import {MessageService} from "../../../utils/services/message/message.service";
|
||||||
import {map, startWith} from "rxjs/operators";
|
import {map, startWith} from "rxjs/operators";
|
||||||
import {MatChipInputEvent} from "@angular/material/chips";
|
import {MatChipInputEvent} from "@angular/material/chips";
|
||||||
import {MatAutocompleteSelectedEvent} from "@angular/material/autocomplete";
|
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<HTMLInputElement>;
|
@ViewChild('tagInput') tagInput: ElementRef<HTMLInputElement>;
|
||||||
|
|
||||||
|
|
||||||
constructor( private fictitiousUtilsService: FictitiousUtilsService,
|
constructor( private messageService: MessageService ) {}
|
||||||
private messageService: MessageService ) {}
|
|
||||||
|
|
||||||
|
|
||||||
ngOnInit(): void
|
ngOnInit(): void
|
||||||
|
|
@ -38,10 +36,20 @@ export class InputInterestsProfilComponent implements OnInit
|
||||||
startWith(null),
|
startWith(null),
|
||||||
map((fruit: string | null) => fruit ? this._filter(fruit) : this.allInterests.slice()));
|
map((fruit: string | null) => fruit ? this._filter(fruit) : this.allInterests.slice()));
|
||||||
|
|
||||||
// --- FAUX CODE ---
|
this.messageService
|
||||||
this.allInterests = this.fictitiousUtilsService.getTags();
|
.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();
|
this.allInterests.sort();
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
add(event: MatChipInputEvent): void
|
add(event: MatChipInputEvent): void
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,8 @@ import {User} from "../../../utils/interfaces/user";
|
||||||
import {MatDialog} from "@angular/material/dialog";
|
import {MatDialog} from "@angular/material/dialog";
|
||||||
import {MatSnackBar} from "@angular/material/snack-bar";
|
import {MatSnackBar} from "@angular/material/snack-bar";
|
||||||
import {PopupUpdateUserComponent} from "../popup-update-user/popup-update-user.component";
|
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
|
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,
|
constructor( public themeService: ThemeService,
|
||||||
private fictitiousUsersService: FictitiousUsersService,
|
|
||||||
public dialog: MatDialog,
|
public dialog: MatDialog,
|
||||||
private snackBar: MatSnackBar ) { }
|
private snackBar: MatSnackBar,
|
||||||
|
private messageService: MessageService,
|
||||||
|
private profilService: ProfilService ) { }
|
||||||
|
|
||||||
|
|
||||||
ngOnInit(): void
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
import {Component, Inject, OnInit} from '@angular/core';
|
import {Component, Inject, OnInit} from '@angular/core';
|
||||||
import {MAT_DIALOG_DATA, MatDialogRef} from "@angular/material/dialog";
|
import {MAT_DIALOG_DATA, MatDialogRef} from "@angular/material/dialog";
|
||||||
import {User} from "../../../utils/interfaces/user";
|
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<PopupUpdateUserComponent>,
|
constructor( public dialogRef: MatDialogRef<PopupUpdateUserComponent>,
|
||||||
@Inject(MAT_DIALOG_DATA) public data) { }
|
@Inject(MAT_DIALOG_DATA) public data,
|
||||||
|
private messageService: MessageService,
|
||||||
|
private profilService: ProfilService ) { }
|
||||||
|
|
||||||
|
|
||||||
ngOnInit(): void
|
ngOnInit(): void
|
||||||
|
|
@ -55,11 +59,30 @@ export class PopupUpdateUserComponent implements OnInit
|
||||||
this.checkField();
|
this.checkField();
|
||||||
if(!this.hasError)
|
if(!this.hasError)
|
||||||
{
|
{
|
||||||
if(this.changePassword) this.userCopy.hashPass = this.hashage(this.newPassword);
|
if(this.changePassword) this.userCopy.hashPass = this.newPassword;
|
||||||
const data = { user: this.userCopy };
|
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);
|
this.dialogRef.close(this.userCopy);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -106,17 +129,4 @@ export class PopupUpdateUserComponent implements OnInit
|
||||||
this.userCopy.interests = myInterets;
|
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();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,7 @@ export class NavbarUserComponent
|
||||||
onDeconnexion(): void
|
onDeconnexion(): void
|
||||||
{
|
{
|
||||||
this.messageService
|
this.messageService
|
||||||
.delete('user/logout', {})
|
.delete('user/logout')
|
||||||
.subscribe(retour => this.onDeconnexionCallback(retour), err => this.onDeconnexionCallback(err));
|
.subscribe(retour => this.onDeconnexionCallback(retour), err => this.onDeconnexionCallback(err));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -19,10 +19,10 @@ export class MessageService
|
||||||
return this.http.post<any>(urlComplete, data, {withCredentials: true});
|
return this.http.post<any>(urlComplete, data, {withCredentials: true});
|
||||||
}
|
}
|
||||||
|
|
||||||
get(url: string, data: any): Observable<any>
|
get(url: string): Observable<any>
|
||||||
{
|
{
|
||||||
const urlComplete = environment.debutUrl + url ;
|
const urlComplete = environment.debutUrl + url ;
|
||||||
return this.http.get<any>(urlComplete, data);
|
return this.http.get<any>(urlComplete,{withCredentials: true});
|
||||||
}
|
}
|
||||||
|
|
||||||
put(url: string, data: any): Observable<any>
|
put(url: string, data: any): Observable<any>
|
||||||
|
|
@ -31,10 +31,10 @@ export class MessageService
|
||||||
return this.http.put<any>(urlComplete, data, {withCredentials: true});
|
return this.http.put<any>(urlComplete, data, {withCredentials: true});
|
||||||
}
|
}
|
||||||
|
|
||||||
delete(url: string, data: any): Observable<any>
|
delete(url: string): Observable<any>
|
||||||
{
|
{
|
||||||
const urlComplete = environment.debutUrl + url ;
|
const urlComplete = environment.debutUrl + url ;
|
||||||
return this.http.delete<any>(urlComplete, data);
|
return this.http.delete<any>(urlComplete,{withCredentials: true});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,5 +5,6 @@ import { Injectable } from '@angular/core';
|
||||||
})
|
})
|
||||||
export class ProfilService
|
export class ProfilService
|
||||||
{
|
{
|
||||||
|
public id: string = "" ;
|
||||||
public profileImageUrl: string = "";
|
public profileImageUrl: string = "";
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Reference in a new issue