kopia lustrzana https://github.com/FacilMap/facilmap
Move GPX export to separate URL (#58)
rodzic
3824f4fd3e
commit
95c226305b
|
@ -1,35 +0,0 @@
|
|||
import 'blob';
|
||||
import {saveAs} from 'file-saver';
|
||||
import fm from '../../app';
|
||||
|
||||
function _parseBbox(bboxStr) {
|
||||
if(!bboxStr)
|
||||
return null;
|
||||
|
||||
var bboxArr = bboxStr.split(bboxStr);
|
||||
if(bboxArr.length != 4)
|
||||
return null;
|
||||
|
||||
var idxs = [ "left", "top", "right", "bottom" ];
|
||||
var ret = { };
|
||||
for(var i=0; i<4; i++) {
|
||||
ret[idxs[i]] = +bboxArr[i];
|
||||
if(!isFinite(ret[idxs[i]]))
|
||||
return null;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
fm.app.factory("fmMapGpx", function() {
|
||||
return function(map) {
|
||||
return {
|
||||
exportGpx : function() {
|
||||
map.socket.emit("exportGpx", { useTracks: true }).then(function(gpx) {
|
||||
saveAs(new Blob([ gpx ], { type: "application/gpx+xml" }), map.socket.padData.name.replace(/[\\\/:*?"<>|]+/g, '_') + '.gpx');
|
||||
}).catch(function(err) {
|
||||
map.messages.showMessage("danger", err);
|
||||
});
|
||||
}
|
||||
};
|
||||
};
|
||||
});
|
|
@ -13,7 +13,7 @@ fm.app.directive("facilmap", function(fmMap) {
|
|||
};
|
||||
});
|
||||
|
||||
fm.app.factory("fmMap", function(fmUtils, fmSocket, fmMapMessages, fmMapMarkers, $compile, fmMapLines, fmMapTypes, fmMapViews, $rootScope, fmMapPad, fmMapToolbox, $timeout, fmMapLegend, fmMapSearch, fmMapGpx, fmMapAbout, $sce, fmMapImport, fmMapHash, fmMapHistory) {
|
||||
fm.app.factory("fmMap", function(fmUtils, fmSocket, fmMapMessages, fmMapMarkers, $compile, fmMapLines, fmMapTypes, fmMapViews, $rootScope, fmMapPad, fmMapToolbox, $timeout, fmMapLegend, fmMapSearch, fmMapAbout, $sce, fmMapImport, fmMapHash, fmMapHistory) {
|
||||
var maps = { };
|
||||
|
||||
var ret = { };
|
||||
|
@ -325,7 +325,6 @@ fm.app.factory("fmMap", function(fmUtils, fmSocket, fmMapMessages, fmMapMarkers,
|
|||
map.viewsUi = fmMapViews(map);
|
||||
map.typesUi = fmMapTypes(map);
|
||||
map.padUi = fmMapPad(map);
|
||||
map.gpxUi = fmMapGpx(map);
|
||||
map.aboutUi = fmMapAbout(map);
|
||||
map.importUi = fmMapImport(map);
|
||||
map.searchUi = fmMapSearch(map);
|
||||
|
|
|
@ -41,7 +41,7 @@
|
|||
<li><a href="javascript:" ng-click="importFile()">Import file</a></li>
|
||||
<li ng-if="padId"><a href="javascript:" ng-click="showHistory()">Show edit history</a></li>
|
||||
<li ng-if="padId"><a href="javascript:" ng-click="filter()">Filter</a></li>
|
||||
<li ng-if="padId"><a href="javascript:" ng-click="exportGpx()">Export GPX</a></li>
|
||||
<li ng-if="padId"><a href="{{padId}}/gpx?useTracks=1">Export GPX</a></li>
|
||||
<li ng-if="padId"><a href="javascript:" ng-click="showTable()">View as table</a></li>
|
||||
<li ng-if="!readonly && padId"><a href="javascript:" ng-click="editPadSettings()">Settings</a></li>
|
||||
<li><a href="javascript:" ng-click="showAbout()">About FacilMap</a></li>
|
||||
|
|
|
@ -40,8 +40,6 @@ fm.app.factory("fmMapToolbox", function($compile, fmTable, fmFilter) {
|
|||
map.importUi.openImportDialog();
|
||||
};
|
||||
|
||||
scope.exportGpx = map.gpxUi.exportGpx.bind(map.gpxUi);
|
||||
|
||||
scope.showAbout = function() {
|
||||
map.aboutUi.showAbout();
|
||||
};
|
||||
|
|
|
@ -26,7 +26,6 @@
|
|||
"ejs": "^2.5.5",
|
||||
"event-stream": "^3.3.4",
|
||||
"express": "^4.14.0",
|
||||
"file-saver": "^1.3.3",
|
||||
"filtrex": "^0.5.4",
|
||||
"jquery": "<3.0.0",
|
||||
"jquery-ui": "^1.12.1",
|
||||
|
|
|
@ -34,6 +34,10 @@ module.exports = function(Database) {
|
|||
return this._conn.model("Pad").findOne({ where: { writeId: writeId }, include: [ { model: this._conn.model("View"), as: "defaultView" } ] });
|
||||
},
|
||||
|
||||
getPadDataByAnyId(padId) {
|
||||
return this._conn.model("Pad").findOne({ where: { $or: { id: padId, writeId: padId } }, include: [ { model: this._conn.model("View"), as: "defaultView" } ] });
|
||||
},
|
||||
|
||||
createPad(data) {
|
||||
return utils.promiseAuto({
|
||||
validate: () => {
|
||||
|
|
|
@ -4,7 +4,6 @@ var domain = require("domain");
|
|||
var utils = require("./utils");
|
||||
var routing = require("./routing");
|
||||
var search = require("./search");
|
||||
var gpx = require("./gpx");
|
||||
|
||||
class Socket {
|
||||
constructor(server, database) {
|
||||
|
@ -400,15 +399,6 @@ utils.extend(SocketConnection.prototype, {
|
|||
});
|
||||
},
|
||||
|
||||
exportGpx : function(data) {
|
||||
return Promise.resolve().then(() => {
|
||||
if(this.padId == null)
|
||||
throw "No pad ID set.";
|
||||
|
||||
return gpx.exportGpx(this.database, this.padId, data.useTracks);
|
||||
});
|
||||
},
|
||||
|
||||
find: function(data) {
|
||||
return Promise.resolve().then(() => {
|
||||
if(!utils.stripObject(data, { query: "string", loadUrls: "boolean" }))
|
||||
|
|
|
@ -9,6 +9,7 @@ const webpackMiddleware = require("webpack-dev-middleware");
|
|||
|
||||
const config = require("../config");
|
||||
const database = require("./database/database");
|
||||
const gpx = require("./gpx");
|
||||
const utils = require("./utils");
|
||||
const webpackConfig = require("../frontend/webpack.config");
|
||||
|
||||
|
@ -81,6 +82,24 @@ const webserver = module.exports = {
|
|||
// If no file with this name has been found, we render a pad
|
||||
app.get("/:padId", padMiddleware);
|
||||
|
||||
app.get("/:padId/gpx", function(req, res, next) {
|
||||
utils.promiseAuto({
|
||||
padData: database.getPadDataByAnyId(req.params.padId).then((padData) => {
|
||||
if(!padData)
|
||||
throw new Error(`Map with ID ${req.params.padId} could not be found.`);
|
||||
return padData;
|
||||
}),
|
||||
gpx: (padData) => {
|
||||
return gpx.exportGpx(database, padData ? padData.id : req.params.padId, req.query.useTracks == "1");
|
||||
},
|
||||
response: (padData, gpx) => {
|
||||
res.set("Content-type", "application/gpx+xml");
|
||||
res.attachment(padData.name.replace(/[\\\/:*?"<>|]+/g, '_') + ".gpx");
|
||||
res.send(gpx);
|
||||
}
|
||||
}).catch(next);
|
||||
});
|
||||
|
||||
let server = http.createServer(app);
|
||||
return Promise.denodeify(server.listen.bind(server))(config.port, config.host).then(() => server);
|
||||
}
|
||||
|
|
|
@ -1827,10 +1827,6 @@ fbjs@^0.8.1, fbjs@^0.8.4:
|
|||
setimmediate "^1.0.5"
|
||||
ua-parser-js "^0.7.9"
|
||||
|
||||
file-saver@^1.3.3:
|
||||
version "1.3.3"
|
||||
resolved "https://registry.yarnpkg.com/file-saver/-/file-saver-1.3.3.tgz#cdd4c44d3aa264eac2f68ec165bc791c34af1232"
|
||||
|
||||
filename-regex@^2.0.0:
|
||||
version "2.0.0"
|
||||
resolved "https://registry.yarnpkg.com/filename-regex/-/filename-regex-2.0.0.tgz#996e3e80479b98b9897f15a8a58b3d084e926775"
|
||||
|
|
Ładowanie…
Reference in New Issue