connexion avec back des pages 'advertiser/adsPopularity' et 'advertiser/subjectsPopularity'
This commit is contained in:
parent
0dd39af7ad
commit
f868e1c91d
1 changed files with 97 additions and 37 deletions
|
|
@ -6,6 +6,8 @@ import { Router} from "@angular/router";
|
||||||
import {FictitiousAdvertsService} from "../../utils/services/fictitiousDatas/fictitiousAdverts/fictitious-adverts.service";
|
import {FictitiousAdvertsService} from "../../utils/services/fictitiousDatas/fictitiousAdverts/fictitious-adverts.service";
|
||||||
import {FictitiousVideosService} from "../../utils/services/fictitiousDatas/fictitiousVideos/fictitious-videos.service";
|
import {FictitiousVideosService} from "../../utils/services/fictitiousDatas/fictitiousVideos/fictitious-videos.service";
|
||||||
import {ThemeService} from "../../utils/services/theme/theme.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;
|
formControl: FormControl;
|
||||||
allCoupleNameViews: CoupleNameViews[] = [];
|
allCoupleNameViews: CoupleNameViews[] = [];
|
||||||
|
|
||||||
|
allInterests: string[] = [];
|
||||||
|
|
||||||
startDate: Date = null;
|
startDate: Date = null;
|
||||||
endDate: Date = null;
|
endDate: Date = null;
|
||||||
step: number = 1;
|
step: number = 1;
|
||||||
|
|
@ -48,38 +52,80 @@ export class PagesPopularityComponent implements OnInit
|
||||||
constructor( private router: Router,
|
constructor( private router: Router,
|
||||||
public themeService: ThemeService,
|
public themeService: ThemeService,
|
||||||
private fictitiousAdvertsService: FictitiousAdvertsService,
|
private fictitiousAdvertsService: FictitiousAdvertsService,
|
||||||
private fictitiousVideosService: FictitiousVideosService ) {}
|
private fictitiousVideosService: FictitiousVideosService,
|
||||||
|
private messageService: MessageService ) {}
|
||||||
|
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
ngOnInit(): void
|
ngOnInit(): void
|
||||||
{
|
{
|
||||||
if(this.router.url.includes("ads")) this.ngOnInitAds();
|
// Sera excuté si on est sur la page 'adsPopularity'
|
||||||
else if(this.router.url.includes("subjects")) this.ngOnInitSubjects();
|
// Remplie l'attribut 'allCoupleNameViews'
|
||||||
this.formControl = new FormControl(this.allCoupleNameViews);
|
if(this.router.url.includes("ads"))
|
||||||
this.onApplyFilter();
|
{
|
||||||
|
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'
|
// Callback: Sera excuté si on est sur la page 'adsPopularity'
|
||||||
// Remplie l'attribut 'allCoupleNameViews'
|
afterReceivingAds(retour: any): void
|
||||||
ngOnInitAds(): 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)
|
for(let advert of allAdverts)
|
||||||
{
|
{
|
||||||
let couple = {name: advert.title, views: advert.views }
|
let couple = {name: advert.title, views: advert.views }
|
||||||
this.allCoupleNameViews.push(couple);
|
this.allCoupleNameViews.push(couple);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.formControl = new FormControl(this.allCoupleNameViews);
|
||||||
|
this.onApplyFilter();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Sera excuté si on est sur la page 'subjectsPopularity'
|
// Callback: Sera excuté si on est sur la page 'subjectsPopularity'
|
||||||
// Remplie l'attribut 'allCoupleNameViews'
|
afterReceivingVideos(retour: any): void
|
||||||
ngOnInitSubjects(): 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();
|
let myMap: Map<string,Date[]> = new Map();
|
||||||
|
|
||||||
|
// parcours des interest de chaque video
|
||||||
for(let video of allVideos)
|
for(let video of allVideos)
|
||||||
{
|
{
|
||||||
const key = video.interest;
|
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())
|
for(const [key, value] of myMap.entries())
|
||||||
{
|
{
|
||||||
let couple = {name: key, views: value }
|
let couple = {name: key, views: value }
|
||||||
this.allCoupleNameViews.push(couple);
|
this.allCoupleNameViews.push(couple);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.formControl = new FormControl(this.allCoupleNameViews);
|
||||||
|
this.onApplyFilter();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
// Applique le filtre
|
// Applique le filtre
|
||||||
|
|
@ -137,7 +197,7 @@ export class PagesPopularityComponent implements OnInit
|
||||||
|
|
||||||
for(let date0 of coupleNameViews.views)
|
for(let date0 of coupleNameViews.views)
|
||||||
{
|
{
|
||||||
const time0 = date0.getTime();
|
const time0 = (new Date(date0)).getTime();
|
||||||
|
|
||||||
if(time0 > endTime) break;
|
if(time0 > endTime) break;
|
||||||
|
|
||||||
|
|
@ -172,7 +232,7 @@ export class PagesPopularityComponent implements OnInit
|
||||||
return date0.toLocaleDateString();
|
return date0.toLocaleDateString();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
const time2 = this.addStep(date0.getTime()) - this.oneDay;
|
const time2 = this.addStep((new Date(date0)).getTime()) - this.oneDay;
|
||||||
let date2 = new Date(time2);
|
let date2 = new Date(time2);
|
||||||
return date0.toLocaleDateString() + " à " + date2.toLocaleDateString();
|
return date0.toLocaleDateString() + " à " + date2.toLocaleDateString();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Reference in a new issue