|
205 | 205 | }); |
206 | 206 |
|
207 | 207 | const filterWithReviewsSelect = document.querySelector('#filter-with-n-reviews'); |
208 | | - filterWithReviewsSelect.addEventListener('change', e => { |
209 | | - e.preventDefault(); |
| 208 | + const filterByStatusInputs = [...document.querySelectorAll('input[name="filter-by-status"]')]; |
| 209 | + const filterByTypeInputs = [...document.querySelectorAll('input[name="filter-by-type"]')]; |
| 210 | + |
| 211 | + const applyFilters = () => { |
| 212 | + const reviewsFilterValue = filterWithReviewsSelect.value; |
210 | 213 |
|
211 | | - const filterValue = parseInt(e.target.value, 10); |
| 214 | + const visibleStatuses = filterByStatusInputs.filter( |
| 215 | + input => input.checked |
| 216 | + ).map( |
| 217 | + input => input.value |
| 218 | + ); |
| 219 | + |
| 220 | + const visibleTypes = filterByTypeInputs.filter( |
| 221 | + input => input.checked |
| 222 | + ).map( |
| 223 | + input => parseInt(input.value, 10) |
| 224 | + ); |
212 | 225 |
|
213 | 226 | document.querySelectorAll('.proposal-item').forEach( |
214 | 227 | proposalRow => { |
215 | | - if (e.target.value === 'all') { |
216 | | - proposalRow.classList.remove('hidden') |
217 | | - return; |
218 | | - } |
219 | | - |
220 | 228 | const proposalId = parseInt(proposalRow.id.split('-')[1], 10); |
221 | 229 | const proposalData = submissionsById[proposalId]; |
222 | 230 |
|
223 | | - const numOfVotes = proposalData.numOfVotes; |
224 | | - if (numOfVotes === filterValue) { |
| 231 | + const reviewsMatch = reviewsFilterValue === 'all' || proposalData.numOfVotes === parseInt(reviewsFilterValue, 10); |
| 232 | + const statusMatch = visibleStatuses.includes(proposalData.originalStatus); |
| 233 | + const typeMatch = visibleTypes.includes(proposalData.typeId); |
| 234 | + |
| 235 | + if (reviewsMatch && statusMatch && typeMatch) { |
225 | 236 | proposalRow.classList.remove('hidden') |
226 | 237 | } else { |
227 | 238 | proposalRow.classList.add('hidden') |
228 | 239 | } |
229 | 240 | } |
230 | | - ) |
| 241 | + ); |
| 242 | + }; |
| 243 | + |
| 244 | + filterWithReviewsSelect.addEventListener('change', e => { |
| 245 | + e.preventDefault(); |
| 246 | + applyFilters(); |
231 | 247 | }); |
232 | 248 |
|
233 | | - const filterByStatusInputs = [...document.querySelectorAll('input[name="filter-by-status"]')]; |
234 | 249 | filterByStatusInputs.forEach( |
235 | 250 | filterByStatusInput => { |
236 | 251 | filterByStatusInput.addEventListener('change', e => { |
237 | 252 | e.preventDefault(); |
| 253 | + applyFilters(); |
| 254 | + }); |
| 255 | + } |
| 256 | + ); |
238 | 257 |
|
239 | | - const filterValue = e.target.value; |
240 | | - const visibleStatuses = filterByStatusInputs.filter( |
241 | | - input => input.checked |
242 | | - ).map( |
243 | | - input => input.value |
244 | | - ); |
245 | | - |
246 | | - document.querySelectorAll('.proposal-item').forEach( |
247 | | - proposalRow => { |
248 | | - const proposalId = parseInt(proposalRow.id.split('-')[1], 10); |
249 | | - const proposalData = submissionsById[proposalId]; |
250 | | - |
251 | | - if (visibleStatuses.includes(proposalData.originalStatus)) { |
252 | | - proposalRow.classList.remove('hidden') |
253 | | - } else { |
254 | | - proposalRow.classList.add('hidden') |
255 | | - } |
256 | | - } |
257 | | - ); |
| 258 | + filterByTypeInputs.forEach( |
| 259 | + filterByTypeInput => { |
| 260 | + filterByTypeInput.addEventListener('change', e => { |
| 261 | + e.preventDefault(); |
| 262 | + applyFilters(); |
258 | 263 | }); |
259 | 264 | } |
260 | 265 | ); |
@@ -352,6 +357,17 @@ <h3>Show proposals with pending status:</h3> |
352 | 357 | {% endfor %} |
353 | 358 | </div> |
354 | 359 | </div> |
| 360 | + <div class="opt-filter"> |
| 361 | + <h3>Show proposals with type:</h3> |
| 362 | + <div> |
| 363 | + {% for submission_type in submission_types %} |
| 364 | + <label> |
| 365 | + <input checked type="checkbox" name="filter-by-type" value="{{ submission_type.id }}"> |
| 366 | + <span>{{ submission_type.name }}</span> |
| 367 | + </label> |
| 368 | + {% endfor %} |
| 369 | + </div> |
| 370 | + </div> |
355 | 371 | </div> |
356 | 372 | <div class="module filtered" id="changelist"> |
357 | 373 | <div class="changelist-form-container"> |
@@ -399,6 +415,7 @@ <h3>Show proposals with pending status:</h3> |
399 | 415 | audienceLevel: {{ item.audience_level.id }}, |
400 | 416 | languages: [{% for language in item.languages.all %}"{{language.code}}",{% endfor %}], |
401 | 417 | numOfVotes: {{item.userreview_set.count}}, |
| 418 | + typeId: {{ item.type.id }}, |
402 | 419 | }; |
403 | 420 | </script> |
404 | 421 | <tr class="proposal-item" id="submission-{{item.id}}" data-original-status="{{ item.current_or_pending_status }}"> |
|
0 commit comments