aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/search/search.component.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-07-20 18:31:49 +0200
committerChocobozzz <me@florianbigard.com>2018-07-24 14:04:05 +0200
commit0b18f4aa80df8868bf34605423c7a298dffbb2aa (patch)
tree25299da5d94fc73e88b21e87aeb2c156999c6fcd /client/src/app/search/search.component.ts
parentd525fc399a14a8b16eaad6d4c0bc0a9c4093c3c9 (diff)
downloadPeerTube-0b18f4aa80df8868bf34605423c7a298dffbb2aa.tar.gz
PeerTube-0b18f4aa80df8868bf34605423c7a298dffbb2aa.tar.zst
PeerTube-0b18f4aa80df8868bf34605423c7a298dffbb2aa.zip
Add advanced search in client
Diffstat (limited to 'client/src/app/search/search.component.ts')
-rw-r--r--client/src/app/search/search.component.ts29
1 files changed, 27 insertions, 2 deletions
diff --git a/client/src/app/search/search.component.ts b/client/src/app/search/search.component.ts
index be1cb3689..09028fec5 100644
--- a/client/src/app/search/search.component.ts
+++ b/client/src/app/search/search.component.ts
@@ -1,5 +1,5 @@
1import { Component, OnDestroy, OnInit } from '@angular/core' 1import { Component, OnDestroy, OnInit } from '@angular/core'
2import { ActivatedRoute } 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 { Subscription } from 'rxjs'
@@ -8,6 +8,7 @@ import { 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'
11 12
12@Component({ 13@Component({
13 selector: 'my-search', 14 selector: 'my-search',
@@ -21,6 +22,8 @@ export class SearchComponent implements OnInit, OnDestroy {
21 itemsPerPage: 10, // It's per object type (so 10 videos, 10 video channels etc) 22 itemsPerPage: 10, // It's per object type (so 10 videos, 10 video channels etc)
22 totalItems: null 23 totalItems: null
23 } 24 }
25 advancedSearch: AdvancedSearch = new AdvancedSearch()
26 isSearchFilterCollapsed = true
24 27
25 private subActivatedRoute: Subscription 28 private subActivatedRoute: Subscription
26 private currentSearch: string 29 private currentSearch: string
@@ -28,6 +31,7 @@ export class SearchComponent implements OnInit, OnDestroy {
28 constructor ( 31 constructor (
29 private i18n: I18n, 32 private i18n: I18n,
30 private route: ActivatedRoute, 33 private route: ActivatedRoute,
34 private router: Router,
31 private metaService: MetaService, 35 private metaService: MetaService,
32 private redirectService: RedirectService, 36 private redirectService: RedirectService,
33 private notificationsService: NotificationsService, 37 private notificationsService: NotificationsService,
@@ -35,6 +39,9 @@ export class SearchComponent implements OnInit, OnDestroy {
35 ) { } 39 ) { }
36 40
37 ngOnInit () { 41 ngOnInit () {
42 this.advancedSearch = new AdvancedSearch(this.route.snapshot.queryParams)
43 if (this.advancedSearch.containsValues()) this.isSearchFilterCollapsed = false
44
38 this.subActivatedRoute = this.route.queryParams.subscribe( 45 this.subActivatedRoute = this.route.queryParams.subscribe(
39 queryParams => { 46 queryParams => {
40 const querySearch = queryParams['search'] 47 const querySearch = queryParams['search']
@@ -42,6 +49,9 @@ export class SearchComponent implements OnInit, OnDestroy {
42 if (!querySearch) return this.redirectService.redirectToHomepage() 49 if (!querySearch) return this.redirectService.redirectToHomepage()
43 if (querySearch === this.currentSearch) return 50 if (querySearch === this.currentSearch) return
44 51
52 // Search updated, reset filters
53 if (this.currentSearch) this.advancedSearch.reset()
54
45 this.currentSearch = querySearch 55 this.currentSearch = querySearch
46 this.updateTitle() 56 this.updateTitle()
47 57
@@ -57,7 +67,7 @@ export class SearchComponent implements OnInit, OnDestroy {
57 } 67 }
58 68
59 search () { 69 search () {
60 return this.searchService.searchVideos(this.currentSearch, this.pagination) 70 return this.searchService.searchVideos(this.currentSearch, this.pagination, this.advancedSearch)
61 .subscribe( 71 .subscribe(
62 ({ videos, totalVideos }) => { 72 ({ videos, totalVideos }) => {
63 this.videos = this.videos.concat(videos) 73 this.videos = this.videos.concat(videos)
@@ -78,6 +88,14 @@ export class SearchComponent implements OnInit, OnDestroy {
78 this.search() 88 this.search()
79 } 89 }
80 90
91 onFiltered () {
92 this.updateUrlFromAdvancedSearch()
93 // Hide the filters
94 this.isSearchFilterCollapsed = true
95
96 this.reload()
97 }
98
81 private reload () { 99 private reload () {
82 this.pagination.currentPage = 1 100 this.pagination.currentPage = 1
83 this.pagination.totalItems = null 101 this.pagination.totalItems = null
@@ -90,4 +108,11 @@ export class SearchComponent implements OnInit, OnDestroy {
90 private updateTitle () { 108 private updateTitle () {
91 this.metaService.setTitle(this.i18n('Search') + ' ' + this.currentSearch) 109 this.metaService.setTitle(this.i18n('Search') + ' ' + this.currentSearch)
92 } 110 }
111
112 private updateUrlFromAdvancedSearch () {
113 this.router.navigate([], {
114 relativeTo: this.route,
115 queryParams: Object.assign({}, this.advancedSearch.toUrlObject(), { search: this.currentSearch })
116 })
117 }
93} 118}