]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - 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
1 import { Observable } from 'rxjs'
2 import {
3 AfterContentInit,
4 Component,
5 ComponentFactoryResolver,
6 ContentChildren,
7 EventEmitter,
8 Input,
9 OnDestroy,
10 OnInit,
11 Output,
12 QueryList,
13 TemplateRef
14 } from '@angular/core'
15 import { ActivatedRoute, Router } from '@angular/router'
16 import { AuthService, ComponentPagination, LocalStorageService, Notifier, ScreenService, ServerService, User, UserService } from '@app/core'
17 import { ResultList, VideoSortField } from '@shared/models'
18 import { PeerTubeTemplateDirective, Video } from '../shared-main'
19 import { AbstractVideoList } from './abstract-video-list'
20 import { MiniatureDisplayOptions, OwnerDisplayType } from './video-miniature.component'
21
22 export 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 })
29 export class VideosSelectionComponent extends AbstractVideoList implements OnInit, OnDestroy, AfterContentInit {
30 @Input() user: User
31 @Input() pagination: ComponentPagination
32 @Input() titlePage: string
33 @Input() miniatureDisplayOptions: MiniatureDisplayOptions
34 @Input() ownerDisplayType: OwnerDisplayType
35
36 @Input() getVideosObservableFunction: (page: number, sort?: VideoSortField) => Observable<ResultList<Video>>
37
38 @ContentChildren(PeerTubeTemplateDirective) templates: QueryList<PeerTubeTemplateDirective<'rowButtons' | 'globalButtons'>>
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,
53 protected userService: UserService,
54 protected screenService: ScreenService,
55 protected storageService: LocalStorageService,
56 protected serverService: ServerService,
57 protected cfr: ComponentFactoryResolver
58 ) {
59 super()
60 }
61
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
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
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 }