diff --git a/src/app/user/history/page-history-user/page-history-user.component.ts b/src/app/user/history/page-history-user/page-history-user.component.ts index b8f7fc8..6c80566 100644 --- a/src/app/user/history/page-history-user/page-history-user.component.ts +++ b/src/app/user/history/page-history-user/page-history-user.component.ts @@ -47,6 +47,7 @@ export class PageHistoryUserComponent implements AfterViewInit 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)); @@ -54,20 +55,37 @@ export class PageHistoryUserComponent implements AfterViewInit this.dataSource.sort = this.sort; this.dataSource.paginator = this.paginator; this.dataSource = this.dataSource; + */ - // --- VRAI CODE --- - /* this.messageService - .sendMessage( "user/get/history", null ) - .subscribe( retour => { + .get("user/history") + .subscribe(ret => this.ngAfterViewInitCallback(ret), err => this.ngAfterViewInitCallback(err)); - if(retour.status === "error") console.log(retour); - else { - this.dataSource = new MatTableDataSource(retour.data); - this.dataSource.sort = this.sort; + } + + + ngAfterViewInitCallback(retour: any): void + { + console.log(retour); + + if(retour.status !== "success") { + //console.log(retour); + } + else { + const tabVideoHistory = retour.data.map( video => { + return { + videoId: video.videoId, + imageUrl: video.imageUrl, + title: video.title, + date: video.watchedDate, + source: video.source, } }); - */ + this.dataSource = new MatTableDataSource(tabVideoHistory); + this.dataSource.sort = this.sort; + this.dataSource.paginator = this.paginator; + this.dataSource = this.dataSource; + } } diff --git a/src/app/user/search/page-search/page-search.component.html b/src/app/user/search/page-search/page-search.component.html index c9154c2..eb2ad12 100644 --- a/src/app/user/search/page-search/page-search.component.html +++ b/src/app/user/search/page-search/page-search.component.html @@ -16,7 +16,7 @@
- + @@ -30,7 +30,7 @@   logo - +   @@ -38,7 +38,7 @@   logo - +  
diff --git a/src/app/user/search/page-search/page-search.component.ts b/src/app/user/search/page-search/page-search.component.ts index 2a2187f..5c64bb0 100644 --- a/src/app/user/search/page-search/page-search.component.ts +++ b/src/app/user/search/page-search/page-search.component.ts @@ -5,12 +5,13 @@ import {Advert} from "../../../utils/interfaces/advert"; import {ThemeService} from "../../../utils/services/theme/theme.service"; import {FictitiousVideosService} from "../../../utils/services/fictitiousDatas/fictitiousVideos/fictitious-videos.service"; import {FictitiousAdvertsService} from "../../../utils/services/fictitiousDatas/fictitiousAdverts/fictitious-adverts.service"; +import {HttpParams} from "@angular/common/http"; let TAB_PLATEFORM = [ - { name: "youtube", isSelected: false }, - { name: "dailymotion", isSelected: false } + { name: "Youtube", isSelected: true }, + { name: "Dailymotion", isSelected: true } ]; @@ -38,53 +39,44 @@ export class PageSearchComponent implements OnInit ngOnInit(): void { // --- FAUX CODE --- - this.tabVideo = this.fictitiousVideosService.getTabVideoAll(90); + //this.tabVideo = this.fictitiousVideosService.getTabVideoAll(90); this.ad1 = this.fictitiousAdvertsService.getAdvert(); this.ad2 = this.fictitiousAdvertsService.getAdvert(); - - // --- VRAI CODE --- - /* - let tabPlateformName = []; - for(let plateform of this.tabPlateform) tabPlateformName.push(plateform.title); - let data = { search: "", plaateforms: tabPlateformName }; - this.messageService - .sendMessage("user/searchVideo", data) - .subscribe( retour => { - if(retour.status === "error") console.log(retour.data); - else { - this.tabVideo = retour.data.videos; - this.ad1 = retour.data.ad1; - this.ad2 = retour.data.ad2; - } - }); - */ + this.onSearch(); } + onSearch() { - // --- FAUX CODE --- - this.tabVideo = this.fictitiousVideosService.getTabVideoAll(2); + let params = new HttpParams(); + params = params.append('q', this.search); + + let sources = ""; + if(this.tabPlateform[0].isSelected && this.tabPlateform[1].isSelected) sources += "yt,dm" ; + else if((!this.tabPlateform[0].isSelected) && this.tabPlateform[1].isSelected) sources += "dm" ; + else if(this.tabPlateform[0].isSelected && (!this.tabPlateform[1].isSelected)) sources += "yt" ; + else sources += "" ; + console.log(sources); + params = params.append('sources', sources); - // --- VRAI CODE --- - /* - let tabPlateformName = []; - for(let plateform of this.tabPlateform) - { - if(plateform.isSelected) tabPlateformName.push(plateform.title); - } - let data = { "search": this.search, "plateforms": tabPlateformName }; this.messageService - .sendMessage("user/searchVideo", data) - .subscribe(retour => { - if(retour.status === "error") console.log(retour.data); - else { - this.tabVideo = retour.data.videos; - this.ad1 = retour.data.ad1; - this.ad2 = retour.data.ad2; - } - }); - */ + .get("video/search", params) + .subscribe(ret => this.onSearchCallback(ret), err => this.onSearchCallback(err)); + } + + + onSearchCallback(retour: any): void + { + console.log("ngOnInitCallback:"); + console.log(retour); + + if(retour.status !== "success") { + //console.log(retour); + } + else { + this.tabVideo = retour.data; + } } } diff --git a/src/app/user/search/video-grid/video-grid.component.html b/src/app/user/search/video-grid/video-grid.component.html index 3cb869c..ec59ef4 100644 --- a/src/app/user/search/video-grid/video-grid.component.html +++ b/src/app/user/search/video-grid/video-grid.component.html @@ -20,8 +20,8 @@ - ytb - dlm + ytb + dlm diff --git a/src/app/user/search/video-grid/video-grid.component.ts b/src/app/user/search/video-grid/video-grid.component.ts index 0d35424..366092d 100644 --- a/src/app/user/search/video-grid/video-grid.component.ts +++ b/src/app/user/search/video-grid/video-grid.component.ts @@ -34,8 +34,8 @@ export class VideoGridComponent implements OnChanges tronquage(str: string) { - if(str.length < 40) return str; - else return str.substring(0, 37) + "..." ; + if(str.length < 33) return str; + else return str.substring(0, 30) + "..." ; } onVideo(video: VideoAll): void @@ -43,4 +43,5 @@ export class VideoGridComponent implements OnChanges const url = '/user/watching/fromSearch/'+video.videoId+'/'+video.source+'/'+this.search; this.router.navigateByUrl(url); } + } diff --git a/src/app/utils/services/message/message.service.ts b/src/app/utils/services/message/message.service.ts index 086b447..a50e75c 100644 --- a/src/app/utils/services/message/message.service.ts +++ b/src/app/utils/services/message/message.service.ts @@ -1,5 +1,5 @@ import { Injectable } from '@angular/core'; -import {HttpClient} from "@angular/common/http"; +import {HttpClient, HttpParams} from "@angular/common/http"; import {environment} from "../../../../environments/environment"; import {Observable} from "rxjs"; @@ -19,10 +19,10 @@ export class MessageService return this.http.post(urlComplete, data, {withCredentials: true}); } - get(url: string): Observable + get(url: string, params:HttpParams = new HttpParams()): Observable { const urlComplete = environment.debutUrl + url ; - return this.http.get(urlComplete,{withCredentials: true}); + return this.http.get(urlComplete,{ withCredentials: true, params: params }); } put(url: string, data: any): Observable