]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/shared/video/videos-selection.component.ts
Add list of instance follows in about page
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / video / videos-selection.component.ts
CommitLineData
693263e9
C
1import {
2 AfterContentInit,
3 Component,
4 ContentChildren,
5 EventEmitter,
6 Input,
7 OnDestroy,
8 OnInit,
9 Output,
10 QueryList,
11 TemplateRef
12} from '@angular/core'
13import { ActivatedRoute, Router } from '@angular/router'
14import { AbstractVideoList } from '@app/shared/video/abstract-video-list'
15import { AuthService, Notifier, ServerService } from '@app/core'
16import { ScreenService } from '@app/shared/misc/screen.service'
17import { MiniatureDisplayOptions } from '@app/shared/video/video-miniature.component'
18import { Observable } from 'rxjs'
19import { Video } from '@app/shared/video/video.model'
20import { PeerTubeTemplateDirective } from '@app/shared/angular/peertube-template.directive'
21import { VideoSortField } from '@app/shared/video/sort-field.type'
8c6781e9 22import { ComponentPagination } from '@app/shared/rest/component-pagination.model'
34c7f429 23import { I18n } from '@ngx-translate/i18n-polyfill'
693263e9
C
24
25export type SelectionType = { [ id: number ]: boolean }
26
27@Component({
28 selector: 'my-videos-selection',
29 templateUrl: './videos-selection.component.html',
30 styleUrls: [ './videos-selection.component.scss' ]
31})
32export class VideosSelectionComponent extends AbstractVideoList implements OnInit, OnDestroy, AfterContentInit {
8c6781e9 33 @Input() pagination: ComponentPagination
693263e9
C
34 @Input() titlePage: string
35 @Input() miniatureDisplayOptions: MiniatureDisplayOptions
36 @Input() getVideosObservableFunction: (page: number, sort?: VideoSortField) => Observable<{ videos: Video[], totalVideos: number }>
37 @ContentChildren(PeerTubeTemplateDirective) templates: QueryList<PeerTubeTemplateDirective>
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 (
34c7f429 48 protected i18n: I18n,
693263e9
C
49 protected router: Router,
50 protected route: ActivatedRoute,
51 protected notifier: Notifier,
52 protected authService: AuthService,
53 protected screenService: ScreenService,
54 protected serverService: ServerService
55 ) {
56 super()
57 }
58
693263e9
C
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
8c6781e9
C
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
693263e9
C
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}