]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/shared/video/videos-selection.component.ts
Merge branch 'release/1.4.0' into develop
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / video / videos-selection.component.ts
CommitLineData
693263e9
C
1import {
2 AfterContentInit,
3 Component,
4 ContentChildren,
5 EventEmitter,
6 Input,
7 OnDestroy,
8 OnInit,
9 Output,
10 QueryList,
11 TemplateRef
12} from '@angular/core'
13import { ActivatedRoute, Router } from '@angular/router'
14import { AbstractVideoList } from '@app/shared/video/abstract-video-list'
15import { AuthService, Notifier, ServerService } from '@app/core'
16import { ScreenService } from '@app/shared/misc/screen.service'
17import { MiniatureDisplayOptions } from '@app/shared/video/video-miniature.component'
18import { Observable } from 'rxjs'
19import { Video } from '@app/shared/video/video.model'
20import { PeerTubeTemplateDirective } from '@app/shared/angular/peertube-template.directive'
21import { VideoSortField } from '@app/shared/video/sort-field.type'
8c6781e9 22import { ComponentPagination } from '@app/shared/rest/component-pagination.model'
34c7f429 23import { I18n } from '@ngx-translate/i18n-polyfill'
93cae479 24import { ResultList } from '@shared/models'
693263e9
C
25
26export type SelectionType = { [ id: number ]: boolean }
27
28@Component({
29 selector: 'my-videos-selection',
30 templateUrl: './videos-selection.component.html',
31 styleUrls: [ './videos-selection.component.scss' ]
32})
33export class VideosSelectionComponent extends AbstractVideoList implements OnInit, OnDestroy, AfterContentInit {
8c6781e9 34 @Input() pagination: ComponentPagination
693263e9
C
35 @Input() titlePage: string
36 @Input() miniatureDisplayOptions: MiniatureDisplayOptions
93cae479 37 @Input() getVideosObservableFunction: (page: number, sort?: VideoSortField) => Observable<ResultList<Video>>
421d935d 38 @ContentChildren(PeerTubeTemplateDirective) templates: QueryList<PeerTubeTemplateDirective<'rowButtons' | 'globalButtons'>>
693263e9
C
39
40 @Output() selectionChange = new EventEmitter<SelectionType>()
41 @Output() videosModelChange = new EventEmitter<Video[]>()
42
43 _selection: SelectionType = {}
44
45 rowButtonsTemplate: TemplateRef<any>
46 globalButtonsTemplate: TemplateRef<any>
47
48 constructor (
34c7f429 49 protected i18n: I18n,
693263e9
C
50 protected router: Router,
51 protected route: ActivatedRoute,
52 protected notifier: Notifier,
53 protected authService: AuthService,
54 protected screenService: ScreenService,
55 protected serverService: ServerService
56 ) {
57 super()
58 }
59
693263e9
C
60 @Input() get selection () {
61 return this._selection
62 }
63
64 set selection (selection: SelectionType) {
65 this._selection = selection
66 this.selectionChange.emit(this._selection)
67 }
68
69 @Input() get videosModel () {
70 return this.videos
71 }
72
73 set videosModel (videos: Video[]) {
74 this.videos = videos
75 this.videosModelChange.emit(this.videos)
76 }
77
78 ngOnInit () {
79 super.ngOnInit()
80 }
81
8c6781e9
C
82 ngAfterContentInit () {
83 {
84 const t = this.templates.find(t => t.name === 'rowButtons')
85 if (t) this.rowButtonsTemplate = t.template
86 }
87
88 {
89 const t = this.templates.find(t => t.name === 'globalButtons')
90 if (t) this.globalButtonsTemplate = t.template
91 }
92 }
93
693263e9
C
94 ngOnDestroy () {
95 super.ngOnDestroy()
96 }
97
98 getVideosObservable (page: number) {
99 return this.getVideosObservableFunction(page, this.sort)
100 }
101
102 abortSelectionMode () {
103 this._selection = {}
104 }
105
106 isInSelectionMode () {
107 return Object.keys(this._selection).some(k => this._selection[ k ] === true)
108 }
109
110 generateSyndicationList () {
111 throw new Error('Method not implemented.')
112 }
113
114 protected onMoreVideos () {
115 this.videosModel = this.videos
116 }
117}