Commit afbdc535 authored by Fintan Mc Gee's avatar Fintan Mc Gee

Added functionality for front end data changes to be replciatied on the...

Added functionality for front end data changes to be replciatied on the server, as well as ficeing issues with layers not saving correctly
parent ed69013d
......@@ -522,6 +522,14 @@ var updateNodePositions_cb = function (req, res) {
res.json({updatedNodeCount: updatedNodeCount});
};
var updateNodeData_cb = function (req, res) {
sLog.debug_log("***********updatePositions" + JSON.stringify(req.body) + "\n\n");
sLog.debug_log("***********graphDB.userGraphs" + JSON.stringify(graphDB.userGraphs) + "\n\n");
var updatedNodeCount = graphObj.userGraphs[req.user.username].getLayerByName(req.body.nodeLayerName).setNodeProperty(req.body.nodeUid,req.body.nodePropName,req.body.nodePropValue);
res.json({msg:"Updated node properety completed"});
};
/**************************************
* updateLayer
* Functionality: Used to create and update graphs on server
......@@ -569,6 +577,42 @@ var updateLayer_cb = function (req, res) {
res.json({msg:"layer operation completed"});
};
/**************************************
* updateAspect
* Functionality: Used to create and update graphs on server
* To keep server instance in sync with front end instance
*
* Created By : Fintan McGee (LIST)
* Date: 19/07/2017
*******************************/
var updateAspect_cb = function (req, res) {
sLog.debug_log("***********updateAspect" + JSON.stringify(req.body) + "\n\n");
sLog.debug_log("***********graphDB.userGraphs" + JSON.stringify(graphDB.userGraphs) + "\n\n");
//var updatedNodeCount = graphObj.userGraphs[req.user.username].updatePositions(req.body.positionMap);
graphObj.userGraphs[req.user.username].mapAspectsToLayerNames(); // ensure aspects (especially Master) are up to date with layers and are using strings
if(req.body.operationType === "createAspect") {
graphObj.userGraphs[req.user.username].createAspect(req.body.aspectName, req.body.layerNames);
}else if(req.body.operationType === "deleteAspect") {
graphObj.userGraphs[req.user.username].deleteAspect(req.body.aspectName);
}else if(req.body.operationType === "addLayersToAspect") {
graphObj.userGraphs[req.user.username].addLayersToAspect(req.body.aspectName, req.body.layerNames);
}else if(req.body.operationType === "removeLayersFromAspect") {
graphObj.userGraphs[req.user.username].removeLayersFromAspect(req.body.aspectName, req.body.layerNames);
}
/*else if(req.body.operationType === "copyNodeToLayer") {
//(targetLayerName,masterProjectionNodeTypes, masterProjectionEdgeTypes, projectionEdgeType)
var node= graphObj.userGraphs[req.user.username].node[req.body.nodeId]
graphObj.userGraphs[req.user.username].getLayerByName(req.body.layerName).copyNodeToLayer(node);
}*/
else {
sLog.log("***********updateLayer: Unknow operation for server updateAspect" + "\n\n");
}
res.json({msg:"Apsect operation completed"});
};
var saveUserGraph_cb = function (req, res) {
sLog.debug_log("***********saveUserGraph" + JSON.stringify(req.body) + "\n\n");
......@@ -763,7 +807,10 @@ simple_serve.post('/getSeriation', blizaarSystem.ensureAuthenticated, getSeriati
simple_serve.post('/doLayout', blizaarSystem.ensureAuthenticated, doLayout_cb);
simple_serve.post('/doGraphClustering', blizaarSystem.ensureAuthenticated, doGraphClustering_cb);
simple_serve.post('/updateNodePositions', blizaarSystem.ensureAuthenticated, updateNodePositions_cb );
simple_serve.post('/updateNodeData', blizaarSystem.ensureAuthenticated, updateNodeData_cb );
simple_serve.post('/updateLayer', blizaarSystem.ensureAuthenticated, updateLayer_cb );
simple_serve.post('/updateAspect', blizaarSystem.ensureAuthenticated, updateAspect_cb);
simple_serve.post('/getEdgeSet', blizaarSystem.ensureAuthenticated, getEdgeSet_cb );
simple_serve.post('/removeTempTagLabel', blizaarSystem.ensureAuthenticated, removeTempTagLabel_cb);
......
......@@ -35,7 +35,7 @@ angular.module('blizaarModule.controllers')
* Created By : Fintan McGee (LIST)
* Date: 25/02/2019
*******************************/
$scope.initializeAspects = function(dataSource) {
$scope.initializeAspects = function() {
$scope.model.availableAspects =[]
if(multiLayerGraphService.getGraph().aspects) {
for (var aspectName in multiLayerGraphService.getGraph().aspects) {
......@@ -47,7 +47,7 @@ angular.module('blizaarModule.controllers')
};
$scope.updateAspects = function(dataSource) {
$scope.updateAspects = function() {
$scope.model.availableAspects =[]
for(var aspectName in multiLayerGraphService.getGraph().aspects) {
$scope.model.availableAspects.push(aspectName);
......@@ -106,4 +106,8 @@ angular.module('blizaarModule.controllers')
$scope.populateLayerList();
}
});
$scope.$on('loadedUserGraph', function() {
$scope.initializeAspects();
});
}]);
\ No newline at end of file
......@@ -109,7 +109,8 @@ angular.module('blizaarModule.controllers')
$("#selectSource").val($scope.model.selectedSource)
});
graphLayeringService.doLayeringByGraphType(dataSource,false); // false is to prevent a new layout
//graphLayeringService.doLayeringByGraphType(dataSource,false); // false is to prevent a new layout
// no layering as layering should be as saved
graphFileAndRenderingService.renderUserServerGraph();
});
};
......
......@@ -3307,12 +3307,12 @@ var MultiLayerGraph = function (nodes, links, layerName) {
g.buildNodeLookUp();
g.buildLinkLookUp();
if(g.name === "MasterLayer") {
g.mapAspectsToLayerNames(); // default as used by the server, overwrritter when rtpepare graph is caleld at froit end
g.mapAspectsToLayerNames(); // default as used by the server, overwrritter when rtpepare graph is called at front end
}
/**************************************
* initAspects()
* Functionality: Initaliseres the aspece with the refercens to the input aspectaspect objects
* Functionality: Initalise the aspects with the refercens to the input aspectaspect objects
*
* @param a JSON object containing the asapects names of keys, and and array of layer names for each aspect
* Created By : Fintan McGee (LIST)
......
......@@ -870,6 +870,40 @@ angular.module('blizaarModule.services')
return err.message;
});
},
/**************************************
* updateAServer NodeData
* Functionality: Updates the vlue of the specified node for the specified property in the specified layer
*
* Created By : Fintan McGee (LIST)
* Date: 03/03/2016
*******************************/
updateNodeDataToServer : function(nodeLayerName,nodeUid,nodePropName,nodePropValue) {
// sending position map to server
return $http({
method: 'post',
url: '/updateNodeData', // url where to get data.
headers: { 'Content-Type': 'application/json' }, // set the headers so angular passing info as form data (not request payload)
data: { graphName: self.currentGraphName,
nodeLayerName:nodeLayerName,
nodeUid: nodeUid,
nodePropName:nodePropName,
nodePropValue: nodePropValue
}
})// Success case
.then(function (response) {
console.log("Updated position of " + response.data.updatedNodeCount + " nodes on the server");
},
// Error handling
function (err) {
alert(err.data);
console.log("updatePositionToServer" + err);
return err.message;
});
},
/**************************************
* saveGraphOnServer
* Functionality: Tells the server the save the graph so it can be retrieved at a later date.
......@@ -1015,8 +1049,17 @@ angular.module('blizaarModule.services')
response.data.graph.layers.forEach(function (layer) {
multiLayerGraphService.getGraph().createLayer(layer.nodes, layer.links, layer.name).prepareGraph();
});
//multiLayerGraphService.getGraph().buildCompleteInterLayerEdgeMap();
}
if( response.data.graph.aspects) {
for(var aspectName in response.data.graph.aspects) {
if( aspectName !== "Master") {
multiLayerGraphService.getGraph().createAspect(aspectName, response.data.graph.aspects[aspectName]);
}
}
}
self.populateGraphIcons();
multiLayerGraphService.getGraph().buildCompleteInterLayerEdgeMap();
self.timeStamp = new Date().toISOString();
......@@ -1068,6 +1111,38 @@ angular.module('blizaarModule.services')
return err.message;
});
},
/**************************************
* updateAspectOnServer
* Functionality: Used to create and update graphs on server
* Front end interactions are replicate in the server graph instance
*
* Created By : Fintan McGee (LIST)
* Date: 20/09/2017
*******************************/
updateAspectOnServer : function(operationType,aspectName,layerNames) {
return $http({
method: 'post',
url: '/updateAspect', // url where to get data.
headers: { 'Content-Type': 'application/json' }, // set the headers so angular passing info as form data (not request payload)
data: {
operationType:operationType,
aspectName:aspectName,
layerNames:layerNames || []
}
})// Success case
.then(function () {
console.log("Updated Aspect successfully ");
return true;
},
// Error handling
function (err) {
alert(err.data);
console.log("updateApect on server error:" + err);
return err.message;
});
},
/**************************************
* buildNodeSetQueryGraph
* Functionality: Fetches the node set specified by name from the server,
......
......@@ -164,9 +164,11 @@ angular.module('blizaarModule.services')
multiLayerGraphService.getLayerNames();
if(multiLayerGraphService.getGraph().aspects.hasOwnProperty("EntityType")) {
multiLayerGraphService.getGraph().addLayersToAspect("EntityType", ["Proteins", "Genes", "Metabolites", "CATALYSIS","DataItems","Experiments"])
multiLayerGraphService.getGraph().addLayersToAspect("EntityType", ["Proteins", "Genes", "Metabolites", "CATALYSIS","DataItems","Experiments"]);
dataService.updateAspectOnServer("addLayersToAspect","EntityType", ["Proteins", "Genes", "Metabolites", "CATALYSIS","DataItems","Experiments"]);
}else {
multiLayerGraphService.getGraph().createAspect("EntityType",["Proteins", "Genes", "Metabolites", "CATALYSIS","DataItems","Experiments"])
multiLayerGraphService.getGraph().createAspect("EntityType",["Proteins", "Genes", "Metabolites", "CATALYSIS","DataItems","Experiments"]);
dataService.updateAspectOnServer("createAspect","EntityType",["Proteins", "Genes", "Metabolites", "CATALYSIS","DataItems","Experiments"]);
}
......@@ -370,6 +372,8 @@ angular.module('blizaarModule.services')
multiLayerGraphService.getGraph().node[n.uid].type = "resource";
multiLayerGraphService.getGraph().node[n.uid].label = "resource";
multiLayerGraphService.getGraph().node[n.uid].colorCategory = "resource";
dataService.updateNodeDataToServer("documents",n.uid,"type","resource");
dataService.updateNodeDataToServer("MasterLayer",n.uid,"type","resource")
});
if(!multiLayerGraphService.getLayerByName("locations")) {
......@@ -409,9 +413,11 @@ angular.module('blizaarModule.services')
// storing layer types as an entitiy
if(multiLayerGraphService.getGraph().aspects.hasOwnProperty("EntityType")) {
multiLayerGraphService.getGraph().addLayersToAspect("EntityType", ["people", "organizations", "documents", "locations"])
multiLayerGraphService.getGraph().addLayersToAspect("EntityType", ["people", "organizations", "documents", "locations"]);
dataService.updateAspectOnServer("addLayersToAspect","EntityType", ["people", "organizations", "documents", "locations"]);
}else {
multiLayerGraphService.getGraph().createAspect("EntityType", ["people", "organizations", "documents", "locations"])
multiLayerGraphService.getGraph().createAspect("EntityType", ["people", "organizations", "documents", "locations"]);
dataService.updateAspectOnServer("createAspect","EntityType", ["people", "organizations", "documents", "locations"]);
}
//multiLayerGraphService.getGraph().cloneLayer("MasterGraph")
......@@ -653,8 +659,10 @@ angular.module('blizaarModule.services')
// dataService.updateLayerOnServer("addLayerNodesAndLinksByUid", targetlayerName,null,null,nodeUids,edgeUids);
if(multiLayerGraphService.getGraph().aspects.hasOwnProperty("temporal")) {
multiLayerGraphService.getGraph().addLayersToAspect("temporal", layerNames);
dataService.updateAspectOnServer("addLayersToAspect","temporal", layerNames);
} else {
multiLayerGraphService.getGraph().createAspect("temporal",layerNames);
dataService.updateAspectOnServer("createAspect","temporal", layerNames);
}
layerNames.forEach(function(temporalLayer){
......@@ -764,6 +772,8 @@ angular.module('blizaarModule.services')
if(multiLayerGraphService.getGraph().aspects.hasOwnProperty("temporal")) {
multiLayerGraphService.getGraph().deleteAspect("temporal");
dataService.updateAspectOnServer("deleteAspect","temporal");
}
var localLayers = {};
......@@ -813,6 +823,7 @@ angular.module('blizaarModule.services')
// dataService.updateLayerOnServer("addLayerNodesAndLinksByUid", targetlayerName,null,null,nodeUids,edgeUids);
// else {
multiLayerGraphService.getGraph().createAspect("temporal",layerNames);
dataService.updateAspectOnServer("createAspect","temporal",layerNames);
//}
layerNames.forEach(function(temporalLayer){
......@@ -858,9 +869,9 @@ angular.module('blizaarModule.services')
return temporalData;
},
getDHTemporalLayeringData: function() {
if(!this._values.temporalData || !this._values.temporalData.length) {
// if(!this._values.temporalData || !this._values.temporalData.length) {
this.setDHTemporalLayeringData();
}
//}
return this._values.temporalData;
}
};
......
......@@ -1852,6 +1852,12 @@ var MultiLayerGraph = function (nodes, links, layerName) {
console.log("Error:addLayerNodesAndLinksByUid was called on layer other than master");
return;
}
if(!g.node) {
g.buildNodeLookUp();
}
if(!g.link) {
g.buildLinkLookUp();
}
var targetLayer = g.getLayerByName(targetLayerName);
if (targetLayer) {
......@@ -2984,6 +2990,13 @@ var MultiLayerGraph = function (nodes, links, layerName) {
layerNames = [layerNames];
}
var usingReferences = false;
if(g.aspects["Master"].length) {
if (typeof(g.aspects["Master"][0]) === "object") {
usingReferences = true;
}
}
layerNames.forEach(function(layerName) {
var l = g.getLayerByName(layerName)
......@@ -2992,7 +3005,10 @@ var MultiLayerGraph = function (nodes, links, layerName) {
// if (typeof(g.aspects["Master"][0]) === "object") {
// check to make sure the layer is not alread in the aspect
if (!g.aspects[aspectName].find( function (layer) {
return layerName === layer.name;
if(!usingReferences) {
return layerName === layer;
}
return layerName === layer.name;
}) ){
g.aspects[aspectName].push(l);
console.log("Added layer " + layerName + " to aspect " + aspectName)
......@@ -3140,13 +3156,18 @@ var MultiLayerGraph = function (nodes, links, layerName) {
for (var aspectName in g.aspects) {
aspectsByRef[aspectName] = [];
g.aspects[aspectName].forEach (function(layerName){
var layerRef = g.layers.find(function(layer) {
if(layer.name === layerName) {
return true;
}
return false;
});
aspectsByRef[aspectName].push(layerRef);
var layerRef = null;
if((typeof(layerName) === "string")) {
layerRef = g.layers.find(function (layer) {
if (layer.name === layerName) {
return true;
}
return false;
});
aspectsByRef[aspectName].push(layerRef);
} else {
layerRef = layerName; // aspects were already references
}
});
}
g.aspects["Master"] = g.layers ;
......@@ -3164,13 +3185,22 @@ var MultiLayerGraph = function (nodes, links, layerName) {
for (var aspectName in g.aspects) {
aspectsByName[aspectName] = [];
g.aspects[aspectName].forEach (function(layer){
aspectsByName[aspectName].push(layer.name);
if((typeof(layer) === "string")) {
// in case layer names are already being used
aspectsByName[aspectName].push(layer);
} else {
aspectsByName[aspectName].push(layer.name);
}
});
}
g.aspects = aspectsByName;
g.aspects["Master"] = [];
g.layers.forEach(function(layer) {
g.aspects["Master"].push(layer.name);
if((typeof(layer) === "string")) {
g.aspects["Master"].push(layer);
} else {
g.aspects["Master"].push(layer.name);
}
});
}
......@@ -3223,7 +3253,7 @@ var MultiLayerGraph = function (nodes, links, layerName) {
usingReferences = false;
}
}
return isUsingReferences
return isUsingReferences;
}
// returns true if the specified property should be found on the layer itslef
......@@ -3422,7 +3452,45 @@ var MultiLayerGraph = function (nodes, links, layerName) {
return jsonVersion;
}
};
g.getSerialisableVersion = function() {
var sVersion = {};
sVersion.nodes = g.nodes;
sVersion.links = g.links;
sVersion.name = g.name
sVersion.master = "MasterLayer"
sVersion.layers = [];
g.layers.forEach(function(layer){
sVersion.layers.push(layer.getSerialisableVersion());
});
var aspectsByName = {};
for (var aspectName in g.aspects) {
aspectsByName[aspectName] = [];
g.aspects[aspectName].forEach (function(layer){
if((typeof(layer) === "string")) {
aspectsByName[aspectName].push(layer);
} else {
aspectsByName[aspectName].push(layer.name);
}
});
}
sVersion.aspects = aspectsByName;
sVersion.aspects["Master"] = [];
g.layers.forEach(function(layer) {
sVersion.aspects["Master"].push(layer.name);
});
return sVersion;
};
return g;
......
......@@ -365,7 +365,9 @@ function saveGraph(graph, graphName, graphSource, username, res) {
// we do not put gtrpah sourc e in the quesry as we may be loadeing a cached graph without knowing it's source
var currentDate = Date.now();
graph.clearLookups();
var data = { username : username, graphName : graphName, graphSource:graphSource,dateSaved: currentDate, graph : graph };
var serialGraph = graph.getSerialisableVersion();
var data = { username : username, graphName : graphName, graphSource:graphSource,dateSaved: currentDate, graph : serialGraph };
GraphCache.findOneAndUpdate(query, data, {upsert:true},function (err) {
if (err) {
sLog.log("Error saving graph ","system.js",err);
......@@ -427,6 +429,13 @@ function loadGraph(graphName, username, res) {
userGraphs[username].createLayer(layer.nodes, layer.links, layer.name)
});
}
if( graphDoc.graph.aspects) {
for(var aspectName in graphDoc.graph.aspects) {
if( aspectName !== "Master") {
userGraphs[username].createAspect(aspectName, graphDoc.graph.aspects[aspectName]);
}
}
}
res.json({graph: graphDoc.graph,
graphSource: graphDoc.graphSource,
graphDoc: graphDoc.username});
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment