diff --git a/frontend/.htaccess b/frontend/.htaccess
index 811cf336..cf783850 100644
--- a/frontend/.htaccess
+++ b/frontend/.htaccess
@@ -1,3 +1,6 @@
RewriteEngine on
+
+RewriteRule ^$ build/index.html
+
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^.+$ build/index.html
\ No newline at end of file
diff --git a/frontend/app/app.js b/frontend/app/app.js
index 2774c4cc..cec76c60 100644
--- a/frontend/app/app.js
+++ b/frontend/app/app.js
@@ -29,7 +29,6 @@ var FacilPad = {
});
fp.app.run([ "$rootScope", "fpUtils", function($rootScope, fpUtils) {
- $rootScope.padId = location.pathname.match(/[^\/]*$/)[0];
$rootScope.urlPrefix = location.protocol + "//" + location.host + location.pathname.replace(/[^\/]*$/, "");
$rootScope.round = fpUtils.round;
@@ -79,14 +78,19 @@ var FacilPad = {
};
fp.app.controller("PadCtrl", function($scope, fpMap, $timeout) {
+ $scope.padId = location.pathname.match(/[^\/]*$/)[0];
+
$timeout(function() {
var map = fpMap.getMap("map");
- if(map.socket.padData)
- $scope.padName = map.socket.padData.name;
map.socket.$watch("padData.name", function(newVal) {
$scope.padName = newVal;
});
+
+ map.socket.$watch("padId", function(padId) {
+ if(padId)
+ history.replaceState(null, "", $scope.urlPrefix + padId);
+ });
}, 0);
});
diff --git a/frontend/app/map/map/map.html b/frontend/app/map/map/map.html
index 96a88016..2328fae0 100644
--- a/frontend/app/map/map/map.html
+++ b/frontend/app/map/map/map.html
@@ -4,7 +4,7 @@
-
+
+
Loading...
\ No newline at end of file
diff --git a/frontend/app/map/map/map.js b/frontend/app/map/map/map.js
index e1249de2..c1733817 100644
--- a/frontend/app/map/map/map.js
+++ b/frontend/app/map/map/map.js
@@ -19,20 +19,18 @@
};
ret.initMap = function(el, id, padId) {
- return maps[id] = new Map(el, id, padId);
+ return maps[id] = new Map(el, padId);
};
return ret;
- function Map(el, id, padId) {
+ function Map(el, padId) {
var map = this;
map.el = el;
map.mapEvents = $rootScope.$new(true); /* Event types: click, layerchange */
map.socket = fpSocket(padId);
- //map.socket.id = id; // To be in scope for template
-
map.layers = { };
[
L.tileLayer("http://korona.geog.uni-heidelberg.de/tiles/roads/x={x}&y={y}&z={z}", {
@@ -91,9 +89,12 @@
direction: "right"
};
+ var scope = map.socket.$new();
+ scope.loaded = false;
+
var tpl = $($templateCache.get("map/map/map.html"));
el.append(tpl);
- $compile(tpl)(map.socket);
+ $compile(tpl)(scope);
map.map = L.map(el.find(".fp-map")[0]);
@@ -268,18 +269,22 @@
fpMapLegend(map);
- var loadedWatcher = map.socket.$watch("loaded", function(loaded) {
- if(loaded) {
- setTimeout(function() {
- map.displayView(map.socket.padData.defaultView);
- }, 0);
- loadedWatcher();
- }
- });
+ if(padId) {
+ var loadedWatcher = map.socket.$watch("padData", function(padData) {
+ if(padData != null) {
+ loadedWatcher();
+ map.displayView(padData.defaultView);
+ scope.loaded = true;
+ }
+ });
+ } else {
+ map.displayView();
+ scope.loaded = true;
+ }
var errorMessage = null;
map.socket.$watch("disconnected", function(disconnected) {
- if(disconnected && !errorMessage)
+ if(disconnected && !errorMessage && !map.socket.serverError)
errorMessage = map.messages.showMessage("danger", "The connection to the server was lost.");
else if(!disconnected && errorMessage) {
errorMessage.close();
@@ -287,8 +292,16 @@
}
});
+ map.socket.$watch("serverError", function(serverError) {
+ if(serverError) {
+ errorMessage && errorMessage.close();
+ map.messages.showMessage("danger", serverError);
+ }
+ });
+
map.map.on("moveend", function() {
- map.socket.updateBbox(fpUtils.leafletToFpBbox(map.map.getBounds(), map.map.getZoom()));
+ if(map.socket.padId)
+ map.socket.updateBbox(fpUtils.leafletToFpBbox(map.map.getBounds(), map.map.getZoom()));
});
}
});
diff --git a/frontend/app/map/pad/pad-settings.html b/frontend/app/map/pad/pad-settings.html
index 84c6e5d4..68c64a2c 100644
--- a/frontend/app/map/pad/pad-settings.html
+++ b/frontend/app/map/pad/pad-settings.html
@@ -1,28 +1,38 @@
\ No newline at end of file
diff --git a/frontend/app/map/pad/pad.js b/frontend/app/map/pad/pad.js
index 96784d06..da108a58 100644
--- a/frontend/app/map/pad/pad.js
+++ b/frontend/app/map/pad/pad.js
@@ -3,22 +3,29 @@
fp.app.factory("fpMapPad", function($uibModal, fpUtils) {
return function(map) {
var ret = {
- editPadSettings : function() {
+ createPad : function() {
+ ret.editPadSettings(true);
+ },
+ editPadSettings : function(create) {
var dialog = $uibModal.open({
templateUrl: "map/pad/pad-settings.html",
scope: map.socket,
controller: "fpMapPadSettingsCtrl",
size: "lg",
resolve: {
- map: function() { return map; }
+ map: function() { return map; },
+ create: function() { return create; }
}
});
- var preserve = fpUtils.preserveObject(map.socket, "padData", "padData", function() {
- dialog.dismiss();
- });
+ if(!create) {
+ // TODO: use child scope!
+ var preserve = fpUtils.preserveObject(map.socket, "padData", "padData", function() {
+ dialog.dismiss();
+ });
- dialog.result.then(preserve.leave.bind(preserve), preserve.revert.bind(preserve));
+ dialog.result.then(preserve.leave.bind(preserve), preserve.revert.bind(preserve));
+ }
}
};
@@ -43,16 +50,43 @@
};
});
- fp.app.controller("fpMapPadSettingsCtrl", function($scope, map) {
- $scope.save = function() {
- var padData = $.extend({ }, map.socket.padData);
- delete padData.defaultView;
- map.socket.emit("editPad", padData, function(err) {
- if(err)
- return $scope.error = err;
+ fp.app.controller("fpMapPadSettingsCtrl", function($scope, map, create, fpUtils) {
+ $scope.create = create;
- $scope.$close();
- });
+ if(create) {
+ $scope.writeId = fpUtils.generateRandomPadId(14);
+ $scope.readId = fpUtils.generateRandomPadId(12);
+ $scope.padName = "New FacilPad";
+ } else {
+ $scope.writeId = map.socket.padData.writeId;
+ $scope.readId = map.socket.padData.id;
+ $scope.padName = map.socket.padData.name;
+ }
+
+ $scope.save = function() {
+ var newData = {
+ name: $scope.padName,
+ id: $scope.readId,
+ writeId: $scope.writeId
+ };
+
+ if(create) {
+ map.socket.emit("createPad", newData, function(err) {
+ if(err)
+ return $scope.error = err;
+
+ map.socket.updateBbox(fpUtils.leafletToFpBbox(map.map.getBounds(), map.map.getZoom()));
+
+ $scope.$close();
+ });
+ } else {
+ map.socket.emit("editPad", newData, function(err) {
+ if(err)
+ return $scope.error = err;
+
+ $scope.$close();
+ });
+ }
};
});
diff --git a/frontend/app/map/toolbox/toolbox.html b/frontend/app/map/toolbox/toolbox.html
index dd6ed5ca..e7dc3226 100644
--- a/frontend/app/map/toolbox/toolbox.html
+++ b/frontend/app/map/toolbox/toolbox.html
@@ -3,7 +3,10 @@