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