]>
Commit | Line | Data |
---|---|---|
1 | import { Component, OnDestroy, OnInit } from '@angular/core' | |
2 | import { ActivatedRoute, Router } from '@angular/router' | |
3 | import { NotificationsService } from 'angular2-notifications' | |
4 | import { Subscription } from 'rxjs/Subscription' | |
5 | import { AuthService } from '../../core/auth' | |
6 | import { AbstractVideoList } from '../../shared/video/abstract-video-list' | |
7 | import { VideoService } from '../../shared/video/video.service' | |
8 | ||
9 | @Component({ | |
10 | selector: 'my-videos-search', | |
11 | styleUrls: [ '../../shared/video/abstract-video-list.scss' ], | |
12 | templateUrl: '../../shared/video/abstract-video-list.html' | |
13 | }) | |
14 | export class VideoSearchComponent extends AbstractVideoList implements OnInit, OnDestroy { | |
15 | titlePage = 'Search' | |
16 | currentRoute = '/videos/search' | |
17 | loadOnInit = false | |
18 | ||
19 | protected otherParams = { | |
20 | search: '' | |
21 | } | |
22 | private subActivatedRoute: Subscription | |
23 | ||
24 | constructor (protected router: Router, | |
25 | protected route: ActivatedRoute, | |
26 | protected notificationsService: NotificationsService, | |
27 | protected authService: AuthService, | |
28 | private videoService: VideoService) { | |
29 | super() | |
30 | } | |
31 | ||
32 | ngOnInit () { | |
33 | super.ngOnInit() | |
34 | ||
35 | this.subActivatedRoute = this.route.queryParams.subscribe( | |
36 | queryParams => { | |
37 | const querySearch = queryParams['search'] | |
38 | if (!querySearch || this.otherParams.search === querySearch) return | |
39 | ||
40 | this.otherParams.search = querySearch | |
41 | this.reloadVideos() | |
42 | }, | |
43 | ||
44 | err => this.notificationsService.error('Error', err.text) | |
45 | ) | |
46 | } | |
47 | ||
48 | ngOnDestroy () { | |
49 | if (this.subActivatedRoute) { | |
50 | this.subActivatedRoute.unsubscribe() | |
51 | } | |
52 | } | |
53 | ||
54 | getVideosObservable () { | |
55 | return this.videoService.searchVideos(this.otherParams.search, this.pagination, this.sort) | |
56 | } | |
57 | } |