diff options
Diffstat (limited to 'client/src/app/shared/shared-video-miniature/videos-selection.component.ts')
-rw-r--r-- | client/src/app/shared/shared-video-miniature/videos-selection.component.ts | 118 |
1 files changed, 118 insertions, 0 deletions
diff --git a/client/src/app/shared/shared-video-miniature/videos-selection.component.ts b/client/src/app/shared/shared-video-miniature/videos-selection.component.ts new file mode 100644 index 000000000..3e0e3b983 --- /dev/null +++ b/client/src/app/shared/shared-video-miniature/videos-selection.component.ts | |||
@@ -0,0 +1,118 @@ | |||
1 | import { Observable } from 'rxjs' | ||
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' | ||
15 | import { AuthService, ComponentPagination, LocalStorageService, Notifier, ScreenService, ServerService, UserService } from '@app/core' | ||
16 | import { I18n } from '@ngx-translate/i18n-polyfill' | ||
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' | ||
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 { | ||
30 | @Input() pagination: ComponentPagination | ||
31 | @Input() titlePage: string | ||
32 | @Input() miniatureDisplayOptions: MiniatureDisplayOptions | ||
33 | @Input() ownerDisplayType: OwnerDisplayType | ||
34 | |||
35 | @Input() getVideosObservableFunction: (page: number, sort?: VideoSortField) => Observable<ResultList<Video>> | ||
36 | |||
37 | @ContentChildren(PeerTubeTemplateDirective) templates: QueryList<PeerTubeTemplateDirective<'rowButtons' | 'globalButtons'>> | ||
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 i18n: I18n, | ||
49 | protected router: Router, | ||
50 | protected route: ActivatedRoute, | ||
51 | protected notifier: Notifier, | ||
52 | protected authService: AuthService, | ||
53 | protected userService: UserService, | ||
54 | protected screenService: ScreenService, | ||
55 | protected storageService: LocalStorageService, | ||
56 | protected serverService: ServerService | ||
57 | ) { | ||
58 | super() | ||
59 | } | ||
60 | |||
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 | |||
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 | |||
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 | } | ||