Skip to content

Add export (txt, csv, json) and import #95

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions client/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -617,3 +617,13 @@ img {
.ui-resizable-ne { cursor: ne-resize; width: 9px; height: 9px; right: -5px; top: -5px;}

.ui-icon-gripsmall-diagonal-se { background-position: -64px -224px; }

.export button, .import * {
margin-right: 15px;
}
#revisions-list li > * {
cursor: pointer;
}
#revisions-list li img {
margin-left: 10px;
}
678 changes: 678 additions & 0 deletions client/lib/moment-with-locales.min.js

Large diffs are not rendered by default.

116 changes: 116 additions & 0 deletions client/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ var keyTrap = null;
var baseurl = location.pathname.substring(0, location.pathname.lastIndexOf('/'));
var socket = io.connect({path: baseurl + "/socket.io"});

moment.locale(navigator.language || navigator.languages[0]);

//an action has happened, send it to the
//server
function sendAction(a, d) {
Expand Down Expand Up @@ -147,6 +149,25 @@ function getMessage(m) {
resizeBoard(message.data);
break;

case 'export':
download(message.data.filename, message.data.text);
break;

case 'addRevision':
addRevision(message.data);
break;

case 'deleteRevision':
$('#revision-'+message.data).remove();
break;

case 'initRevisions':
$('#revisions-list').empty();
for (var i = 0; i < message.data.length; i++) {
addRevision(message.data[i]);
}
break;

default:
//unknown message
alert('unknown action: ' + JSON.stringify(message));
Expand Down Expand Up @@ -679,6 +700,53 @@ function adjustCard(offsets, doSync) {
//////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////

function download(filename, text) {
var element = document.createElement('a');
var mime = 'text/plain';
if (filename.match(/.csv$/)) {
mime = 'text/csv';
}
element.setAttribute('href', 'data:'+mime+';charset=utf-8,' + encodeURIComponent(text));
element.setAttribute('download', filename);

element.style.display = 'none';
document.body.appendChild(element);

element.click();

document.body.removeChild(element);
}

function addRevision(timestamp) {
var li = $('<li id="revision-'+timestamp+'"></li>');
var s1 = $('<span></span>');
var s2 = $('<img src="../images/stickers/sticker-deletestar.png" alt="delete revision">');
if (typeof(timestamp) === 'string') {
timestamp = parseInt(timestamp);
}
s1.text(moment(timestamp).format('LLLL'));

li.append(s1);
li.append(s2);
$('#revisions-list').append(li);

s1.click(function() {
socket.json.send({
action: 'exportRevision',
data: timestamp
});
});
s2.click(function() {
socket.json.send({
action: 'deleteRevision',
data: timestamp
});
});
}

//////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////

$(function() {


Expand Down Expand Up @@ -840,5 +908,53 @@ $(function() {
containment: 'parent'
});

$('#export-txt').click(function() {
socket.json.send({
action: 'exportTxt',
data: ($('.col').length !== 0) ? $('.col').css('width').replace('px', '') : null
});
})

$('#export-csv').click(function() {
socket.json.send({
action: 'exportCsv',
data: ($('.col').length !== 0) ? $('.col').css('width').replace('px', '') : null
});
})

$('#export-json').click(function() {
socket.json.send({
action: 'exportJson',
data: {
width: $('.board-outline').css('width').replace('px', ''),
height: $('.board-outline').css('height').replace('px', '')
}
});
})

$('#import-file').click(function(evt) {
evt.stopPropagation();
evt.preventDefault();

var f = $('#import-input').get(0).files[0];
var fr = new FileReader();
fr.onloadend = function() {
var text = fr.result;
socket.json.send({
action: 'importJson',
data: JSON.parse(text)
});
};
fr.readAsBinaryString(f);
})

$('#create-revision').click(function() {
socket.json.send({
action: 'createRevision',
data: {
width: $('.board-outline').css('width').replace('px', ''),
height: $('.board-outline').css('height').replace('px', '')
}
});
})
});
5 changes: 5 additions & 0 deletions lib/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ db.prototype = {

getTheme: function(room, callback) { },

// revisions commands
setRevisions: function(room, revisions) { },

getRevisions: function(room, callback) { },

// Column commands
createColumn: function(room, name, callback) { },

Expand Down
22 changes: 22 additions & 0 deletions lib/data/mongodb.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,28 @@ db.prototype = {
);
},

// revision commands
setRevisions: function(room, revisions) {
this.rooms.update(
{name:room},
{$set:{revisions:revisions}}
);
},

getRevisions: function(room, callback) {
this.rooms.findOne(
{name:room},
{revisions:true},
function(err, room) {
if(room) {
callback(room.revisions);
} else {
callback();
}
}
);
},

// Column commands
createColumn: function(room, name, callback)
{
Expand Down
15 changes: 15 additions & 0 deletions lib/data/redis.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,21 @@ db.prototype = {
});
},

// revision commands
setRevisions: function(room, revisions) {
if (Object.keys(revisions).length === 0) {
redisClient.del(REDIS_PREFIX + '-room:' + room + '-revisions');
} else {
redisClient.set(REDIS_PREFIX + '-room:' + room + '-revisions', JSON.stringify(revisions));
}
},

getRevisions: function(room, callback) {
redisClient.get(REDIS_PREFIX + '-room:' + room + '-revisions', function (err, res) {
callback(JSON.parse(res));
});
},

// Column commands
createColumn: function(room, name, callback) {
redisClient.rpush(REDIS_PREFIX + '-room:' + room + '-columns', name,
Expand Down
Loading