Skip to content

Commit

Permalink
MMGIS 1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
tariqksoliman committed Nov 6, 2019
1 parent c556905 commit 2f40f8a
Show file tree
Hide file tree
Showing 124 changed files with 248,089 additions and 2,498 deletions.
11 changes: 5 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,19 @@
/config/Passwords.txt
/Missions_dev/
/Missions_rel/
resources/CRISM_Master
resources/Themis
/resources/CRISM_Master
/resources/Themis
/documentation
.vscode
.DS_Store
README.md
node_modules/
.env
/API/logs/
API/logs/*

/Missions/
/Missions
/db/
/config/configconfig.json
/config/db/
/scripts/ignore
sessions

#tools
1 change: 1 addition & 0 deletions API/data/test.json

Large diffs are not rendered by default.

549 changes: 549 additions & 0 deletions API/layers/Waypoints.csv

Large diffs are not rendered by default.

303 changes: 303 additions & 0 deletions API/layers/terrain.json

Large diffs are not rendered by default.

392 changes: 392 additions & 0 deletions API/layers/traverse.json

Large diffs are not rendered by default.

143 changes: 143 additions & 0 deletions API/models/geodatasets.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@

/***********************************************************
* Loading all required dependencies, libraries and packages
**********************************************************/
const Sequelize = require('sequelize');
const { sequelize } = require('../connection');
const logger = require('../logger');


const attributes = {
id: {
type: Sequelize.INTEGER,
primaryKey: true,
autoIncrement: true
},
name: {
type: Sequelize.STRING,
unique: true,
allowNull: false
},
table: {
type: Sequelize.STRING,
unique: true,
allowNull: false
},
}

const options = {
timestamps: true,
}

// setup User model and its fields.
var Geodatasets = sequelize.define('geodatasets', attributes, options )


// create all the defined tables in the specified database.
sequelize.sync()
.then(() => logger.info('The Geodatasets table has been successfully created, if one hadn\'t existed'))
.catch(error => logger.error('This error occurred' + error));

function makeNewGeodatasetTable( name, success, failure ) {

name = name.replace(/[`~!@#$%^&*()|+\-=?;:'",.<>\{\}\[\]\\\/]/gi, '');

const attributes = {
id: {
type: Sequelize.INTEGER,
primaryKey: true,
autoIncrement: true
},
properties: {
type: Sequelize.JSON,
allowNull: true,
defaultValue: {}
},
geometry_type: {
type: Sequelize.STRING,
unique: false,
allowNull: false
},
geom: {
type: Sequelize.GEOMETRY,
allowNull: true
},
}

const options = {
timestamps: false,
}


Geodatasets.findOne({ where: { name: name } })
.then((result) => {
if( result ) {
let GeodatasetTable = sequelize.define(result.dataValues.table, attributes, options)
Geodatasets.update({ updatedAt: new Date().toISOString() }, { where: { name: name }, silent: true })
.then( r => {
success({
name: result.dataValues.name,
table: result.dataValues.table,
tableObj: GeodatasetTable
})

return null;
})
.catch(error => failure({
status: 'failure',
message: 'Failed to update geodatasets'
}));
}
else {
sequelize.query( 'SELECT COUNT(*) FROM geodatasets' )
.spread((results) => {
let newTable = 'g' + (parseInt(results[0].count) + 1) + '_geodatasets';
Geodatasets.create({
name: name,
table: newTable
})
.then( (created) => {
let GeodatasetTable = sequelize.define(newTable, attributes, options)
sequelize.sync()
.then(() => {
success({
name: name,
table: newTable,
tableObj: GeodatasetTable
})
return null;
} )
.catch(error => failure({
status: 'failure',
message: 'Failed to sync'
}));

return null;
} )
.catch(error => failure({
status: 'failure',
message: 'Failed to create'
}));
return null;
} )
.catch(error => failure({
status: 'failure',
message: 'Failed to count existing geodatasets'
}));
}

return null;
} )
.catch(error => failure({
status: 'failure',
message: 'Failed to find existing geodatasets',
error: error,
name: name
}));
}

// export User model for use in other files.
module.exports = {
Geodatasets: Geodatasets,
makeNewGeodatasetTable: makeNewGeodatasetTable
};
38 changes: 38 additions & 0 deletions API/models/publishedstore.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@

/***********************************************************
* Loading all required dependencies, libraries and packages
**********************************************************/
const Sequelize = require('sequelize');
const { sequelize } = require('../connection');
const logger = require('../logger');

// setup Store model and its fields.
var PublishedStore = sequelize.define('published_stores',
{
name: {
type: Sequelize.STRING,
unique: false,
allowNull: false
},
value: {
type: Sequelize.TEXT,
allowNull: true,
defaultValue: ''
},
time: {
type: Sequelize.BIGINT,
allowNull: false
},
},
{
timestamps: false,
updatedAt: false,
});

// create all the defined tables in the specified database.
sequelize.sync()
.then(() => logger.info('Published Store table has been successfully created, if one hadn\'t existed'))
.catch(error => logger.error('This error occurred' + error));

// export User model for use in other files.
module.exports = PublishedStore;
2 changes: 1 addition & 1 deletion API/models/userfeatures.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ var UserfeaturesTEST = sequelize.define('user_features_tests', attributes, optio
// create all the defined tables in the specified database.
sequelize.sync()
.then(() => {
logger.info('user_features table has been successfully created, if one doesn\'t exist')
logger.info('User Features table has been successfully created, if one doesn\'t exist')
})
.catch(error => logger.error('This error occurred' + error));

Expand Down
3 changes: 2 additions & 1 deletion API/models/userfiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,8 @@ const makeMasterFiles = ( intents ) => {
// userResult is the user instance

if (created) {
console.log( 'Created a new Lead file!' )
// created will be true if a new user was created
console.log( 'Created Lead ' + intent + ' file!')
}
makeMasterFile( i + 1, Table );
return null;
Expand Down
25 changes: 22 additions & 3 deletions API/routes/configs.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@
**********************************************************/
const express = require('express');
const router = express.Router();
const crypto = require('crypto');
const bcrypt = require('bcryptjs');
const buf = crypto.randomBytes(128);
const execFile = require("child_process").execFile;

const logger = require('../logger');
const Config = require('../models/config');
const config_template = require('../templates/config_template');

const fs = require('fs');

function get(req, res, next, cb ) {
Config.findAll( {
where: {
Expand Down Expand Up @@ -88,6 +87,13 @@ function add(req, res, next, cb) {
configTemplate = req.body.config || configTemplate;
configTemplate.msv.mission = req.body.mission;

if( req.body.mission !== req.body.mission.replace(/[`~!@#$%^&*()|+\-=?;:'",.<>\{\}\[\]\\\/]/gi, '') &&
req.body.mission.length === 0 &&
!isNaN(req.body.mission[0]) ) {
res.send( { status: 'failure', message: 'Bad mission name.' } );
return;
}

let newConfig = {
mission: req.body.mission,
config: configTemplate,
Expand All @@ -105,6 +111,19 @@ function add(req, res, next, cb) {
if( !mission ) {
Config.create(newConfig)
.then(created => {
let dir = './Missions/' + created.mission
if (!fs.existsSync(dir)){
fs.mkdirSync(dir);
let dir2 = dir + '/Layers'
if (!fs.existsSync(dir2)){
fs.mkdirSync(dir2);
}
let dir3 = dir + '/Data'
if (!fs.existsSync(dir3)){
fs.mkdirSync(dir3);
}
}

if( cb )
cb( { status: 'success', mission: created.mission, version: created.version } );
else
Expand Down
32 changes: 24 additions & 8 deletions API/routes/draw.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const express = require('express');
const logger = require('../logger');
const database = require('../database');
const Sequelize = require('sequelize');
const uuidv4 = require('uuid/v4');
const fhistories = require('../models/filehistories')
const Filehistories = fhistories.Filehistories
const FilehistoriesTEST = fhistories.FilehistoriesTEST
Expand Down Expand Up @@ -255,6 +256,7 @@ const clipUnder = function(req, res, newFeature, time, successCallback, failureC
history = history.join(',');
history = history || 'NULL';

//Continually clip the added feature with the other features of the file
let q = [
"WITH RECURSIVE clipper (n, clippedgeom) AS (",
"SELECT 0 n, ST_MakeValid(ST_GeomFromGeoJSON(:geom)) clippedgeom",
Expand Down Expand Up @@ -307,12 +309,17 @@ const clipUnder = function(req, res, newFeature, time, successCallback, failureC
return null;
}
let clippedFeature = Object.assign({}, newFeature );
clippedFeature.properties = JSON.parse( newFeature.properties );
clippedFeature.geom = JSON.parse(results[i].geom);
clippedFeature.geom.crs = { type: 'name', properties: { name: 'EPSG:4326' } };

clippedFeature.properties.uuid = uuidv4();
clippedFeature.properties = JSON.stringify( clippedFeature.properties )


Features.create( clippedFeature )
.then( (created) => {
newIds.push(created.id)
//now update the
addLoop( i + 1 )
return null;
} )
Expand All @@ -327,7 +334,6 @@ const clipUnder = function(req, res, newFeature, time, successCallback, failureC
return null;
} )
.catch( err => {
console.log( 'A', err )
failureCallback();
} );

Expand Down Expand Up @@ -437,6 +443,9 @@ const add = function( req, res, successCallback, failureCallback1, failureCallba
} )
}
else {
newFeature.properties = JSON.parse( newFeature.properties )
newFeature.properties.uuid = uuidv4();
newFeature.properties = JSON.stringify( newFeature.properties )
// Insert new feature into the feature table
Features.create( newFeature )
.then( (created) => {
Expand Down Expand Up @@ -475,7 +484,6 @@ const add = function( req, res, successCallback, failureCallback1, failureCallba
return null;
} )
.catch( err => {
console.log( err );
if( typeof failureCallback2 === 'function' )
failureCallback2();

Expand Down Expand Up @@ -566,7 +574,6 @@ const edit = function( req, res, successCallback, failureCallback ) {
} )
.then( feature => {
if( !feature && !req.body.addIfNotFound ) {
console.log( 'No feature' )
failureCallback()
}
else {
Expand All @@ -586,22 +593,31 @@ const edit = function( req, res, successCallback, failureCallback ) {
else {
newAttributes.geom = JSON.parse( feature.dataValues.geojson_geom );
}
if( req.body.hasOwnProperty('reassignUUID') && req.body.reassignUUID == 'true' ) {
newAttributes.properties = JSON.parse( newAttributes.properties )
newAttributes.properties.uuid = uuidv4();
newAttributes.properties = JSON.stringify( newAttributes.properties )
}

newAttributes.geom.crs = { type: 'name', properties: { name: 'EPSG:4326' } };

Features.create( newAttributes )
.then( (created) => {
let createdId = created.id;
let createdUUID = JSON.parse(created.properties).uuid
let createdIntent = created.intent

if( req.body.to_history ) {
pushToHistory( Histories, req.body.file_id, created.id, req.body.feature_id, time, null, 1,
() => {
successCallback()
successCallback(createdId, createdUUID, createdIntent)
},
() => {
failureCallback()
} )
}
else {
successCallback(created.id)
successCallback(createdId, createdUUID, createdIntent)
}
return null;
} )
Expand All @@ -625,11 +641,11 @@ const edit = function( req, res, successCallback, failureCallback ) {

router.post('/edit', function(req, res) {
edit( req, res,
( createdId, createdIntent) => {
( createdId, createdUUID, createdIntent ) => {
res.send( {
status: 'success',
message: 'Successfully edited feature.',
body: { id: createdId, intent: createdIntent }
body: { id: createdId, uuid: createdUUID, intent: createdIntent }
} );
},
() => {
Expand Down
Loading

0 comments on commit 2f40f8a

Please sign in to comment.