From 30b17ff6c92df07922f875071e864cf688902293 Mon Sep 17 00:00:00 2001 From: Sebastian Molle Date: Sat, 28 Apr 2018 22:17:56 +0200 Subject: Fix Wekan import / Export for ChecklistItems --- models/export.js | 3 +++ models/wekanCreator.js | 58 ++++++++++++++++++++++++++++++++------------------ 2 files changed, 40 insertions(+), 21 deletions(-) diff --git a/models/export.js b/models/export.js index c6632198..aff66801 100644 --- a/models/export.js +++ b/models/export.js @@ -57,9 +57,12 @@ class Exporter { result.comments = CardComments.find(byBoard, noBoardId).fetch(); result.activities = Activities.find(byBoard, noBoardId).fetch(); result.checklists = []; + result.checklistItems = []; result.cards.forEach((card) => { result.checklists.push(...Checklists.find({ cardId: card._id }).fetch()); + result.checklistItems.push(...ChecklistItems.find({ cardId: card._id }).fetch()); }); + // [Old] for attachments we only export IDs and absolute url to original doc // [New] Encode attachment to base64 const getBase64Data = function(doc, callback) { diff --git a/models/wekanCreator.js b/models/wekanCreator.js index 99d1df2d..aabcc717 100644 --- a/models/wekanCreator.js +++ b/models/wekanCreator.js @@ -36,6 +36,8 @@ export class WekanCreator { this.attachmentIds = {}; // Map of checklists Wekan ID => Wekan ID this.checklists = {}; + // Map of checklistItems Wekan ID => Wekan ID + this.checklistItems = {}; // The comments, indexed by Wekan card id (to map when importing cards) this.comments = {}; // the members, indexed by Wekan member id => Wekan user ID @@ -135,10 +137,13 @@ export class WekanCreator { check(wekanChecklists, [Match.ObjectIncluding({ cardId: String, title: String, - items: [Match.ObjectIncluding({ - isFinished: Boolean, - title: String, - })], + })]); + } + + checkChecklistItems(wekanChecklistItems) { + check(wekanChecklistItems, [Match.ObjectIncluding({ + cardId: String, + title: String, })]); } @@ -435,6 +440,7 @@ export class WekanCreator { } createChecklists(wekanChecklists) { + const result = []; wekanChecklists.forEach((checklist, checklistIndex) => { // Create the checklist const checklistToCreate = { @@ -444,19 +450,24 @@ export class WekanCreator { sort: checklist.sort ? checklist.sort : checklistIndex, }; const checklistId = Checklists.direct.insert(checklistToCreate); - // keep track of Wekan id => WeKan id this.checklists[checklist._id] = checklistId; - // Now add the items to the checklist - const itemsToCreate = []; - checklist.items.forEach((item, itemIndex) => { - itemsToCreate.push({ - _id: checklistId + itemsToCreate.length, - title: item.title, - isFinished: item.isFinished, - sort: item.sort ? item.sort : itemIndex, - }); - }); - Checklists.direct.update(checklistId, {$set: {items: itemsToCreate}}); + result.push(checklistId); + }); + return result; + } + + createChecklistItems(wekanChecklistItems) { + wekanChecklistItems.forEach((checklistitem, checklistitemIndex) => { + // Create the checklistItem + const checklistItemTocreate = { + title: checklistitem.title, + checklistId: this.checklists[checklistitem.checklistId], + cardId: this.cards[checklistitem.cardId], + sort: checklistitem.sort ? checklistitem.sort : checklistitemIndex, + isFinished: checklistitem.isFinished, + }; + const checklistItemId = ChecklistItems.direct.insert(checklistItemTocreate); + this.checklistItems[checklistitem._id] = checklistItemId; }); } @@ -470,14 +481,17 @@ export class WekanCreator { const wekanAttachment = wekanBoard.attachments.filter((attachment) => { return attachment._id === activity.attachmentId; })[0]; - if(wekanAttachment.url || wekanAttachment.file) { + + if ( typeof wekanAttachment !== 'undefined' && wekanAttachment ) { + if(wekanAttachment.url || wekanAttachment.file) { // we cannot actually create the Wekan attachment, because we don't yet // have the cards to attach it to, so we store it in the instance variable. - const wekanCardId = activity.cardId; - if(!this.attachments[wekanCardId]) { - this.attachments[wekanCardId] = []; + const wekanCardId = activity.cardId; + if(!this.attachments[wekanCardId]) { + this.attachments[wekanCardId] = []; + } + this.attachments[wekanCardId].push(wekanAttachment); } - this.attachments[wekanCardId].push(wekanAttachment); } break; } @@ -635,6 +649,7 @@ export class WekanCreator { this.checkSwimlanes(board.swimlanes); this.checkCards(board.cards); this.checkChecklists(board.checklists); + this.checkChecklistItems(board.checklistItems); } catch (e) { throw new Meteor.Error('error-json-schema'); } @@ -654,6 +669,7 @@ export class WekanCreator { this.createSwimlanes(board.swimlanes, boardId); this.createCards(board.cards, boardId); this.createChecklists(board.checklists); + this.createChecklistItems(board.checklistItems); this.importActivities(board.activities, boardId); // XXX add members return boardId; -- cgit v1.2.3-1-g7c22 From 6167d447fd82362528e0be4f4037cd87a2e7bdac Mon Sep 17 00:00:00 2001 From: Lauri Ojansivu Date: Sun, 29 Apr 2018 09:11:23 +0300 Subject: - Fix Wekan import / Export for ChecklistItems. Thanks to zebby76 ! --- CHANGELOG.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 843eb016..c1042c91 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,12 @@ +# Upcoming Wekan release + +This release fixes the following bugs: + +- [Fix Wekan import / Export for + ChecklistItems](https://github.com/wekan/wekan/commit/30b17ff6c92df07922f875071e864cf688902293). + +Thanks to Github user zebby76 for contributions. + # v0.88 2018-04-27 Wekan release This release fixes the following bugs: -- cgit v1.2.3-1-g7c22