aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/search/advanced-search.model.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2020-06-23 14:49:20 +0200
committerChocobozzz <chocobozzz@cpy.re>2020-06-23 16:00:49 +0200
commit1942f11d5ee6926ad93dc1b79fae18325ba5de18 (patch)
tree3f2a3cd9466a56c419d197ac832a3e9cbc86bec4 /client/src/app/search/advanced-search.model.ts
parent67ed6552b831df66713bac9e672738796128d33f (diff)
downloadPeerTube-1942f11d5ee6926ad93dc1b79fae18325ba5de18.tar.gz
PeerTube-1942f11d5ee6926ad93dc1b79fae18325ba5de18.tar.zst
PeerTube-1942f11d5ee6926ad93dc1b79fae18325ba5de18.zip
Lazy load all routes
Diffstat (limited to 'client/src/app/search/advanced-search.model.ts')
-rw-r--r--client/src/app/search/advanced-search.model.ts160
1 files changed, 0 insertions, 160 deletions
diff --git a/client/src/app/search/advanced-search.model.ts b/client/src/app/search/advanced-search.model.ts
deleted file mode 100644
index 516854a8c..000000000
--- a/client/src/app/search/advanced-search.model.ts
+++ /dev/null
@@ -1,160 +0,0 @@
1import { NSFWQuery, SearchTargetType } from '@shared/models'
2
3export class AdvancedSearch {
4 startDate: string // ISO 8601
5 endDate: string // ISO 8601
6
7 originallyPublishedStartDate: string // ISO 8601
8 originallyPublishedEndDate: string // ISO 8601
9
10 nsfw: NSFWQuery
11
12 categoryOneOf: string
13
14 licenceOneOf: string
15
16 languageOneOf: string
17
18 tagsOneOf: string
19 tagsAllOf: string
20
21 durationMin: number // seconds
22 durationMax: number // seconds
23
24 sort: string
25
26 searchTarget: SearchTargetType
27
28 // Filters we don't want to count, because they are mandatory
29 private silentFilters = new Set([ 'sort', 'searchTarget' ])
30
31 constructor (options?: {
32 startDate?: string
33 endDate?: string
34 originallyPublishedStartDate?: string
35 originallyPublishedEndDate?: string
36 nsfw?: NSFWQuery
37 categoryOneOf?: string
38 licenceOneOf?: string
39 languageOneOf?: string
40 tagsOneOf?: string
41 tagsAllOf?: string
42 durationMin?: string
43 durationMax?: string
44 sort?: string
45 searchTarget?: SearchTargetType
46 }) {
47 if (!options) return
48
49 this.startDate = options.startDate || undefined
50 this.endDate = options.endDate || undefined
51 this.originallyPublishedStartDate = options.originallyPublishedStartDate || undefined
52 this.originallyPublishedEndDate = options.originallyPublishedEndDate || undefined
53
54 this.nsfw = options.nsfw || undefined
55 this.categoryOneOf = options.categoryOneOf || undefined
56 this.licenceOneOf = options.licenceOneOf || undefined
57 this.languageOneOf = options.languageOneOf || undefined
58 this.tagsOneOf = options.tagsOneOf || undefined
59 this.tagsAllOf = options.tagsAllOf || undefined
60 this.durationMin = parseInt(options.durationMin, 10)
61 this.durationMax = parseInt(options.durationMax, 10)
62
63 this.searchTarget = options.searchTarget || undefined
64
65 if (isNaN(this.durationMin)) this.durationMin = undefined
66 if (isNaN(this.durationMax)) this.durationMax = undefined
67
68 this.sort = options.sort || '-match'
69 }
70
71 containsValues () {
72 const exceptions = new Set([ 'sort', 'searchTarget' ])
73
74 const obj = this.toUrlObject()
75 for (const k of Object.keys(obj)) {
76 if (this.silentFilters.has(k)) continue
77
78 if (obj[k] !== undefined && obj[k] !== '') return true
79 }
80
81 return false
82 }
83
84 reset () {
85 this.startDate = undefined
86 this.endDate = undefined
87 this.originallyPublishedStartDate = undefined
88 this.originallyPublishedEndDate = undefined
89 this.nsfw = undefined
90 this.categoryOneOf = undefined
91 this.licenceOneOf = undefined
92 this.languageOneOf = undefined
93 this.tagsOneOf = undefined
94 this.tagsAllOf = undefined
95 this.durationMin = undefined
96 this.durationMax = undefined
97
98 this.sort = '-match'
99 }
100
101 toUrlObject () {
102 return {
103 startDate: this.startDate,
104 endDate: this.endDate,
105 originallyPublishedStartDate: this.originallyPublishedStartDate,
106 originallyPublishedEndDate: this.originallyPublishedEndDate,
107 nsfw: this.nsfw,
108 categoryOneOf: this.categoryOneOf,
109 licenceOneOf: this.licenceOneOf,
110 languageOneOf: this.languageOneOf,
111 tagsOneOf: this.tagsOneOf,
112 tagsAllOf: this.tagsAllOf,
113 durationMin: this.durationMin,
114 durationMax: this.durationMax,
115 sort: this.sort,
116 searchTarget: this.searchTarget
117 }
118 }
119
120 toAPIObject () {
121 return {
122 startDate: this.startDate,
123 endDate: this.endDate,
124 originallyPublishedStartDate: this.originallyPublishedStartDate,
125 originallyPublishedEndDate: this.originallyPublishedEndDate,
126 nsfw: this.nsfw,
127 categoryOneOf: this.intoArray(this.categoryOneOf),
128 licenceOneOf: this.intoArray(this.licenceOneOf),
129 languageOneOf: this.intoArray(this.languageOneOf),
130 tagsOneOf: this.intoArray(this.tagsOneOf),
131 tagsAllOf: this.intoArray(this.tagsAllOf),
132 durationMin: this.durationMin,
133 durationMax: this.durationMax,
134 sort: this.sort,
135 searchTarget: this.searchTarget
136 }
137 }
138
139 size () {
140 let acc = 0
141
142 const obj = this.toUrlObject()
143 for (const k of Object.keys(obj)) {
144 if (this.silentFilters.has(k)) continue
145
146 if (obj[k] !== undefined && obj[k] !== '') acc++
147 }
148
149 return acc
150 }
151
152 private intoArray (value: any) {
153 if (!value) return undefined
154 if (Array.isArray(value)) return value
155
156 if (typeof value === 'string') return value.split(',')
157
158 return [ value ]
159 }
160}