mirror of
https://github.com/wekan/wekan.git
synced 2026-01-01 07:08:49 +01:00
Import board: create board, lists, and cards
This commit is contained in:
parent
595d5f97ac
commit
469d47cd9f
1 changed files with 66 additions and 13 deletions
|
|
@ -1,18 +1,21 @@
|
||||||
const trelloCreator = {
|
class TrelloCreator {
|
||||||
// the object creation dates, indexed by Trello id (so we only parse actions once!)
|
constructor() {
|
||||||
createdAt: {
|
// the object creation dates, indexed by Trello id (so we only parse actions once!)
|
||||||
board: null,
|
this.createdAt = {
|
||||||
cards: {},
|
board: null,
|
||||||
lists: {},
|
cards: {},
|
||||||
},
|
lists: {},
|
||||||
|
};
|
||||||
// the labels we created, indexed by Trello id (to map when importing cards)
|
// the labels we created, indexed by Trello id (to map when importing cards)
|
||||||
labels: {},
|
this.labels = {};
|
||||||
|
// the lists we created, indexed by Trello id (to map when importing cards)
|
||||||
|
this.lists = {};
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* must call parseActions before calling this one
|
* must call parseActions before calling this one
|
||||||
*/
|
*/
|
||||||
createBoard(trelloBoard, dateOfImport) {
|
createBoardAndLabels(trelloBoard, dateOfImport) {
|
||||||
const createdAt = this.createdAt.board;
|
const createdAt = this.createdAt.board;
|
||||||
const boardToCreate = {
|
const boardToCreate = {
|
||||||
archived: trelloBoard.closed,
|
archived: trelloBoard.closed,
|
||||||
|
|
@ -42,8 +45,51 @@ const trelloCreator = {
|
||||||
boardToCreate.labels.push(labelToCreate);
|
boardToCreate.labels.push(labelToCreate);
|
||||||
});
|
});
|
||||||
const boardId = Boards.direct.insert(boardToCreate);
|
const boardId = Boards.direct.insert(boardToCreate);
|
||||||
|
// XXX add activities
|
||||||
return boardId;
|
return boardId;
|
||||||
},
|
}
|
||||||
|
|
||||||
|
createLists(trelloLists, boardId, dateOfImport) {
|
||||||
|
trelloLists.forEach((list) => {
|
||||||
|
const listToCreate = {
|
||||||
|
archived: list.closed,
|
||||||
|
boardId,
|
||||||
|
createdAt: this.createdAt.lists[list.id],
|
||||||
|
title: list.name,
|
||||||
|
userId: Meteor.userId(),
|
||||||
|
};
|
||||||
|
listToCreate._id = Lists.direct.insert(listToCreate);
|
||||||
|
this.lists[list.id] = listToCreate;
|
||||||
|
// XXX add activities
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
createCards(trelloCards, boardId, dateOfImport) {
|
||||||
|
trelloCards.forEach((card) => {
|
||||||
|
const cardToCreate = {
|
||||||
|
archived: card.closed,
|
||||||
|
boardId,
|
||||||
|
createdAt: this.createdAt.cards[card.id],
|
||||||
|
dateLastActivity: dateOfImport,
|
||||||
|
description: card.desc,
|
||||||
|
listId: this.lists[card.idList]._id,
|
||||||
|
sort: card.pos,
|
||||||
|
title: card.name,
|
||||||
|
// XXX use the original user?
|
||||||
|
userId: Meteor.userId(),
|
||||||
|
};
|
||||||
|
// add labels
|
||||||
|
if(card.idLabels) {
|
||||||
|
cardToCreate.labelIds = card.idLabels.map((trelloId) => {
|
||||||
|
return this.labels[trelloId]._id;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
Cards.direct.insert(cardToCreate);
|
||||||
|
// XXX add comments
|
||||||
|
// XXX add attachments
|
||||||
|
// XXX add activities
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
parseActions(trelloActions) {
|
parseActions(trelloActions) {
|
||||||
trelloActions.forEach((action) =>{
|
trelloActions.forEach((action) =>{
|
||||||
|
|
@ -59,6 +105,7 @@ const trelloCreator = {
|
||||||
const listId = action.data.list.id;
|
const listId = action.data.list.id;
|
||||||
this.createdAt.lists[listId] = action.date;
|
this.createdAt.lists[listId] = action.date;
|
||||||
break;
|
break;
|
||||||
|
// XXX extract comments as well
|
||||||
default:
|
default:
|
||||||
// do nothing
|
// do nothing
|
||||||
break;
|
break;
|
||||||
|
|
@ -199,6 +246,7 @@ Meteor.methods({
|
||||||
return cardId;
|
return cardId;
|
||||||
},
|
},
|
||||||
importTrelloBoard(trelloBoard, data) {
|
importTrelloBoard(trelloBoard, data) {
|
||||||
|
const trelloCreator = new TrelloCreator();
|
||||||
// 1. check parameters are ok from a syntax point of view
|
// 1. check parameters are ok from a syntax point of view
|
||||||
try {
|
try {
|
||||||
// XXX do proper checking
|
// XXX do proper checking
|
||||||
|
|
@ -212,7 +260,12 @@ Meteor.methods({
|
||||||
// 3. create all elements
|
// 3. create all elements
|
||||||
const dateOfImport = new Date();
|
const dateOfImport = new Date();
|
||||||
trelloCreator.parseActions(trelloBoard.actions);
|
trelloCreator.parseActions(trelloBoard.actions);
|
||||||
const boardId = trelloCreator.createBoard(trelloBoard, dateOfImport);
|
const boardId = trelloCreator.createBoardAndLabels(trelloBoard, dateOfImport);
|
||||||
|
trelloCreator.createLists(trelloBoard.lists, boardId, dateOfImport);
|
||||||
|
trelloCreator.createCards(trelloBoard.cards, boardId, dateOfImport);
|
||||||
|
// XXX add activities
|
||||||
|
// XXX set modifiedAt or lastActivity
|
||||||
|
// XXX add members
|
||||||
return boardId;
|
return boardId;
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue