connexion avec back de la page 'user/history'

This commit is contained in:
MiharyR 2021-12-13 21:19:23 +01:00
parent 8f39312a6e
commit 7030a0ea21
2 changed files with 26 additions and 57 deletions

View file

@ -3,7 +3,6 @@ import {ThemeService} from "../../../utils/services/theme/theme.service";
import {MessageService} from "../../../utils/services/message/message.service"; import {MessageService} from "../../../utils/services/message/message.service";
import {MatTableDataSource} from "@angular/material/table"; import {MatTableDataSource} from "@angular/material/table";
import {MatSort} from "@angular/material/sort"; import {MatSort} from "@angular/material/sort";
import {UserHistoryService} from "../../utils/services/userHistory/userHistory.service";
import {MatPaginator} from "@angular/material/paginator"; import {MatPaginator} from "@angular/material/paginator";
import {FictitiousVideosService} from "../../../utils/services/fictitiousDatas/fictitiousVideos/fictitious-videos.service"; import {FictitiousVideosService} from "../../../utils/services/fictitiousDatas/fictitiousVideos/fictitious-videos.service";
import {VideoAll} from "../../../utils/interfaces/video"; import {VideoAll} from "../../../utils/interfaces/video";
@ -11,16 +10,6 @@ import {Router} from "@angular/router";
interface VideoHistory {
videoId: string,
imageUrl: string,
title: string,
date: Date,
source: string,
}
@Component({ @Component({
selector: 'app-page-history-user', selector: 'app-page-history-user',
templateUrl: './page-history-user.component.html', templateUrl: './page-history-user.component.html',
@ -37,43 +26,27 @@ export class PageHistoryUserComponent implements AfterViewInit
constructor( public themeService: ThemeService, constructor( public themeService: ThemeService,
private messageService: MessageService, private messageService: MessageService,
private fictitiousVideosService: FictitiousVideosService, private fictitiousVideosService: FictitiousVideosService,
private userHistoryService: UserHistoryService,
private router: Router ) { } private router: Router ) { }
// charge la page // charge la page
ngAfterViewInit(): void ngAfterViewInit(): void
{ {
this.userHistoryService.clearTabVideoUrlClicked();
// --- FAUX CODE ---
/*
const tabVideoAll: VideoAll[] = this.fictitiousVideosService.getTabVideoAll(8);
let tabVideoHistory: VideoHistory[] = [];
for(let videoAll of tabVideoAll) tabVideoHistory.push(this.videoAllToVideoHistory(videoAll));
this.dataSource = new MatTableDataSource(tabVideoHistory);
this.dataSource.sort = this.sort;
this.dataSource.paginator = this.paginator;
this.dataSource = this.dataSource;
*/
this.messageService this.messageService
.get("user/history") .get("user/history")
.subscribe(ret => this.ngAfterViewInitCallback(ret), err => this.ngAfterViewInitCallback(err)); .subscribe(ret => this.ngAfterViewInitCallback(ret), err => this.ngAfterViewInitCallback(err));
} }
ngAfterViewInitCallback(retour: any): void ngAfterViewInitCallback(retour: any): void
{ {
console.log(retour);
if(retour.status !== "success") { if(retour.status !== "success") {
//console.log(retour); console.log(retour);
} }
else { else {
const tabVideoHistory = retour.data.map( video => { const tabVideoHistory = retour.data.map( video => {
return { return {
_id: video._id,
videoId: video.videoId, videoId: video.videoId,
imageUrl: video.imageUrl, imageUrl: video.imageUrl,
title: video.title, title: video.title,
@ -98,48 +71,42 @@ export class PageHistoryUserComponent implements AfterViewInit
// Supprime la video // Supprime la video
onDelete(video: VideoAll): void onDelete(video: any): void
{ {
// --- FAUX CODE --- this.messageService
.put("video/update/"+video._id, { watchedDates: []})
.subscribe(ret => this.onDeleteCallback(ret, video), err => this.onDeleteCallback(err, video))
}
onDeleteCallback(retour: any, video: any): void
{
if(retour.status !== "success") {
console.log(retour);
}
else {
const index = this.dataSource.data.indexOf(video); const index = this.dataSource.data.indexOf(video);
this.dataSource.data.splice(index, 1); this.dataSource.data.splice(index, 1);
this.dataSource.data = this.dataSource.data; this.dataSource.data = this.dataSource.data;
this.dataSource = this.dataSource; this.dataSource = this.dataSource;
// --- VRAI CODE ---
/*
this.messageService
.sendMessage("user/delete/videoSeen", { "watchedVideo": watchedVideo})
.subscribe( retour => {
if(retour.status === "error") console.log(retour);
else {
const index = this.dataSource.data.indexOf(watchedVideo);
this.dataSource.data.splice(index, 1);
this.dataSource.data = this.dataSource.data;
this.dataSource = this.dataSource;
} }
});
*/
} }
onVideo(video: VideoAll): void onVideo(video: VideoAll): void
{ {
this.messageService
.put("video/update/"+video._id, { watchedDate: true})
.subscribe(ret => this.onVideoCallback(ret), err => this.onVideoCallback(err));
const url = '/user/watching/fromHistory/'+video.videoId+'/'+video.source ; const url = '/user/watching/fromHistory/'+video.videoId+'/'+video.source ;
this.router.navigateByUrl(url); this.router.navigateByUrl(url);
} }
videoAllToVideoHistory(videoAll: VideoAll): VideoHistory onVideoCallback(retour: any): void
{ {
return { if(retour.status !== "success") console.log(retour);
videoId: videoAll.videoId,
imageUrl: videoAll.imageUrl,
title: videoAll.title,
date: videoAll.watchedDates[videoAll.watchedDates.length-1],
source: videoAll.source,
}
} }
} }

View file

@ -105,6 +105,7 @@ export class PopupAddVideoToPlaylistsComponent implements OnInit
} }
else { else {
this.isFinishedForExistingPlaylist = true; this.isFinishedForExistingPlaylist = true;
console.log("isFinishedForExistingPlaylist: true");
} }
} }
@ -120,6 +121,7 @@ export class PopupAddVideoToPlaylistsComponent implements OnInit
} }
else { else {
this.isFinishedForNewPlaylist = true; this.isFinishedForNewPlaylist = true;
console.log("isFinishedForNewPlaylist: true");
} }
} }