aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/shared/video/videos-selection.component.ts
blob: b6bedafd8a52eaf7acfbf0243a47b3ecddf4f101 (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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
import {
  AfterContentInit,
  Component,
  ContentChildren,
  EventEmitter,
  Input,
  OnDestroy,
  OnInit,
  Output,
  QueryList,
  TemplateRef
} from '@angular/core'
import { ActivatedRoute, Router } from '@angular/router'
import { AbstractVideoList } from '@app/shared/video/abstract-video-list'
import { AuthService, Notifier, ServerService } from '@app/core'
import { ScreenService } from '@app/shared/misc/screen.service'
import { MiniatureDisplayOptions } from '@app/shared/video/video-miniature.component'
import { Observable } from 'rxjs'
import { Video } from '@app/shared/video/video.model'
import { PeerTubeTemplateDirective } from '@app/shared/angular/peertube-template.directive'
import { VideoSortField } from '@app/shared/video/sort-field.type'

export type SelectionType = { [ id: number ]: boolean }

@Component({
  selector: 'my-videos-selection',
  templateUrl: './videos-selection.component.html',
  styleUrls: [ './videos-selection.component.scss' ]
})
export class VideosSelectionComponent extends AbstractVideoList implements OnInit, OnDestroy, AfterContentInit {
  @Input() titlePage: string
  @Input() miniatureDisplayOptions: MiniatureDisplayOptions
  @Input() getVideosObservableFunction: (page: number, sort?: VideoSortField) => Observable<{ videos: Video[], totalVideos: number }>
  @ContentChildren(PeerTubeTemplateDirective) templates: QueryList<PeerTubeTemplateDirective>

  @Output() selectionChange = new EventEmitter<SelectionType>()
  @Output() videosModelChange = new EventEmitter<Video[]>()

  _selection: SelectionType = {}

  rowButtonsTemplate: TemplateRef<any>
  globalButtonsTemplate: TemplateRef<any>

  constructor (
    protected router: Router,
    protected route: ActivatedRoute,
    protected notifier: Notifier,
    protected authService: AuthService,
    protected screenService: ScreenService,
    protected serverService: ServerService
  ) {
    super()
  }

  ngAfterContentInit () {
    {
      const t = this.templates.find(t => t.name === 'rowButtons')
      if (t) this.rowButtonsTemplate = t.template
    }

    {
      const t = this.templates.find(t => t.name === 'globalButtons')
      if (t) this.globalButtonsTemplate = t.template
    }
  }

  @Input() get selection () {
    return this._selection
  }

  set selection (selection: SelectionType) {
    this._selection = selection
    this.selectionChange.emit(this._selection)
  }

  @Input() get videosModel () {
    return this.videos
  }

  set videosModel (videos: Video[]) {
    this.videos = videos
    this.videosModelChange.emit(this.videos)
  }

  ngOnInit () {
    super.ngOnInit()
  }

  ngOnDestroy () {
    super.ngOnDestroy()
  }

  getVideosObservable (page: number) {
    return this.getVideosObservableFunction(page, this.sort)
  }

  abortSelectionMode () {
    this._selection = {}
  }

  isInSelectionMode () {
    return Object.keys(this._selection).some(k => this._selection[ k ] === true)
  }

  generateSyndicationList () {
    throw new Error('Method not implemented.')
  }

  protected onMoreVideos () {
    this.videosModel = this.videos
  }
}