aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/search/advanced-search.model.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/advanced-search.model.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/advanced-search.model.ts')
-rw-r--r--client/src/app/search/advanced-search.model.ts101
1 files changed, 101 insertions, 0 deletions
diff --git a/client/src/app/search/advanced-search.model.ts b/client/src/app/search/advanced-search.model.ts
new file mode 100644
index 000000000..a0f333175
--- /dev/null
+++ b/client/src/app/search/advanced-search.model.ts
@@ -0,0 +1,101 @@
1import { NSFWQuery } from '../../../../shared/models/search'
2
3export class AdvancedSearch {
4 startDate: string // ISO 8601
5 endDate: string // ISO 8601
6
7 nsfw: NSFWQuery
8
9 categoryOneOf: string
10
11 licenceOneOf: string
12
13 languageOneOf: string
14
15 tagsOneOf: string
16 tagsAllOf: string
17
18 durationMin: number // seconds
19 durationMax: number // seconds
20
21 constructor (options?: {
22 startDate?: string
23 endDate?: string
24 nsfw?: NSFWQuery
25 categoryOneOf?: string
26 licenceOneOf?: string
27 languageOneOf?: string
28 tagsOneOf?: string
29 tagsAllOf?: string
30 durationMin?: string
31 durationMax?: string
32 }) {
33 if (!options) return
34
35 this.startDate = options.startDate
36 this.endDate = options.endDate
37 this.nsfw = options.nsfw
38 this.categoryOneOf = options.categoryOneOf
39 this.licenceOneOf = options.licenceOneOf
40 this.languageOneOf = options.languageOneOf
41 this.tagsOneOf = options.tagsOneOf
42 this.tagsAllOf = options.tagsAllOf
43 this.durationMin = parseInt(options.durationMin, 10)
44 this.durationMax = parseInt(options.durationMax, 10)
45
46 if (isNaN(this.durationMin)) this.durationMin = undefined
47 if (isNaN(this.durationMax)) this.durationMax = undefined
48 }
49
50 containsValues () {
51 const obj = this.toUrlObject()
52 for (const k of Object.keys(obj)) {
53 if (obj[k] !== undefined) return true
54 }
55
56 return false
57 }
58
59 reset () {
60 this.startDate = undefined
61 this.endDate = undefined
62 this.nsfw = undefined
63 this.categoryOneOf = undefined
64 this.licenceOneOf = undefined
65 this.languageOneOf = undefined
66 this.tagsOneOf = undefined
67 this.tagsAllOf = undefined
68 this.durationMin = undefined
69 this.durationMax = undefined
70 }
71
72 toUrlObject () {
73 return {
74 startDate: this.startDate,
75 endDate: this.endDate,
76 nsfw: this.nsfw,
77 categoryOneOf: this.categoryOneOf,
78 licenceOneOf: this.licenceOneOf,
79 languageOneOf: this.languageOneOf,
80 tagsOneOf: this.tagsOneOf,
81 tagsAllOf: this.tagsAllOf,
82 durationMin: this.durationMin,
83 durationMax: this.durationMax
84 }
85 }
86
87 toAPIObject () {
88 return {
89 startDate: this.startDate,
90 endDate: this.endDate,
91 nsfw: this.nsfw,
92 categoryOneOf: this.categoryOneOf ? this.categoryOneOf.split(',') : undefined,
93 licenceOneOf: this.licenceOneOf ? this.licenceOneOf.split(',') : undefined,
94 languageOneOf: this.languageOneOf ? this.languageOneOf.split(',') : undefined,
95 tagsOneOf: this.tagsOneOf ? this.tagsOneOf.split(',') : undefined,
96 tagsAllOf: this.tagsAllOf ? this.tagsAllOf.split(',') : undefined,
97 durationMin: this.durationMin,
98 durationMax: this.durationMax
99 }
100 }
101}