From 456674f1114f6e698891ad3b5b8b4bd505a550c5 Mon Sep 17 00:00:00 2001 From: Xavier Priour Date: Mon, 19 Oct 2015 11:46:04 +0200 Subject: Import board: set proper color and modifiedAt dates --- models/import.js | 35 ++++++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/models/import.js b/models/import.js index 5095ee2e..e925d028 100644 --- a/models/import.js +++ b/models/import.js @@ -21,8 +21,7 @@ class TrelloCreator { const createdAt = this.createdAt.board; const boardToCreate = { archived: trelloBoard.closed, - // XXX map from Trello colors - color: Boards.simpleSchema()._schema.color.allowedValues[0], + color: this.getColor(trelloBoard.prefs.background), createdAt, labels: [], members: [{ @@ -46,12 +45,14 @@ class TrelloCreator { this.labels[label.id] = labelToCreate; boardToCreate.labels.push(labelToCreate); }); + const now = new Date(); const boardId = Boards.direct.insert(boardToCreate); + Boards.direct.update(boardId, {$set: {modifiedAt: now}}); // log activity Activities.direct.insert({ activityType: 'importBoard', boardId, - createdAt: new Date(), + createdAt: now, source: { id: trelloBoard.id, system: 'Trello', @@ -72,14 +73,17 @@ class TrelloCreator { title: list.name, userId: Meteor.userId(), }; - listToCreate._id = Lists.direct.insert(listToCreate); + const listId = Lists.direct.insert(listToCreate); + const now = new Date(); + Lists.direct.update(listId, {$set: {'updatedAt': now}}); + listToCreate._id = listId; this.lists[list.id] = listToCreate; // log activity Activities.direct.insert({ activityType: 'importList', boardId, - createdAt: new Date(), - listId: listToCreate._id, + createdAt: now, + listId, source: { id: list.id, system: 'Trello', @@ -139,6 +143,7 @@ class TrelloCreator { // XXX use the original comment user instead userId: Meteor.userId(), }; + // dateLastActivity will be set from activity insert, no need to update it ourselves const commentId = CardComments.direct.insert(commentToCreate); Activities.direct.insert({ activityType: 'addComment', @@ -154,6 +159,23 @@ class TrelloCreator { }); } + getColor(trelloColorCode) { + // trello color name => wekan color + const mapColors = { + 'blue': 'belize', + 'orange': 'pumpkin', + 'green': 'nephritis', + 'red': 'pomegranate', + 'purple': 'wisteria', + 'pink': 'pomegranate', + 'lime': 'nephritis', + 'sky': 'belize', + 'grey': 'midnight', + }; + const wekanColor = mapColors[trelloColorCode]; + return wekanColor || Boards.simpleSchema()._schema.color.allowedValues[0]; + } + parseActions(trelloActions) { trelloActions.forEach((action) => { switch (action.type) { @@ -202,7 +224,6 @@ Meteor.methods({ const boardId = trelloCreator.createBoardAndLabels(trelloBoard); trelloCreator.createLists(trelloBoard.lists, boardId); trelloCreator.createCardsAndComments(trelloBoard.cards, boardId); - // XXX set modifiedAt or lastActivity // XXX add members return boardId; }, -- cgit v1.2.3-1-g7c22