Skip to content

Commit

Permalink
feat(date filter) aggregate partial date controls (mm dd yyyy) into s…
Browse files Browse the repository at this point in the history
…ingle query param and back; addresses #288
  • Loading branch information
tuurma committed Nov 29, 2017
1 parent b04001d commit fef81e8
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 2 deletions.
2 changes: 2 additions & 0 deletions pages/search/_filter-date.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ <h3 class="hsg-sidebar-title-second-level">From</h3>
<label for="start_date_3">Year</label>
<input class="hsg-input-inline form-control" data-template="templates:form-control" placeholder="yyyy" aria-describedby="startDateHint" id="start_date_3" name="start_date_3" type="number" min="1600" max="2025" step="1" value=""/>
</div>
<input type="hidden" name="start_date" data-template="templates:form-control"/>
</div>
</fieldset>

Expand Down Expand Up @@ -86,6 +87,7 @@ <h3 class="hsg-sidebar-title-second-level">To</h3>
<input class="hsg-input-inline form-control" data-template="templates:form-control" placeholder="yyyy" aria-describedby="endDateHint" id="end_date_3" name="end_date_3" type="number" min="1600" max="2025" step="1" value=""/>
</div>
</div>
<input type="hidden" name="end_date" data-template="templates:form-control"/>
</fieldset>

<fieldset>
Expand Down
2 changes: 1 addition & 1 deletion pages/search/_filter-row.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
<div class="row">
<div data-template="templates:include" data-template-path="pages/search/_filter-querystring.html"/>
<div data-template="templates:include" data-template-path="pages/search/_sort-by-button.html"/>
</div>
</div>
2 changes: 1 addition & 1 deletion pages/search/_sort-by-button.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@
<input type="hidden" name="sorting" value="date_desc"/>
</form>
</div>
</div>
</div>
29 changes: 29 additions & 0 deletions resources/scripts/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,18 @@ $(document).ready(function() {
action += '&' + volumesFilter.serialize();
action += serializeFiltersByName(queryForm, 'match');
action += serializeFiltersByName(formFilters, 'section');
//action += serializeFiltersByName(dateFilter, 'start_date');
//aggregate criteria from partial date controls (month day year) into single query param
if ($('#start_date_3').val()) {
var startDate = [$('#start_date_3').val().padStart(4, '0'), $('#start_date_1').val().padStart(2, '0'), $('#start_date_2').val().padStart(2, '0')];
action += '&start_date=' + startDate.join('-');
}
//action += serializeFiltersByName(dateFilter, 'end_date');
var endDate = [$('#end_date_3').val().padStart(4, '0'), $('#end_date_1').val().padStart(2, '0'), $('#end_date_2').val().padStart(2, '0')];
action += '&end_date=' + endDate.join('-');
console.log(action);
//action += serializeFiltersByName(dateFilter, 'start_time');
//action += serializeFiltersByName(dateFilter, 'end_time');
action += serializeFiltersByName(sectionFilter, 'within');

var currentActiveSorting = sortingForm.find('.active');
Expand All @@ -138,6 +150,19 @@ $(document).ready(function() {
}

if (mainForm.get(0)) {

//TODO refactor and cover cases of empty day/month
//split aggregated date query and set up values for partial date controls
var startDate = mainForm.find('input[name="start_date"]').val();
var splitStartDate = startDate.split('-');
$('#start_date_3').val(splitStartDate[0]);
$('#start_date_1').val(splitStartDate[1]);
$('#start_date_2').val(splitStartDate[2]);
var endDate = mainForm.find('input[name="end_date"]').val();
var splitEndDate = endDate.split('-');
$('#end_date_3').val(splitEndDate[0]);
$('#end_date_1').val(splitEndDate[1]);
$('#end_date_2').val(splitEndDate[2]);
mainForm.on('submit', submitSearch);
mainButton.on('click', submitSearch);
}
Expand Down Expand Up @@ -203,8 +228,12 @@ $(document).ready(function() {
if (documentsInput.is( ":checked" ) && allSelectedButDocuments()) {
dateComponent.removeClass("hsg-hidden");
dateComponent.addClass("hsg-active");
<<<<<<< HEAD
s }

=======
}
>>>>>>> feat(date filter) aggregate partial date controls (mm dd yyyy) into single query param and back; addresses #288
else {
dateComponent.addClass("hsg-hidden");
dateComponent.removeClass("hsg-active");
Expand Down

0 comments on commit fef81e8

Please sign in to comment.