Skip to content

Commit d92f8ae

Browse files
committed
Merge branch 'feature/51-issuefilter' into 'develop'
Feature/51 issuefilter See merge request gtt/redmine_gtt!11
2 parents 21aea7b + 169a1d8 commit d92f8ae

File tree

14 files changed

+13325
-11024
lines changed

14 files changed

+13325
-11024
lines changed

Gemfile

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,5 @@ gem 'immutable-struct'
55
gem "rgeo"
66
gem "rgeo-geojson"
77
gem "rgeo-activerecord"
8-
gem 'pg', '~> 0.18.1'
9-
gem 'activerecord-postgis-adapter'
10-
8+
gem "pg"
9+
gem 'activerecord-postgis-adapter', '~> 3.1'

app/views/issues/index.api.rsb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ api.array :issues, api_meta(:total_count => @issue_count, :offset => @offset, :l
2626
api.geojson ""
2727
end
2828

29+
if issue.distance
30+
api.distance issue.distance
31+
end
32+
2933
render_api_custom_values issue.visible_custom_field_values, api
3034

3135
api.created_on issue.created_on

app/views/issues/index/_map.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<fieldset id="location" class="collapsible">
44
<legend onclick="toggleFieldset(this);"><%= l(:field_location) %></legend>
55

6-
<%= map_tag map: @project.map, geom: Issue.array_to_geojson(@issues, include_properties: { only: %i(id subject) }), popup: { href: '/issues/[id]' } %>
6+
<%= map_tag map: @project.map, geom: (Issue.array_to_geojson(@issues, include_properties: { only: %i(id subject) }) if @issues), popup: { href: '/issues/[id]' } %>
77
</fieldset>
88

99
<% end %>

assets/javascripts/app.js

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,9 @@ var App = (function ($, publ) {
193193

194194
// Add LayerSwitcher Image Toolbar
195195
map.addControl(new ol.control.LayerPopup());
196+
197+
// Add map events
198+
map.on('moveend', publ.updateFilter);
196199
};
197200

198201
/**
@@ -343,6 +346,33 @@ var App = (function ($, publ) {
343346
}
344347
};
345348

349+
/**
350+
* Updates map settings for Redmine filter
351+
*/
352+
publ.updateFilter = function () {
353+
var center = map.getView().getCenter();
354+
var extent = map.getView().calculateExtent(map.getSize());
355+
356+
center = ol.proj.transform(center,'EPSG:3857','EPSG:4326');
357+
console.log("Map Center (WGS84): ", center);
358+
$('fieldset#location').data('center', center);
359+
$('#tr_distance #values_distance_3').val(center[0]);
360+
$('#tr_distance #values_distance_4').val(center[1]);
361+
362+
363+
extent = ol.proj.transformExtent(extent,'EPSG:3857','EPSG:4326').join('|');
364+
console.log("Map Extent (WGS84): ",extent);
365+
$('select[name="v[bbox][]"]').find('option').first().val(extent);
366+
// adjust the value of the 'On map' option tag
367+
// Also adjust the JSON data that's the basis for building the filter row
368+
// html (this is relevant if the map is moved first and then the filter is
369+
// added.)
370+
if(window.availableFilters && window.availableFilters.bbox) {
371+
window.availableFilters.bbox.values = [['On map', extent]];
372+
}
373+
},
374+
375+
346376
/**
347377
* Parse page for WKT strings in history
348378
*/
@@ -647,3 +677,68 @@ var App = (function ($, publ) {
647677
return publ;
648678

649679
})(jQuery, App || {});
680+
681+
/**
682+
* Extend core Redmine's buildFilterRow method
683+
*/
684+
window.buildFilterRowWithoutDistanceFilter = window.buildFilterRow;
685+
window.buildFilterRow = function(field, operator, values) {
686+
if(field == 'distance') {
687+
buildDistanceFilterRow(operator, values);
688+
} else {
689+
buildFilterRowWithoutDistanceFilter(field, operator, values);
690+
}
691+
};
692+
693+
function buildDistanceFilterRow(operator, values){
694+
var field = 'distance';
695+
var fieldId = field;
696+
var filterTable = $("#filters-table");
697+
var filterOptions = availableFilters[field];
698+
if (!filterOptions) return;
699+
var operators = operatorByType[filterOptions['type']];
700+
var filterValues = filterOptions['values'];
701+
var i, select;
702+
703+
var tr = $('<tr class="filter">').attr('id', 'tr_'+fieldId).html(
704+
'<td class="field"><input checked="checked" id="cb_'+fieldId+'" name="f[]" value="'+field+'" type="checkbox"><label for="cb_'+fieldId+'"> '+filterOptions['name']+'</label></td>' +
705+
'<td class="operator"><select id="operators_'+fieldId+'" name="op['+field+']"></td>' +
706+
'<td class="values"></td>'
707+
);
708+
filterTable.append(tr);
709+
710+
select = tr.find('td.operator select');
711+
for (i = 0; i < operators.length; i++) {
712+
var option = $('<option>').val(operators[i]).text(operatorLabels[operators[i]]);
713+
if (operators[i] == operator) { option.attr('selected', true); }
714+
select.append(option);
715+
}
716+
select.change(function(){ toggleOperator(field); });
717+
718+
tr.find('td.values').append(
719+
'<span style="display:none;"><input type="text" name="v['+field+'][]" id="values_'+fieldId+'_1" size="14" class="value" /></span>' +
720+
' <span style="display:none;"><input type="text" name="v['+field+'][]" id="values_'+fieldId+'_2" size="14" class="value" /></span>' +
721+
'<input type="hidden" name="v['+field+'][]" id="values_'+fieldId+'_3" />' +
722+
'<input type="hidden" name="v['+field+'][]" id="values_'+fieldId+'_4" />'
723+
);
724+
$('#values_'+fieldId+'_1').val(values[0]);
725+
var base_idx = 1;
726+
if(values.length == 2 || values.length == 4) {
727+
// upper bound for 'between' operator
728+
$('#values_'+fieldId+'_2').val(values[1]);
729+
base_idx = 2;
730+
}
731+
var x,y;
732+
if(values.length > 2){
733+
console.log('distance center point from values: ', values[base_idx], values[base_idx+1]);
734+
x = values[base_idx];
735+
y = values[base_idx+1];
736+
} else {
737+
console.log('taking distance from map fieldset: ', $('fieldset#location').data('center'));
738+
var xy = $('fieldset#location').data('center');
739+
x = xy[0]; y = xy[1];
740+
}
741+
$('#values_'+fieldId+'_3').val(x);
742+
$('#values_'+fieldId+'_4').val(y);
743+
}
744+

0 commit comments

Comments
 (0)