add allow advancedSearch with empty search

a.k.a. filters on all videos

also added a badge showing the rough number of active filters
pull/1162/head
Rigel Kent 2018-10-01 17:21:03 +02:00
parent 99cc653f47
commit c5d04b4f35
No known key found for this signature in database
GPG Key ID: EA12971B0E438F36
4 changed files with 26 additions and 4 deletions

View File

@ -110,6 +110,19 @@ export class AdvancedSearch {
}
}
size () {
let acc = 0
const obj = this.toUrlObject()
for (const k of Object.keys(obj)) {
if (k === 'sort') continue // Exception
if (obj[k] !== undefined) acc++
}
return acc
}
private intoArray (value: any) {
if (!value) return undefined

View File

@ -13,7 +13,10 @@
[attr.aria-expanded]="!isSearchFilterCollapsed" aria-controls="collapseBasic"
>
<span class="icon icon-filter"></span>
<ng-container i18n>Filters</ng-container>
<ng-container i18n>
Filters
<span *ngIf="numberOfFilters() > 0" class="badge badge-secondary">{{ numberOfFilters() }}</span>
</ng-container>
</div>
</div>

View File

@ -30,7 +30,7 @@ export class SearchComponent implements OnInit, OnDestroy {
currentSearch: string
private subActivatedRoute: Subscription
private isInitialLoad = true
private isInitialLoad = false // set to false to show the search filters on first arrival
private firstSearch = true
private channelsPerPage = 2
@ -137,6 +137,10 @@ export class SearchComponent implements OnInit, OnDestroy {
this.updateUrlFromAdvancedSearch()
}
numberOfFilters () {
return this.advancedSearch.size()
}
private resetPagination () {
this.pagination.currentPage = 1
this.pagination.totalItems = null
@ -150,9 +154,11 @@ export class SearchComponent implements OnInit, OnDestroy {
}
private updateUrlFromAdvancedSearch () {
const search = (this.currentSearch && this.currentSearch !== '') ? this.currentSearch : undefined
this.router.navigate([], {
relativeTo: this.route,
queryParams: Object.assign({}, this.advancedSearch.toUrlObject(), { search: this.currentSearch })
queryParams: Object.assign({}, this.advancedSearch.toUrlObject(), { search })
})
}
}

View File

@ -23,7 +23,7 @@
//@import '~bootstrap/scss/card';
//@import '~bootstrap/scss/breadcrumb';
//@import '~bootstrap/scss/pagination';
//@import '~bootstrap/scss/badge';
@import '~bootstrap/scss/badge';
//@import '~bootstrap/scss/jumbotron';
@import '~bootstrap/scss/alert';
//@import '~bootstrap/scss/progress';