Merge remote-tracking branch 'origin/main' into main
This commit is contained in:
commit
5f20411dd8
27 changed files with 443 additions and 218 deletions
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -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<PopupUpdateAdminComponent>,
|
||||
@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();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -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<PopupUpdateAdvertiserComponent>,
|
||||
@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();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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');
|
||||
|
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<HTMLInputElement>;
|
||||
|
||||
|
||||
constructor( private fictitiousUtilsService: FictitiousUtilsService,
|
||||
private messageService: MessageService ) {}
|
||||
constructor( private messageService: MessageService ) {}
|
||||
|
||||
|
||||
ngOnInit(): void
|
||||
|
|
@ -36,10 +36,20 @@ 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.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();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
add(event: MatChipInputEvent): void
|
||||
|
|
|
|||
|
|
@ -109,9 +109,9 @@
|
|||
</mat-form-field>
|
||||
|
||||
<!-- interests -->
|
||||
<app-input-interests-profil
|
||||
<app-input-interests-register
|
||||
[myInterests]="user.interests"
|
||||
(eventEmitter)="onEventInputInterests($event)"></app-input-interests-profil>
|
||||
(eventEmitter)="onEventInputInterests($event)"></app-input-interests-register>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -53,17 +53,18 @@ 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
|
||||
{
|
||||
if(retour.status !== "success") {
|
||||
|
|
|
|||
|
|
@ -16,7 +16,11 @@
|
|||
<div *ngFor="let playlist of tabPlaylist" class="playlistContainer">
|
||||
|
||||
<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">
|
||||
<span class="playlistName"> {{playlist.name}} </span><br>
|
||||
<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 {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,14 +27,31 @@ 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.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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// s'execute lorsqu'on écrit sur la barre de recherche
|
||||
|
|
@ -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
|
||||
{
|
||||
|
|
|
|||
|
|
@ -10,7 +10,10 @@
|
|||
|
||||
<div style="text-align: right ; margin: 0px; padding: 0px">
|
||||
<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>
|
||||
|
|
@ -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<PopupCreatePlaylistComponent>;
|
||||
let component: PopupCreateOrUpdatePlaylistComponent;
|
||||
let fixture: ComponentFixture<PopupCreateOrUpdatePlaylistComponent>;
|
||||
|
||||
beforeEach(async () => {
|
||||
await TestBed.configureTestingModule({
|
||||
declarations: [ PopupCreatePlaylistComponent ]
|
||||
declarations: [ PopupCreateOrUpdatePlaylistComponent ]
|
||||
})
|
||||
.compileComponents();
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(PopupCreatePlaylistComponent);
|
||||
fixture = TestBed.createComponent(PopupCreateOrUpdatePlaylistComponent);
|
||||
component = fixture.componentInstance;
|
||||
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
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<HTMLInputElement>;
|
||||
|
||||
|
||||
constructor( private fictitiousUtilsService: FictitiousUtilsService,
|
||||
private messageService: MessageService ) {}
|
||||
constructor( private messageService: MessageService ) {}
|
||||
|
||||
|
||||
ngOnInit(): void
|
||||
|
|
@ -38,10 +36,20 @@ 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.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();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
add(event: MatChipInputEvent): void
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -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<PopupUpdateUserComponent>,
|
||||
@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();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,10 +19,10 @@ export class MessageService
|
|||
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 ;
|
||||
return this.http.get<any>(urlComplete, data);
|
||||
return this.http.get<any>(urlComplete,{withCredentials: true});
|
||||
}
|
||||
|
||||
put(url: string, data: any): Observable<any>
|
||||
|
|
@ -31,10 +31,10 @@ export class MessageService
|
|||
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 ;
|
||||
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
|
||||
{
|
||||
public id: string = "" ;
|
||||
public profileImageUrl: string = "";
|
||||
}
|
||||
|
|
|
|||
Reference in a new issue