connexion avec back des pages 'advertiser/manageAds' et 'admin/adList'

This commit is contained in:
MiharyR 2021-12-12 19:04:40 +01:00
parent c91fc523aa
commit 0dd39af7ad
8 changed files with 183 additions and 97 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

@ -10,6 +10,7 @@ import {PopupDeleteAdAdminComponent} from "../popup-delete-ad-admin/popup-delete
import {PopupVisualizeImagesAdminComponent} from "../popup-visualize-images-admin/popup-visualize-images-admin.component";
import {FormControl} from "@angular/forms";
import {MessageService} from "../../../utils/services/message/message.service";
import {HttpParams} from "@angular/common/http";
@ -66,8 +67,10 @@ export class PageAdListAdminComponent implements AfterViewInit
ngAfterViewInit(): void
{
// Ask for ads and then for advertiser
let params = new HttpParams();
params = params.append("isActive", true);
this.messageService
.get("ad/findAll")
.get("ad/findAll", params)
.subscribe(ret => this.afterReceivingAds(ret), err => this.afterReceivingAds(err) );
// Ask for interest
@ -79,11 +82,8 @@ export class PageAdListAdminComponent implements AfterViewInit
afterReceivingAds(retour: any): void
{
console.log("afterReceivingAds");
console.log(retour);
if(retour.status !== "success") {
//console.log(retour);
console.log(retour);
}
else {
const tabAdvert = retour.data;
@ -96,11 +96,8 @@ export class PageAdListAdminComponent implements AfterViewInit
afterReceivingAdvertiser(retour: any, tabAdvert): void
{
console.log("afterReceivingAdvertiser");
console.log(retour);
if(retour.status !== "success") {
//console.log(retour);
console.log(retour);
}
else {
this.tabAdvertiser = retour.data.filter(x => x.role.name === "advertiser");
@ -113,14 +110,10 @@ export class PageAdListAdminComponent implements AfterViewInit
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();
}
@ -135,6 +128,8 @@ export class PageAdListAdminComponent implements AfterViewInit
onVisualizeImages(advert: AdvertWithCountViewsAndCompany)
{
if(advert.images.length !== 0)
{
const config = {
width: '30%',
@ -150,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

View file

@ -40,6 +40,8 @@ export class PopupDeleteAdAdminComponent implements OnInit
this.dialogRef.close();
}
else {
console.log("suppr");
console.log(retour);
this.dialogRef.close(true);
}
}

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

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