]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
Add ability to search live videos
authorChocobozzz <me@florianbigard.com>
Wed, 5 May 2021 10:10:00 +0000 (12:10 +0200)
committerChocobozzz <me@florianbigard.com>
Wed, 5 May 2021 10:10:00 +0000 (12:10 +0200)
client/src/app/+search/search-filters.component.html
client/src/app/+search/search-filters.component.ts
client/src/app/shared/shared-search/advanced-search.model.ts
shared/models/search/boolean-both-query.model.ts

index 1d1e7b868fd8f9c90ded0756817299a23bd80601..421bc7f6f1bd8a758e66bb892473d6be1c61fdf9 100644 (file)
         </div>
       </div>
 
+      <div class="form-group">
+        <div class="radio-label label-container">
+          <label i18n>Display only</label>
+          <button i18n class="reset-button reset-button-small" (click)="resetField('isLive')" *ngIf="advancedSearch.isLive !== undefined">
+            Reset
+          </button>
+        </div>
+
+        <div class="peertube-radio-container">
+          <input type="radio" name="isLive" id="isLiveTrue" value="true" [(ngModel)]="advancedSearch.isLive">
+          <label i18n for="isLiveTrue" class="radio">Live videos</label>
+        </div>
+
+        <div class="peertube-radio-container">
+          <input type="radio" name="isLive" id="isLiveFalse" value="false" [(ngModel)]="advancedSearch.isLive">
+          <label i18n for="isLiveFalse" class="radio">VOD videos</label>
+        </div>
+      </div>
+
       <div class="form-group">
         <div class="radio-label label-container">
           <label i18n>Display sensitive content</label>
@@ -44,7 +63,7 @@
         </div>
 
         <div class="peertube-radio-container" *ngFor="let date of publishedDateRanges">
-          <input type="radio" (change)="inputUpdated()" name="publishedDateRange" [id]="date.id" [value]="date.id" [(ngModel)]="publishedDateRange">
+          <input type="radio" (change)="onInputUpdated()" name="publishedDateRange" [id]="date.id" [value]="date.id" [(ngModel)]="publishedDateRange">
           <label [for]="date.id" class="radio">{{ date.label }}</label>
         </div>
       </div>
@@ -60,7 +79,7 @@
         <div class="row">
           <div class="pl-0 col-sm-6">
             <input
-              (change)="inputUpdated()"
+              (change)="onInputUpdated()"
               (keydown.enter)="$event.preventDefault()"
               type="text" id="original-publication-after" name="original-publication-after"
               i18n-placeholder placeholder="After..."
@@ -70,7 +89,7 @@
           </div>
           <div class="pr-0 col-sm-6">
             <input
-              (change)="inputUpdated()"
+              (change)="onInputUpdated()"
               (keydown.enter)="$event.preventDefault()"
               type="text" id="original-publication-before" name="original-publication-before"
               i18n-placeholder placeholder="Before..."
         </div>
 
         <div class="peertube-radio-container" *ngFor="let duration of durationRanges">
-          <input type="radio" (change)="inputUpdated()" name="durationRange" [id]="duration.id" [value]="duration.id" [(ngModel)]="durationRange">
+          <input type="radio" (change)="onInputUpdated()" name="durationRange" [id]="duration.id" [value]="duration.id" [(ngModel)]="durationRange">
           <label [for]="duration.id" class="radio">{{ duration.label }}</label>
         </div>
       </div>
index a2af9a9427a3b3ab3a2ef0fed56a1c5628421475..59aba22ff8b6a13239ad02ae2ad5ccf9647adbb0 100644 (file)
@@ -3,6 +3,8 @@ import { ServerService } from '@app/core'
 import { AdvancedSearch } from '@app/shared/shared-search'
 import { ServerConfig, VideoConstant } from '@shared/models'
 
+type FormOption = { id: string, label: string }
+
 @Component({
   selector: 'my-search-filters',
   styleUrls: [ './search-filters.component.scss' ],
@@ -17,9 +19,10 @@ export class SearchFiltersComponent implements OnInit {
   videoLicences: VideoConstant<number>[] = []
   videoLanguages: VideoConstant<string>[] = []
 
-  publishedDateRanges: { id: string, label: string }[] = []
-  sorts: { id: string, label: string }[] = []
-  durationRanges: { id: string, label: string }[] = []
+  publishedDateRanges: FormOption[] = []
+  sorts: FormOption[] = []
+  durationRanges: FormOption[] = []
+  videoType: FormOption[] = []
 
   publishedDateRange: string
   durationRange: string
@@ -33,10 +36,6 @@ export class SearchFiltersComponent implements OnInit {
     private serverService: ServerService
   ) {
     this.publishedDateRanges = [
-      {
-        id: 'any_published_date',
-        label: $localize`Any`
-      },
       {
         id: 'today',
         label: $localize`Today`
@@ -55,11 +54,18 @@ export class SearchFiltersComponent implements OnInit {
       }
     ]
 
-    this.durationRanges = [
+    this.videoType = [
       {
-        id: 'any_duration',
-        label: $localize`Any`
+        id: 'vod',
+        label: $localize`VOD videos`
       },
+      {
+        id: 'live',
+        label: $localize`Live videos`
+      }
+    ]
+
+    this.durationRanges = [
       {
         id: 'short',
         label: $localize`Short (< 4 min)`
@@ -104,24 +110,26 @@ export class SearchFiltersComponent implements OnInit {
     this.loadOriginallyPublishedAtYears()
   }
 
-  inputUpdated () {
+  onInputUpdated () {
     this.updateModelFromDurationRange()
     this.updateModelFromPublishedRange()
     this.updateModelFromOriginallyPublishedAtYears()
   }
 
   formUpdated () {
-    this.inputUpdated()
+    this.onInputUpdated()
     this.filtered.emit(this.advancedSearch)
   }
 
   reset () {
     this.advancedSearch.reset()
+
+    this.resetOriginalPublicationYears()
+
     this.durationRange = undefined
     this.publishedDateRange = undefined
-    this.originallyPublishedStartYear = undefined
-    this.originallyPublishedEndYear = undefined
-    this.inputUpdated()
+
+    this.onInputUpdated()
   }
 
   resetField (fieldName: string, value?: any) {
@@ -130,7 +138,7 @@ export class SearchFiltersComponent implements OnInit {
 
   resetLocalField (fieldName: string, value?: any) {
     this[fieldName] = value
-    this.inputUpdated()
+    this.onInputUpdated()
   }
 
   resetOriginalPublicationYears () {
index 0e3924841a38fa182c2cbad8b1ba61505d947dec..2c83f53b64c3a12d611b2a10ee2478b76f23fa83 100644 (file)
@@ -1,4 +1,4 @@
-import { BooleanBothQuery, SearchTargetType } from '@shared/models'
+import { BooleanBothQuery, BooleanQuery, SearchTargetType, VideosSearchQuery } from '@shared/models'
 
 export class AdvancedSearch {
   startDate: string // ISO 8601
@@ -21,6 +21,8 @@ export class AdvancedSearch {
   durationMin: number // seconds
   durationMax: number // seconds
 
+  isLive: BooleanQuery
+
   sort: string
 
   searchTarget: SearchTargetType
@@ -41,6 +43,8 @@ export class AdvancedSearch {
     tagsOneOf?: any
     tagsAllOf?: any
 
+    isLive?: BooleanQuery
+
     durationMin?: string
     durationMax?: string
     sort?: string
@@ -54,6 +58,8 @@ export class AdvancedSearch {
     this.originallyPublishedEndDate = options.originallyPublishedEndDate || undefined
 
     this.nsfw = options.nsfw || undefined
+    this.isLive = options.isLive || undefined
+
     this.categoryOneOf = options.categoryOneOf || undefined
     this.licenceOneOf = options.licenceOneOf || undefined
     this.languageOneOf = options.languageOneOf || undefined
@@ -94,6 +100,7 @@ export class AdvancedSearch {
     this.tagsAllOf = undefined
     this.durationMin = undefined
     this.durationMax = undefined
+    this.isLive = undefined
 
     this.sort = '-match'
   }
@@ -112,12 +119,16 @@ export class AdvancedSearch {
       tagsAllOf: this.tagsAllOf,
       durationMin: this.durationMin,
       durationMax: this.durationMax,
+      isLive: this.isLive,
       sort: this.sort,
       searchTarget: this.searchTarget
     }
   }
 
-  toAPIObject () {
+  toAPIObject (): VideosSearchQuery {
+    let isLive: boolean
+    if (this.isLive) isLive = this.isLive === 'true'
+
     return {
       startDate: this.startDate,
       endDate: this.endDate,
@@ -131,6 +142,7 @@ export class AdvancedSearch {
       tagsAllOf: this.tagsAllOf,
       durationMin: this.durationMin,
       durationMax: this.durationMax,
+      isLive,
       sort: this.sort,
       searchTarget: this.searchTarget
     }
index 57b0e8d44e8dc71be892118bc7bfa1d8a3a4f5c8..d6a438249ed696a16f4a4f319695dce1298bb4fa 100644 (file)
@@ -1 +1,2 @@
 export type BooleanBothQuery = 'true' | 'false' | 'both'
+export type BooleanQuery = 'true' | 'false'