Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

gexf file cache

  • Loading branch information...
commit 648f849a91d4bf6b318b4cc4fe88b92b6ee89b2d 1 parent 5ca69e6
@janmarek authored
Showing with 40 additions and 19 deletions.
  1. +2 −1  .gitignore
  2. +38 −18 controllers/ExportController.js
View
3  .gitignore
@@ -1,3 +1,4 @@
node_modules
.project
-.settings
+.settings
+tmp
View
56 controllers/ExportController.js
@@ -1,7 +1,8 @@
// imports
var controllerHelpers = require('../app/controllerHelpers'),
xmlFactory = require('../app/XmlBuilderFactory'),
- request = require('request');
+ request = require('request'),
+ fs = require('fs');
// constructor
function ExportController(gexfModel) {
@@ -22,26 +23,45 @@ ExportController.prototype = {
*/
defaultAction: function(req, res)
{
+ res.header('Content-Type', 'application/xml');
var self = this;
- this.model.getEdges(function (edges) {
- self.model.getNodes(function (nodes) {
- var data = [
- {name: 'graph', attrs: {mode: "static", defaultedgetype: "undirected"}, children: [
- {name: 'nodes', children: nodes},
- {name: 'edges', children: edges},
- ]}
- ];
-
- var doc = xmlFactory.create('gexf', data, {
- xmlns: "http://www.gexf.net/1.2draft",
- 'xmlns:viz': "http://www.gexf.net/1.2draft/viz",
- version: "1.2"
+
+ var cacheFile = __dirname + '/../tmp/cache.gexf';
+ fs.readFile(cacheFile, function (err, content) {
+ if (err) {
+ self.model.getEdges(function (edges) {
+ self.model.getNodes(function (nodes) {
+ var data = [
+ {name: 'graph', attrs: {mode: "static", defaultedgetype: "undirected"}, children: [
+ {name: 'nodes', children: nodes},
+ {name: 'edges', children: edges},
+ ]}
+ ];
+
+ var doc = xmlFactory.create('gexf', data, {
+ xmlns: "http://www.gexf.net/1.2draft",
+ 'xmlns:viz': "http://www.gexf.net/1.2draft/viz",
+ version: "1.2"
+ });
+
+
+ var xmlstr = doc.toString({ pretty: true });
+ fs.writeFile(cacheFile, xmlstr, function (err) {
+ if (err) {
+ res.end('<err>unable to write cache file</err>');
+ return;
+ }
+ res.end(xmlstr);
+ })
+ });
});
+ } else {
+ res.end(content);
+ }
+ })
- res.header('Content-Type', 'application/xml');
- res.end(doc.toString({ pretty: true }));
- });
- });
+
+
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.