Skip to content

Commit

Permalink
MMGIS-1.3.3
Browse files Browse the repository at this point in the history
  • Loading branch information
tariqksoliman committed Aug 7, 2020
1 parent 9d301f1 commit cdae339
Show file tree
Hide file tree
Showing 15 changed files with 5,767 additions and 4,665 deletions.
30 changes: 19 additions & 11 deletions API/Backend/Draw/routes/draw.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@ const pushToHistory = (
order: [["history_id", "DESC"]],
})
.then((lastHistory) => {
let maxHistoryId = -Infinity;
let bestI = -1;
if (lastHistory && lastHistory.length > 0) {
return {
historyIndex: lastHistory[0].history_id + 1,
Expand Down Expand Up @@ -185,8 +183,6 @@ const clipOver = function (
order: [["history_id", "DESC"]],
})
.then((lastHistory) => {
let maxHistoryId = -Infinity;
let bestI = -1;
if (lastHistory && lastHistory.length > 0) {
return {
historyIndex: lastHistory[0].history_id + 1,
Expand Down Expand Up @@ -315,8 +311,6 @@ const clipUnder = function (
order: [["history_id", "DESC"]],
})
.then((lastHistory) => {
let maxHistoryId = -Infinity;
let bestI = -1;
if (lastHistory && lastHistory.length > 0) {
return {
historyIndex: lastHistory[0].history_id + 1,
Expand Down Expand Up @@ -547,6 +541,12 @@ const add = function (
id = req.body.bulk_ids;
id.push(created.id);
}

let createdUUID = null;
try {
createdUUID = JSON.parse(created.properties).uuid;
} catch (e) {}

if (req.body.clip === "over") {
clipOver(
req,
Expand All @@ -556,7 +556,11 @@ const add = function (
time,
() => {
if (typeof successCallback === "function")
successCallback(created.id, created.intent);
successCallback(
created.id,
created.intent,
createdUUID
);
},
(err) => {
if (typeof failureCallback2 === "function")
Expand All @@ -574,7 +578,11 @@ const add = function (
0,
() => {
if (typeof successCallback === "function")
successCallback(created.id, created.intent);
successCallback(
created.id,
created.intent,
createdUUID
);
},
(err) => {
if (typeof failureCallback2 === "function")
Expand All @@ -584,7 +592,7 @@ const add = function (
}
} else {
if (typeof successCallback === "function")
successCallback(created.id, created.intent);
successCallback(created.id, created.intent, createdUUID);
}
return null;
})
Expand All @@ -602,12 +610,12 @@ router.post("/add", function (req, res, next) {
add(
req,
res,
(id, intent) => {
(id, intent, uuid) => {
logger("info", "Successfully added a new feature.", req.originalUrl, req);
res.send({
status: "success",
message: "Successfully added a new feature.",
body: { id: id, intent: intent },
body: { id: id, intent: intent, uuid: uuid, tag: req.body.tag },
});
},
(err) => {
Expand Down
18 changes: 8 additions & 10 deletions API/Backend/Draw/routes/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -775,11 +775,11 @@ const compile = function (req, res, callback) {
" " +
"AND a.id != b.id" +
" " +
"AND ((ST_OVERLAPS(a.geom, b.geom)" +
"AND ((ST_OVERLAPS(ST_BUFFER(a.geom, -0.000005, 'join=mitre'), b.geom)" +
" " +
"AND NOT ST_Touches(a.geom, b.geom))" +
" " +
"OR ST_CROSSES(a.geom, b.geom))" +
"OR ST_CROSSES(ST_BUFFER(a.geom, -0.000005, 'join=mitre'), b.geom))" +
" " +
"UNION ALL" +
" " +
Expand Down Expand Up @@ -1493,19 +1493,17 @@ router.post("/publish", function (req, res, next) {
failureCallback
) {
Table.findAll({
limit: 1,
where: {
file_id: file_id,
},
order: [["history_id", "DESC"]],
})
.then((histories) => {
let maxHistoryId = -Infinity;
if (histories && histories.length > 0) {
for (let i = 0; i < histories.length; i++) {
maxHistoryId = Math.max(histories[i].history_id, maxHistoryId);
}
.then((lastHistory) => {
if (lastHistory && lastHistory.length > 0) {
return {
historyIndex: maxHistoryId + 1,
history: histories[maxHistoryId].history,
historyIndex: lastHistory[0].history_id + 1,
history: lastHistory[0].history,
};
} else return { historyIndex: 0, history: [] };
})
Expand Down
174 changes: 87 additions & 87 deletions API/Backend/Shortener/routes/shortener.js
Original file line number Diff line number Diff line change
@@ -1,87 +1,87 @@
/***********************************************************
* JavaScript syntax format: ES5/ES6 - ECMAScript 2015
* Loading all required dependencies, libraries and packages
**********************************************************/
const express = require("express");
const router = express.Router();

const logger = require("../../../logger");
const us = require("../models/url_shortener");
const UrlShortener = us.UrlShortener;
const UrlShortener_s = us.sequelize;

/**
* Creates and saves a shortened url and returns it
* @param url
* @param text *optional*
*/
router.post("/shorten", function(req, res, next) {
var loop = 0;
var maxLoop = 20;

shorten();
function shorten() {
var short = Math.random()
.toString(36)
.substr(2, 4);

let newUrlShortened = {
full: encodeURIComponent(req.body.url),
short: short,
creator: req.user
};

UrlShortener.create(newUrlShortened)
.then(created => {
res.send({
status: "success",
message: "Successfully shortened URL.",
body: { url: short }
});
})
.catch(err => {
if (
loop < maxLoop &&
err.hasOwnProperty("errors") &&
err.errors[0] &&
err.errors[0].hasOwnProperty("path") &&
err.errors[0].hasOwnProperty("type")
) {
loop++;
shorten();
} else {
logger("error", "Failed to shorten URL.", req.originalUrl, req, err);
res.send({
status: "failure",
message: "Failed to shorten URL.",
body: {}
});
}
});
}
});

router.post("/expand", function(req, res, next) {
UrlShortener.findOne({
where: {
short: req.body.short
}
}).then(url => {
if (!url) {
logger("error", "Failed to find short URL.", req.originalUrl, req);
res.send({
status: "failure",
message: "Failure to find URL.",
body: {}
});
} else {
res.send({
status: "success",
message: "Successfully shortened URL.",
body: { url: decodeURIComponent(url.full) }
});
}
});
});

module.exports = router;
/***********************************************************
* JavaScript syntax format: ES5/ES6 - ECMAScript 2015
* Loading all required dependencies, libraries and packages
**********************************************************/
const express = require("express");
const router = express.Router();

const logger = require("../../../logger");
const us = require("../models/url_shortener");
const UrlShortener = us.UrlShortener;
const UrlShortener_s = us.sequelize;

/**
* Creates and saves a shortened url and returns it
* @param url
* @param text *optional*
*/
router.post("/shorten", function (req, res, next) {
var loop = 0;
var maxLoop = 20;

shorten();
function shorten() {
var short = Math.random()
.toString(36)
.substr(2, 5 + loop);

let newUrlShortened = {
full: encodeURIComponent(req.body.url),
short: short,
creator: req.user,
};

UrlShortener.create(newUrlShortened)
.then((created) => {
res.send({
status: "success",
message: "Successfully shortened URL.",
body: { url: short },
});
})
.catch((err) => {
if (
loop < maxLoop &&
err.hasOwnProperty("errors") &&
err.errors[0] &&
err.errors[0].hasOwnProperty("path") &&
err.errors[0].hasOwnProperty("type")
) {
loop++;
shorten();
} else {
logger("error", "Failed to shorten URL.", req.originalUrl, req, err);
res.send({
status: "failure",
message: "Failed to shorten URL.",
body: {},
});
}
});
}
});

router.post("/expand", function (req, res, next) {
UrlShortener.findOne({
where: {
short: req.body.short,
},
}).then((url) => {
if (!url) {
logger("error", "Failed to find short URL.", req.originalUrl, req);
res.send({
status: "failure",
message: "Failure to find URL.",
body: {},
});
} else {
res.send({
status: "success",
message: "Successfully shortened URL.",
body: { url: decodeURIComponent(url.full) },
});
}
});
});

module.exports = router;
Loading

0 comments on commit cdae339

Please sign in to comment.