@ -1,4 +1,5 @@
import { Component , OnInit } from "@angular/core" ;
import { Component , OnInit } from "@angular/core" ;
import { DomSanitizer } from "@angular/platform-browser" ;
import { TranslateService } from "@ngx-translate/core" ;
import { TranslateService } from "@ngx-translate/core" ;
import "rxjs/add/operator/debounceTime" ;
import "rxjs/add/operator/debounceTime" ;
import "rxjs/add/operator/distinctUntilChanged" ;
import "rxjs/add/operator/distinctUntilChanged" ;
@ -24,7 +25,7 @@ export class MovieSearchComponent implements OnInit {
constructor ( private searchService : SearchService , private requestService : RequestService ,
constructor ( private searchService : SearchService , private requestService : RequestService ,
private notificationService : NotificationService , private authService : AuthService ,
private notificationService : NotificationService , private authService : AuthService ,
private readonly translate : TranslateService ) {
private readonly translate : TranslateService , private sanitizer : DomSanitizer ) {
this . searchChanged
this . searchChanged
. debounceTime ( 600 ) // Wait Xms afterthe last event before emitting last event
. debounceTime ( 600 ) // Wait Xms afterthe last event before emitting last event
@ -53,8 +54,7 @@ export class MovieSearchComponent implements OnInit {
message : "" ,
message : "" ,
result : false ,
result : false ,
errorMessage : "" ,
errorMessage : "" ,
} ;
} ;
}
}
public search ( text : any ) {
public search ( text : any ) {
@ -134,15 +134,23 @@ export class MovieSearchComponent implements OnInit {
private getExtaInfo() {
private getExtaInfo() {
this . movieResults . forEach ( ( val , index ) = > {
this . movieResults . forEach ( ( val , index ) = > {
val . background = this . sanitizer .
bypassSecurityTrustStyle
( "linear-gradient(to bottom, rgba(0,0,0,0.6) 0%,rgba(0,0,0,0.6) 100%),url(" + "https://image.tmdb.org/t/p/w1280" + val . backdropPath + ")" ) ;
this . searchService . getMovieInformation ( val . id )
this . searchService . getMovieInformation ( val . id )
. subscribe ( m = > this . updateItem ( val , m ) ) ;
. subscribe ( m = > {
this . updateItem ( val , m ) ;
} ) ;
} ) ;
} ) ;
}
}
private updateItem ( key : ISearchMovieResult , updated : ISearchMovieResult ) {
private updateItem ( key : ISearchMovieResult , updated : ISearchMovieResult ) {
const index = this . movieResults . indexOf ( key , 0 ) ;
const index = this . movieResults . indexOf ( key , 0 ) ;
if ( index > - 1 ) {
if ( index > - 1 ) {
this . movieResults [ index ] = updated ;
// const originalBackdrop = Object.create(this.movieResults[index]);
// this.movieResults[index] = updated;
// this.movieResults[index].backdropPath = originalBackdrop;
}
}
}
}
private clearResults() {
private clearResults() {