diff options
Diffstat (limited to 'client/src/app/shared/shared-video-miniature/abstract-video-list.ts')
-rw-r--r-- | client/src/app/shared/shared-video-miniature/abstract-video-list.ts | 50 |
1 files changed, 47 insertions, 3 deletions
diff --git a/client/src/app/shared/shared-video-miniature/abstract-video-list.ts b/client/src/app/shared/shared-video-miniature/abstract-video-list.ts index a5f22585d..3e84589cd 100644 --- a/client/src/app/shared/shared-video-miniature/abstract-video-list.ts +++ b/client/src/app/shared/shared-video-miniature/abstract-video-list.ts | |||
@@ -1,6 +1,16 @@ | |||
1 | import { fromEvent, Observable, Subject, Subscription } from 'rxjs' | 1 | import { fromEvent, Observable, Subject, Subscription } from 'rxjs' |
2 | import { debounceTime, switchMap, tap } from 'rxjs/operators' | 2 | import { debounceTime, switchMap, tap } from 'rxjs/operators' |
3 | import { Directive, OnDestroy, OnInit } from '@angular/core' | 3 | import { |
4 | AfterContentInit, | ||
5 | ComponentFactoryResolver, | ||
6 | Directive, | ||
7 | Injector, | ||
8 | OnDestroy, | ||
9 | OnInit, | ||
10 | Type, | ||
11 | ViewChild, | ||
12 | ViewContainerRef | ||
13 | } from '@angular/core' | ||
4 | import { ActivatedRoute, Router } from '@angular/router' | 14 | import { ActivatedRoute, Router } from '@angular/router' |
5 | import { | 15 | import { |
6 | AuthService, | 16 | AuthService, |
@@ -19,6 +29,7 @@ import { ServerConfig, UserRight, VideoFilter, VideoSortField } from '@shared/mo | |||
19 | import { NSFWPolicyType } from '@shared/models/videos/nsfw-policy.type' | 29 | import { NSFWPolicyType } from '@shared/models/videos/nsfw-policy.type' |
20 | import { Syndication, Video } from '../shared-main' | 30 | import { Syndication, Video } from '../shared-main' |
21 | import { MiniatureDisplayOptions, OwnerDisplayType } from './video-miniature.component' | 31 | import { MiniatureDisplayOptions, OwnerDisplayType } from './video-miniature.component' |
32 | import { GenericHeaderComponent, VideoListHeaderComponent } from './video-list-header.component' | ||
22 | 33 | ||
23 | enum GroupDate { | 34 | enum GroupDate { |
24 | UNKNOWN = 0, | 35 | UNKNOWN = 0, |
@@ -32,7 +43,12 @@ enum GroupDate { | |||
32 | 43 | ||
33 | @Directive() | 44 | @Directive() |
34 | // tslint:disable-next-line: directive-class-suffix | 45 | // tslint:disable-next-line: directive-class-suffix |
35 | export abstract class AbstractVideoList implements OnInit, OnDestroy, DisableForReuseHook { | 46 | export abstract class AbstractVideoList implements OnInit, OnDestroy, AfterContentInit, DisableForReuseHook { |
47 | @ViewChild('videoListHeader', { static: true, read: ViewContainerRef }) videoListHeader: ViewContainerRef | ||
48 | |||
49 | HeaderComponent: Type<GenericHeaderComponent> = VideoListHeaderComponent | ||
50 | headerComponentInjector: Injector | ||
51 | |||
36 | pagination: ComponentPaginationLight = { | 52 | pagination: ComponentPaginationLight = { |
37 | currentPage: 1, | 53 | currentPage: 1, |
38 | itemsPerPage: 25 | 54 | itemsPerPage: 25 |
@@ -92,6 +108,7 @@ export abstract class AbstractVideoList implements OnInit, OnDestroy, DisableFor | |||
92 | protected abstract screenService: ScreenService | 108 | protected abstract screenService: ScreenService |
93 | protected abstract storageService: LocalStorageService | 109 | protected abstract storageService: LocalStorageService |
94 | protected abstract router: Router | 110 | protected abstract router: Router |
111 | protected abstract cfr: ComponentFactoryResolver | ||
95 | abstract titlePage: string | 112 | abstract titlePage: string |
96 | 113 | ||
97 | private resizeSubscription: Subscription | 114 | private resizeSubscription: Subscription |
@@ -153,6 +170,13 @@ export abstract class AbstractVideoList implements OnInit, OnDestroy, DisableFor | |||
153 | if (this.resizeSubscription) this.resizeSubscription.unsubscribe() | 170 | if (this.resizeSubscription) this.resizeSubscription.unsubscribe() |
154 | } | 171 | } |
155 | 172 | ||
173 | ngAfterContentInit () { | ||
174 | if (this.videoListHeader) { | ||
175 | // some components don't use the header: they use their own template, like my-history.component.html | ||
176 | this.setHeader.apply(this, [ this.HeaderComponent, this.headerComponentInjector ]) | ||
177 | } | ||
178 | } | ||
179 | |||
156 | disableForReuse () { | 180 | disableForReuse () { |
157 | this.disabled = true | 181 | this.disabled = true |
158 | } | 182 | } |
@@ -268,7 +292,27 @@ export abstract class AbstractVideoList implements OnInit, OnDestroy, DisableFor | |||
268 | } | 292 | } |
269 | 293 | ||
270 | toggleModerationDisplay () { | 294 | toggleModerationDisplay () { |
271 | throw new Error('toggleModerationDisplay is not implemented') | 295 | throw new Error('toggleModerationDisplay ' + $localize`function is not implemented`) |
296 | } | ||
297 | |||
298 | setHeader ( | ||
299 | t: Type<any> = this.HeaderComponent, | ||
300 | i: Injector = this.headerComponentInjector | ||
301 | ) { | ||
302 | const injector = i || Injector.create({ | ||
303 | providers: [{ | ||
304 | provide: 'data', | ||
305 | useValue: { | ||
306 | titlePage: this.titlePage, | ||
307 | titleTooltip: this.titleTooltip | ||
308 | } | ||
309 | }] | ||
310 | }) | ||
311 | const viewContainerRef = this.videoListHeader | ||
312 | viewContainerRef.clear() | ||
313 | |||
314 | const componentFactory = this.cfr.resolveComponentFactory(t) | ||
315 | viewContainerRef.createComponent(componentFactory, 0, injector) | ||
272 | } | 316 | } |
273 | 317 | ||
274 | // On videos hook for children that want to do something | 318 | // On videos hook for children that want to do something |