diff options
Diffstat (limited to 'client/src/app/videos/video-list/shared/abstract-video-list.ts')
-rw-r--r-- | client/src/app/videos/video-list/shared/abstract-video-list.ts | 28 |
1 files changed, 5 insertions, 23 deletions
diff --git a/client/src/app/videos/video-list/shared/abstract-video-list.ts b/client/src/app/videos/video-list/shared/abstract-video-list.ts index 87d5bc48a..262ea4e21 100644 --- a/client/src/app/videos/video-list/shared/abstract-video-list.ts +++ b/client/src/app/videos/video-list/shared/abstract-video-list.ts | |||
@@ -1,25 +1,19 @@ | |||
1 | import { OnDestroy, OnInit } from '@angular/core' | 1 | import { OnDestroy, OnInit } from '@angular/core' |
2 | import { ActivatedRoute, Router } from '@angular/router' | 2 | import { ActivatedRoute, Router } from '@angular/router' |
3 | import { Subscription } from 'rxjs/Subscription' | ||
4 | import { BehaviorSubject } from 'rxjs/BehaviorSubject' | ||
5 | import { Observable } from 'rxjs/Observable' | ||
6 | 3 | ||
7 | import { NotificationsService } from 'angular2-notifications' | 4 | import { NotificationsService } from 'angular2-notifications' |
5 | import { Observable } from 'rxjs/Observable' | ||
6 | import { Subscription } from 'rxjs/Subscription' | ||
8 | 7 | ||
9 | import { | 8 | import { SortField, Video, VideoPagination } from '../../shared' |
10 | SortField, | ||
11 | Video, | ||
12 | VideoPagination | ||
13 | } from '../../shared' | ||
14 | 9 | ||
15 | export abstract class AbstractVideoList implements OnInit, OnDestroy { | 10 | export abstract class AbstractVideoList implements OnInit, OnDestroy { |
16 | loading: BehaviorSubject<boolean> = new BehaviorSubject(false) | ||
17 | pagination: VideoPagination = { | 11 | pagination: VideoPagination = { |
18 | currentPage: 1, | 12 | currentPage: 1, |
19 | itemsPerPage: 25, | 13 | itemsPerPage: 25, |
20 | totalItems: null | 14 | totalItems: null |
21 | } | 15 | } |
22 | sort: SortField | 16 | sort: SortField = '-createdAt' |
23 | videos: Video[] = [] | 17 | videos: Video[] = [] |
24 | 18 | ||
25 | protected notificationsService: NotificationsService | 19 | protected notificationsService: NotificationsService |
@@ -28,6 +22,7 @@ export abstract class AbstractVideoList implements OnInit, OnDestroy { | |||
28 | 22 | ||
29 | protected subActivatedRoute: Subscription | 23 | protected subActivatedRoute: Subscription |
30 | 24 | ||
25 | abstract titlePage: string | ||
31 | abstract getVideosObservable (): Observable<{ videos: Video[], totalVideos: number}> | 26 | abstract getVideosObservable (): Observable<{ videos: Video[], totalVideos: number}> |
32 | 27 | ||
33 | ngOnInit () { | 28 | ngOnInit () { |
@@ -44,7 +39,6 @@ export abstract class AbstractVideoList implements OnInit, OnDestroy { | |||
44 | } | 39 | } |
45 | 40 | ||
46 | getVideos () { | 41 | getVideos () { |
47 | this.loading.next(true) | ||
48 | this.videos = [] | 42 | this.videos = [] |
49 | 43 | ||
50 | const observable = this.getVideosObservable() | 44 | const observable = this.getVideosObservable() |
@@ -53,17 +47,11 @@ export abstract class AbstractVideoList implements OnInit, OnDestroy { | |||
53 | ({ videos, totalVideos }) => { | 47 | ({ videos, totalVideos }) => { |
54 | this.videos = videos | 48 | this.videos = videos |
55 | this.pagination.totalItems = totalVideos | 49 | this.pagination.totalItems = totalVideos |
56 | |||
57 | this.loading.next(false) | ||
58 | }, | 50 | }, |
59 | error => this.notificationsService.error('Error', error.text) | 51 | error => this.notificationsService.error('Error', error.text) |
60 | ) | 52 | ) |
61 | } | 53 | } |
62 | 54 | ||
63 | isThereNoVideo () { | ||
64 | return !this.loading.getValue() && this.videos.length === 0 | ||
65 | } | ||
66 | |||
67 | onPageChanged (event: { page: number }) { | 55 | onPageChanged (event: { page: number }) { |
68 | // Be sure the current page is set | 56 | // Be sure the current page is set |
69 | this.pagination.currentPage = event.page | 57 | this.pagination.currentPage = event.page |
@@ -71,12 +59,6 @@ export abstract class AbstractVideoList implements OnInit, OnDestroy { | |||
71 | this.navigateToNewParams() | 59 | this.navigateToNewParams() |
72 | } | 60 | } |
73 | 61 | ||
74 | onSort (sort: SortField) { | ||
75 | this.sort = sort | ||
76 | |||
77 | this.navigateToNewParams() | ||
78 | } | ||
79 | |||
80 | protected buildRouteParams () { | 62 | protected buildRouteParams () { |
81 | // There is always a sort and a current page | 63 | // There is always a sort and a current page |
82 | const params = { | 64 | const params = { |