commencement de la partie admin

This commit is contained in:
MiharyR 2021-11-13 13:35:08 +01:00
parent 11472d0045
commit de939b47f1
67 changed files with 1233 additions and 554 deletions

View file

@ -1,73 +0,0 @@
<div [class]="themeService.getClassTheme()">
<div class="myContainer">
<div class="boite">
<!-- Photo de profil -->
<div style="text-align: center">
<img [src]="model.profilePictureUrl"
onerror="this.onerror=null; this.src='assets/profil.png'"
alt="">
<br>
<button mat-button (click)="onChangePP()"> Changer photo de profil</button>
</div>
<br>
<!-- Pseudo -->
<mat-form-field appearance="fill">
<mat-label>Pseudo</mat-label>
<input matInput type="text" [(ngModel)]="model.login">
</mat-form-field>
<br>
<!-- Email -->
<mat-form-field appearance="fill">
<mat-label>Email</mat-label>
<input matInput type="text" [(ngModel)]="model.mail">
</mat-form-field>
<br>
<!-- Role -->
<mat-form-field appearance="fill">
<mat-label>Type de compte</mat-label>
<input matInput type="text" *ngIf="model.role==='user'" value="Utilisateur" disabled>
<input matInput type="text" *ngIf="model.role==='advertiser'" value="Annonceur" disabled>
<input matInput type="text" *ngIf="model.role==='admin'" value="Admin" disabled>
</mat-form-field>
<br>
<!-- Modifier mot de passe -->
Modifier mot de passe:
<mat-checkbox [(ngModel)]="changePassword"></mat-checkbox>
<br>
<!-- Nouveau mot de passe -->
<div *ngIf="changePassword">
<!-- Nouveau mot de passe -->
<mat-form-field appearance="fill">
<mat-label>Nouveau mot de passe</mat-label>
<input matInput type="password" [(ngModel)]="model.newPassword">
</mat-form-field>
<br>
<!-- Confirmation npuveau mot de passe -->
<mat-form-field appearance="fill">
<mat-label>Confirmation nouveau mot de passe</mat-label>
<input matInput type="password" [(ngModel)]="confirmNewPassword">
</mat-form-field>
</div>
<br>
<!-- Bouton valider -->
<div style="width: 100%; text-align: center">
<button mat-button (click)="onEnregistrer()"> Enregistrer </button>
</div>
<!-- Message d'erreur -->
<div *ngIf="hasError" style="text-align: center; margin-top: 10px;">
<span class="mat-error"> {{errorMessage}} </span>
</div>
</div>
</div>
</div>

View file

@ -1,67 +0,0 @@
.myContainer {
max-width: 100vw;
height: 100vh;
overflow-x: hidden;
}
h1 {
text-align: center;
margin-bottom: 30px;
}
.boite {
margin-left: auto;
margin-right: auto;
width: 20%;
margin-top: 20px;
border: solid 3px;
border-radius: 10px;
padding: 20px 40px 20px 40px;
background-color: #ffffff;
text-align: center;
box-shadow: 10px 5px 5px black;
}
.lightTheme .boite {
border-color: black;
}
.darkTheme .boite {
border-color: white;
}
img {
margin: 0px 0px 10px 0px;
width: 5vw;
height: 5vw;
border: solid 2px black;
border-radius: 50%;
font-size: xxx-large;
}
mat-form-field {
padding: 2px 0px 2px 0px;
width: 70%;
}
button {
border: solid 1px black;
}
// -------------------------------------------------------------------------
// aura
::ng-deep .mat-checkbox-ripple .mat-ripple-element {
background-color: grey !important;
}
// contenu coche
::ng-deep .mat-checkbox-checked.mat-accent .mat-checkbox-background {
background-color: black !important;
}
// indeterminate
::ng-deep .mat-checkbox .mat-checkbox-frame {
border-color: black !important;
background-color: white !important;
}

View file

@ -1,25 +0,0 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { PageMyProfilComponent } from './page-my-profil.component';
describe('PageMyProfilComponent', () => {
let component: PageMyProfilComponent;
let fixture: ComponentFixture<PageMyProfilComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [ PageMyProfilComponent ]
})
.compileComponents();
});
beforeEach(() => {
fixture = TestBed.createComponent(PageMyProfilComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

View file

@ -1,164 +0,0 @@
import { Component, OnInit } from '@angular/core';
import {MessageService} from "../../../services/message/message.service";
import {ThemeService} from "../../../services/theme/theme.service";
import {FictitiousDatasService} from "../../../services/fictitiousDatas/fictitious-datas.service";
import {MatDialog} from "@angular/material/dialog";
import {PopupAddVideoToPlaylistsComponent} from "../../popup-add-video-to-playlists/popup-add-video-to-playlists.component";
import {PopupPictureProfilUrlComponent} from "../popup-picture-profil-url/popup-picture-profil-url.component";
import {MatSnackBar} from "@angular/material/snack-bar";
import {Router} from "@angular/router";
@Component({
selector: 'app-page-my-profil',
templateUrl: './page-my-profil.component.html',
styleUrls: ['./page-my-profil.component.scss']
})
export class PageMyProfilComponent implements OnInit
{
model = {
_id: "",
profilePictureUrl: "",
login: "",
mail: "",
role: "",
newPassword: ""
};
confirmNewPassword: string = "" ;
changePassword: boolean = false ;
hasError: boolean = false;
errorMessage: string = "" ;
forNavbar: string = "" ;
constructor( private messageService: MessageService,
public themeService: ThemeService,
private fictitiousDatasService: FictitiousDatasService,
public dialog: MatDialog,
private snackBar: MatSnackBar,
private router: Router ) { }
ngOnInit(): void
{
// --- FAUX CODE ---
let profil ;
if(this.router.url.startsWith("/user")) {
profil = this.fictitiousDatasService.getUser();
this.forNavbar = "user";
}
else if(this.router.url.startsWith("/advertiser")) {
profil = this.fictitiousDatasService.getAdvertiser();
this.forNavbar = "advertiser";
}
else if(this.router.url.startsWith("/admin")) {
profil = this.fictitiousDatasService.getAdmin();
this.forNavbar = "admin";
}
this.model._id = profil._id;
this.model.profilePictureUrl = profil.profilePictureUrl;
this.model.login = profil.login;
this.model.mail = profil.mail;
this.model.role = profil.role;
// --- VRAI CODE ---
/*
this.messageService
.sendMessage("user/get/profil", null)
.subscribe( retour => {
if(retour.status === "error") console.log(retour);
else {
const profil = retour.data.profil;
this.model._id = profil._id;
this.model.profilePictureUrl = profil.profilePictureUrl;
this.model.pseudo = profil.pseudo;
this.model.email = profil.email;
this.model.role = profil.role;
this.model.newPassword = profil.newPassword;
}
});
*/
}
onEnregistrer()
{
console.log(this.model);
this.checkField();
// --- VRAI CODE ---
/*
if(!this.hasError)
{
this.messageService
.sendMessage("user/set/profil", this.model)
.subscribe( retour => {} );
}
*/
}
checkField()
{
if(this.model.login.length === 0) {
this.errorMessage = "Veuillez remplir le champ 'pseudo'"
this.hasError = true;
}
else if(this.model.mail.length === 0)
{
this.errorMessage = "Veuillez remplir le champ 'email'"
this.hasError = true;
}
else if(!this.isValidEmail(this.model.mail))
{
this.errorMessage = "Email invalide"
this.hasError = true;
}
else if(this.changePassword)
{
if (this.model.newPassword.length === 0) {
this.errorMessage = "Veuillez remplir le champ 'mot de passe'"
this.hasError = true;
} else if (this.model.newPassword !== this.confirmNewPassword) {
this.errorMessage = "Le mot de passe est différent de sa confirmation"
this.hasError = true;
}
}
else {
this.errorMessage = "" ;
this.hasError = false;
}
}
isValidEmail(email)
{
let re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
return re.test(email);
}
onChangePP()
{
const config = {
width: '25%',
data: { profilePictureUrl: this.model.profilePictureUrl }
};
this.dialog
.open(PopupPictureProfilUrlComponent, config )
.afterClosed()
.subscribe(retour => {
if((retour === null) || (retour === undefined)) {
const config = { duration: 1000, panelClass: "custom-class" };
this.snackBar.open( "Opération annulé", "", config);
}
else {
this.model.profilePictureUrl = retour;
}
});
}
}

View file

@ -1,9 +0,0 @@
<div class="myContainer">
<img [src]="profilePictureUrl"
onerror="this.onerror=null; this.src='https://www.qualibre-formations.fr/wp-content/uploads/2020/02/icon_single.png'"
routerLink="/advertiser/myProfil"
alt="???">
<br>
<input [(ngModel)]="profilePictureUrl" placeholder="url de l'image"><br>
<button mat-button (click)="onValider()"> Valider </button>
</div>

View file

@ -1,20 +0,0 @@
.myContainer {
margin: 0px;
padding: 0px;
text-align: center;
}
img {
margin: 0px 0px 10px 0px;
width: 10vw;
height: 10vw;
border: solid 2px black;
border-radius: 50%;
font-size: xxx-large;
}
input {
margin: 0px;
margin: 0px 0px 10px 0px;
width: 100%;
}

View file

@ -1,25 +0,0 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { PopupPictureProfilUrlComponent } from './popup-picture-profil-url.component';
describe('PopupPictureProfilUrlComponent', () => {
let component: PopupPictureProfilUrlComponent;
let fixture: ComponentFixture<PopupPictureProfilUrlComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [ PopupPictureProfilUrlComponent ]
})
.compileComponents();
});
beforeEach(() => {
fixture = TestBed.createComponent(PopupPictureProfilUrlComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

View file

@ -1,28 +0,0 @@
import {Component, Inject, OnInit} from '@angular/core';
import {MAT_DIALOG_DATA, MatDialogRef} from "@angular/material/dialog";
@Component({
selector: 'app-popup-picture-profil-url',
templateUrl: './popup-picture-profil-url.component.html',
styleUrls: ['./popup-picture-profil-url.component.scss']
})
export class PopupPictureProfilUrlComponent implements OnInit
{
profilePictureUrl: string = "" ;
constructor( public dialogRef: MatDialogRef<PopupPictureProfilUrlComponent>,
@Inject(MAT_DIALOG_DATA) public data ) { }
ngOnInit(): void
{
this.profilePictureUrl = this.data.profilePictureUrl;
}
onValider()
{
this.dialogRef.close(this.profilePictureUrl);
}
}

View file

@ -11,6 +11,6 @@ export interface Advert
comment: string,
views: number,
createdAt: Date,
lastUpdate: Date,
updatedAt: Date,
isVisible: boolean,
}

View file

@ -4,7 +4,7 @@ import {Playlist} from "../../interfaces/playlist";
import {Advert} from "../../interfaces/advert";
import {User} from "../../interfaces/user";
// ------------------------------------------------------------------------------------------------------------------------------
const TAB_VIDEO: Video[] = [
{
@ -95,11 +95,11 @@ const TAB_VIDEO: Video[] = [
views: 111,
watched: []
},
]
];
// ------------------------------------------------------------------------------------------------------------------------------
const TAB_ADVERT = [
const TAB_ADVERT: Advert[] = [
{
_id: "idNutella",
title: "pot de nutella XXL",
@ -113,7 +113,7 @@ const TAB_ADVERT = [
comment: "pub pour vacances de noêl",
views: 5,
createdAt: new Date(),
lastUpdate: new Date(),
updatedAt: new Date(),
isVisible: true
},
{
@ -128,13 +128,71 @@ const TAB_ADVERT = [
comment: "pub pour cette année",
views: 2,
createdAt: new Date(),
lastUpdate: new Date(),
updatedAt: new Date(),
isVisible: true
},
]
];
// ------------------------------------------------------------------------------------------------------------------------------
const USER: User = {
_id: "ririId",
login: "Riri",
hashPass: "agourgroou",
mail: "riri@gmail.com",
role: {
name: "user",
permission: 0,
},
profilePictureUrl: "https://www.figurines-goodies.com/1185-thickbox_default/huey-duck-tales-disney-funko-pop.jpg",
dateOfBirth: new Date(),
gender: "man",
interests: ["foot", "jeux-vidéo"],
isActive: true,
isAccepted: true,
createdAt: new Date(),
updatedAt: new Date(),
};
const ADVERTISER: User = {
_id: "fifiId",
login: "Fifi",
hashPass: "agourgroou",
mail: "fifi@gmail.com",
role: {
name: "advertiser",
permission: 5,
},
profilePictureUrl: "https://www.figurines-goodies.com/1188-large_default/dewey-duck-tales-disney-funko-pop.jpg",
dateOfBirth: null,
gender: "",
interests: [],
isActive: true,
isAccepted: true,
createdAt: new Date(),
updatedAt: new Date(),
};
const ADMIN: User = {
_id: "loulouId",
login: "Loulou",
hashPass: "agourgroou",
mail: "loulou@gmail.com",
role: {
name: "admin",
permission: 5,
},
profilePictureUrl: "https://www.reference-gaming.com/assets/media/product/41195/figurine-pop-duck-tales-n-309-loulou.jpg?format=product-cover-large&k=1519639530",
dateOfBirth: null,
gender: "",
interests: [],
isActive: true,
isAccepted: true,
createdAt: new Date(),
updatedAt: new Date(),
};
// ------------------------------------------------------------------------------------------------------------------------------
@Injectable({
providedIn: 'root'
@ -158,6 +216,7 @@ export class FictitiousDatasService
return new Date(start.getTime() + Math.random() * (end.getTime() - start.getTime()));
}
// ------------------------------------------------------------------------------------------------
getVideo(): Video
{
@ -184,6 +243,7 @@ export class FictitiousDatasService
return tabVideo;
}
// ------------------------------------------------------------------------------------------------
getTabPlaylist(nbPlaylist: number, nbVideoMax: number)
{
@ -203,6 +263,7 @@ export class FictitiousDatasService
return tabTabPlaylist
}
// ------------------------------------------------------------------------------------------------
getAdvert(): Advert
{
@ -221,73 +282,52 @@ export class FictitiousDatasService
return tabAdvert;
}
// ------------------------------------------------------------------------------------------------
getUser(): User
private getUserOrAdvertiserOrAdmin(modele: User): User
{
return {
_id: "ririId",
login: "Riri",
hashPass: "agourgroou",
mail: "riri@gmail.com",
role: {
name: "user",
permission: 0,
},
profilePictureUrl: "https://www.figurines-goodies.com/1185-thickbox_default/huey-duck-tales-disney-funko-pop.jpg",
dateOfBirth: new Date(),
gender: "man",
interests: ["foot", "jeux-vidéo"],
isActive: true,
isAccepted: true,
createdAt: new Date(),
updatedAt: new Date(),
}
const res = Object.assign({}, modele);
res._id += this.makeid(5);
res.login += (Math.floor(Math.random() * 1000)).toString();
res.mail = res.login + "@gmail.com" ;
res.isAccepted = (Math.random() < 0.5);
return res;
}
getAdvertiser(): User
{
return {
_id: "fifiId",
login: "Fifi",
hashPass: "agourgroou",
mail: "fifi@gmail.com",
role: {
name: "advertiser",
permission: 5,
},
profilePictureUrl: "https://www.figurines-goodies.com/1188-large_default/dewey-duck-tales-disney-funko-pop.jpg",
dateOfBirth: null,
gender: "",
interests: [],
isActive: true,
isAccepted: true,
createdAt: new Date(),
updatedAt: new Date(),
}
getUser(): User {
return this.getUserOrAdvertiserOrAdmin(USER);
}
getAdmin(): User
{
return {
_id: "loulouId",
login: "Loulou",
hashPass: "agourgroou",
mail: "loulou@gmail.com",
role: {
name: "admin",
permission: 5,
},
profilePictureUrl: "https://www.reference-gaming.com/assets/media/product/41195/figurine-pop-duck-tales-n-309-loulou.jpg?format=product-cover-large&k=1519639530",
dateOfBirth: null,
gender: "",
interests: [],
isActive: true,
isAccepted: true,
createdAt: new Date(),
updatedAt: new Date(),
}
getAdvertiser(): User {
return this.getUserOrAdvertiserOrAdmin(ADVERTISER);
}
getAdmin(): User {
return this.getUserOrAdvertiserOrAdmin(ADMIN);
}
getTabUser(n: number): User[]
{
const res: User[] = [];
for(let i=0 ; i<n ; i++) res.push(this.getUser());
return res;
}
getTabAdvertiser(n: number): User[]
{
const res: User[] = [];
for(let i=0 ; i<n ; i++) res.push(this.getAdvertiser());
return res;
}
getTabAdmin(n: number): User[]
{
const res: User[] = [];
for(let i=0 ; i<n ; i++) res.push(this.getAdmin());
return res;
}
// ------------------------------------------------------------------------------------------------
getTags(): string[]
{