]>
Commit | Line | Data |
---|---|---|
67ed6552 | 1 | import { Observable } from 'rxjs' |
693263e9 C |
2 | import { |
3 | AfterContentInit, | |
4 | Component, | |
5bcbcbe3 | 5 | ComponentFactoryResolver, |
693263e9 C |
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' | |
241609f1 | 16 | import { AuthService, ComponentPagination, LocalStorageService, Notifier, ScreenService, ServerService, User, UserService } from '@app/core' |
67ed6552 C |
17 | import { ResultList, VideoSortField } from '@shared/models' |
18 | import { PeerTubeTemplateDirective, Video } from '../shared-main' | |
19 | import { AbstractVideoList } from './abstract-video-list' | |
733dbc53 | 20 | import { MiniatureDisplayOptions } from './video-miniature.component' |
693263e9 C |
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 { | |
241609f1 | 30 | @Input() user: User |
8c6781e9 | 31 | @Input() pagination: ComponentPagination |
693263e9 C |
32 | @Input() titlePage: string |
33 | @Input() miniatureDisplayOptions: MiniatureDisplayOptions | |
c4a6f790 | 34 | |
93cae479 | 35 | @Input() getVideosObservableFunction: (page: number, sort?: VideoSortField) => Observable<ResultList<Video>> |
c4a6f790 | 36 | |
421d935d | 37 | @ContentChildren(PeerTubeTemplateDirective) templates: QueryList<PeerTubeTemplateDirective<'rowButtons' | 'globalButtons'>> |
693263e9 C |
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, | |
d3217560 | 52 | protected userService: UserService, |
693263e9 | 53 | protected screenService: ScreenService, |
d3217560 | 54 | protected storageService: LocalStorageService, |
5bcbcbe3 RK |
55 | protected serverService: ServerService, |
56 | protected cfr: ComponentFactoryResolver | |
693263e9 C |
57 | ) { |
58 | super() | |
59 | } | |
60 | ||
693263e9 C |
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 | ||
8c6781e9 C |
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 | ||
693263e9 C |
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 | } |