]>
Commit | Line | Data |
---|---|---|
67ed6552 | 1 | import { Observable } from 'rxjs' |
693263e9 C |
2 | import { |
3 | AfterContentInit, | |
4 | Component, | |
5 | ContentChildren, | |
6 | EventEmitter, | |
7 | Input, | |
8 | OnDestroy, | |
9 | OnInit, | |
10 | Output, | |
11 | QueryList, | |
12 | TemplateRef | |
13 | } from '@angular/core' | |
14 | import { ActivatedRoute, Router } from '@angular/router' | |
67ed6552 | 15 | import { AuthService, ComponentPagination, LocalStorageService, Notifier, ScreenService, ServerService, UserService } from '@app/core' |
67ed6552 C |
16 | import { ResultList, VideoSortField } from '@shared/models' |
17 | import { PeerTubeTemplateDirective, Video } from '../shared-main' | |
18 | import { AbstractVideoList } from './abstract-video-list' | |
19 | import { MiniatureDisplayOptions, OwnerDisplayType } from './video-miniature.component' | |
693263e9 C |
20 | |
21 | export type SelectionType = { [ id: number ]: boolean } | |
22 | ||
23 | @Component({ | |
24 | selector: 'my-videos-selection', | |
25 | templateUrl: './videos-selection.component.html', | |
26 | styleUrls: [ './videos-selection.component.scss' ] | |
27 | }) | |
28 | export class VideosSelectionComponent extends AbstractVideoList implements OnInit, OnDestroy, AfterContentInit { | |
8c6781e9 | 29 | @Input() pagination: ComponentPagination |
693263e9 C |
30 | @Input() titlePage: string |
31 | @Input() miniatureDisplayOptions: MiniatureDisplayOptions | |
c4a6f790 C |
32 | @Input() ownerDisplayType: OwnerDisplayType |
33 | ||
93cae479 | 34 | @Input() getVideosObservableFunction: (page: number, sort?: VideoSortField) => Observable<ResultList<Video>> |
c4a6f790 | 35 | |
421d935d | 36 | @ContentChildren(PeerTubeTemplateDirective) templates: QueryList<PeerTubeTemplateDirective<'rowButtons' | 'globalButtons'>> |
693263e9 C |
37 | |
38 | @Output() selectionChange = new EventEmitter<SelectionType>() | |
39 | @Output() videosModelChange = new EventEmitter<Video[]>() | |
40 | ||
41 | _selection: SelectionType = {} | |
42 | ||
43 | rowButtonsTemplate: TemplateRef<any> | |
44 | globalButtonsTemplate: TemplateRef<any> | |
45 | ||
46 | constructor ( | |
47 | protected router: Router, | |
48 | protected route: ActivatedRoute, | |
49 | protected notifier: Notifier, | |
50 | protected authService: AuthService, | |
d3217560 | 51 | protected userService: UserService, |
693263e9 | 52 | protected screenService: ScreenService, |
d3217560 | 53 | protected storageService: LocalStorageService, |
693263e9 C |
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 | } |