realisation de la page user/historique

This commit is contained in:
MiharyR 2021-10-30 16:18:57 +02:00
parent d0ca04aefc
commit e358b6fa0e
18 changed files with 370 additions and 28 deletions

View file

@ -25,7 +25,7 @@
<a routerLink="/myPlaylists"> Mes playlists </a>
</li>
<li class="cliquable">
<a routerLink="/search"> Historique </a>
<a routerLink="/historique"> Historique </a>
</li>
<li style="float:right; margin-right: 20px;">
<a routerLink="/search">

View file

@ -0,0 +1,7 @@
export interface WatchedVideo
{
_id: string,
url: string,
title: string,
date: Date
}

View file

@ -2,6 +2,7 @@ import { Injectable } from '@angular/core';
import {Video} from "../../interfaces/video";
import {Playlist} from "../../interfaces/playlist";
import {Advert} from "../../interfaces/advert";
import {WatchedVideo} from "../../interfaces/watchedVideo";
@ -145,4 +146,25 @@ export class FictitiousDatasService
}
}
getTabWatchedVideo(n): WatchedVideo[]
{
let tabWatchedVideo = [];
const l = TAB_VIDEO.length;
for(let i=0 ; i<n ; i++)
{
const idx = Math.floor(Math.random() * l);
const video: Video = TAB_VIDEO[idx];
const watchedVideo: WatchedVideo = {
_id: video._id,
url: video.url,
title: video.title,
date: new Date()
};
tabWatchedVideo.push(watchedVideo);
}
return tabWatchedVideo;
}
}

View file

@ -0,0 +1,16 @@
import { TestBed } from '@angular/core/testing';
import { HistoriqueService } from './historique.service';
describe('HistoriqueService', () => {
let service: HistoriqueService;
beforeEach(() => {
TestBed.configureTestingModule({});
service = TestBed.inject(HistoriqueService);
});
it('should be created', () => {
expect(service).toBeTruthy();
});
});

View file

@ -0,0 +1,52 @@
import { Injectable } from '@angular/core';
import {Video} from "../../interfaces/video";
import {WatchedVideo} from "../../interfaces/watchedVideo";
import {MessageService} from "../message/message.service";
@Injectable({
providedIn: 'root'
})
export class HistoriqueService
{
private tabVideoUrlClicked: string[] = [];
constructor(private messageService: MessageService) { }
public addVideoToHistoque(video: Video): void
{
if (!this.tabVideoUrlClicked.includes(video.url))
{
this.tabVideoUrlClicked.push(video.url);
const watchedVideo0: WatchedVideo = {
_id: video._id,
url: video.url,
title: video.title,
date: new Date()
};
console.log(watchedVideo0);
this.addWatchedVideoToHistorique(watchedVideo0);
}
}
public addWatchedVideoToHistorique(watchedVideo0: WatchedVideo): void
{
// --- VRAI CODE ---
/*
this.messageService
.sendMessage("user/add/watchedVideo", {watchedVideo: watchedVideo0})
.subscribe(retour => {});
*/
}
public clearTabVideoUrlClicked()
{
this.tabVideoUrlClicked = [];
}
}