diff options
author | Andrés Maldonado <amaldona@etu.utc.fr> | 2018-11-27 18:57:02 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2019-02-12 11:14:37 +0100 |
commit | 31d065cc50e17a9abf263ed8c606cb272cd4933d (patch) | |
tree | 5e4516cb48dd36490e817bd9e59c41f3cad0d968 /client/src/app/search/search-filters.component.ts | |
parent | 7f8f8bdb4a1fb695a114874c4679605ac8911e2d (diff) | |
download | PeerTube-31d065cc50e17a9abf263ed8c606cb272cd4933d.tar.gz PeerTube-31d065cc50e17a9abf263ed8c606cb272cd4933d.tar.zst PeerTube-31d065cc50e17a9abf263ed8c606cb272cd4933d.zip |
Add search by original publication date
Diffstat (limited to 'client/src/app/search/search-filters.component.ts')
-rw-r--r-- | client/src/app/search/search-filters.component.ts | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/client/src/app/search/search-filters.component.ts b/client/src/app/search/search-filters.component.ts index 3fdc6df35..762a6b7f2 100644 --- a/client/src/app/search/search-filters.component.ts +++ b/client/src/app/search/search-filters.component.ts | |||
@@ -25,6 +25,9 @@ export class SearchFiltersComponent implements OnInit { | |||
25 | publishedDateRange: string | 25 | publishedDateRange: string |
26 | durationRange: string | 26 | durationRange: string |
27 | 27 | ||
28 | originallyPublishedStartYear: string | ||
29 | originallyPublishedEndYear: string | ||
30 | |||
28 | constructor ( | 31 | constructor ( |
29 | private i18n: I18n, | 32 | private i18n: I18n, |
30 | private serverService: ServerService | 33 | private serverService: ServerService |
@@ -86,15 +89,27 @@ export class SearchFiltersComponent implements OnInit { | |||
86 | 89 | ||
87 | this.loadFromDurationRange() | 90 | this.loadFromDurationRange() |
88 | this.loadFromPublishedRange() | 91 | this.loadFromPublishedRange() |
92 | this.loadOriginallyPublishedAtYears() | ||
89 | } | 93 | } |
90 | 94 | ||
91 | formUpdated () { | 95 | formUpdated () { |
92 | this.updateModelFromDurationRange() | 96 | this.updateModelFromDurationRange() |
93 | this.updateModelFromPublishedRange() | 97 | this.updateModelFromPublishedRange() |
98 | this.updateModelFromOriginallyPublishedAtYears() | ||
94 | 99 | ||
95 | this.filtered.emit(this.advancedSearch) | 100 | this.filtered.emit(this.advancedSearch) |
96 | } | 101 | } |
97 | 102 | ||
103 | private loadOriginallyPublishedAtYears () { | ||
104 | this.originallyPublishedStartYear = this.advancedSearch.originallyPublishedStartDate | ||
105 | ? new Date(this.advancedSearch.originallyPublishedStartDate).getFullYear().toString() | ||
106 | : null | ||
107 | |||
108 | this.originallyPublishedEndYear = this.advancedSearch.originallyPublishedEndDate | ||
109 | ? new Date(this.advancedSearch.originallyPublishedEndDate).getFullYear().toString() | ||
110 | : null | ||
111 | } | ||
112 | |||
98 | private loadFromDurationRange () { | 113 | private loadFromDurationRange () { |
99 | if (this.advancedSearch.durationMin || this.advancedSearch.durationMax) { | 114 | if (this.advancedSearch.durationMin || this.advancedSearch.durationMax) { |
100 | const fourMinutes = 60 * 4 | 115 | const fourMinutes = 60 * 4 |
@@ -127,6 +142,32 @@ export class SearchFiltersComponent implements OnInit { | |||
127 | } | 142 | } |
128 | } | 143 | } |
129 | 144 | ||
145 | private updateModelFromOriginallyPublishedAtYears () { | ||
146 | const baseDate = new Date() | ||
147 | baseDate.setHours(0, 0, 0, 0) | ||
148 | baseDate.setMonth(0, 1) | ||
149 | |||
150 | if (this.originallyPublishedStartYear) { | ||
151 | const year = parseInt(this.originallyPublishedStartYear, 10) | ||
152 | const start = new Date(baseDate) | ||
153 | start.setFullYear(year) | ||
154 | |||
155 | this.advancedSearch.originallyPublishedStartDate = start.toISOString() | ||
156 | } else { | ||
157 | this.advancedSearch.originallyPublishedStartDate = null | ||
158 | } | ||
159 | |||
160 | if (this.originallyPublishedEndYear) { | ||
161 | const year = parseInt(this.originallyPublishedEndYear, 10) | ||
162 | const end = new Date(baseDate) | ||
163 | end.setFullYear(year) | ||
164 | |||
165 | this.advancedSearch.originallyPublishedEndDate = end.toISOString() | ||
166 | } else { | ||
167 | this.advancedSearch.originallyPublishedEndDate = null | ||
168 | } | ||
169 | } | ||
170 | |||
130 | private updateModelFromDurationRange () { | 171 | private updateModelFromDurationRange () { |
131 | if (!this.durationRange) return | 172 | if (!this.durationRange) return |
132 | 173 | ||
@@ -174,4 +215,5 @@ export class SearchFiltersComponent implements OnInit { | |||
174 | 215 | ||
175 | this.advancedSearch.startDate = date.toISOString() | 216 | this.advancedSearch.startDate = date.toISOString() |
176 | } | 217 | } |
218 | |||
177 | } | 219 | } |