aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/search/search.component.ts
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/app/search/search.component.ts')
-rw-r--r--client/src/app/search/search.component.ts26
1 files changed, 19 insertions, 7 deletions
diff --git a/client/src/app/search/search.component.ts b/client/src/app/search/search.component.ts
index 8d615fd05..f88df6391 100644
--- a/client/src/app/search/search.component.ts
+++ b/client/src/app/search/search.component.ts
@@ -2,13 +2,15 @@ import { Component, OnDestroy, OnInit } from '@angular/core'
2import { ActivatedRoute, Router } from '@angular/router' 2import { ActivatedRoute, Router } from '@angular/router'
3import { RedirectService } from '@app/core' 3import { RedirectService } from '@app/core'
4import { NotificationsService } from 'angular2-notifications' 4import { NotificationsService } from 'angular2-notifications'
5import { Subscription } from 'rxjs' 5import { forkJoin, Subscription } from 'rxjs'
6import { SearchService } from '@app/search/search.service' 6import { SearchService } from '@app/search/search.service'
7import { ComponentPagination } from '@app/shared/rest/component-pagination.model' 7import { ComponentPagination } from '@app/shared/rest/component-pagination.model'
8import { I18n } from '@ngx-translate/i18n-polyfill' 8import { I18n } from '@ngx-translate/i18n-polyfill'
9import { Video } from '../../../../shared' 9import { Video } from '../../../../shared'
10import { MetaService } from '@ngx-meta/core' 10import { MetaService } from '@ngx-meta/core'
11import { AdvancedSearch } from '@app/search/advanced-search.model' 11import { AdvancedSearch } from '@app/search/advanced-search.model'
12import { VideoChannel } from '@app/shared/video-channel/video-channel.model'
13import { immutableAssign } from '@app/shared/misc/utils'
12 14
13@Component({ 15@Component({
14 selector: 'my-search', 16 selector: 'my-search',
@@ -17,18 +19,22 @@ import { AdvancedSearch } from '@app/search/advanced-search.model'
17}) 19})
18export class SearchComponent implements OnInit, OnDestroy { 20export class SearchComponent implements OnInit, OnDestroy {
19 videos: Video[] = [] 21 videos: Video[] = []
22 videoChannels: VideoChannel[] = []
23
20 pagination: ComponentPagination = { 24 pagination: ComponentPagination = {
21 currentPage: 1, 25 currentPage: 1,
22 itemsPerPage: 10, // It's per object type (so 10 videos, 10 video channels etc) 26 itemsPerPage: 10, // Only for videos, use another variable for channels
23 totalItems: null 27 totalItems: null
24 } 28 }
25 advancedSearch: AdvancedSearch = new AdvancedSearch() 29 advancedSearch: AdvancedSearch = new AdvancedSearch()
26 isSearchFilterCollapsed = true 30 isSearchFilterCollapsed = true
31 currentSearch: string
27 32
28 private subActivatedRoute: Subscription 33 private subActivatedRoute: Subscription
29 private currentSearch: string
30 private isInitialLoad = true 34 private isInitialLoad = true
31 35
36 private channelsPerPage = 2
37
32 constructor ( 38 constructor (
33 private i18n: I18n, 39 private i18n: I18n,
34 private route: ActivatedRoute, 40 private route: ActivatedRoute,
@@ -74,17 +80,23 @@ export class SearchComponent implements OnInit, OnDestroy {
74 } 80 }
75 81
76 search () { 82 search () {
77 return this.searchService.searchVideos(this.currentSearch, this.pagination, this.advancedSearch) 83 forkJoin([
84 this.searchService.searchVideos(this.currentSearch, this.pagination, this.advancedSearch),
85 this.searchService.searchVideoChannels(this.currentSearch, immutableAssign(this.pagination, { itemsPerPage: this.channelsPerPage }))
86 ])
78 .subscribe( 87 .subscribe(
79 ({ videos, totalVideos }) => { 88 ([ videosResult, videoChannelsResult ]) => {
80 this.videos = this.videos.concat(videos) 89 this.videos = this.videos.concat(videosResult.videos)
81 this.pagination.totalItems = totalVideos 90 this.pagination.totalItems = videosResult.totalVideos
91
92 this.videoChannels = videoChannelsResult.data
82 }, 93 },
83 94
84 error => { 95 error => {
85 this.notificationsService.error(this.i18n('Error'), error.message) 96 this.notificationsService.error(this.i18n('Error'), error.message)
86 } 97 }
87 ) 98 )
99
88 } 100 }
89 101
90 onNearOfBottom () { 102 onNearOfBottom () {