diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2016-10-02 15:39:09 +0200 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2016-10-02 15:39:09 +0200 |
commit | a6375e69668ea42e19531c6bc68dcd37f3f7cbd7 (patch) | |
tree | 03204a408d56311692c3528bedcf95d2455e94f2 /client/src/app/videos/video-list/video-list.component.ts | |
parent | 052937db8a8d282eccdbdf38d487ed8d85d3c0a7 (diff) | |
parent | c4403b29ad4db097af528a7f04eea07e0ed320d0 (diff) | |
download | PeerTube-a6375e69668ea42e19531c6bc68dcd37f3f7cbd7.tar.gz PeerTube-a6375e69668ea42e19531c6bc68dcd37f3f7cbd7.tar.zst PeerTube-a6375e69668ea42e19531c6bc68dcd37f3f7cbd7.zip |
Merge branch 'master' into webseed-merged
Diffstat (limited to 'client/src/app/videos/video-list/video-list.component.ts')
-rw-r--r-- | client/src/app/videos/video-list/video-list.component.ts | 35 |
1 files changed, 16 insertions, 19 deletions
diff --git a/client/src/app/videos/video-list/video-list.component.ts b/client/src/app/videos/video-list/video-list.component.ts index 5691d684e..6b086e938 100644 --- a/client/src/app/videos/video-list/video-list.component.ts +++ b/client/src/app/videos/video-list/video-list.component.ts | |||
@@ -1,39 +1,30 @@ | |||
1 | import { ChangeDetectorRef, Component, OnDestroy, OnInit } from '@angular/core'; | 1 | import { ChangeDetectorRef, Component, OnDestroy, OnInit } from '@angular/core'; |
2 | import { AsyncPipe } from '@angular/common'; | 2 | import { ActivatedRoute, Router } from '@angular/router'; |
3 | import { ActivatedRoute, Router, ROUTER_DIRECTIVES } from '@angular/router'; | ||
4 | import { BehaviorSubject } from 'rxjs/BehaviorSubject'; | 3 | import { BehaviorSubject } from 'rxjs/BehaviorSubject'; |
5 | 4 | ||
6 | import { PAGINATION_DIRECTIVES } from 'ng2-bootstrap/components/pagination'; | ||
7 | |||
8 | import { | 5 | import { |
9 | LoaderComponent, | ||
10 | Pagination, | ||
11 | SortField, | 6 | SortField, |
12 | Video, | 7 | Video, |
13 | VideoService | 8 | VideoService |
14 | } from '../shared'; | 9 | } from '../shared'; |
15 | import { AuthService, Search, SearchField, User } from '../../shared'; | 10 | import { AuthService, AuthUser, RestPagination, Search, SearchField } from '../../shared'; |
16 | import { VideoMiniatureComponent } from './video-miniature.component'; | ||
17 | import { VideoSortComponent } from './video-sort.component'; | ||
18 | import { SearchService } from '../../shared'; | 11 | import { SearchService } from '../../shared'; |
19 | 12 | ||
20 | @Component({ | 13 | @Component({ |
21 | selector: 'my-videos-list', | 14 | selector: 'my-videos-list', |
22 | styles: [ require('./video-list.component.scss') ], | 15 | styleUrls: [ './video-list.component.scss' ], |
23 | pipes: [ AsyncPipe ], | 16 | templateUrl: './video-list.component.html' |
24 | template: require('./video-list.component.html'), | ||
25 | directives: [ LoaderComponent, PAGINATION_DIRECTIVES, ROUTER_DIRECTIVES, VideoMiniatureComponent, VideoSortComponent ] | ||
26 | }) | 17 | }) |
27 | 18 | ||
28 | export class VideoListComponent implements OnInit, OnDestroy { | 19 | export class VideoListComponent implements OnInit, OnDestroy { |
29 | loading: BehaviorSubject<boolean> = new BehaviorSubject(false); | 20 | loading: BehaviorSubject<boolean> = new BehaviorSubject(false); |
30 | pagination: Pagination = { | 21 | pagination: RestPagination = { |
31 | currentPage: 1, | 22 | currentPage: 1, |
32 | itemsPerPage: 9, | 23 | itemsPerPage: 9, |
33 | totalItems: null | 24 | totalItems: null |
34 | }; | 25 | }; |
35 | sort: SortField; | 26 | sort: SortField; |
36 | user: User = null; | 27 | user: AuthUser = null; |
37 | videos: Video[] = []; | 28 | videos: Video[] = []; |
38 | 29 | ||
39 | private search: Search; | 30 | private search: Search; |
@@ -51,7 +42,7 @@ export class VideoListComponent implements OnInit, OnDestroy { | |||
51 | 42 | ||
52 | ngOnInit() { | 43 | ngOnInit() { |
53 | if (this.authService.isLoggedIn()) { | 44 | if (this.authService.isLoggedIn()) { |
54 | this.user = User.load(); | 45 | this.user = AuthUser.load(); |
55 | } | 46 | } |
56 | 47 | ||
57 | // Subscribe to route changes | 48 | // Subscribe to route changes |
@@ -66,6 +57,8 @@ export class VideoListComponent implements OnInit, OnDestroy { | |||
66 | // Subscribe to search changes | 57 | // Subscribe to search changes |
67 | this.subSearch = this.searchService.searchUpdated.subscribe(search => { | 58 | this.subSearch = this.searchService.searchUpdated.subscribe(search => { |
68 | this.search = search; | 59 | this.search = search; |
60 | // Reset pagination | ||
61 | this.pagination.currentPage = 1; | ||
69 | 62 | ||
70 | this.navigateToNewParams(); | 63 | this.navigateToNewParams(); |
71 | }); | 64 | }); |
@@ -76,7 +69,7 @@ export class VideoListComponent implements OnInit, OnDestroy { | |||
76 | this.subSearch.unsubscribe(); | 69 | this.subSearch.unsubscribe(); |
77 | } | 70 | } |
78 | 71 | ||
79 | getVideos(detectChanges = true) { | 72 | getVideos() { |
80 | this.loading.next(true); | 73 | this.loading.next(true); |
81 | this.videos = []; | 74 | this.videos = []; |
82 | 75 | ||
@@ -97,7 +90,7 @@ export class VideoListComponent implements OnInit, OnDestroy { | |||
97 | 90 | ||
98 | this.loading.next(false); | 91 | this.loading.next(false); |
99 | }, | 92 | }, |
100 | error => alert(error) | 93 | error => alert(error.text) |
101 | ); | 94 | ); |
102 | } | 95 | } |
103 | 96 | ||
@@ -153,7 +146,11 @@ export class VideoListComponent implements OnInit, OnDestroy { | |||
153 | 146 | ||
154 | this.sort = <SortField>routeParams['sort'] || '-createdDate'; | 147 | this.sort = <SortField>routeParams['sort'] || '-createdDate'; |
155 | 148 | ||
156 | this.pagination.currentPage = parseInt(routeParams['page']) || 1; | 149 | if (routeParams['page'] !== undefined) { |
150 | this.pagination.currentPage = parseInt(routeParams['page']); | ||
151 | } else { | ||
152 | this.pagination.currentPage = 1; | ||
153 | } | ||
157 | 154 | ||
158 | this.changeDetector.detectChanges(); | 155 | this.changeDetector.detectChanges(); |
159 | } | 156 | } |