]>
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 | |
2e46eb97 C |
34 | @Input() noResultMessage = $localize`No results.` |
35 | @Input() enableSelection = true | |
36 | @Input() loadOnInit = true | |
c4a6f790 | 37 | |
93cae479 | 38 | @Input() getVideosObservableFunction: (page: number, sort?: VideoSortField) => Observable<ResultList<Video>> |
c4a6f790 | 39 | |
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 ( | |
51 | protected router: Router, | |
52 | protected route: ActivatedRoute, | |
53 | protected notifier: Notifier, | |
54 | protected authService: AuthService, | |
d3217560 | 55 | protected userService: UserService, |
693263e9 | 56 | protected screenService: ScreenService, |
d3217560 | 57 | protected storageService: LocalStorageService, |
5bcbcbe3 RK |
58 | protected serverService: ServerService, |
59 | protected cfr: ComponentFactoryResolver | |
693263e9 C |
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 | } |