]>
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' |
34c7f429 | 16 | import { I18n } from '@ngx-translate/i18n-polyfill' |
67ed6552 C |
17 | import { ResultList, VideoSortField } from '@shared/models' |
18 | import { PeerTubeTemplateDirective, Video } from '../shared-main' | |
19 | import { AbstractVideoList } from './abstract-video-list' | |
20 | import { MiniatureDisplayOptions, OwnerDisplayType } 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 { | |
8c6781e9 | 30 | @Input() pagination: ComponentPagination |
693263e9 C |
31 | @Input() titlePage: string |
32 | @Input() miniatureDisplayOptions: MiniatureDisplayOptions | |
c4a6f790 C |
33 | @Input() ownerDisplayType: OwnerDisplayType |
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 ( | |
34c7f429 | 48 | protected i18n: I18n, |
693263e9 C |
49 | protected router: Router, |
50 | protected route: ActivatedRoute, | |
51 | protected notifier: Notifier, | |
52 | protected authService: AuthService, | |
d3217560 | 53 | protected userService: UserService, |
693263e9 | 54 | protected screenService: ScreenService, |
d3217560 | 55 | protected storageService: LocalStorageService, |
693263e9 C |
56 | protected serverService: ServerService |
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 | } |