]>
Commit | Line | Data |
---|---|---|
f3aaa9a9 C |
1 | import { Component, OnDestroy, OnInit } from '@angular/core' |
2 | import { ActivatedRoute, Router } from '@angular/router' | |
fc62e39c | 3 | import { RedirectService } from '@app/core' |
0cd4344f | 4 | import { immutableAssign } from '@app/shared/misc/utils' |
f3aaa9a9 | 5 | import { NotificationsService } from 'angular2-notifications' |
f3aaa9a9 | 6 | import { Subscription } from 'rxjs/Subscription' |
b2731bff | 7 | import { AuthService } from '../../core/auth' |
7bfd1b1e | 8 | import { AbstractVideoList } from '../../shared/video/abstract-video-list' |
f3aaa9a9 C |
9 | import { VideoService } from '../../shared/video/video.service' |
10 | ||
11 | @Component({ | |
12 | selector: 'my-videos-search', | |
13 | styleUrls: [ '../../shared/video/abstract-video-list.scss' ], | |
14 | templateUrl: '../../shared/video/abstract-video-list.html' | |
15 | }) | |
16 | export class VideoSearchComponent extends AbstractVideoList implements OnInit, OnDestroy { | |
17 | titlePage = 'Search' | |
18 | currentRoute = '/videos/search' | |
19 | loadOnInit = false | |
20 | ||
0cd4344f | 21 | protected otherRouteParams = { |
c88593f7 C |
22 | search: '' |
23 | } | |
f3aaa9a9 C |
24 | private subActivatedRoute: Subscription |
25 | ||
26 | constructor (protected router: Router, | |
27 | protected route: ActivatedRoute, | |
28 | protected notificationsService: NotificationsService, | |
b2731bff | 29 | protected authService: AuthService, |
fc62e39c C |
30 | private videoService: VideoService, |
31 | private redirectService: RedirectService | |
32 | ) { | |
f3aaa9a9 C |
33 | super() |
34 | } | |
35 | ||
36 | ngOnInit () { | |
37 | super.ngOnInit() | |
38 | ||
39 | this.subActivatedRoute = this.route.queryParams.subscribe( | |
40 | queryParams => { | |
c88593f7 | 41 | const querySearch = queryParams['search'] |
5b5e333f | 42 | |
fc62e39c C |
43 | if (!querySearch) return this.redirectService.redirectToHomepage() |
44 | if (this.otherRouteParams.search === querySearch) return | |
c88593f7 | 45 | |
0cd4344f | 46 | this.otherRouteParams.search = querySearch |
f3aaa9a9 C |
47 | this.reloadVideos() |
48 | }, | |
49 | ||
50 | err => this.notificationsService.error('Error', err.text) | |
51 | ) | |
52 | } | |
53 | ||
54 | ngOnDestroy () { | |
9af61e84 C |
55 | super.ngOnDestroy() |
56 | ||
57 | if (this.subActivatedRoute) this.subActivatedRoute.unsubscribe() | |
f3aaa9a9 C |
58 | } |
59 | ||
0cd4344f C |
60 | getVideosObservable (page: number) { |
61 | const newPagination = immutableAssign(this.pagination, { currentPage: page }) | |
62 | return this.videoService.searchVideos(this.otherRouteParams.search, newPagination, this.sort) | |
f3aaa9a9 | 63 | } |
244e76a5 RK |
64 | |
65 | generateSyndicationList () { | |
66dc5907 | 66 | throw new Error('Search does not support syndication.') |
244e76a5 | 67 | } |
f3aaa9a9 | 68 | } |