Enable migration to new format

pull/1/head
yflory 5 years ago
parent fdea16d601
commit e139d46b26

@ -376,7 +376,7 @@ define([
}; };
// Kanban code // Kanban code
var initKanban = function (framework, boards) { var getDefaultBoards = function () {
var items = {}; var items = {};
for (var i=1; i<=6; i++) { for (var i=1; i<=6; i++) {
items[i] = { items[i] = {
@ -405,13 +405,41 @@ define([
}, },
items: items items: items
}; };
return defaultBoards;
};
var migrate = function (framework, boards) {
if (!Array.isArray(boards)) { return; }
console.log("Migration to new format");
var b = {
list: [],
data: {},
items: {}
};
var i = 1;
boards.forEach(function (board) {
board.id = i;
b.list.push(i);
b.data[i] = board;
i++;
if (!Array.isArray(board.item)) { return; }
board.item = board.item.map(function (item) {
item.id = i;
b.items[i] = item;
return i++; // return current id and incrmeent after
});
});
return b;
};
var initKanban = function (framework, boards) {
var migrated = false
if (!boards) { if (!boards) {
verbose("Initializing with default boards content"); verbose("Initializing with default boards content");
boards = defaultBoards; boards = getDefaultBoards();
} else if (Array.isArray(boards)) { } else if (Array.isArray(boards)) {
// XXX also migrate colors! boards = migrate(framework, boards);
throw new Error("NEED MIGRATION"); // XXX migrated = true;
} else { } else {
verbose("Initializing with boards content " + boards); verbose("Initializing with boards content " + boards);
} }
@ -659,6 +687,8 @@ define([
boards: boards boards: boards
}); });
if (migrated) { framework.localChange(); }
var addBoardDefault = document.getElementById('kanban-addboard'); var addBoardDefault = document.getElementById('kanban-addboard');
$(addBoardDefault).attr('title', Messages.kanban_addBoard); $(addBoardDefault).attr('title', Messages.kanban_addBoard);
addBoardDefault.addEventListener('click', function () { addBoardDefault.addEventListener('click', function () {

Loading…
Cancel
Save