Skip to content

Commit

Permalink
FEATURE: Freemind representation of a viewpoint.
Browse files Browse the repository at this point in the history
Part of feature #3.
  • Loading branch information
benel committed Apr 30, 2014
1 parent fe2d55e commit 74b3694
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 177 deletions.
29 changes: 29 additions & 0 deletions lib/hypertopic.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ exports.Viewpoint = function(o) {
}
}

var util = require("lib/util");

this.addRow = function(key, value) {
var subject = key[key.length-1];
var predicate = Object.keys(value)[0];
Expand Down Expand Up @@ -79,6 +81,33 @@ exports.Viewpoint = function(o) {
send("</ul>");
send("</section>");
}

this.sendFreemindNode = function(id) {
var node = this.data.topics[id];
send('<node TEXT="' + util.xmlencode(node.name)
+ '" ID="' + id + '">');
for each (var child in node.narrower) {
this.sendFreemindNode(child.id);
}
send('</node>');
}

this.sendFreemind = function() {
start({headers:{
"Content-Type": "application/x-freemind",
"Content-Disposition": "attachment; filename="
+ this.data.viewpoint_name.replace(/[ ,]/g, "_") + ".mm;"
}});
send('<map version="1.0.0">');
send('<!-- To be opened with http://freemind.sourceforge.net/ -->');
send('<node TEXT="' + util.xmlencode(this.data.viewpoint_name)
+ '" ID="' + this.data._id + '">');
for each (var upper in this.data.upper) {
this.sendFreemindNode(upper.id);
}
send('</node>');
send('</map>');
}
}

exports.Item = function() {
Expand Down
25 changes: 0 additions & 25 deletions lib/utf8.js

This file was deleted.

38 changes: 11 additions & 27 deletions lib/util.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,3 @@
exports.normalize = function(obj)
{
if(!obj.rows) return obj;
var rows = obj.rows;
var result = {};
for(var i=0; i < rows.length; i++)
{
var r = rows[i];
var keys = r.key;
var current = result;
for(var k=0; k < keys.length; k++)
{
if(!current[keys[k]])
current[keys[k]] = {};
current = current[keys[k]];
}
var value = r.value;
for(var attribute in value)
{
if(!current[attribute])
current[attribute] = [];
current[attribute].push(value[attribute]);
}
}
return result;
}

exports.sendView = function() {
send('{"rows":[');
var row = getRow();
Expand All @@ -35,3 +8,14 @@ exports.sendView = function() {
}
send(']}');
}

exports.xmlencode = function(data) {
switch (typeof data) {
case "object":
data = data[0];
case "string":
data = data.replace(/\&/g,'&'+'amp;').replace(/</g,'&'+'lt;');
}
return data;
}

38 changes: 0 additions & 38 deletions lists/freemind.js

This file was deleted.

8 changes: 3 additions & 5 deletions lists/topicV1.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
function(head, req) {
var util = require("lib/util");

start({
"headers": {
"Content-Type": "text/xml"
Expand All @@ -13,10 +15,6 @@ function(head, req) {
return result;
}

function xmlencode(string) {
return string.replace(/\&/g,'&'+'amp;').replace(/</g,'&'+'lt;');
}

var name;
var broader = [];
var narrower = [];
Expand Down Expand Up @@ -57,7 +55,7 @@ function(head, req) {
for each (h in highlights) {
send('<entity href="../../../entity/'+h.corpus+"/"+h.item+"/");
send(format(h.coordinates)+'">');
send(xmlencode(h.text));
send(util.xmlencode(h.text));
send('</entity>\n');
}
send('</topic>\n');
Expand Down
14 changes: 13 additions & 1 deletion lists/viewpoint.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,18 @@ function (head, req) {
while (row = getRow()) {
viewpoint.addRow(row.key, row.value);
}
viewpoint.sendHTML();
if (req.query.download) {
viewpoint.sendFreemind();
} else {
viewpoint.sendHTML();
}
});

registerType("freemind", "application/x-freemind");
provides("freemind", function() {
while (row = getRow()) {
viewpoint.addRow(row.key, row.value);
}
viewpoint.sendFreemind();
});
}
7 changes: 2 additions & 5 deletions shows/itemV1.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
function(o, req) {

function xmlencode(string) {
return string.replace(/\&/g,'&'+'amp;').replace(/</g,'&'+'lt;');
}
var util = require("lib/util");

send('<entity>\n');
for (var key in o) {
Expand All @@ -20,7 +17,7 @@ function(o, req) {
break;
case 'resource':
send('<resource name="source" href="');
send(xmlencode(o.resource));
send(util.xmlencode(o.resource));
send('"/>\n');
if (o.resource.indexOf('picture')>=0) {
send('<resource name="thumbnail" href="');
Expand Down
76 changes: 0 additions & 76 deletions shows/viewpoint_freemind.js

This file was deleted.

0 comments on commit 74b3694

Please sign in to comment.