]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/shared/shared-video-miniature/videos-selection.component.ts
Refactor search filters
[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 } 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() noResultMessage = $localize`No results.`
35 @Input() enableSelection = true
36 @Input() loadOnInit = true
37
38 @Input() getVideosObservableFunction: (page: number, sort?: VideoSortField) => Observable<ResultList<Video>>
39
40 @ContentChildren(PeerTubeTemplateDirective) templates: QueryList<PeerTubeTemplateDirective<'rowButtons' | 'globalButtons'>>
41
42 @Output() selectionChange = new EventEmitter<SelectionType>()
43 @Output() videosModelChange = new EventEmitter<Video[]>()
44
45 _selection: SelectionType = {}
46
47 rowButtonsTemplate: TemplateRef<any>
48 globalButtonsTemplate: TemplateRef<any>
49
50 constructor (
51 protected router: Router,
52 protected route: ActivatedRoute,
53 protected notifier: Notifier,
54 protected authService: AuthService,
55 protected userService: UserService,
56 protected screenService: ScreenService,
57 protected storageService: LocalStorageService,
58 protected serverService: ServerService,
59 protected cfr: ComponentFactoryResolver
60 ) {
61 super()
62 }
63
64 @Input() get selection () {
65 return this._selection
66 }
67
68 set selection (selection: SelectionType) {
69 this._selection = selection
70 this.selectionChange.emit(this._selection)
71 }
72
73 @Input() get videosModel () {
74 return this.videos
75 }
76
77 set videosModel (videos: Video[]) {
78 this.videos = videos
79 this.videosModelChange.emit(this.videos)
80 }
81
82 ngOnInit () {
83 super.ngOnInit()
84 }
85
86 ngAfterContentInit () {
87 {
88 const t = this.templates.find(t => t.name === 'rowButtons')
89 if (t) this.rowButtonsTemplate = t.template
90 }
91
92 {
93 const t = this.templates.find(t => t.name === 'globalButtons')
94 if (t) this.globalButtonsTemplate = t.template
95 }
96 }
97
98 ngOnDestroy () {
99 super.ngOnDestroy()
100 }
101
102 getVideosObservable (page: number) {
103 return this.getVideosObservableFunction(page, this.sort)
104 }
105
106 abortSelectionMode () {
107 this._selection = {}
108 }
109
110 isInSelectionMode () {
111 return Object.keys(this._selection).some(k => this._selection[ k ] === true)
112 }
113
114 generateSyndicationList () {
115 throw new Error('Method not implemented.')
116 }
117
118 protected onMoreVideos () {
119 this.videosModel = this.videos
120 }
121 }