diff options
author | Lauri Ojansivu <x@xet7.org> | 2017-07-20 04:04:36 +0300 |
---|---|---|
committer | Lauri Ojansivu <x@xet7.org> | 2017-07-20 04:04:36 +0300 |
commit | 604146b29468c01d5c5c63c5466f6722fc0bc0f9 (patch) | |
tree | e5c012066a86aaef5973f8e7b9b36c9409ca9232 | |
parent | 31400673304d39c95ecb04c430aceff2f96e1987 (diff) | |
parent | e48198353fa73f0144617f262793dff1016ddb13 (diff) | |
download | wekan-604146b29468c01d5c5c63c5466f6722fc0bc0f9.tar.gz wekan-604146b29468c01d5c5c63c5466f6722fc0bc0f9.tar.bz2 wekan-604146b29468c01d5c5c63c5466f6722fc0bc0f9.zip |
Merge branch 'GhassenRjab-export-import-checklists' into devel
Export and import checklists. Thanks to GhassenRjab !
-rw-r--r-- | CHANGELOG.md | 1 | ||||
-rw-r--r-- | models/export.js | 5 | ||||
-rw-r--r-- | models/wekanCreator.js | 71 |
3 files changed, 40 insertions, 37 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 7e38c994..fa0cc356 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ This release adds the following new features: * [Export and import attachments as base64 encoded files](https://github.com/wekan/wekan/pull/1134); +* [Export and import checklists](https://github.com/wekan/wekan/pull/1140); and fixes the following bugs: diff --git a/models/export.js b/models/export.js index 7243cf24..49656134 100644 --- a/models/export.js +++ b/models/export.js @@ -55,6 +55,10 @@ class Exporter { result.cards = Cards.find(byBoard, noBoardId).fetch(); result.comments = CardComments.find(byBoard, noBoardId).fetch(); result.activities = Activities.find(byBoard, noBoardId).fetch(); + result.checklists = []; + result.cards.forEach((card) => { + result.checklists.push(...Checklists.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) { @@ -99,6 +103,7 @@ class Exporter { }); result.comments.forEach((comment) => { users[comment.userId] = true; }); result.activities.forEach((activity) => { users[activity.userId] = true; }); + result.checklists.forEach((checklist) => { users[checklist.userId] = true; }); const byUserIds = { _id: { $in: Object.getOwnPropertyNames(users) } }; // we use whitelist to be sure we do not expose inadvertently // some secret fields that gets added to User later. diff --git a/models/wekanCreator.js b/models/wekanCreator.js index 723c5c67..6dd56fb1 100644 --- a/models/wekanCreator.js +++ b/models/wekanCreator.js @@ -116,17 +116,16 @@ export class WekanCreator { })]); } - // checkChecklists(wekanChecklists) { - // check(wekanChecklists, [Match.ObjectIncluding({ - // idBoard: String, - // idCard: String, - // name: String, - // checkItems: [Match.ObjectIncluding({ - // state: String, - // name: String, - // })], - // })]); - // } + checkChecklists(wekanChecklists) { + check(wekanChecklists, [Match.ObjectIncluding({ + cardId: String, + title: String, + items: [Match.ObjectIncluding({ + isFinished: Boolean, + title: String, + })], + })]); + } // You must call parseActions before calling this one. createBoardAndLabels(wekanBoard) { @@ -248,7 +247,7 @@ export class WekanCreator { // insert card const cardId = Cards.direct.insert(cardToCreate); // keep track of Wekan id => WeKan id - this.cards[card.id] = cardId; + this.cards[card._id] = cardId; // log activity Activities.direct.insert({ activityType: 'importCard', @@ -391,27 +390,27 @@ export class WekanCreator { }); } - // createChecklists(wekanChecklists) { - // wekanChecklists.forEach((checklist) => { - // // Create the checklist - // const checklistToCreate = { - // cardId: this.cards[checklist.cardId], - // title: checklist.title, - // createdAt: this._now(), - // }; - // const checklistId = Checklists.direct.insert(checklistToCreate); - // // Now add the items to the checklist - // const itemsToCreate = []; - // checklist.checkItems.forEach((item) => { - // itemsToCreate.push({ - // _id: checklistId + itemsToCreate.length, - // title: item.title, - // isFinished: item.isFinished, - // }); - // }); - // Checklists.direct.update(checklistId, {$set: {items: itemsToCreate}}); - // }); - // } + createChecklists(wekanChecklists) { + wekanChecklists.forEach((checklist) => { + // Create the checklist + const checklistToCreate = { + cardId: this.cards[checklist.cardId], + title: checklist.title, + createdAt: checklist.createdAt, + }; + const checklistId = Checklists.direct.insert(checklistToCreate); + // Now add the items to the checklist + const itemsToCreate = []; + checklist.items.forEach((item) => { + itemsToCreate.push({ + _id: checklistId + itemsToCreate.length, + title: item.title, + isFinished: item.isFinished, + }); + }); + Checklists.direct.update(checklistId, {$set: {items: itemsToCreate}}); + }); + } parseActivities(wekanBoard) { wekanBoard.activities.forEach((activity) => { @@ -473,8 +472,7 @@ export class WekanCreator { this.checkLabels(board.labels); this.checkLists(board.lists); this.checkCards(board.cards); - // Checklists are not exported yet - // this.checkChecklists(board.checklists); + this.checkChecklists(board.checklists); } catch (e) { throw new Meteor.Error('error-json-schema'); } @@ -485,8 +483,7 @@ export class WekanCreator { const boardId = this.createBoardAndLabels(board); this.createLists(board.lists, boardId); this.createCards(board.cards, boardId); - // Checklists are not exported yet - // this.createChecklists(board.checklists); + this.createChecklists(board.checklists); // XXX add members return boardId; } |