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