diff options
Diffstat (limited to 'client/src/app/shared/video')
-rw-r--r-- | client/src/app/shared/video/abstract-video-list.ts | 24 | ||||
-rw-r--r-- | client/src/app/shared/video/video.service.ts | 9 |
2 files changed, 16 insertions, 17 deletions
diff --git a/client/src/app/shared/video/abstract-video-list.ts b/client/src/app/shared/video/abstract-video-list.ts index cf717cf4c..84ca5cbe4 100644 --- a/client/src/app/shared/video/abstract-video-list.ts +++ b/client/src/app/shared/video/abstract-video-list.ts | |||
@@ -1,25 +1,25 @@ | |||
1 | import { OnDestroy, OnInit } from '@angular/core' | 1 | import { OnInit } from '@angular/core' |
2 | import { ActivatedRoute, Router } from '@angular/router' | 2 | import { ActivatedRoute, Router } from '@angular/router' |
3 | import { NotificationsService } from 'angular2-notifications' | 3 | import { NotificationsService } from 'angular2-notifications' |
4 | import { Observable } from 'rxjs/Observable' | 4 | import { Observable } from 'rxjs/Observable' |
5 | import { Subscription } from 'rxjs/Subscription' | ||
6 | import { SortField } from './sort-field.type' | 5 | import { SortField } from './sort-field.type' |
7 | import { VideoPagination } from './video-pagination.model' | 6 | import { VideoPagination } from './video-pagination.model' |
8 | import { Video } from './video.model' | 7 | import { Video } from './video.model' |
9 | 8 | ||
10 | export abstract class AbstractVideoList implements OnInit, OnDestroy { | 9 | export abstract class AbstractVideoList implements OnInit { |
11 | pagination: VideoPagination = { | 10 | pagination: VideoPagination = { |
12 | currentPage: 1, | 11 | currentPage: 1, |
13 | itemsPerPage: 25, | 12 | itemsPerPage: 25, |
14 | totalItems: null | 13 | totalItems: null |
15 | } | 14 | } |
16 | sort: SortField = '-createdAt' | 15 | sort: SortField = '-createdAt' |
16 | defaultSort: SortField = '-createdAt' | ||
17 | videos: Video[] = [] | 17 | videos: Video[] = [] |
18 | loadOnInit = true | ||
18 | 19 | ||
19 | protected notificationsService: NotificationsService | 20 | protected notificationsService: NotificationsService |
20 | protected router: Router | 21 | protected router: Router |
21 | protected route: ActivatedRoute | 22 | protected route: ActivatedRoute |
22 | protected subActivatedRoute: Subscription | ||
23 | 23 | ||
24 | protected abstract currentRoute: string | 24 | protected abstract currentRoute: string |
25 | 25 | ||
@@ -32,13 +32,7 @@ export abstract class AbstractVideoList implements OnInit, OnDestroy { | |||
32 | // Subscribe to route changes | 32 | // Subscribe to route changes |
33 | const routeParams = this.route.snapshot.params | 33 | const routeParams = this.route.snapshot.params |
34 | this.loadRouteParams(routeParams) | 34 | this.loadRouteParams(routeParams) |
35 | this.loadMoreVideos('after') | 35 | if (this.loadOnInit === true) this.loadMoreVideos('after') |
36 | } | ||
37 | |||
38 | ngOnDestroy () { | ||
39 | if (this.subActivatedRoute) { | ||
40 | this.subActivatedRoute.unsubscribe() | ||
41 | } | ||
42 | } | 36 | } |
43 | 37 | ||
44 | onNearOfTop () { | 38 | onNearOfTop () { |
@@ -53,6 +47,12 @@ export abstract class AbstractVideoList implements OnInit, OnDestroy { | |||
53 | } | 47 | } |
54 | } | 48 | } |
55 | 49 | ||
50 | reloadVideos () { | ||
51 | this.videos = [] | ||
52 | this.loadedPages = {} | ||
53 | this.loadMoreVideos('before') | ||
54 | } | ||
55 | |||
56 | loadMoreVideos (where: 'before' | 'after') { | 56 | loadMoreVideos (where: 'before' | 'after') { |
57 | if (this.loadedPages[this.pagination.currentPage] === true) return | 57 | if (this.loadedPages[this.pagination.currentPage] === true) return |
58 | 58 | ||
@@ -105,7 +105,7 @@ export abstract class AbstractVideoList implements OnInit, OnDestroy { | |||
105 | } | 105 | } |
106 | 106 | ||
107 | protected loadRouteParams (routeParams: { [ key: string ]: any }) { | 107 | protected loadRouteParams (routeParams: { [ key: string ]: any }) { |
108 | this.sort = routeParams['sort'] as SortField || '-createdAt' | 108 | this.sort = routeParams['sort'] as SortField || this.defaultSort |
109 | 109 | ||
110 | if (routeParams['page'] !== undefined) { | 110 | if (routeParams['page'] !== undefined) { |
111 | this.pagination.currentPage = parseInt(routeParams['page'], 10) | 111 | this.pagination.currentPage = parseInt(routeParams['page'], 10) |
diff --git a/client/src/app/shared/video/video.service.ts b/client/src/app/shared/video/video.service.ts index b2a26417c..3f35b67c4 100644 --- a/client/src/app/shared/video/video.service.ts +++ b/client/src/app/shared/video/video.service.ts | |||
@@ -11,7 +11,7 @@ import { VideoRateType } from '../../../../../shared/models/videos/video-rate.ty | |||
11 | import { VideoUpdate } from '../../../../../shared/models/videos/video-update.model' | 11 | import { VideoUpdate } from '../../../../../shared/models/videos/video-update.model' |
12 | import { RestExtractor } from '../rest/rest-extractor.service' | 12 | import { RestExtractor } from '../rest/rest-extractor.service' |
13 | import { RestService } from '../rest/rest.service' | 13 | import { RestService } from '../rest/rest.service' |
14 | import { Search } from '../search/search.model' | 14 | import { Search } from '../header/search.model' |
15 | import { UserService } from '../users/user.service' | 15 | import { UserService } from '../users/user.service' |
16 | import { SortField } from './sort-field.type' | 16 | import { SortField } from './sort-field.type' |
17 | import { VideoDetails } from './video-details.model' | 17 | import { VideoDetails } from './video-details.model' |
@@ -91,15 +91,14 @@ export class VideoService { | |||
91 | .catch((res) => this.restExtractor.handleError(res)) | 91 | .catch((res) => this.restExtractor.handleError(res)) |
92 | } | 92 | } |
93 | 93 | ||
94 | searchVideos (search: Search, videoPagination: VideoPagination, sort: SortField): Observable<{ videos: Video[], totalVideos: number}> { | 94 | searchVideos (search: string, videoPagination: VideoPagination, sort: SortField): Observable<{ videos: Video[], totalVideos: number}> { |
95 | const url = VideoService.BASE_VIDEO_URL + 'search/' + encodeURIComponent(search.value) | 95 | const url = VideoService.BASE_VIDEO_URL + 'search' |
96 | 96 | ||
97 | const pagination = this.videoPaginationToRestPagination(videoPagination) | 97 | const pagination = this.videoPaginationToRestPagination(videoPagination) |
98 | 98 | ||
99 | let params = new HttpParams() | 99 | let params = new HttpParams() |
100 | params = this.restService.addRestGetParams(params, pagination, sort) | 100 | params = this.restService.addRestGetParams(params, pagination, sort) |
101 | 101 | params = params.append('search', search) | |
102 | if (search.field) params.set('field', search.field) | ||
103 | 102 | ||
104 | return this.authHttp | 103 | return this.authHttp |
105 | .get<ResultList<VideoServerModel>>(url, { params }) | 104 | .get<ResultList<VideoServerModel>>(url, { params }) |