aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/shared/video
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-12-05 17:46:33 +0100
committerChocobozzz <florian.bigard@gmail.com>2017-12-05 18:25:29 +0100
commitf3aaa9a95cc2b61f1f255472d7014d08faa66561 (patch)
tree95e70c8d0ed5b6f1c71c32a77cb7d6cf8478c9d4 /client/src/app/shared/video
parentd235f6b0d1054a2a3451dacade927caefce8f30c (diff)
downloadPeerTube-f3aaa9a95cc2b61f1f255472d7014d08faa66561.tar.gz
PeerTube-f3aaa9a95cc2b61f1f255472d7014d08faa66561.tar.zst
PeerTube-f3aaa9a95cc2b61f1f255472d7014d08faa66561.zip
Fix client search
Diffstat (limited to 'client/src/app/shared/video')
-rw-r--r--client/src/app/shared/video/abstract-video-list.ts24
-rw-r--r--client/src/app/shared/video/video.service.ts9
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 @@
1import { OnDestroy, OnInit } from '@angular/core' 1import { OnInit } from '@angular/core'
2import { ActivatedRoute, Router } from '@angular/router' 2import { ActivatedRoute, Router } from '@angular/router'
3import { NotificationsService } from 'angular2-notifications' 3import { NotificationsService } from 'angular2-notifications'
4import { Observable } from 'rxjs/Observable' 4import { Observable } from 'rxjs/Observable'
5import { Subscription } from 'rxjs/Subscription'
6import { SortField } from './sort-field.type' 5import { SortField } from './sort-field.type'
7import { VideoPagination } from './video-pagination.model' 6import { VideoPagination } from './video-pagination.model'
8import { Video } from './video.model' 7import { Video } from './video.model'
9 8
10export abstract class AbstractVideoList implements OnInit, OnDestroy { 9export 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
11import { VideoUpdate } from '../../../../../shared/models/videos/video-update.model' 11import { VideoUpdate } from '../../../../../shared/models/videos/video-update.model'
12import { RestExtractor } from '../rest/rest-extractor.service' 12import { RestExtractor } from '../rest/rest-extractor.service'
13import { RestService } from '../rest/rest.service' 13import { RestService } from '../rest/rest.service'
14import { Search } from '../search/search.model' 14import { Search } from '../header/search.model'
15import { UserService } from '../users/user.service' 15import { UserService } from '../users/user.service'
16import { SortField } from './sort-field.type' 16import { SortField } from './sort-field.type'
17import { VideoDetails } from './video-details.model' 17import { 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 })