Skip to content

Commit

Permalink
feat: deadline year input and handling for custom one-click map filters
Browse files Browse the repository at this point in the history
  • Loading branch information
gdmhrogut authored Nov 8, 2024
1 parent 763fa3a commit cd61c9e
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 7 deletions.
12 changes: 11 additions & 1 deletion datenmanagement/static/datenmanagement/js/customMapFilters.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function customMapFilters(filterId) {
let filterList = [];

// get current date
let currentDate = new Date().toJSON().slice(0, 10);
const currentDate = new Date().toJSON().slice(0, 10);

// handle one-click filters
switch (filterId) {
Expand All @@ -29,6 +29,16 @@ function customMapFilters(filterId) {
filterList.push(createFilter('status', 'list', 'both', 'negative', 'im Bau (LP8)'));
filterList.push(createFilter('status', 'list', 'both', 'negative', 'abgeschlossen'));
break;
case 'baustellen-geplant-stichjahr':
// get deadline year
const deadlineYear = $('#deadline-year-span').text();
// add filter objects to defined list with filter objects
filterList.push(createFilter('beginn', 'date', 'right', 'positive', deadlineYear + '-12-31'));
filterList.push(createFilter('ende', 'date', 'left', 'positive', deadlineYear + '-01-01'));
filterList.push(createFilter('status', 'list', 'both', 'negative', 'strategische Planung'));
filterList.push(createFilter('status', 'list', 'both', 'negative', 'im Bau (LP8)'));
filterList.push(createFilter('status', 'list', 'both', 'negative', 'abgeschlossen'));
break;
}

return filterList;
Expand Down
57 changes: 51 additions & 6 deletions datenmanagement/templates/datenmanagement/map.html
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,19 @@ <h5>Filter für Kartenobjekte</h5>
<div id="filter-alert" class="alert alert-warning" role="alert">Filter wirken <strong>additiv</strong> (wie „UND“)</div>
{% if map_one_click_filters %}
<h6>Ein-Klick-Filter</h6>
<div id="filter-one-click" class="btn-group-vertical">
{% if model_name == 'Baustellen_geplant' %}
<button id="baustellen-geplant-ende-nicht-abgeschlossen" class="filter-one-click-button btn btn-outline-success"><i class="fas fa-gears"></i> beendet, aber Status != abgeschlossen</button>
<button id="baustellen-geplant-beginn-nicht-imbau" class="filter-one-click-button btn btn-outline-success"><i class="fas fa-gears"></i> begonnen (nicht beendet), aber Status != im Bau (LP8) und Status != abgeschlossen</button>
{% endif %}
</div>
{% if model_name == 'Baustellen_geplant' %}
<div class="input-group mb-2">
<label for="deadline-year-input" class="mt-2 me-2">Stichjahr für Ein-Klick-Filter:</label>
<input id="deadline-year-input" type="number" name="stichjahr" class="form-control filter-one-click-other">
<button class="deadline-year-set filter-one-click-other btn btn-outline-secondary"><i class="fas fa-check" title="setzen"></i></button>
<button class="deadline-year-reset filter-one-click-other btn btn-outline-secondary"><i class="fas fa-undo" title="zurücksetzen"></i></button>
</div>
<div id="filter-one-click" class="btn-group-vertical">
<button id="baustellen-geplant-ende-nicht-abgeschlossen" class="filter-one-click-button btn btn-outline-success"><i class="fas fa-gears"></i> beendet, aber Status != abgeschlossen</button>
<button id="baustellen-geplant-beginn-nicht-imbau" class="filter-one-click-button btn btn-outline-success"><i class="fas fa-gears"></i> begonnen (nicht beendet), aber Status != im Bau (LP8) und Status != abgeschlossen</button>
<button id="baustellen-geplant-stichjahr" class="filter-one-click-button btn btn-outline-success"><i class="fas fa-gears"></i> Stichjahr <span id="deadline-year-span"></span> sowie Status != strategische Planung, Status != im Bau (LP8) und Status != abgeschlossen</button>
</div>
{% endif %}
<hr>
{% endif %}
{% if map_deadlinefilter_fields %}
Expand Down Expand Up @@ -544,6 +551,30 @@ <h5>Adressensuche</h5>
}
});

// handle deadline year for one-click-filters
{% if model_name == 'Baustellen_geplant' %}
// initially, set deadline year to current year
const currentYear = new Date().getFullYear();
const deadlineYearInput = $('#deadline-year-input');
deadlineYearInput.prop('min', currentYear - 10);
deadlineYearInput.prop('max', currentYear + 10);
deadlineYearInput.prop('value', currentYear);
$('#deadline-year-span').text(currentYear);

// on clicking the button to set the deadline year...
$('.deadline-year-set').on('click', function() {
// set deadline year to year entered
$('#deadline-year-span').text(deadlineYearInput.val());
});

// on clicking the button to reset the deadline year...
$('.deadline-year-reset').on('click', function() {
// reset deadline year to current year
deadlineYearInput.prop('value', currentYear);
$('#deadline-year-span').text(currentYear);
});
{% endif %}

// on clicking a one-click-filter button...
$('.filter-one-click-button').on('click', function(e) {
let $this = $(this);
Expand All @@ -555,6 +586,10 @@ <h5>Adressensuche</h5>
$(this).prop('disabled', true);
}
});
// disable all other one-click-filter control elements
$('.filter-one-click-other').each(function() {
$(this).prop('disabled', true);
});
// disable button to apply filters
$('#filter-apply').prop('disabled', true);
// declare and fill the filter object list
Expand All @@ -573,6 +608,11 @@ <h5>Adressensuche</h5>
$(this).prop('disabled', true);
});

// disable all other one-click-filter control elements
$('.filter-one-click-other').each(function() {
$(this).prop('disabled', true);
});

// declare a variable for the filter object list
let filterAttributesList = [];

Expand Down Expand Up @@ -655,6 +695,11 @@ <h5>Adressensuche</h5>
$(this).prop('disabled', false);
});

// (re)enable all other one-click-filter control elements
$('.filter-one-click-other').each(function() {
$(this).prop('disabled', false);
});

// (re)enable button to apply the filters
$('#filter-apply').prop('disabled', false);

Expand Down

0 comments on commit cd61c9e

Please sign in to comment.