From 471bc22f19767c1cb1e7ba7ad0ddf0ff5f0e88f4 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 23 May 2016 09:30:18 +0200 Subject: Add search with field choose support in client --- .../angular/videos/components/list/videos-list.component.ts | 10 +++++++--- client/angular/videos/videos.service.ts | 12 +++++++----- 2 files changed, 14 insertions(+), 8 deletions(-) (limited to 'client/angular/videos') diff --git a/client/angular/videos/components/list/videos-list.component.ts b/client/angular/videos/components/list/videos-list.component.ts index 341afdaa6..a17b06cd9 100644 --- a/client/angular/videos/components/list/videos-list.component.ts +++ b/client/angular/videos/components/list/videos-list.component.ts @@ -9,6 +9,7 @@ import { User } from '../../../users/models/user'; import { VideosService } from '../../videos.service'; import { Video } from '../../video'; import { VideoMiniatureComponent } from './video-miniature.component'; +import { Search, SearchField } from '../../../app/search'; @Component({ selector: 'my-videos-list', @@ -26,14 +27,17 @@ export class VideosListComponent implements OnInit { total: 0 } - private search: string; + private search: Search; constructor( private _authService: AuthService, private _videosService: VideosService, private _routeParams: RouteParams ) { - this.search = this._routeParams.get('search'); + this.search = { + value: this._routeParams.get('search'), + field: this._routeParams.get('field') + } } ngOnInit() { @@ -47,7 +51,7 @@ export class VideosListComponent implements OnInit { getVideos() { let observable = null; - if (this.search !== null) { + if (this.search.value !== null) { observable = this._videosService.searchVideos(this.search, this.pagination); } else { observable = this._videosService.getVideos(this.pagination); diff --git a/client/angular/videos/videos.service.ts b/client/angular/videos/videos.service.ts index 94ef418eb..1329ead49 100644 --- a/client/angular/videos/videos.service.ts +++ b/client/angular/videos/videos.service.ts @@ -5,6 +5,7 @@ import { Observable } from 'rxjs/Rx'; import { Pagination } from './pagination'; import { Video } from './video'; import { AuthService } from '../users/services/auth.service'; +import { Search } from '../app/search'; @Injectable() export class VideosService { @@ -13,8 +14,8 @@ export class VideosService { constructor (private http: Http, private _authService: AuthService) {} getVideos(pagination: Pagination) { - const params = { search: this.createPaginationParams(pagination) }; - return this.http.get(this._baseVideoUrl, params) + const params = this.createPaginationParams(pagination); + return this.http.get(this._baseVideoUrl, { search: params }) .map(res => res.json()) .map(this.extractVideos) .catch(this.handleError); @@ -33,9 +34,10 @@ export class VideosService { .catch(this.handleError); } - searchVideos(search: string, pagination: Pagination) { - const params = { search: this.createPaginationParams(pagination) }; - return this.http.get(this._baseVideoUrl + 'search/' + encodeURIComponent(search), params) + searchVideos(search: Search, pagination: Pagination) { + const params = this.createPaginationParams(pagination); + if (search.field) params.set('field', search.field); + return this.http.get(this._baseVideoUrl + 'search/' + encodeURIComponent(search.value), { search: params }) .map(res => res.json()) .map(this.extractVideos) .catch(this.handleError); -- cgit v1.2.3