]>
Commit | Line | Data |
---|---|---|
693263e9 C |
1 | import { |
2 | AfterContentInit, | |
3 | Component, | |
4 | ContentChildren, | |
5 | EventEmitter, | |
6 | Input, | |
7 | OnDestroy, | |
8 | OnInit, | |
9 | Output, | |
10 | QueryList, | |
11 | TemplateRef | |
12 | } from '@angular/core' | |
13 | import { ActivatedRoute, Router } from '@angular/router' | |
14 | import { AbstractVideoList } from '@app/shared/video/abstract-video-list' | |
15 | import { AuthService, Notifier, ServerService } from '@app/core' | |
16 | import { ScreenService } from '@app/shared/misc/screen.service' | |
c4a6f790 | 17 | import { MiniatureDisplayOptions, OwnerDisplayType } from '@app/shared/video/video-miniature.component' |
693263e9 C |
18 | import { Observable } from 'rxjs' |
19 | import { Video } from '@app/shared/video/video.model' | |
20 | import { PeerTubeTemplateDirective } from '@app/shared/angular/peertube-template.directive' | |
21 | import { VideoSortField } from '@app/shared/video/sort-field.type' | |
8c6781e9 | 22 | import { ComponentPagination } from '@app/shared/rest/component-pagination.model' |
34c7f429 | 23 | import { I18n } from '@ngx-translate/i18n-polyfill' |
93cae479 | 24 | import { ResultList } from '@shared/models' |
d3217560 RK |
25 | import { UserService } from '../users' |
26 | import { LocalStorageService } from '../misc/storage.service' | |
693263e9 C |
27 | |
28 | export 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 | }) | |
35 | export class VideosSelectionComponent extends AbstractVideoList implements OnInit, OnDestroy, AfterContentInit { | |
8c6781e9 | 36 | @Input() pagination: ComponentPagination |
693263e9 C |
37 | @Input() titlePage: string |
38 | @Input() miniatureDisplayOptions: MiniatureDisplayOptions | |
c4a6f790 C |
39 | @Input() ownerDisplayType: OwnerDisplayType |
40 | ||
93cae479 | 41 | @Input() getVideosObservableFunction: (page: number, sort?: VideoSortField) => Observable<ResultList<Video>> |
c4a6f790 | 42 | |
421d935d | 43 | @ContentChildren(PeerTubeTemplateDirective) templates: QueryList<PeerTubeTemplateDirective<'rowButtons' | 'globalButtons'>> |
693263e9 C |
44 | |
45 | @Output() selectionChange = new EventEmitter<SelectionType>() | |
46 | @Output() videosModelChange = new EventEmitter<Video[]>() | |
47 | ||
48 | _selection: SelectionType = {} | |
49 | ||
50 | rowButtonsTemplate: TemplateRef<any> | |
51 | globalButtonsTemplate: TemplateRef<any> | |
52 | ||
53 | constructor ( | |
34c7f429 | 54 | protected i18n: I18n, |
693263e9 C |
55 | protected router: Router, |
56 | protected route: ActivatedRoute, | |
57 | protected notifier: Notifier, | |
58 | protected authService: AuthService, | |
d3217560 | 59 | protected userService: UserService, |
693263e9 | 60 | protected screenService: ScreenService, |
d3217560 | 61 | protected storageService: LocalStorageService, |
693263e9 C |
62 | protected serverService: ServerService |
63 | ) { | |
64 | super() | |
65 | } | |
66 | ||
693263e9 C |
67 | @Input() get selection () { |
68 | return this._selection | |
69 | } | |
70 | ||
71 | set selection (selection: SelectionType) { | |
72 | this._selection = selection | |
73 | this.selectionChange.emit(this._selection) | |
74 | } | |
75 | ||
76 | @Input() get videosModel () { | |
77 | return this.videos | |
78 | } | |
79 | ||
80 | set videosModel (videos: Video[]) { | |
81 | this.videos = videos | |
82 | this.videosModelChange.emit(this.videos) | |
83 | } | |
84 | ||
85 | ngOnInit () { | |
86 | super.ngOnInit() | |
87 | } | |
88 | ||
8c6781e9 C |
89 | ngAfterContentInit () { |
90 | { | |
91 | const t = this.templates.find(t => t.name === 'rowButtons') | |
92 | if (t) this.rowButtonsTemplate = t.template | |
93 | } | |
94 | ||
95 | { | |
96 | const t = this.templates.find(t => t.name === 'globalButtons') | |
97 | if (t) this.globalButtonsTemplate = t.template | |
98 | } | |
99 | } | |
100 | ||
693263e9 C |
101 | ngOnDestroy () { |
102 | super.ngOnDestroy() | |
103 | } | |
104 | ||
105 | getVideosObservable (page: number) { | |
106 | return this.getVideosObservableFunction(page, this.sort) | |
107 | } | |
108 | ||
109 | abortSelectionMode () { | |
110 | this._selection = {} | |
111 | } | |
112 | ||
113 | isInSelectionMode () { | |
114 | return Object.keys(this._selection).some(k => this._selection[ k ] === true) | |
115 | } | |
116 | ||
117 | generateSyndicationList () { | |
118 | throw new Error('Method not implemented.') | |
119 | } | |
120 | ||
121 | protected onMoreVideos () { | |
122 | this.videosModel = this.videos | |
123 | } | |
124 | } |