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