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

This commit is contained in:
Yûki VACHOT 2021-12-12 20:47:15 +01:00
commit 2b02e13321
23 changed files with 457 additions and 223 deletions

View file

@ -97,9 +97,9 @@
<ng-container matColumnDef="interests">
<th mat-header-cell *matHeaderCellDef> Sujets </th>
<td mat-cell *matCellDef="let advert">
<span *ngFor="let interest of advert.interests; let isLast = last;">
<span *ngIf="!isLast"> {{interest}}, </span>
<span *ngIf="isLast"> {{interest}} </span>
<span *ngFor="let objectInterest of advert.interests; let isLast = last;">
<span *ngIf="!isLast"> {{objectInterest.interest}}, </span>
<span *ngIf="isLast"> {{objectInterest.interest}} </span>
</span>
</td>
</ng-container>

View file

@ -8,16 +8,14 @@ import {MatTableDataSource} from "@angular/material/table";
import {Advert} from "../../../utils/interfaces/advert";
import {PopupDeleteAdAdminComponent} from "../popup-delete-ad-admin/popup-delete-ad-admin.component";
import {PopupVisualizeImagesAdminComponent} from "../popup-visualize-images-admin/popup-visualize-images-admin.component";
import {FictitiousAdvertsService} from "../../../utils/services/fictitiousDatas/fictitiousAdverts/fictitious-adverts.service";
import {FormControl} from "@angular/forms";
import {FictitiousUtilsService} from "../../../utils/services/fictitiousDatas/fictitiousUtils/fictitious-utils.service";
import {User} from "../../../utils/interfaces/user";
import {FictitiousUsersService} from "../../../utils/services/fictitiousDatas/fictitiousUsers/fictitious-users.service";
import {MessageService} from "../../../utils/services/message/message.service";
import {HttpParams} from "@angular/common/http";
export interface AdvertWithCountViewsAndCompany {
_id: string,
id: string,
userId: string,
company: string,
title: string,
@ -46,7 +44,7 @@ export interface AdvertWithCountViewsAndCompany {
export class PageAdListAdminComponent implements AfterViewInit
{
tabAdvertWithCountViews: AdvertWithCountViewsAndCompany[] = [];
tabAdvertiser: User[];
tabAdvertiser: any[];
displayedColumns: string[] = [ 'title', 'company', 'interests', 'createdAt', 'updatedAt', 'countViews', 'isVisible', 'actions' ];
dataSource ;
@ViewChild(MatSort) sort: MatSort;
@ -61,24 +59,65 @@ export class PageAdListAdminComponent implements AfterViewInit
constructor( public themeService: ThemeService,
private fictitiousAdvertsService: FictitiousAdvertsService,
private fictitiousUtilsService: FictitiousUtilsService,
private fictitiousUsersService: FictitiousUsersService,
public dialog: MatDialog,
private snackBar: MatSnackBar ) { }
private snackBar: MatSnackBar,
private messageService: MessageService) { }
ngAfterViewInit(): void
{
// --- FAUX CODE ---
const tabAdvert = this.fictitiousAdvertsService.getTabAdvert(8);
this.allInterests = this.fictitiousUtilsService.getTags();
this.tabAdvertiser = this.fictitiousUsersService.getTabAdvertiser(3);
// Ask for ads and then for advertiser
let params = new HttpParams();
params = params.append("isActive", true);
this.messageService
.get("ad/findAll", params)
.subscribe(ret => this.afterReceivingAds(ret), err => this.afterReceivingAds(err) );
// Ask for interest
this.messageService
.get("misc/getInterests")
.subscribe(ret => this.afterReceivingInterests(ret), err => this.afterReceivingInterests(err) );
}
afterReceivingAds(retour: any): void
{
if(retour.status !== "success") {
console.log(retour);
}
else {
const tabAdvert = retour.data;
this.messageService
.get("user/findAll")
.subscribe(ret => this.afterReceivingAdvertiser(ret, tabAdvert), err => this.afterReceivingAdvertiser(err, tabAdvert) );
}
}
afterReceivingAdvertiser(retour: any, tabAdvert): void
{
if(retour.status !== "success") {
console.log(retour);
}
else {
this.tabAdvertiser = retour.data.filter(x => x.role.name === "advertiser");
for(let advert of tabAdvert) this.tabAdvertWithCountViews.push(this.advertToAdvertWithCountViewsAndCompany(advert));
this.dataSource = new MatTableDataSource<Advert>();
this.onFilter();
}
}
afterReceivingInterests(retour: any): void
{
if(retour.status !== "success") {
console.log(retour);
}
else {
this.allInterests = retour.data.map(x => x.interest);
this.allInterests.sort();
}
}
applyFilter(event: Event): void
@ -89,6 +128,8 @@ export class PageAdListAdminComponent implements AfterViewInit
onVisualizeImages(advert: AdvertWithCountViewsAndCompany)
{
if(advert.images.length !== 0)
{
const config = {
width: '30%',
@ -104,6 +145,12 @@ export class PageAdListAdminComponent implements AfterViewInit
.afterClosed()
.subscribe(retour => {});
}
else {
const config = { duration: 2000, panelClass: "custom-class" };
const message = "Cette annonce ne contient aucune image" ;
this.snackBar.open( message, "", config);
}
}
onDelete(advert: AdvertWithCountViewsAndCompany): void
@ -122,7 +169,7 @@ export class PageAdListAdminComponent implements AfterViewInit
message = "Opération annulée" ;
}
else {
const index = this.dataSource.data.findIndex( elt => (elt._id === advert._id));
const index = this.dataSource.data.findIndex( elt => (elt.id === advert.id));
this.dataSource.data.splice(index, 1);
this.dataSource.data = this.dataSource.data;
this.dataSource = this.dataSource;
@ -187,19 +234,19 @@ export class PageAdListAdminComponent implements AfterViewInit
}
advertToAdvertWithCountViewsAndCompany(advert: Advert): AdvertWithCountViewsAndCompany
advertToAdvertWithCountViewsAndCompany(advert): AdvertWithCountViewsAndCompany
{
let company0 = "company" ;
for(let advertiser of this.tabAdvertiser)
{
if(advert.userId === advertiser._id) {
if(advert.userId === advertiser.id) {
company0 = advertiser.company;
break;
}
}
return {
_id: advert._id,
id: advert.id,
userId: advert.userId,
title: advert.title,
company: company0,

View file

@ -1,5 +1,4 @@
import {Component, Inject, OnInit} from '@angular/core';
import {Advert} from "../../../utils/interfaces/advert";
import {MAT_DIALOG_DATA, MatDialogRef} from "@angular/material/dialog";
import {MessageService} from "../../../utils/services/message/message.service";
@ -12,7 +11,7 @@ import {MessageService} from "../../../utils/services/message/message.service";
})
export class PopupDeleteAdAdminComponent implements OnInit
{
advert: Advert;
advert: any;
constructor( public dialogRef: MatDialogRef<PopupDeleteAdAdminComponent>,
@ -28,24 +27,23 @@ export class PopupDeleteAdAdminComponent implements OnInit
onValidate(): void
{
// --- FAUX CODE ---
this.dialogRef.close(true);
// --- VRAI CODE ---
/*
this.messageService
.sendMessage("url/delete/ad", {"advert": this.advert})
.subscribe( retour => {
.delete("ad/delete/"+this.advert.id)
.subscribe(ret => this.onValidateCallback(ret), err => this.onValidateCallback(err));
}
if(retour.status === "error") {
onValidateCallback(retour: any): void
{
if(retour.status !== "success") {
console.log(retour);
this.dialogRef.close();
}
else {
console.log("suppr");
console.log(retour);
this.dialogRef.close(true);
}
});
*/
}
}

View file

@ -24,14 +24,14 @@ export class PageProfilAdminComponent implements OnInit
role: {
name: "admin",
permission: 10,
isAccepted: true,
},
profileImageUrl: "",
dateOfBirth: null,
gender: "man",
interests: [],
company: "",
isActive: false,
isAccepted: false,
isActive: true,
createdAt: new Date(),
updatedAt: new Date(),
lastConnexion: null

View file

@ -38,6 +38,7 @@ export class PopupUpdateAdminComponent implements OnInit
role: {
name: admin0.role.name,
permission: admin0.role.permission,
isAccepted: admin0.role.isAccepted,
},
profileImageUrl: admin0.profileImageUrl,
dateOfBirth: admin0.dateOfBirth,
@ -45,7 +46,6 @@ export class PopupUpdateAdminComponent implements OnInit
interests: [],
company: "",
isActive: admin0.isActive,
isAccepted: admin0.isisAccepted,
createdAt: admin0.createdAt,
updatedAt: admin0.updatedAt,
lastConnexion: admin0.lastConnexion

View file

@ -93,7 +93,8 @@
<mat-icon>power_settings_new</mat-icon>
</th>
<td mat-cell *matCellDef="let user">
<mat-slide-toggle [(ngModel)]="user.isActive" (click)="onSliderIsActive(user)"></mat-slide-toggle>
<mat-slide-toggle *ngIf="user.role.name !== 'superAdmin'" [(ngModel)]="user.isActive" (click)="onSliderIsActive(user)"></mat-slide-toggle>
<mat-slide-toggle *ngIf="user.role.name === 'superAdmin'" [(ngModel)]="user.isActive" disabled></mat-slide-toggle>
</td>
</ng-container>
@ -107,7 +108,7 @@
<!-- Mail Column -->
<ng-container matColumnDef="email">
<th mat-header-cell *matHeaderCellDef mat-sort-header> Mail </th>
<th mat-header-cell *matHeaderCellDef mat-sort-header> Email </th>
<td mat-cell *matCellDef="let user">
{{user.email}}
</td>
@ -171,7 +172,7 @@
<ng-container matColumnDef="isAccepted">
<th mat-header-cell *matHeaderCellDef mat-sort-header> Accepté </th>
<td mat-cell *matCellDef="let user">
<mat-slide-toggle [(ngModel)]="user.isAccepted" (click)="onSlideIsAccepted(user)"></mat-slide-toggle>
<mat-slide-toggle [(ngModel)]="user.role.isAccepted" (click)="onSlideIsAccepted(user)"></mat-slide-toggle>
</td>
</ng-container>

View file

@ -5,10 +5,9 @@ import {ThemeService} from "../../../utils/services/theme/theme.service";
import {MatDialog} from "@angular/material/dialog";
import {MatSnackBar} from "@angular/material/snack-bar";
import {MatTableDataSource} from "@angular/material/table";
import {User} from "../../../utils/interfaces/user";
import {PopupDeleteUserComponent} from "../popup-delete-user/popup-delete-user.component";
import {PopupCreateUserComponent} from "../popup-create-user/popup-create-user.component";
import {FictitiousUsersService} from "../../../utils/services/fictitiousDatas/fictitiousUsers/fictitious-users.service";
import {MessageService} from "../../../utils/services/message/message.service";
@ -25,8 +24,8 @@ export class PageUserListComponent implements AfterViewInit
displayedColumnsAdmin: string[] = [ 'isActive', 'login', 'email', 'createdAt', 'lastConnexion' ];
tabUser: any[] = [];
tabAdvertiser: User[] = [];
tabAdmin: User[] = [];
tabAdvertiser: any[] = [];
tabAdmin: any[] = [];
roleName: string = "user" ;
dataSource ;
@ -40,22 +39,37 @@ export class PageUserListComponent implements AfterViewInit
constructor( public themeService: ThemeService,
private fictitiousUsersService: FictitiousUsersService,
public dialog: MatDialog,
private snackBar: MatSnackBar ) { }
private snackBar: MatSnackBar,
private messageService: MessageService ) { }
ngAfterViewInit(): void
{
// --- FAUX CODE ---
this.tabUser = this.fictitiousUsersService.getTabUser(32);
this.tabAdvertiser = this.fictitiousUsersService.getTabAdvertiser(8);
this.tabAdmin = this.fictitiousUsersService.getTabAdmin(4);
this.messageService
.get("user/findAll")
.subscribe(ret => this.ngAfterViewInitCallback(ret), err => this.ngAfterViewInitCallback(err));
}
for(const user of this.tabUser) user.age = this.getAge(user.dateOfBirth);
ngAfterViewInitCallback(retour: any): void
{
if(retour.status !== "success") {
console.log(retour);
}
else {
for(let person of retour.data)
{
if(person.role.name === "user") {
person["age"] = this.getAge(person.dateOfBirth);
this.tabUser.push(person);
}
else if(person.role.name === "advertiser") this.tabAdvertiser.push(person);
else this.tabAdmin.push(person);
}
this.onFilter();
}
}
applyFilter(event: Event): void
@ -65,7 +79,7 @@ export class PageUserListComponent implements AfterViewInit
}
onDelete(user: User): void
onDelete(user: any): void
{
const config = {
data: { user: user }
@ -81,13 +95,13 @@ export class PageUserListComponent implements AfterViewInit
message = "Opération annulée" ;
}
else {
const index = this.dataSource.data.findIndex( elt => (elt._id === user._id));
const index = this.dataSource.data.findIndex( elt => (elt.id === user.id));
this.dataSource.data.splice(index, 1);
this.dataSource.data = this.dataSource.data;
this.dataSource = this.dataSource;
message = user.login + " a bien été supprimée ✔" ;
}
this.snackBar.open( message, "", config);
this.snackBar.open(message, "", config);
});
}
@ -106,20 +120,47 @@ export class PageUserListComponent implements AfterViewInit
}
else {
this.snackBar.open( "L'utilisateur a bien été créé", "", config);
if(retour.role.name === "user") this.tabUser.push(retour);
else if(retour.role.name === "advertiser") this.tabAdvertiser.push(retour);
else if(retour.role.name === "admin") this.tabAdmin.push(retour);
this.onFilter();
}
});
}
onSliderIsActive(user: User): void
onSliderIsActive(user: any): void
{
// il faut envoyer la négation de user.isActive
this.messageService
.put("user/update/"+user.id, { isActive: !user.isActive })
.subscribe(
ret => {},
err => {
console.log("onSliderIsActive");
console.log(err);
}
);
}
onSlideIsAccepted(user: User): void
onSlideIsAccepted(user: any): void
{
// il faut envoyer la négation de user.isActive
// il faut envoyer la négation de user.role.isAccepted
const role0 = {
name: user.role.name,
permission: user.role.permission,
isAccepted: !user.role.isAccepted,
};
this.messageService
.put("user/update/"+user.id, {role: role0})
.subscribe(
ret => {},
err => {
console.log("onSlideIsAccepted");
console.log(err);
}
);
}
@ -127,7 +168,7 @@ export class PageUserListComponent implements AfterViewInit
{
if((date === null) || (date === undefined)) return -1;
else {
const diff = Date.now() - date.getTime();
const diff = Date.now() - (new Date(date)).getTime();
const age = new Date(diff);
return Math.abs(age.getUTCFullYear() - 1970);
}

View file

@ -126,12 +126,12 @@
<!-- email -->
<mat-form-field appearance="fill">
<mat-label>Email</mat-label>
<input matInput type="text" [(ngModel)]="user.email">
<input matInput type="text" [(ngModel)]="user.email" required>
</mat-form-field><br>
<!-- login -->
<mat-form-field appearance="fill">
<mat-label>Pseudo</mat-label>
<input matInput type="text" [(ngModel)]="user.login">
<input matInput type="text" [(ngModel)]="user.login" required>
</mat-form-field><br>
<!-- company -->
<mat-form-field appearance="fill" *ngIf="user.role.name === 'advertiser'">
@ -145,12 +145,12 @@
<!-- mot de passe -->
<mat-form-field appearance="fill">
<mat-label>Mot de passe</mat-label>
<input matInput type="password" [(ngModel)]="password">
<input matInput type="password" [(ngModel)]="password" required>
</mat-form-field><br>
<!-- confirmation mot de passe -->
<mat-form-field appearance="fill">
<mat-label>Confirmation nouveau mot de passe</mat-label>
<input matInput type="password" [(ngModel)]="confirmPassword">
<input matInput type="password" [(ngModel)]="confirmPassword" required>
</mat-form-field>
</div>

View file

@ -1,6 +1,6 @@
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";
@ -11,7 +11,7 @@ import {User} from "../../../utils/interfaces/user";
})
export class PopupCreateUserComponent implements OnInit
{
user: User;
user: any;
hasError: boolean = false;
errorMessage: string = "";
password: string = "";
@ -19,7 +19,8 @@ export class PopupCreateUserComponent implements OnInit
constructor( public dialogRef: MatDialogRef<PopupCreateUserComponent>,
@Inject(MAT_DIALOG_DATA) public data ) { }
@Inject(MAT_DIALOG_DATA) public data,
private messageService: MessageService ) { }
// Initialise l'utilisateur qui va être créé
@ -33,6 +34,7 @@ export class PopupCreateUserComponent implements OnInit
role: {
name: "",
permission: 0,
isAccepted: false,
},
profileImageUrl: "",
dateOfBirth: null,
@ -40,7 +42,6 @@ export class PopupCreateUserComponent implements OnInit
interests: [],
company: "",
isActive: false,
isAccepted: false,
createdAt: new Date(),
updatedAt: new Date(),
lastConnexion: new Date()
@ -52,12 +53,25 @@ export class PopupCreateUserComponent implements OnInit
onEnregistrer(): void
{
this.checkField();
if(!this.hasError)
{
this.user.hashPass = this.hashage(this.password);
this.dialogRef.close(this.user);
// VRAI CODE ...
this.user.hashPass = this.password;
this.user.role = this.user.role.name;
this.messageService
.post("user/create", this.user)
.subscribe(ret => this.onEnregistrerCallback(ret), err => this.onEnregistrerCallback(err));
}
}
// Callback de 'onEnregistrer'
onEnregistrerCallback(retour: any): void
{
if(retour.status !== "success") {
console.log(retour);
}
else {
this.dialogRef.close(retour.data);
}
}
@ -110,17 +124,4 @@ export class PopupCreateUserComponent implements OnInit
this.user.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

@ -38,10 +38,19 @@ export class InputInterestsAdComponent implements OnInit
startWith(null),
map((fruit: string | null) => fruit ? this._filter(fruit) : this.allTags.slice()));
// --- FAUX CODE ---
this.allTags = this.fictitiousUtilsService.getTags();
this.messageService
.get("misc/getInterests")
.subscribe( retour => {
if(retour.status !== "success") {
console.log(retour);
}
else {
this.allTags = retour.data.map(x => x.interest)
this.allTags.sort();
}
});
}
add(event: MatChipInputEvent): void

View file

@ -12,6 +12,8 @@ import {PopupVisualizeImagesAdvertiserComponent} from "../popup-visualize-images
import {FictitiousAdvertsService} from "../../../utils/services/fictitiousDatas/fictitiousAdverts/fictitious-adverts.service";
import {FormControl} from "@angular/forms";
import {FictitiousUtilsService} from "../../../utils/services/fictitiousDatas/fictitiousUtils/fictitious-utils.service";
import {MessageService} from "../../../utils/services/message/message.service";
import {HttpParams} from "@angular/common/http";
@ -24,7 +26,7 @@ export class PageAdListAdvertiserComponent implements AfterViewInit
{
displayedColumns: string[] = [ 'isVisible', 'title', 'interests', 'createdAt', 'updatedAt', 'countViews', 'actions' ];
tabAdvertWithCountViews: AdvertWithCountViews[] = [];
dataSource ;
dataSource;
@ViewChild(MatSort) sort: MatSort;
@ViewChild(MatPaginator) paginator: MatPaginator;
@ -33,6 +35,8 @@ export class PageAdListAdvertiserComponent implements AfterViewInit
startDate: Date = null;
endDate: Date = null;
formControlInterests = new FormControl();
allVideoCategorie = [];
allInterests: string[] = [];
@ -40,19 +44,51 @@ export class PageAdListAdvertiserComponent implements AfterViewInit
private fictitiousAdvertsService: FictitiousAdvertsService,
private fictitiousUtilsService: FictitiousUtilsService,
public dialog: MatDialog,
private snackBar: MatSnackBar ) { }
private snackBar: MatSnackBar,
private messageService: MessageService ) { }
ngAfterViewInit(): void
{
// --- FAUX CODE ---
const tabAdvert = this.fictitiousAdvertsService.getTabAdvert(8);
this.allInterests = this.fictitiousUtilsService.getTags();
// Ask interests
this.messageService
.get("misc/getInterests")
.subscribe(ret => this.afterReceivingInterests(ret), err => this.afterReceivingInterests(err) );
for(let advert of tabAdvert) this.tabAdvertWithCountViews.push(this.advertToAdvertWithCountViews(advert));
this.dataSource = new MatTableDataSource<Advert>();
// Ask ads
let params = new HttpParams();
params = params.append("isActive", true);
this.messageService
.get("ad/findAll", params)
.subscribe(ret => this.afterReceivingAds(ret), err => this.afterReceivingAds(err));
}
afterReceivingInterests(retour: any): void
{
if(retour.status !== "success") {
console.log("afterReceivingInterests");
console.log(retour);
}
else {
this.allVideoCategorie = retour.data;
this.allInterests = retour.data.map(x => x.interest);
this.allInterests.sort();
}
}
afterReceivingAds(retour: any): void
{
if(retour.status !== "success") {
console.log(retour);
}
else {
for(let advert of retour.data) this.tabAdvertWithCountViews.push(this.advertToAdvertWithCountViews(advert));
this.dataSource = new MatTableDataSource<AdvertWithCountViews>();
this.onFilter();
}
}
applyFilter(event: Event): void
@ -86,7 +122,7 @@ export class PageAdListAdvertiserComponent implements AfterViewInit
width: '75%',
height: '80%',
panelClass: 'custom-dialog-container',
data: { action: "add", advert: null }
data: { action: "add", advert: null, allVideoCategorie: this.allVideoCategorie }
};
this.dialog
.open(PopupAddOrUpdateAdComponent, config)
@ -99,10 +135,9 @@ export class PageAdListAdvertiserComponent implements AfterViewInit
message = "Opération annulée" ;
}
else {
this.dataSource.data.push(advertAdded);
this.dataSource.data = this.dataSource.data;
this.dataSource = this.dataSource;
message = "L'annoonce a bien été ajoutée ✔"
this.tabAdvertWithCountViews.push(this.advertToAdvertWithCountViews(advertAdded));
this.onFilter();
message = "L'annoonce a bien été ajoutée ✔" ;
}
this.snackBar.open( message, "", config);
});
@ -115,7 +150,7 @@ export class PageAdListAdvertiserComponent implements AfterViewInit
width: '75%',
height: '80%',
panelClass: 'custom-dialog-container',
data: { action: "update", advert: advertToUpdate }
data: { action: "update", advert: advertToUpdate, allVideoCategorie: this.allVideoCategorie }
};
this.dialog
.open(PopupAddOrUpdateAdComponent, config)
@ -128,11 +163,10 @@ export class PageAdListAdvertiserComponent implements AfterViewInit
message = "Opération annulée" ;
}
else {
const index = this.dataSource.data.findIndex( elt => (elt._id === advertToUpdate._id));
this.dataSource.data.splice(index, 1, advertUpdated);
this.dataSource.data = this.dataSource.data;
this.dataSource = this.dataSource;
message = "L'annonce a bien été modifiée ✔"
const index = this.tabAdvertWithCountViews.findIndex(elt => (elt.id === advertToUpdate.id));
this.tabAdvertWithCountViews.splice(index, 1, this.advertToAdvertWithCountViews(advertUpdated));
this.onFilter();
message = "L'annonce a bien été modifiée ✔" ;
}
this.snackBar.open( message, "", config);
});
@ -155,7 +189,7 @@ export class PageAdListAdvertiserComponent implements AfterViewInit
message = "Opération annulée" ;
}
else {
const index = this.dataSource.data.findIndex( elt => (elt._id === advert._id));
const index = this.dataSource.data.findIndex( elt => (elt.id === advert.id));
this.dataSource.data.splice(index, 1);
this.dataSource.data = this.dataSource.data;
this.dataSource = this.dataSource;
@ -168,6 +202,7 @@ export class PageAdListAdvertiserComponent implements AfterViewInit
onFilter(): void
{
if(this.dataSource === null || this.dataSource === undefined) this.dataSource = new MatTableDataSource();
this.dataSource.data = [];
for(let advert of this.tabAdvertWithCountViews)
{
@ -220,21 +255,30 @@ export class PageAdListAdvertiserComponent implements AfterViewInit
}
onSliderIsVisible(advert: Advert): void
onSliderIsVisible(advert: any): void
{
// il faut envoyer la négation de user.isActive
this.messageService
.put("ad/update/"+advert.id, { isVisible: !advert.isVisible })
.subscribe(
ret => {},
err => {
console.log("onSliderIsVisible");
console.log(err);
}
);
}
advertToAdvertWithCountViews(advert: Advert): AdvertWithCountViews
advertToAdvertWithCountViews(advert): AdvertWithCountViews
{
return {
_id: advert._id,
id: advert.id,
userId: advert.userId,
title: advert.title,
url: advert.url,
images: advert.images,
interests: advert.interests,
interests: advert.interests.map(x => x.interest),
comment: advert.comment,
views: advert.views,
countViews: advert.views.length,

View file

@ -28,9 +28,9 @@ const ADVERT_VIDE: Advert = {
})
export class PopupAddOrUpdateAdComponent implements OnInit
{
advert: Advert;
urlBackend: string = "" ;
advert: any;
title: string = "" ;
allVideoCategorie = [];
tabWaitingFile: File[] = []; // fichiers selectionnés mais pas encore "validés"
tabSelectedFile: File[] = []; // fichier "validés"
_event;
@ -44,18 +44,17 @@ export class PopupAddOrUpdateAdComponent implements OnInit
ngOnInit(): void
{
this.allVideoCategorie = this.data.allVideoCategorie
if(this.data.action === "add")
{
this.advert = Object.assign({}, ADVERT_VIDE);
this.advert.interests = [];
this.urlBackend = "url/add/ad" ;
this.title = "Ajouter annonce" ;
}
else
{
this.advert = Object.assign({}, this.data.advert);
this.advert.interests = this.data.advert.interests.slice();
this.urlBackend = "url/update/ad" ;
this.title = "Modifier annonce" ;
}
}
@ -63,24 +62,59 @@ export class PopupAddOrUpdateAdComponent implements OnInit
onValidate(): void
{
// --- FAUX CODE ---
this.dialogRef.close(this.advert);
// On transforme 'this.user.interests' en tableau de 'videoCategorie'
let interests = []; // tableau de videoCategorie
for(let interest of this.advert.interests)
{
for(let videoCategorie of this.allVideoCategorie)
{
if(videoCategorie.interest === interest) {
interests.push(videoCategorie);
break;
}
}
}
this.advert.interests = interests;
// --- VRAI CODE ---
/*
if(this.data.action === "add")
{
this.messageService
.sendMessage(this.urlBackend, this.advert)
.subscribe( retour => {
if(retour.status === "error") {
console.log(retour);
this.dialogRef.close(this.advert);
.post("ad/create", this.advert)
.subscribe(ret => this.onCreateCallback(ret), err => this.onCreateCallback(err));
}
else {
this.dialogRef.close(retour.data.advert);
const id = this.advert.id;
Reflect.deleteProperty(this.advert, "id");
Reflect.deleteProperty(this.advert, "_id");
this.messageService
.put("ad/update/"+id, this.advert)
.subscribe(ret => this.onUpdateCallback(ret,id), err => this.onUpdateCallback(err,id));
}
}
onCreateCallback(retour: any): void
{
if(retour.status !== "success") {
console.log(retour);
this.dialogRef.close();
}
else {
this.dialogRef.close(retour.data);
}
}
onUpdateCallback(retour: any, id: string): void
{
if(retour.status !== "success") {
console.log(retour);
this.dialogRef.close();
}
else {
this.advert.id = id;
this.dialogRef.close(this.advert);
}
});
*/
}

View file

@ -1,7 +1,6 @@
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 {Advert} from "../../../utils/interfaces/advert";
@ -12,7 +11,7 @@ import {Advert} from "../../../utils/interfaces/advert";
})
export class PopupDeleteAdAdvertiserComponent implements OnInit
{
advert: Advert;
advert: any;
constructor( public dialogRef: MatDialogRef<PopupDeleteAdAdvertiserComponent>,
@ -28,24 +27,21 @@ export class PopupDeleteAdAdvertiserComponent implements OnInit
onValidate(): void
{
// --- FAUX CODE ---
this.dialogRef.close(true);
// --- VRAI CODE ---
/*
this.messageService
.sendMessage("url/delete/ad", {"advert": this.advert})
.subscribe( retour => {
.delete("ad/delete/"+this.advert.id)
.subscribe(ret => this.onValidateCallback(ret), err => this.onValidateCallback(err));
}
if(retour.status === "error") {
onValidateCallback(retour: any): void
{
if(retour.status !== "success") {
console.log(retour);
this.dialogRef.close();
}
else {
this.dialogRef.close(true);
}
});
*/
}
}

View file

@ -24,14 +24,14 @@ export class PageProfilAdvertiserComponent implements OnInit
role: {
name: "advertiser",
permission: 5,
isAccepted: true,
},
profileImageUrl: "",
dateOfBirth: null,
gender: "man",
interests: [],
company: "",
isActive: false,
isAccepted: false,
isActive: true,
createdAt: new Date(),
updatedAt: new Date(),
lastConnexion: null

View file

@ -38,6 +38,7 @@ export class PopupUpdateAdvertiserComponent implements OnInit
role: {
name: advertiser0.role.name,
permission: advertiser0.role.permission,
isAccepted: advertiser0.role.isAccepted,
},
profileImageUrl: advertiser0.profileImageUrl,
dateOfBirth: advertiser0.dateOfBirth,
@ -45,7 +46,6 @@ export class PopupUpdateAdvertiserComponent implements OnInit
interests: [],
company: advertiser0.company,
isActive: advertiser0.isActive,
isAccepted: advertiser0.isAccepted,
createdAt: advertiser0.createdAt,
updatedAt: advertiser0.updatedAt,
lastConnexion: new Date()

View file

@ -6,6 +6,8 @@ import { Router} from "@angular/router";
import {FictitiousAdvertsService} from "../../utils/services/fictitiousDatas/fictitiousAdverts/fictitious-adverts.service";
import {FictitiousVideosService} from "../../utils/services/fictitiousDatas/fictitiousVideos/fictitious-videos.service";
import {ThemeService} from "../../utils/services/theme/theme.service";
import {MessageService} from "../../utils/services/message/message.service";
import {HttpParams} from "@angular/common/http";
@ -26,6 +28,8 @@ export class PagesPopularityComponent implements OnInit
formControl: FormControl;
allCoupleNameViews: CoupleNameViews[] = [];
allInterests: string[] = [];
startDate: Date = null;
endDate: Date = null;
step: number = 1;
@ -48,38 +52,80 @@ export class PagesPopularityComponent implements OnInit
constructor( private router: Router,
public themeService: ThemeService,
private fictitiousAdvertsService: FictitiousAdvertsService,
private fictitiousVideosService: FictitiousVideosService ) {}
private fictitiousVideosService: FictitiousVideosService,
private messageService: MessageService ) {}
// -----------------------------------------------------------------------------------------------------
ngOnInit(): void
{
if(this.router.url.includes("ads")) this.ngOnInitAds();
else if(this.router.url.includes("subjects")) this.ngOnInitSubjects();
this.formControl = new FormControl(this.allCoupleNameViews);
this.onApplyFilter();
// Sera excuté si on est sur la page 'adsPopularity'
// Remplie l'attribut 'allCoupleNameViews'
if(this.router.url.includes("ads"))
{
let params = new HttpParams();
params = params.append("isActive", true);
this.messageService
.get("ad/findAll", params )
.subscribe(ret => this.afterReceivingAds(ret), err => this.afterReceivingAds(err));
}
// Sera excuté si on est sur la page 'subjectsPopularity'
// Remplie l'attribut 'allCoupleNameViews'
else if(this.router.url.includes("subjects"))
{
this.messageService
.get("misc/getInterests")
.subscribe( retour => {
if(retour.status !== "success") {
console.log(retour);
}
else {
this.allInterests = retour.data.map(x => x.interest);
this.allInterests.sort();
this.messageService
.get("video/findAll")
.subscribe(ret => this.afterReceivingVideos(ret), err => this.afterReceivingVideos(err));
}
});
}
}
// Sera excuté si on est sur la page 'adsPopularity'
// Remplie l'attribut 'allCoupleNameViews'
ngOnInitAds(): void
// Callback: Sera excuté si on est sur la page 'adsPopularity'
afterReceivingAds(retour: any): void
{
const allAdverts = this.fictitiousAdvertsService.get_TAB_ADVERT();
if(retour.status !== "success") {
console.log(retour);
}
else {
const allAdverts = retour.data;
for(let advert of allAdverts)
{
let couple = {name: advert.title, views: advert.views }
this.allCoupleNameViews.push(couple);
}
this.formControl = new FormControl(this.allCoupleNameViews);
this.onApplyFilter();
}
}
// Sera excuté si on est sur la page 'subjectsPopularity'
// Remplie l'attribut 'allCoupleNameViews'
ngOnInitSubjects(): void
// Callback: Sera excuté si on est sur la page 'subjectsPopularity'
afterReceivingVideos(retour: any): void
{
const allVideos = this.fictitiousVideosService.get_TAB_VIDEO();
if(retour.status !== "success") {
console.log(retour);
}
else {
const allVideos = retour.data;
let myMap: Map<string,Date[]> = new Map();
// parcours des interest de chaque video
for(let video of allVideos)
{
const key = video.interest;
@ -91,12 +137,26 @@ export class PagesPopularityComponent implements OnInit
}
}
// parcours les interest qui n'ont pas p été vu dans les videos
for(let interest of this.allInterests)
{
if(!myMap.has(interest)) myMap.set(interest, []);
}
// parcours de la map pour remplir 'allCoupleNameViews'
for(const [key, value] of myMap.entries())
{
let couple = {name: key, views: value }
this.allCoupleNameViews.push(couple);
}
this.formControl = new FormControl(this.allCoupleNameViews);
this.onApplyFilter();
}
}
// -----------------------------------------------------------------------------------------------------
// Applique le filtre
@ -137,7 +197,7 @@ export class PagesPopularityComponent implements OnInit
for(let date0 of coupleNameViews.views)
{
const time0 = date0.getTime();
const time0 = (new Date(date0)).getTime();
if(time0 > endTime) break;
@ -172,7 +232,7 @@ export class PagesPopularityComponent implements OnInit
return date0.toLocaleDateString();
}
else {
const time2 = this.addStep(date0.getTime()) - this.oneDay;
const time2 = this.addStep((new Date(date0)).getTime()) - this.oneDay;
let date2 = new Date(time2);
return date0.toLocaleDateString() + " à " + date2.toLocaleDateString();
}

View file

@ -27,14 +27,14 @@ export class PageRegisterComponent
role: {
name: "user",
permission: 0,
isAccepted: false,
},
profileImageUrl: "",
dateOfBirth: null,
gender: "man",
interests: [],
company: "",
isActive: false,
isAccepted: false,
isActive: true,
createdAt: new Date(),
updatedAt: new Date(),
lastConnexion: null

View file

@ -16,7 +16,7 @@
</mat-chip>
<input
placeholder="Tapez un centre d'intérêt"
placeholder="Tapez centres d'intérêt"
#tagInput
[formControl]="formControl"
[matAutocomplete]="auto"

View file

@ -24,14 +24,14 @@ export class PageProfilUserComponent implements OnInit
role: {
name: "user",
permission: 0,
isAccepted: false,
},
profileImageUrl: "",
dateOfBirth: null,
gender: "man",
interests: [],
company: "",
isActive: false,
isAccepted: false,
isActive: true,
createdAt: new Date(),
updatedAt: new Date(),
lastConnexion: null

View file

@ -38,6 +38,7 @@ export class PopupUpdateUserComponent implements OnInit
role: {
name: user0.role.name,
permission: user0.role.permission,
isAccepted: user0.role.isAccepted,
},
profileImageUrl: user0.profileImageUrl,
dateOfBirth: user0.dateOfBirth,
@ -45,7 +46,6 @@ export class PopupUpdateUserComponent implements OnInit
interests: [],
company: "",
isActive: user0.isActive,
isAccepted: user0.isAccepted,
createdAt: user0.createdAt,
updatedAt: user0.updatedAt,
lastConnexion: new Date()

View file

@ -20,7 +20,7 @@ export interface Advert
export interface AdvertWithCountViews {
_id: string,
id: string,
userId: string,
title: string,
url: string,

View file

@ -7,6 +7,7 @@ export interface User
role: {
name: string,
permission: number,
isAccepted: boolean,
},
profileImageUrl: string,
dateOfBirth: Date,
@ -14,7 +15,6 @@ export interface User
interests: any[],
company: string,
isActive: boolean,
isAccepted: boolean,
lastConnexion: Date,
createdAt: Date,
updatedAt: Date

View file

@ -12,6 +12,8 @@ const USER: User = {
role: {
name: "user",
permission: 0,
isAccepted: true,
},
profileImageUrl: "https://www.figurines-goodies.com/1185-thickbox_default/huey-duck-tales-disney-funko-pop.jpg",
dateOfBirth: new Date(),
@ -19,7 +21,6 @@ const USER: User = {
interests: ["foot", "jeux-vidéo"],
company: "",
isActive: true,
isAccepted: true,
lastConnexion: new Date(),
createdAt: new Date(),
updatedAt: new Date()
@ -33,6 +34,8 @@ const ADVERTISER: User = {
role: {
name: "advertiser",
permission: 5,
isAccepted: true,
},
profileImageUrl: "https://www.figurines-goodies.com/1188-large_default/dewey-duck-tales-disney-funko-pop.jpg",
dateOfBirth: null,
@ -40,7 +43,6 @@ const ADVERTISER: User = {
interests: [],
company: "My company",
isActive: true,
isAccepted: true,
lastConnexion: new Date(),
createdAt: new Date(),
updatedAt: new Date(),
@ -54,6 +56,7 @@ const ADMIN: User = {
role: {
name: "admin",
permission: 5,
isAccepted: true,
},
profileImageUrl: "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,
@ -61,7 +64,6 @@ const ADMIN: User = {
interests: [],
company: "",
isActive: true,
isAccepted: true,
lastConnexion: new Date(),
createdAt: new Date(),
updatedAt: new Date(),
@ -83,7 +85,7 @@ export class FictitiousUsersService
res._id += this.fictitiousUtilsService.makeid(5);
res.login += (Math.floor(Math.random() * 1000)).toString();
res.email = res.login + "@gmail.com" ;
res.isAccepted = (Math.random() < 0.5);
res.role.isAccepted = (Math.random() < 0.5);
res.isActive = (Math.random() < 0.5);
res.dateOfBirth = this.fictitiousUtilsService.randomDate(new Date(1900, 0, 1), new Date());
res.lastConnexion = this.fictitiousUtilsService.randomDate(new Date(2000, 0, 1), new Date());
@ -122,4 +124,5 @@ export class FictitiousUsersService
for(let i=0 ; i<n ; i++) res.push(this.getAdmin());
return res;
}
}