Merge remote-tracking branch 'origin/main' into main

This commit is contained in:
Yûki VACHOT 2021-12-12 00:04:44 +01:00
commit 5f20411dd8
27 changed files with 443 additions and 218 deletions

View file

@ -4,7 +4,8 @@ import {ThemeService} from "../../../utils/services/theme/theme.service";
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 {PopupUpdateAdminComponent} from "../popup-update-admin/popup-update-admin.component"; 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 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, 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.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;
}
} }

View file

@ -1,6 +1,8 @@
import {Component, Inject, OnInit} from '@angular/core'; import {Component, Inject, OnInit} from '@angular/core';
import {User} from "../../../utils/interfaces/user"; import {User} from "../../../utils/interfaces/user";
import {MAT_DIALOG_DATA, MatDialogRef} from "@angular/material/dialog"; 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<PopupUpdateAdminComponent>, constructor( public dialogRef: MatDialogRef<PopupUpdateAdminComponent>,
@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,27 @@ export class PopupUpdateAdminComponent implements OnInit
this.checkField(); this.checkField();
if(!this.hasError) if(!this.hasError)
{ {
if(this.changePassword) this.adminCopy.hashPass = this.hashage(this.newPassword); if(this.changePassword) this.adminCopy.hashPass = this.newPassword;
const data = { user: this.adminCopy }; 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); this.dialogRef.close(this.adminCopy);
} }
} }
@ -100,17 +120,4 @@ export class PopupUpdateAdminComponent implements OnInit
return re.test(email); 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();
}
} }

View file

@ -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));
} }

View file

@ -168,7 +168,6 @@ export class PageAdListAdvertiserComponent implements AfterViewInit
onFilter(): void onFilter(): void
{ {
console.log("b:" + this.formControlInterests.value);
this.dataSource.data = []; this.dataSource.data = [];
for(let advert of this.tabAdvertWithCountViews) for(let advert of this.tabAdvertWithCountViews)
{ {

View file

@ -4,7 +4,8 @@ import {ThemeService} from "../../../utils/services/theme/theme.service";
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 {PopupUpdateAdvertiserComponent} from "../popup-update-advertiser/popup-update-advertiser.component"; 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 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, 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.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;
}
} }

View file

@ -1,6 +1,8 @@
import {Component, Inject, OnInit} from '@angular/core'; import {Component, Inject, OnInit} from '@angular/core';
import {User} from "../../../utils/interfaces/user"; import {User} from "../../../utils/interfaces/user";
import {MAT_DIALOG_DATA, MatDialogRef} from "@angular/material/dialog"; 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<PopupUpdateAdvertiserComponent>, constructor( public dialogRef: MatDialogRef<PopupUpdateAdvertiserComponent>,
@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,28 @@ export class PopupUpdateAdvertiserComponent implements OnInit
this.checkField(); this.checkField();
if(!this.hasError) if(!this.hasError)
{ {
if(this.changePassword) this.advertiserCopy.hashPass = this.hashage(this.newPassword); if(this.changePassword) this.advertiserCopy.hashPass = this.newPassword;
const data = { user: this.advertiserCopy }; 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); this.dialogRef.close(this.advertiserCopy);
} }
} }
@ -100,16 +121,4 @@ export class PopupUpdateAdvertiserComponent implements OnInit
return re.test(email); 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();
}
} }

View file

@ -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));
} }

View file

@ -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,

View file

@ -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');
@ -97,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();
}
} }

View file

@ -6,7 +6,8 @@ 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";
@Component({ @Component({
selector: 'app-input-interests-register', selector: 'app-input-interests-register',
@ -26,8 +27,7 @@ export class InputInterestsRegisterComponent 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
@ -36,9 +36,19 @@ export class InputInterestsRegisterComponent 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")
this.allInterests.sort(); .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();
}
});
} }

View file

@ -109,9 +109,9 @@
</mat-form-field> </mat-form-field>
<!-- interests --> <!-- interests -->
<app-input-interests-profil <app-input-interests-register
[myInterests]="user.interests" [myInterests]="user.interests"
(eventEmitter)="onEventInputInterests($event)"></app-input-interests-profil> (eventEmitter)="onEventInputInterests($event)"></app-input-interests-register>
</div> </div>
</div> </div>

View file

@ -53,17 +53,18 @@ export class PageRegisterComponent
this.checkField(); this.checkField();
if(!this.hasError) if(!this.hasError)
{ {
if(this.user.role.name === "user") this.user.role.permission = 0; let data: any = Object.assign({}, this.user);
else this.user.role.permission = 5; if(this.user.role.name === "user") data.role = "user" ;
this.user.hashPass = this.password; else data.role = "advertiser";
data.hashPass = this.password;
this.messageService this.messageService
.post('user/create', this.user) .post('user/create', data)
.subscribe(retour => this.onEnregistrerCallback(retour), err => this.onEnregistrerCallback(err)); .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 onEnregistrerCallback(retour): void
{ {
if(retour.status !== "success") { if(retour.status !== "success") {

View file

@ -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>

View file

@ -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,13 +27,30 @@ 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
this.tabPlaylist = [].concat(this.allPlaylists); .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 // 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
{ {

View file

@ -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>

View file

@ -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();
}); });

View file

@ -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);
}
}

View file

@ -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);
}
}

View file

@ -22,7 +22,20 @@ export class PopupDeletePlaylistComponent implements OnInit
onValidate(): void 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);
}
} }
} }

View file

@ -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,9 +36,19 @@ 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")
this.allInterests.sort(); .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();
}
});
} }

View file

@ -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;
}
} }

View file

@ -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();
}
} }

View file

@ -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));
} }

View file

@ -11,7 +11,7 @@ export interface User
profileImageUrl: string, profileImageUrl: string,
dateOfBirth: Date, dateOfBirth: Date,
gender: string, gender: string,
interests: string[], interests: any[],
company: string, company: string,
isActive: boolean, isActive: boolean,
isAccepted: boolean, isAccepted: boolean,
@ -19,3 +19,15 @@ export interface User
createdAt: Date, createdAt: Date,
updatedAt: Date updatedAt: Date
} }
interface VideoCategorie
{
id: number
interest: string
categories: {
id: string
name: string
source: string
}
}

View file

@ -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});
} }
} }

View file

@ -5,5 +5,6 @@ import { Injectable } from '@angular/core';
}) })
export class ProfilService export class ProfilService
{ {
public id: string = "" ;
public profileImageUrl: string = ""; public profileImageUrl: string = "";
} }