aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/videos/video-list/video-search.component.ts
blob: e874636af0081d840210a449173610dfd4cb762f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import { Component, OnDestroy, OnInit } from '@angular/core'
import { ActivatedRoute, Router } from '@angular/router'
import { NotificationsService } from 'angular2-notifications'
import { Subscription } from 'rxjs/Subscription'
import { AbstractVideoList } from '../../shared/video/abstract-video-list'
import { VideoService } from '../../shared/video/video.service'

@Component({
  selector: 'my-videos-search',
  styleUrls: [ '../../shared/video/abstract-video-list.scss' ],
  templateUrl: '../../shared/video/abstract-video-list.html'
})
export class VideoSearchComponent extends AbstractVideoList implements OnInit, OnDestroy {
  titlePage = 'Search'
  currentRoute = '/videos/search'
  loadOnInit = false

  private search = ''
  private subActivatedRoute: Subscription

  constructor (protected router: Router,
               protected route: ActivatedRoute,
               protected notificationsService: NotificationsService,
               private videoService: VideoService) {
    super()
  }

  ngOnInit () {
    super.ngOnInit()

    this.subActivatedRoute = this.route.queryParams.subscribe(
      queryParams => {
        this.search = queryParams['search']
        this.reloadVideos()
      },

      err => this.notificationsService.error('Error', err.text)
    )
  }

  ngOnDestroy () {
    if (this.subActivatedRoute) {
      this.subActivatedRoute.unsubscribe()
    }
  }

  getVideosObservable () {
    return this.videoService.searchVideos(this.search, this.pagination, this.sort)
  }
}