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