diff --git a/frontend/app/filter/filter-dialog.css b/frontend/app/filter/filter-dialog.css new file mode 100644 index 00000000..0ce41ffa --- /dev/null +++ b/frontend/app/filter/filter-dialog.css @@ -0,0 +1,5 @@ +.alert pre { + border: none; + padding: 0; + background: transparent; +} \ No newline at end of file diff --git a/frontend/app/filter/filter-dialog.html b/frontend/app/filter/filter-dialog.html new file mode 100644 index 00000000..f7a26da4 --- /dev/null +++ b/frontend/app/filter/filter-dialog.html @@ -0,0 +1,183 @@ + + + \ No newline at end of file diff --git a/frontend/app/filter/filter.js b/frontend/app/filter/filter.js index db16b748..08e0c635 100644 --- a/frontend/app/filter/filter.js +++ b/frontend/app/filter/filter.js @@ -1,14 +1,26 @@ (function(fm, $, ng, undefined) { - fm.app.factory("fmFilter", function(compileExpression) { + fm.app.factory("fmFilter", function(compileExpression, $rootScope, $uibModal) { var currentVal; var fmFilter = { customFuncs: { prop: function(obj, key) { return obj && obj[key]; + }, + + random: function() { } // Does not work well with angular digest cycles + }, + + hasError: function(expr) { + try { + if(expr && expr.trim()) + compileExpression(expr, fmFilter.customFuncs); + } catch(e) { + return e; } }, + compileExpression: function(expr) { if(!expr || !expr.trim()) return function() { return true; }; @@ -86,10 +98,34 @@ } return obj; + }, + + showFilterDialog: function(currentFilter, types) { + var dialog = $uibModal.open({ + templateUrl: "filter/filter-dialog.html", + scope: $rootScope, + controller: "fmFilterDialogCtrl", + size: "lg", + resolve: { + currentFilter: function() { return currentFilter; }, + types: function() { return types; } + } + }); + + return dialog.result; } }; return fmFilter; }); + fm.app.controller("fmFilterDialogCtrl", function(currentFilter, types, $scope, fmFilter) { + $scope.filter = currentFilter; + $scope.types = types; + + $scope.$watch("filter", function(newFilter) { + $scope.error = fmFilter.hasError(newFilter); + }) + }); + })(FacilMap, jQuery, angular); \ No newline at end of file diff --git a/frontend/app/map/map/map.js b/frontend/app/map/map/map.js index 17ca7d4e..3fb406bb 100644 --- a/frontend/app/map/map/map.js +++ b/frontend/app/map/map/map.js @@ -188,7 +188,7 @@ map.mapEvents.$emit("layerchange"); }); - map.getCurrentView = function() { + map.getCurrentView = function(addFilter) { var ret = fmUtils.leafletToFmBbox(map.map.getBounds()); ret.layers = [ ]; @@ -199,6 +199,9 @@ ret.layers.push(it.options.fmKey); }); + if(addFilter) + ret.filter = map.socket.filterExpr; + return ret; }; @@ -224,6 +227,8 @@ } catch(e) { map.map.setView(bounds.getCenter(), map.map.getBoundsZoom(bounds, !view)); } + + map.socket.setFilter(view.filter); }; map.map.createPane("fmClickListener"); diff --git a/frontend/app/map/toolbox/toolbox.html b/frontend/app/map/toolbox/toolbox.html index 244a6128..3109eed8 100644 --- a/frontend/app/map/toolbox/toolbox.html +++ b/frontend/app/map/toolbox/toolbox.html @@ -39,6 +39,7 @@