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 | |
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')
-rw-r--r-- | client/src/app/search/advanced-search.model.ts | 14 | ||||
-rw-r--r-- | client/src/app/search/search-filters.component.html | 23 | ||||
-rw-r--r-- | client/src/app/search/search-filters.component.ts | 42 |
3 files changed, 78 insertions, 1 deletions
diff --git a/client/src/app/search/advanced-search.model.ts b/client/src/app/search/advanced-search.model.ts index 033fa9bba..5b713e145 100644 --- a/client/src/app/search/advanced-search.model.ts +++ b/client/src/app/search/advanced-search.model.ts | |||
@@ -4,6 +4,9 @@ export class AdvancedSearch { | |||
4 | startDate: string // ISO 8601 | 4 | startDate: string // ISO 8601 |
5 | endDate: string // ISO 8601 | 5 | endDate: string // ISO 8601 |
6 | 6 | ||
7 | originallyPublishedStartDate: string // ISO 8601 | ||
8 | originallyPublishedEndDate: string // ISO 8601 | ||
9 | |||
7 | nsfw: NSFWQuery | 10 | nsfw: NSFWQuery |
8 | 11 | ||
9 | categoryOneOf: string | 12 | categoryOneOf: string |
@@ -23,6 +26,8 @@ export class AdvancedSearch { | |||
23 | constructor (options?: { | 26 | constructor (options?: { |
24 | startDate?: string | 27 | startDate?: string |
25 | endDate?: string | 28 | endDate?: string |
29 | originallyPublishedStartDate?: string | ||
30 | originallyPublishedEndDate?: string | ||
26 | nsfw?: NSFWQuery | 31 | nsfw?: NSFWQuery |
27 | categoryOneOf?: string | 32 | categoryOneOf?: string |
28 | licenceOneOf?: string | 33 | licenceOneOf?: string |
@@ -37,6 +42,9 @@ export class AdvancedSearch { | |||
37 | 42 | ||
38 | this.startDate = options.startDate || undefined | 43 | this.startDate = options.startDate || undefined |
39 | this.endDate = options.endDate || undefined | 44 | this.endDate = options.endDate || undefined |
45 | this.originallyPublishedStartDate = options.originallyPublishedStartDate || undefined | ||
46 | this.originallyPublishedEndDate = options.originallyPublishedEndDate || undefined | ||
47 | |||
40 | this.nsfw = options.nsfw || undefined | 48 | this.nsfw = options.nsfw || undefined |
41 | this.categoryOneOf = options.categoryOneOf || undefined | 49 | this.categoryOneOf = options.categoryOneOf || undefined |
42 | this.licenceOneOf = options.licenceOneOf || undefined | 50 | this.licenceOneOf = options.licenceOneOf || undefined |
@@ -66,6 +74,8 @@ export class AdvancedSearch { | |||
66 | reset () { | 74 | reset () { |
67 | this.startDate = undefined | 75 | this.startDate = undefined |
68 | this.endDate = undefined | 76 | this.endDate = undefined |
77 | this.originallyPublishedStartDate = undefined | ||
78 | this.originallyPublishedEndDate = undefined | ||
69 | this.nsfw = undefined | 79 | this.nsfw = undefined |
70 | this.categoryOneOf = undefined | 80 | this.categoryOneOf = undefined |
71 | this.licenceOneOf = undefined | 81 | this.licenceOneOf = undefined |
@@ -82,6 +92,8 @@ export class AdvancedSearch { | |||
82 | return { | 92 | return { |
83 | startDate: this.startDate, | 93 | startDate: this.startDate, |
84 | endDate: this.endDate, | 94 | endDate: this.endDate, |
95 | originallyPublishedStartDate: this.originallyPublishedStartDate, | ||
96 | originallyPublishedEndDate: this.originallyPublishedEndDate, | ||
85 | nsfw: this.nsfw, | 97 | nsfw: this.nsfw, |
86 | categoryOneOf: this.categoryOneOf, | 98 | categoryOneOf: this.categoryOneOf, |
87 | licenceOneOf: this.licenceOneOf, | 99 | licenceOneOf: this.licenceOneOf, |
@@ -98,6 +110,8 @@ export class AdvancedSearch { | |||
98 | return { | 110 | return { |
99 | startDate: this.startDate, | 111 | startDate: this.startDate, |
100 | endDate: this.endDate, | 112 | endDate: this.endDate, |
113 | originallyPublishedStartDate: this.originallyPublishedStartDate, | ||
114 | originallyPublishedEndDate: this.originallyPublishedEndDate, | ||
101 | nsfw: this.nsfw, | 115 | nsfw: this.nsfw, |
102 | categoryOneOf: this.intoArray(this.categoryOneOf), | 116 | categoryOneOf: this.intoArray(this.categoryOneOf), |
103 | licenceOneOf: this.intoArray(this.licenceOneOf), | 117 | licenceOneOf: this.intoArray(this.licenceOneOf), |
diff --git a/client/src/app/search/search-filters.component.html b/client/src/app/search/search-filters.component.html index 74bb781f4..8220a990b 100644 --- a/client/src/app/search/search-filters.component.html +++ b/client/src/app/search/search-filters.component.html | |||
@@ -21,6 +21,27 @@ | |||
21 | </div> | 21 | </div> |
22 | 22 | ||
23 | <div class="form-group"> | 23 | <div class="form-group"> |
24 | <label i18n for="original-publication-after">Original publication year</label> | ||
25 | |||
26 | <div class="row"> | ||
27 | <div class="col-sm-6"> | ||
28 | <input | ||
29 | type="text" id="original-publication-after" name="original-publication-after" | ||
30 | i18n-placeholder placeholder="After..." | ||
31 | [(ngModel)]="originallyPublishedStartYear" | ||
32 | > | ||
33 | </div> | ||
34 | <div class="col-sm-6"> | ||
35 | <input | ||
36 | type="text" id="original-publication-before" name="original-publication-before" | ||
37 | i18n-placeholder placeholder="Before..." | ||
38 | [(ngModel)]="originallyPublishedEndYear" | ||
39 | > | ||
40 | </div> | ||
41 | </div> | ||
42 | </div> | ||
43 | |||
44 | <div class="form-group"> | ||
24 | <div i18n class="radio-label">Duration</div> | 45 | <div i18n class="radio-label">Duration</div> |
25 | 46 | ||
26 | <div class="peertube-radio-container" *ngFor="let duration of durationRanges"> | 47 | <div class="peertube-radio-container" *ngFor="let duration of durationRanges"> |
@@ -93,4 +114,4 @@ | |||
93 | <div class="submit-button"> | 114 | <div class="submit-button"> |
94 | <input type="submit" i18n-value value="Filter"> | 115 | <input type="submit" i18n-value value="Filter"> |
95 | </div> | 116 | </div> |
96 | </form> \ No newline at end of file | 117 | </form> |
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 | } |