>
</div>
+ <div class="form-group">
+ <div class="radio-label label-container">
+ <label i18n>Result types</label>
+ <button i18n class="reset-button reset-button-small" (click)="resetField('resultType')" *ngIf="advancedSearch.resultType !== undefined">
+ Reset
+ </button>
+ </div>
+
+ <div class="peertube-radio-container">
+ <input type="radio" name="resultType" id="resultTypeVideos" value="videos" [(ngModel)]="advancedSearch.resultType">
+ <label i18n for="resultTypeVideos" class="radio">Videos</label>
+ </div>
+
+ <div class="peertube-radio-container">
+ <input type="radio" name="resultType" id="resultTypeChannels" value="channels" [(ngModel)]="advancedSearch.resultType">
+ <label i18n for="resultTypeChannels" class="radio">Channels</label>
+ </div>
+
+ <div class="peertube-radio-container">
+ <input type="radio" name="resultType" id="resultTypePlaylists" value="playlists" [(ngModel)]="advancedSearch.resultType">
+ <label i18n for="resultTypePlaylists" class="radio">Playlists</label>
+ </div>
+
+ </div>
+
<div class="form-group" *ngIf="isSearchTargetEnabled()">
<div class="radio-label label-container">
<label i18n>Search target</label>
publishedDateRanges: FormOption[] = []
sorts: FormOption[] = []
durationRanges: FormOption[] = []
- videoType: FormOption[] = []
publishedDateRange: string
durationRange: string
}
]
- this.videoType = [
- {
- id: 'vod',
- label: $localize`VOD videos`
- },
- {
- id: 'live',
- label: $localize`Live videos`
- }
- ]
-
this.durationRanges = [
{
id: 'short',
private subActivatedRoute: Subscription
private isInitialLoad = false // set to false to show the search filters on first arrival
- private channelsPerPage = 2
- private playlistsPerPage = 2
- private videosPerPage = 10
-
private hasMoreResults = true
private isSearching = false
private resetPagination () {
this.pagination.currentPage = 1
this.pagination.totalItems = null
- this.channelsPerPage = 2
this.results = []
}
private getVideosObs () {
const params = {
search: this.currentSearch,
- componentPagination: immutableAssign(this.pagination, { itemsPerPage: this.videosPerPage }),
+ componentPagination: immutableAssign(this.pagination, { itemsPerPage: 10 }),
advancedSearch: this.advancedSearch
}
private getVideoChannelObs () {
const params = {
search: this.currentSearch,
- componentPagination: immutableAssign(this.pagination, { itemsPerPage: this.channelsPerPage }),
+ componentPagination: immutableAssign(this.pagination, { itemsPerPage: this.buildChannelsPerPage() }),
advancedSearch: this.advancedSearch
}
private getVideoPlaylistObs () {
const params = {
search: this.currentSearch,
- componentPagination: immutableAssign(this.pagination, { itemsPerPage: this.playlistsPerPage }),
+ componentPagination: immutableAssign(this.pagination, { itemsPerPage: this.buildPlaylistsPerPage() }),
advancedSearch: this.advancedSearch
}
return undefined
}
+
+ private buildChannelsPerPage () {
+ if (this.advancedSearch.resultType === 'channels') return 10
+
+ return 2
+ }
+
+ private buildPlaylistsPerPage () {
+ if (this.advancedSearch.resultType === 'playlists') return 10
+
+ return 2
+ }
}
VideosSearchQuery
} from '@shared/models'
+export type AdvancedSearchResultType = 'videos' | 'playlists' | 'channels'
+
export class AdvancedSearch {
startDate: string // ISO 8601
endDate: string // ISO 8601
sort: string
searchTarget: SearchTargetType
+ resultType: AdvancedSearchResultType
// Filters we don't want to count, because they are mandatory
private silentFilters = new Set([ 'sort', 'searchTarget' ])
durationMax?: string
sort?: string
searchTarget?: SearchTargetType
+ resultType?: AdvancedSearchResultType
}) {
if (!options) return
this.searchTarget = options.searchTarget || undefined
+ this.resultType = options.resultType || undefined
+
+ if (!this.resultType && this.hasVideoFilter()) {
+ this.resultType = 'videos'
+ }
+
if (isNaN(this.durationMin)) this.durationMin = undefined
if (isNaN(this.durationMax)) this.durationMax = undefined
isLive: this.isLive,
host: this.host,
sort: this.sort,
- searchTarget: this.searchTarget
+ searchTarget: this.searchTarget,
+ resultType: this.resultType
}
}
return true
}
+
+ private hasVideoFilter () {
+ return this.startDate !== undefined ||
+ this.endDate !== undefined ||
+ this.originallyPublishedStartDate !== undefined ||
+ this.originallyPublishedEndDate !== undefined ||
+ this.nsfw !== undefined !== undefined ||
+ this.categoryOneOf !== undefined ||
+ this.licenceOneOf !== undefined ||
+ this.languageOneOf !== undefined ||
+ this.tagsOneOf !== undefined ||
+ this.tagsAllOf !== undefined ||
+ this.durationMin !== undefined ||
+ this.durationMax !== undefined ||
+ this.host !== undefined ||
+ this.isLive !== undefined
+ }
}
-import { Observable } from 'rxjs'
+import { Observable, of } from 'rxjs'
import { catchError, map, switchMap } from 'rxjs/operators'
import { HttpClient, HttpParams } from '@angular/common/http'
import { Injectable } from '@angular/core'
}): Observable<ResultList<Video>> {
const { search, uuids, componentPagination, advancedSearch } = parameters
+ if (advancedSearch.resultType !== undefined && advancedSearch.resultType !== 'videos') {
+ return of({ total: 0, data: [] })
+ }
+
const url = SearchService.BASE_SEARCH_URL + 'videos'
let pagination: RestPagination
}): Observable<ResultList<VideoChannel>> {
const { search, advancedSearch, componentPagination, handles } = parameters
+ if (advancedSearch.resultType !== undefined && advancedSearch.resultType !== 'channels') {
+ return of({ total: 0, data: [] })
+ }
+
const url = SearchService.BASE_SEARCH_URL + 'video-channels'
let pagination: RestPagination
}): Observable<ResultList<VideoPlaylist>> {
const { search, advancedSearch, componentPagination, uuids } = parameters
+ if (advancedSearch.resultType !== undefined && advancedSearch.resultType !== 'playlists') {
+ return of({ total: 0, data: [] })
+ }
+
const url = SearchService.BASE_SEARCH_URL + 'video-playlists'
let pagination: RestPagination