]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/app/shared/shared-search/advanced-search.model.ts
Update angular
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / shared-search / advanced-search.model.ts
index 724c4d83498847c08d746e15b68d946d7643de76..29fe3e8dc9e7ed3b348cf48d6c23c1f8fb50af68 100644 (file)
@@ -1,4 +1,4 @@
-import { intoArray } from '@app/helpers'
+import { splitIntoArray } from '@app/helpers'
 import {
   BooleanBothQuery,
   BooleanQuery,
@@ -40,8 +40,7 @@ export class AdvancedSearch {
   searchTarget: SearchTargetType
   resultType: AdvancedSearchResultType
 
-  // Filters we don't want to count, because they are mandatory
-  private silentFilters = new Set([ 'sort', 'searchTarget' ])
+  excludeAlreadyWatched?: boolean
 
   constructor (options?: {
     startDate?: string
@@ -65,6 +64,8 @@ export class AdvancedSearch {
     sort?: string
     searchTarget?: SearchTargetType
     resultType?: AdvancedSearchResultType
+
+    excludeAlreadyWatched?: boolean
   }) {
     if (!options) return
 
@@ -79,10 +80,10 @@ export class AdvancedSearch {
     this.categoryOneOf = options.categoryOneOf || undefined
     this.licenceOneOf = options.licenceOneOf || undefined
     this.languageOneOf = options.languageOneOf || undefined
-    this.tagsOneOf = intoArray(options.tagsOneOf)
-    this.tagsAllOf = intoArray(options.tagsAllOf)
-    this.durationMin = parseInt(options.durationMin, 10)
-    this.durationMax = parseInt(options.durationMax, 10)
+    this.tagsOneOf = splitIntoArray(options.tagsOneOf)
+    this.tagsAllOf = splitIntoArray(options.tagsAllOf)
+    this.durationMin = options.durationMin ? parseInt(options.durationMin, 10) : undefined
+    this.durationMax = options.durationMax ? parseInt(options.durationMax, 10) : undefined
 
     this.host = options.host || undefined
 
@@ -90,6 +91,8 @@ export class AdvancedSearch {
 
     this.resultType = options.resultType || undefined
 
+    this.excludeAlreadyWatched = options.excludeAlreadyWatched || undefined
+
     if (!this.resultType && this.hasVideoFilter()) {
       this.resultType = 'videos'
     }
@@ -101,14 +104,7 @@ export class AdvancedSearch {
   }
 
   containsValues () {
-    const obj = this.toUrlObject()
-    for (const k of Object.keys(obj)) {
-      if (this.silentFilters.has(k)) continue
-
-      if (this.isValidValue(obj[k])) return true
-    }
-
-    return false
+    return this.size() !== 0
   }
 
   reset () {
@@ -148,7 +144,8 @@ export class AdvancedSearch {
       host: this.host,
       sort: this.sort,
       searchTarget: this.searchTarget,
-      resultType: this.resultType
+      resultType: this.resultType,
+      excludeAlreadyWatched: this.excludeAlreadyWatched
     }
   }
 
@@ -162,9 +159,9 @@ export class AdvancedSearch {
       originallyPublishedStartDate: this.originallyPublishedStartDate,
       originallyPublishedEndDate: this.originallyPublishedEndDate,
       nsfw: this.nsfw,
-      categoryOneOf: intoArray(this.categoryOneOf),
-      licenceOneOf: intoArray(this.licenceOneOf),
-      languageOneOf: intoArray(this.languageOneOf),
+      categoryOneOf: splitIntoArray(this.categoryOneOf),
+      licenceOneOf: splitIntoArray(this.licenceOneOf),
+      languageOneOf: splitIntoArray(this.languageOneOf),
       tagsOneOf: this.tagsOneOf,
       tagsAllOf: this.tagsAllOf,
       durationMin: this.durationMin,
@@ -172,7 +169,8 @@ export class AdvancedSearch {
       host: this.host,
       isLive,
       sort: this.sort,
-      searchTarget: this.searchTarget
+      searchTarget: this.searchTarget,
+      excludeAlreadyWatched: this.excludeAlreadyWatched
     }
   }
 
@@ -193,12 +191,19 @@ export class AdvancedSearch {
   size () {
     let acc = 0
 
-    const obj = this.toUrlObject()
-    for (const k of Object.keys(obj)) {
-      if (this.silentFilters.has(k)) continue
+    if (this.isValidValue(this.startDate) || this.isValidValue(this.endDate)) acc++
+    if (this.isValidValue(this.originallyPublishedStartDate) || this.isValidValue(this.originallyPublishedEndDate)) acc++
 
-      if (this.isValidValue(obj[k])) acc++
-    }
+    if (this.isValidValue(this.nsfw)) acc++
+    if (this.isValidValue(this.categoryOneOf)) acc++
+    if (this.isValidValue(this.licenceOneOf)) acc++
+    if (this.isValidValue(this.languageOneOf)) acc++
+    if (this.isValidValue(this.tagsOneOf)) acc++
+    if (this.isValidValue(this.tagsAllOf)) acc++
+    if (this.isValidValue(this.durationMin) || this.isValidValue(this.durationMax)) acc++
+    if (this.isValidValue(this.isLive)) acc++
+    if (this.isValidValue(this.host)) acc++
+    if (this.isValidValue(this.resultType)) acc++
 
     return acc
   }
@@ -216,7 +221,7 @@ export class AdvancedSearch {
       this.endDate !== undefined ||
       this.originallyPublishedStartDate !== undefined ||
       this.originallyPublishedEndDate !== undefined ||
-      this.nsfw !== undefined !== undefined ||
+      this.nsfw !== undefined ||
       this.categoryOneOf !== undefined ||
       this.licenceOneOf !== undefined ||
       this.languageOneOf !== undefined ||
@@ -224,7 +229,6 @@ export class AdvancedSearch {
       this.tagsAllOf !== undefined ||
       this.durationMin !== undefined ||
       this.durationMax !== undefined ||
-      this.host !== undefined ||
       this.isLive !== undefined
   }
 }