Kanban import from Trello

pull/1/head
yflory 4 years ago
parent eaa02bb8b8
commit 51c5b7d3e4

@ -13,6 +13,73 @@ define([
})); }));
}; };
module.import = function (content) {
// Import from Trello
var c = {
data: {},
items: {},
list: []
};
var colorMap = {
red: 'color1',
orange: 'color2',
yellow: 'color3',
lime: 'color4',
green: 'color5',
sky: 'color6',
blue: 'color7',
purple: 'color8',
pink: 'color9',
black: 'nocolor'
};
content.cards.forEach(function (obj, i) {
var tags;
var color;
if (Array.isArray(obj.labels)) {
obj.labels.forEach(function (l) {
if (!color) {
color = colorMap[l.color] || '';
}
if (l.name) {
tags = tags || [];
var n = l.name.toLowerCase().trim();
if (tags.indexOf(n) === -1) { tags.push(n); }
}
});
}
c.items[(i+1)] = {
id: (i+1),
title: obj.name,
body: obj.desc,
color: color,
tags: tags
};
});
var id = 1;
content.lists.forEach(function (obj) {
var _id = obj.id;
var cards = [];
content.cards.forEach(function (card, i) {
if (card.idList === _id) {
cards.push(i+1);
}
});
c.data[id] = {
id: id,
title: obj.name,
item: cards
};
c.list.push(id);
id++;
});
return c;
};
return module; return module;
}); });

@ -18,6 +18,7 @@ define([
'/bower_components/marked/marked.min.js', '/bower_components/marked/marked.min.js',
'cm/lib/codemirror', 'cm/lib/codemirror',
'/kanban/jkanban_cp.js', '/kanban/jkanban_cp.js',
'/kanban/export.js',
'cm/mode/gfm/gfm', 'cm/mode/gfm/gfm',
'cm/addon/edit/closebrackets', 'cm/addon/edit/closebrackets',
@ -50,7 +51,8 @@ define([
ChainPad, ChainPad,
Marked, Marked,
CodeMirror, CodeMirror,
jKanban) jKanban,
Export)
{ {
var verbose = function (x) { console.log(x); }; var verbose = function (x) { console.log(x); };
@ -1060,6 +1062,11 @@ define([
var parsed; var parsed;
try { parsed = JSON.parse(content); } try { parsed = JSON.parse(content); }
catch (e) { return void console.error(e); } catch (e) { return void console.error(e); }
if (parsed && parsed.id && parsed.lists && parsed.cards) {
return { content: Export.import(parsed) };
}
return { content: parsed }; return { content: parsed };
}); });

Loading…
Cancel
Save