Skip to content

Commit 60d5b31

Browse files
committed
Merge branch 'feature/51-issuefilter' into 'develop'
Feature/51 issuefilter See merge request gtt/redmine_gtt!12
2 parents d92f8ae + 8745964 commit 60d5b31

File tree

3 files changed

+46
-141
lines changed

3 files changed

+46
-141
lines changed

Gemfile

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

Gemfile.lock

Lines changed: 0 additions & 127 deletions
This file was deleted.

assets/javascripts/app.js

Lines changed: 44 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ var App = (function ($, publ) {
99
var map, vector, bounds, contents, toolbar, geolocation = null;
1010
var features = [];
1111
var layerArr = [];
12+
var filters = {
13+
location: false,
14+
distance: false
15+
};
1216

1317
// Quick hack
1418
var quick_hack = {
@@ -149,15 +153,14 @@ var App = (function ($, publ) {
149153
this.setView();
150154
this.setGeolocation();
151155
this.setGeocoding();
152-
this.zoomToExtent();
153156
this.parseHistory();
154157

155158
// Control button
156159
var maximizeCtrl = new ol.control.Button({
157160
html: '<i class="icon-maximize" ></i>',
158161
title: "Maximize",
159162
handleClick: function () {
160-
publ.zoomToExtent();
163+
publ.zoomToExtent(true);
161164
}
162165
});
163166
toolbar.addControl(maximizeCtrl);
@@ -194,8 +197,19 @@ var App = (function ($, publ) {
194197
// Add LayerSwitcher Image Toolbar
195198
map.addControl(new ol.control.LayerPopup());
196199

197-
// Add map events
198-
map.on('moveend', publ.updateFilter);
200+
// Because Redmine filter functions are applied later, the Window onload
201+
// event provides a workaround to have filters loaded before executing
202+
// the following code
203+
$(window).bind('load', function() {
204+
if ($("tr#tr_bbox").length > 0) {
205+
filters.location = true;
206+
}
207+
if ($("tr#tr_distance").length > 0) {
208+
filters.distance = true;
209+
}
210+
publ.zoomToExtent();
211+
map.on('moveend', publ.updateFilter);
212+
});
199213
};
200214

201215
/**
@@ -204,7 +218,7 @@ var App = (function ($, publ) {
204218
publ.setBasemap = function (layers) {
205219

206220
if (layers.length === 0) {
207-
console.error("There is no baselayer availaable!");
221+
console.error("There is no baselayer available!");
208222
return;
209223
}
210224

@@ -326,8 +340,18 @@ var App = (function ($, publ) {
326340
/**
327341
*
328342
*/
329-
publ.zoomToExtent = function () {
330-
if (vector.getSource().getFeatures().length > 0) {
343+
publ.zoomToExtent = function (force) {
344+
if (!force && (filters.distance || filters.location)) {
345+
// Do not zoom to extent but show the previous extent stored as cookie
346+
var parts = (getCookie("_redmine_gtt_permalink")).split("/");
347+
map.getView().setZoom(parseInt(parts[0], 10));
348+
map.getView().setCenter(ol.proj.transform([
349+
parseFloat(parts[1]),
350+
parseFloat(parts[2])
351+
],'EPSG:4326','EPSG:3857'));
352+
map.getView().setRotation(parseFloat(parts[3]));
353+
}
354+
else if (vector.getSource().getFeatures().length > 0) {
331355
var extent = ol.extent.createEmpty();
332356
// Because the vector layer is set to "useSpatialIndex": false, we cannot
333357
// make use of "vector.getSource().getExtent()"
@@ -354,14 +378,23 @@ var App = (function ($, publ) {
354378
var extent = map.getView().calculateExtent(map.getSize());
355379

356380
center = ol.proj.transform(center,'EPSG:3857','EPSG:4326');
357-
console.log("Map Center (WGS84): ", center);
381+
// console.log("Map Center (WGS84): ", center);
358382
$('fieldset#location').data('center', center);
359383
$('#tr_distance #values_distance_3').val(center[0]);
360384
$('#tr_distance #values_distance_4').val(center[1]);
361385

386+
// Set Permalink as Cookie
387+
var cookie = [];
388+
var hash = map.getView().getZoom() + '/' +
389+
Math.round(center[0] * 1000000) / 1000000 + '/' +
390+
Math.round(center[1] * 1000000) / 1000000 + '/' +
391+
map.getView().getRotation();
392+
cookie.push("_redmine_gtt_permalink=" + hash);
393+
cookie.push("path=" + window.location.pathname);
394+
document.cookie = cookie.join(";");
362395

363396
extent = ol.proj.transformExtent(extent,'EPSG:3857','EPSG:4326').join('|');
364-
console.log("Map Extent (WGS84): ",extent);
397+
// console.log("Map Extent (WGS84): ",extent);
365398
$('select[name="v[bbox][]"]').find('option').first().val(extent);
366399
// adjust the value of the 'On map' option tag
367400
// Also adjust the JSON data that's the basis for building the filter row
@@ -730,15 +763,14 @@ function buildDistanceFilterRow(operator, values){
730763
}
731764
var x,y;
732765
if(values.length > 2){
733-
console.log('distance center point from values: ', values[base_idx], values[base_idx+1]);
766+
// console.log('distance center point from values: ', values[base_idx], values[base_idx+1]);
734767
x = values[base_idx];
735768
y = values[base_idx+1];
736769
} else {
737-
console.log('taking distance from map fieldset: ', $('fieldset#location').data('center'));
770+
// console.log('taking distance from map fieldset: ', $('fieldset#location').data('center'));
738771
var xy = $('fieldset#location').data('center');
739772
x = xy[0]; y = xy[1];
740773
}
741774
$('#values_'+fieldId+'_3').val(x);
742775
$('#values_'+fieldId+'_4').val(y);
743776
}
744-

0 commit comments

Comments
 (0)