connexion avec back de 'admin/adList'

This commit is contained in:
MiharyR 2021-12-12 13:34:45 +01:00
parent b617af0051
commit fd722f613d
15 changed files with 112 additions and 50 deletions

View file

@ -13,11 +13,12 @@ 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";
export interface AdvertWithCountViewsAndCompany {
_id: string,
id: string,
userId: string,
company: string,
title: string,
@ -46,7 +47,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;
@ -65,19 +66,81 @@ export class PageAdListAdminComponent implements AfterViewInit
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);
for(let advert of tabAdvert) this.tabAdvertWithCountViews.push(this.advertToAdvertWithCountViewsAndCompany(advert));
this.dataSource = new MatTableDataSource<Advert>();
this.onFilter();
*/
// Ask for interest
this.messageService
.get("misc/getInterests")
.subscribe(ret => this.afterReceivingInterests(ret), err => this.afterReceivingInterests(err) );
// Ask for ads
this.messageService
.get("ad/findAll")
.subscribe(ret => this.afterReceivingAds(ret), err => this.afterReceivingAds(err) );
}
afterReceivingAds(retour: any): void
{
console.log("afterReceivingAds");
console.log(retour);
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
{
console.log("afterReceivingAdvertiser");
console.log(retour);
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
{
console.log("afterReceivingInterests");
console.log(retour);
if(retour.status !== "success") {
console.log(retour);
}
else {
this.allInterests = [];
this.allInterests = retour.data.map(x => x.interest);
this.allInterests.sort();
}
}
@ -122,7 +185,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 +250,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,21 @@ 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") {
console.log(retour);
this.dialogRef.close();
}
else {
this.dialogRef.close(true);
}
});
*/
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 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

@ -107,7 +107,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 +171,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

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

@ -33,6 +33,7 @@ export class PopupCreateUserComponent implements OnInit
role: {
name: "",
permission: 0,
isAccepted: false,
},
profileImageUrl: "",
dateOfBirth: null,
@ -40,7 +41,6 @@ export class PopupCreateUserComponent implements OnInit
interests: [],
company: "",
isActive: false,
isAccepted: false,
createdAt: new Date(),
updatedAt: new Date(),
lastConnexion: new Date()

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

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

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