diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2016-05-23 09:30:18 +0200 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2016-05-23 09:38:38 +0200 |
commit | 471bc22f19767c1cb1e7ba7ad0ddf0ff5f0e88f4 (patch) | |
tree | 606ccf517d76baf08539be7501d07dfd065884a9 /client/angular/videos | |
parent | 322940742b4dca168de6dfed0d1ebf5926dab528 (diff) | |
download | PeerTube-471bc22f19767c1cb1e7ba7ad0ddf0ff5f0e88f4.tar.gz PeerTube-471bc22f19767c1cb1e7ba7ad0ddf0ff5f0e88f4.tar.zst PeerTube-471bc22f19767c1cb1e7ba7ad0ddf0ff5f0e88f4.zip |
Add search with field choose support in client
Diffstat (limited to 'client/angular/videos')
-rw-r--r-- | client/angular/videos/components/list/videos-list.component.ts | 10 | ||||
-rw-r--r-- | client/angular/videos/videos.service.ts | 12 |
2 files changed, 14 insertions, 8 deletions
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'; | |||
9 | import { VideosService } from '../../videos.service'; | 9 | import { VideosService } from '../../videos.service'; |
10 | import { Video } from '../../video'; | 10 | import { Video } from '../../video'; |
11 | import { VideoMiniatureComponent } from './video-miniature.component'; | 11 | import { VideoMiniatureComponent } from './video-miniature.component'; |
12 | import { Search, SearchField } from '../../../app/search'; | ||
12 | 13 | ||
13 | @Component({ | 14 | @Component({ |
14 | selector: 'my-videos-list', | 15 | selector: 'my-videos-list', |
@@ -26,14 +27,17 @@ export class VideosListComponent implements OnInit { | |||
26 | total: 0 | 27 | total: 0 |
27 | } | 28 | } |
28 | 29 | ||
29 | private search: string; | 30 | private search: Search; |
30 | 31 | ||
31 | constructor( | 32 | constructor( |
32 | private _authService: AuthService, | 33 | private _authService: AuthService, |
33 | private _videosService: VideosService, | 34 | private _videosService: VideosService, |
34 | private _routeParams: RouteParams | 35 | private _routeParams: RouteParams |
35 | ) { | 36 | ) { |
36 | this.search = this._routeParams.get('search'); | 37 | this.search = { |
38 | value: this._routeParams.get('search'), | ||
39 | field: <SearchField>this._routeParams.get('field') | ||
40 | } | ||
37 | } | 41 | } |
38 | 42 | ||
39 | ngOnInit() { | 43 | ngOnInit() { |
@@ -47,7 +51,7 @@ export class VideosListComponent implements OnInit { | |||
47 | getVideos() { | 51 | getVideos() { |
48 | let observable = null; | 52 | let observable = null; |
49 | 53 | ||
50 | if (this.search !== null) { | 54 | if (this.search.value !== null) { |
51 | observable = this._videosService.searchVideos(this.search, this.pagination); | 55 | observable = this._videosService.searchVideos(this.search, this.pagination); |
52 | } else { | 56 | } else { |
53 | observable = this._videosService.getVideos(this.pagination); | 57 | 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'; | |||
5 | import { Pagination } from './pagination'; | 5 | import { Pagination } from './pagination'; |
6 | import { Video } from './video'; | 6 | import { Video } from './video'; |
7 | import { AuthService } from '../users/services/auth.service'; | 7 | import { AuthService } from '../users/services/auth.service'; |
8 | import { Search } from '../app/search'; | ||
8 | 9 | ||
9 | @Injectable() | 10 | @Injectable() |
10 | export class VideosService { | 11 | export class VideosService { |
@@ -13,8 +14,8 @@ export class VideosService { | |||
13 | constructor (private http: Http, private _authService: AuthService) {} | 14 | constructor (private http: Http, private _authService: AuthService) {} |
14 | 15 | ||
15 | getVideos(pagination: Pagination) { | 16 | getVideos(pagination: Pagination) { |
16 | const params = { search: this.createPaginationParams(pagination) }; | 17 | const params = this.createPaginationParams(pagination); |
17 | return this.http.get(this._baseVideoUrl, params) | 18 | return this.http.get(this._baseVideoUrl, { search: params }) |
18 | .map(res => res.json()) | 19 | .map(res => res.json()) |
19 | .map(this.extractVideos) | 20 | .map(this.extractVideos) |
20 | .catch(this.handleError); | 21 | .catch(this.handleError); |
@@ -33,9 +34,10 @@ export class VideosService { | |||
33 | .catch(this.handleError); | 34 | .catch(this.handleError); |
34 | } | 35 | } |
35 | 36 | ||
36 | searchVideos(search: string, pagination: Pagination) { | 37 | searchVideos(search: Search, pagination: Pagination) { |
37 | const params = { search: this.createPaginationParams(pagination) }; | 38 | const params = this.createPaginationParams(pagination); |
38 | return this.http.get(this._baseVideoUrl + 'search/' + encodeURIComponent(search), params) | 39 | if (search.field) params.set('field', search.field); |
40 | return this.http.get(this._baseVideoUrl + 'search/' + encodeURIComponent(search.value), { search: params }) | ||
39 | .map(res => res.json()) | 41 | .map(res => res.json()) |
40 | .map(this.extractVideos) | 42 | .map(this.extractVideos) |
41 | .catch(this.handleError); | 43 | .catch(this.handleError); |