kopia lustrzana https://github.com/FacilMap/facilmap
Added function to copy pad
rodzic
efebe61130
commit
101fd38523
|
@ -171,6 +171,7 @@
|
|||
$scope.layers = fp.getLayerInfo();
|
||||
$scope.colours = fp.COLOURS;
|
||||
$scope.readonly = null;
|
||||
$scope.copyPadId = fp.generateRandomPadId();
|
||||
|
||||
socket.emit("setPadId", FacilPad.padId);
|
||||
|
||||
|
@ -494,6 +495,20 @@
|
|||
});
|
||||
};
|
||||
|
||||
$scope.copyPad = function() {
|
||||
socket.emit("copyPad", { toId: $scope.copyPadId }, function(err) {
|
||||
if(err) {
|
||||
$scope.dialogError = err;
|
||||
return;
|
||||
}
|
||||
|
||||
$scope.closeDialog();
|
||||
var url = $scope.urlPrefix + $scope.copyPadId;
|
||||
$scope.showMessage("success", "The pad has been copied to", [ { label: url, url: url } ]);
|
||||
$scope.copyPadId = fp.generateRandomPadId();
|
||||
});
|
||||
};
|
||||
|
||||
$scope.openDialog = function(id) {
|
||||
var el = $("#"+id);
|
||||
|
||||
|
|
|
@ -367,6 +367,17 @@ var FacilPad = {
|
|||
}
|
||||
};
|
||||
|
||||
var LETTERS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
|
||||
var LENGTH = 12;
|
||||
|
||||
fp.generateRandomPadId = function() {
|
||||
var randomPadId = "";
|
||||
for(var i=0; i<LENGTH; i++) {
|
||||
randomPadId += LETTERS[Math.floor(Math.random() * LETTERS.length)];
|
||||
}
|
||||
return randomPadId;
|
||||
};
|
||||
|
||||
fp.padId = location.pathname.match(/[^\/]*$/)[0];
|
||||
|
||||
})(FacilPad);
|
|
@ -90,6 +90,10 @@ dd input, dd textarea {
|
|||
width: 100%;
|
||||
}
|
||||
|
||||
dd input.inline {
|
||||
width: 10em;
|
||||
}
|
||||
|
||||
dl:after {
|
||||
clear: left;
|
||||
display: block;
|
||||
|
|
|
@ -32,13 +32,16 @@
|
|||
</a>
|
||||
</li>
|
||||
</ul></li>
|
||||
<li><a href="javascript:">Tools</a><ul>
|
||||
<li><a href="javascript:" ng-click="openDialog('copy-pad-dialog')" ng-hide="readonly">Copy pad</a></li>
|
||||
<li><a href="javascript:" ng-click="openDialog('pad-settings-dialog')" ng-hide="readonly">Pad settings</a></li>
|
||||
</ul></li>
|
||||
</ul>
|
||||
|
||||
<div id="messages">
|
||||
<p ng-repeat="message in messages" class="{{message.type}}">
|
||||
{{message.message}}
|
||||
<span ng-repeat="button in message.buttons"> <a href="javascript:" ng-click="button.click()">{{button.label}}</a></span>
|
||||
<span ng-repeat="button in message.buttons"> <a href="{{button.url || 'javascript:'}}" ng-click="button.click && button.click()">{{button.label}}</a></span>
|
||||
<a href="javascript:" class="close-button" ng-click="closeMessage(message)">×</a>
|
||||
</p>
|
||||
</div>
|
||||
|
@ -172,6 +175,19 @@
|
|||
</form>
|
||||
</div>
|
||||
|
||||
<div id="copy-pad-dialog" title="Copy pad" fp-dialog>
|
||||
<form>
|
||||
<p class="error" ng-show="dialogError">{{dialogError}}</p>
|
||||
<dl>
|
||||
<dt>Copy to</dt>
|
||||
<dd>{{urlPrefix}}<input ng-model="copyPadId" class="inline" /></dd>
|
||||
</dl>
|
||||
<div>
|
||||
<button ng-click="copyPad()">Copy</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<ul id="colour-picker">
|
||||
<li ng-repeat="colour in colours" ng-style="{ 'background-color': '#'+colour }" data-colour="{{colour}}"></li>
|
||||
</ul>
|
||||
|
|
|
@ -113,19 +113,13 @@ function createLine(padId, data, callback) {
|
|||
_calculateRouting(data, function(err, actualPoints) { // Also sets data.distance and data.time
|
||||
if(err)
|
||||
return callback(err);
|
||||
backend.createLine(padId, data, function(err, data) {
|
||||
|
||||
_createLine(padId, data, function(err, data) {
|
||||
if(err)
|
||||
return callback(err);
|
||||
|
||||
backend.setLinePoints(data.id, actualPoints, function(err) {
|
||||
if(err)
|
||||
return callback(err);
|
||||
|
||||
listeners.notifyPadListeners(data._pad, "line", data);
|
||||
listeners.notifyPadListeners(data._pad, "linePoints", function(bboxWithZoom) {
|
||||
return { reset: true, id: data.id, points : routing.prepareForBoundingBox(actualPoints, bboxWithZoom) };
|
||||
});
|
||||
callback(null, data);
|
||||
_setLinePoints(padId, data.id, actualPoints, function(err) {
|
||||
callback(err, data);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -147,27 +141,49 @@ function updateLine(lineId, data, callback) {
|
|||
_calculateRouting(data, next); // Also sets data.distance and data.time
|
||||
} ],
|
||||
updateLine : [ "calculateRouting", function(next) {
|
||||
backend.updateLine(lineId, data, next);
|
||||
_updateLine(lineId, data, next);
|
||||
} ],
|
||||
setLinePoints : [ "calculateRouting", function(next, res) {
|
||||
setLinePoints : [ "originalLine", "calculateRouting", function(next, res) {
|
||||
if(!res.calculateRouting)
|
||||
return next();
|
||||
|
||||
backend.setLinePoints(lineId, res.calculateRouting, next);
|
||||
_setLinePoints(res.originalLine._pad, lineId, res.calculateRouting, next);
|
||||
} ]
|
||||
}, function(err, res) {
|
||||
if(err)
|
||||
return callback(err);
|
||||
|
||||
listeners.notifyPadListeners(res.updateLine._pad, "line", res.updateLine);
|
||||
|
||||
if(res.calculateRouting) {
|
||||
listeners.notifyPadListeners(res.updateLine._pad, "linePoints", function(bboxWithZoom) {
|
||||
return { reset: true, id: data.id, points : routing.prepareForBoundingBox(res.calculateRouting, bboxWithZoom) };
|
||||
callback(err, res.updateLine);
|
||||
});
|
||||
}
|
||||
|
||||
callback(null, res.updateLine);
|
||||
function _createLine(padId, data, callback) {
|
||||
backend.createLine(padId, data, function(err, data) {
|
||||
if(err)
|
||||
return callback(err);
|
||||
|
||||
listeners.notifyPadListeners(data._pad, "line", data);
|
||||
callback(null, data);
|
||||
});
|
||||
}
|
||||
|
||||
function _updateLine(lineId, data, callback) {
|
||||
backend.updateLine(lineId, data, function(err, data) {
|
||||
if(err)
|
||||
return callback(err);
|
||||
|
||||
listeners.notifyPadListeners(data._pad, "line", data);
|
||||
callback(null, data);
|
||||
});
|
||||
}
|
||||
|
||||
function _setLinePoints(padId, lineId, points, callback) {
|
||||
backend.setLinePoints(lineId, points, function(err) {
|
||||
if(err)
|
||||
return callback(err);
|
||||
|
||||
listeners.notifyPadListeners(padId, "linePoints", function(bboxWithZoom) {
|
||||
return { reset: true, id: lineId, points : routing.prepareForBoundingBox(points, bboxWithZoom) };
|
||||
});
|
||||
|
||||
callback(null);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -200,6 +216,72 @@ function getLinePoints(padId, bboxWithZoom) {
|
|||
});
|
||||
}
|
||||
|
||||
function copyPad(fromPadId, toPadId, callback) {
|
||||
function _handleStream(stream, next, cb) {
|
||||
stream.on("data", function(data) {
|
||||
stream.pause();
|
||||
cb(data, function() {
|
||||
stream.resume();
|
||||
});
|
||||
});
|
||||
|
||||
stream.on("error", next);
|
||||
stream.on("end", next);
|
||||
}
|
||||
|
||||
async.auto({
|
||||
fromPadData : function(next) {
|
||||
backend.getPadData(fromPadId, next);
|
||||
},
|
||||
toPadData : function(next) {
|
||||
getPadData(toPadId, next);
|
||||
},
|
||||
padsExist : [ "fromPadData", "toPadData", function(next, r) {
|
||||
if(!r.fromPadData)
|
||||
return next(new Error("Pad "+fromPadId+" does not exist."));
|
||||
if(!r.toPadData.writable)
|
||||
return next(new Error("Destination pad is read-only."));
|
||||
|
||||
toPadId = r.toPadData.id;
|
||||
|
||||
next();
|
||||
}],
|
||||
copyMarkers : [ "padsExist", function(next) {
|
||||
_handleStream(getPadMarkers(fromPadId, null), next, function(marker, cb) {
|
||||
createMarker(toPadId, marker, cb);
|
||||
});
|
||||
}],
|
||||
copyLines : [ "padsExist", function(next) {
|
||||
_handleStream(getPadLines(fromPadId), next, function(line, cb) {
|
||||
async.auto({
|
||||
createLine : function(next) {
|
||||
_createLine(toPadId, line, next);
|
||||
},
|
||||
getLinePoints : function(next) {
|
||||
backend.getLinePoints(line.id, next);
|
||||
},
|
||||
setLinePoints : [ "createLine", "getLinePoints", function(next, r) {
|
||||
_setLinePoints(toPadId, r.createLine.id, r.getLinePoints, next);
|
||||
} ]
|
||||
}, cb);
|
||||
});
|
||||
}],
|
||||
copyViews : [ "padsExist", function(next, r) {
|
||||
_handleStream(getViews(fromPadId), next, function(view, cb) {
|
||||
createView(toPadId, view, function(err, newView) {
|
||||
if(err)
|
||||
return cb(err);
|
||||
|
||||
if(r.fromPadData.defaultView && r.fromPadData.defaultView.id == view.id && r.toPadData.defaultView == null)
|
||||
updatePadData(toPadId, { defaultView: newView.id }, cb);
|
||||
else
|
||||
cb();
|
||||
});
|
||||
});
|
||||
}]
|
||||
}, callback);
|
||||
}
|
||||
|
||||
function _calculateRouting(line, callback) {
|
||||
if(line.points && line.points.length >= 2 && line.mode) {
|
||||
routing.calculateRouting(line.points, line.mode, function(err, routeData) {
|
||||
|
@ -273,5 +355,6 @@ module.exports = {
|
|||
createLine : createLine,
|
||||
updateLine : updateLine,
|
||||
deleteLine : deleteLine,
|
||||
getLinePoints : getLinePoints
|
||||
getLinePoints : getLinePoints,
|
||||
copyPad : copyPad
|
||||
};
|
|
@ -144,7 +144,7 @@ function getLine(lineId, callback) {
|
|||
}
|
||||
|
||||
function createLine(padId, data, callback) {
|
||||
data._pad = padId;
|
||||
data = utils.extend({ }, data, { _pad: padId });
|
||||
Line.create(data, _fixIdCallback(callback));
|
||||
}
|
||||
|
||||
|
@ -156,17 +156,21 @@ function deleteLine(lineId, callback) {
|
|||
Line.findByIdAndRemove(lineId, _fixIdCallback(callback));
|
||||
}
|
||||
|
||||
function getLinePoints(lineId, callback) {
|
||||
LinePoints.find({ _line: lineId }).sort("idx").exec(_linePointsCallback(callback));
|
||||
}
|
||||
|
||||
function getLinePointsByBbox(lineId, bboxWithZoom, callback) {
|
||||
var condition = { $and: [ _makeBboxCondition(bboxWithZoom), {
|
||||
"_line" : lineId,
|
||||
"zoom" : { $lte: bboxWithZoom.zoom }
|
||||
} ] };
|
||||
|
||||
LinePoints.find(condition, "idx zoom", { sort: "idx" }).exec(callback);
|
||||
LinePoints.find(condition, "idx zoom", { sort: "idx" }).exec(_linePointsCallback(callback));
|
||||
}
|
||||
|
||||
function getLinePointsByIdx(lineId, indexes, callback) {
|
||||
LinePoints.find({ _line: lineId, idx: { $in: indexes } }).select("lon lat idx").sort("idx").exec(callback);
|
||||
LinePoints.find({ _line: lineId, idx: { $in: indexes } }).select("lon lat idx").sort("idx").exec(_linePointsCallback(callback));
|
||||
}
|
||||
|
||||
function setLinePoints(lineId, points, callback) {
|
||||
|
@ -199,6 +203,11 @@ function _fixId(data) {
|
|||
data.defaultView.id = data.defaultView._id;
|
||||
delete data.defaultView._id;
|
||||
}
|
||||
|
||||
if(data.points) {
|
||||
for(var i=0; i<data.points.length; i++)
|
||||
delete data.points[i]._id;
|
||||
}
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
@ -213,7 +222,25 @@ function _fixIdStream(stream) {
|
|||
return utils.filterStream(stream, _fixId);
|
||||
}
|
||||
|
||||
function _linePointsCallback(callback) {
|
||||
return function(err, linePoints) {
|
||||
if(err)
|
||||
return callback(err);
|
||||
|
||||
var ret = [ ];
|
||||
for(var i=0; i<linePoints.length; i++) {
|
||||
var c = JSON.parse(JSON.stringify(linePoints[i]));
|
||||
delete c._id;
|
||||
ret.push(c);
|
||||
}
|
||||
callback(null, ret);
|
||||
};
|
||||
}
|
||||
|
||||
function _makeBboxCondition(bbox, prefix) {
|
||||
if(!bbox)
|
||||
return { };
|
||||
|
||||
prefix = prefix || "";
|
||||
|
||||
function cond(key, value) {
|
||||
|
@ -263,6 +290,7 @@ module.exports = {
|
|||
createLine : createLine,
|
||||
updateLine : updateLine,
|
||||
deleteLine : deleteLine,
|
||||
getLinePoints : getLinePoints,
|
||||
getLinePointsByBbox : getLinePointsByBbox,
|
||||
getLinePointsByIdx : getLinePointsByIdx,
|
||||
setLinePoints : setLinePoints
|
||||
|
|
|
@ -138,6 +138,10 @@ database.connect(function(err) {
|
|||
return callback(new Error("In read-only mode."));
|
||||
|
||||
database.deleteView(data.id, callback);
|
||||
},
|
||||
|
||||
copyPad : function(data, callback) {
|
||||
database.copyPad(socket.padId, data.toId, callback);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue