]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/shared/video/videos-selection.component.ts
Remove deprecated NgbTabsetModule module
[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'
93cae479 24import { ResultList } from '@shared/models'
d3217560
RK
25import { UserService } from '../users'
26import { LocalStorageService } from '../misc/storage.service'
693263e9
C
27
28export type SelectionType = { [ id: number ]: boolean }
29
30@Component({
31 selector: 'my-videos-selection',
32 templateUrl: './videos-selection.component.html',
33 styleUrls: [ './videos-selection.component.scss' ]
34})
35export class VideosSelectionComponent extends AbstractVideoList implements OnInit, OnDestroy, AfterContentInit {
8c6781e9 36 @Input() pagination: ComponentPagination
693263e9
C
37 @Input() titlePage: string
38 @Input() miniatureDisplayOptions: MiniatureDisplayOptions
93cae479 39 @Input() getVideosObservableFunction: (page: number, sort?: VideoSortField) => Observable<ResultList<Video>>
421d935d 40 @ContentChildren(PeerTubeTemplateDirective) templates: QueryList<PeerTubeTemplateDirective<'rowButtons' | 'globalButtons'>>
693263e9
C
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 (
34c7f429 51 protected i18n: I18n,
693263e9
C
52 protected router: Router,
53 protected route: ActivatedRoute,
54 protected notifier: Notifier,
55 protected authService: AuthService,
d3217560 56 protected userService: UserService,
693263e9 57 protected screenService: ScreenService,
d3217560 58 protected storageService: LocalStorageService,
693263e9
C
59 protected serverService: ServerService
60 ) {
61 super()
62 }
63
693263e9
C
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
8c6781e9
C
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
693263e9
C
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}