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