diff options
author | Ghassen Rjab <rjab.ghassen@gmail.com> | 2017-07-08 13:23:33 +0100 |
---|---|---|
committer | Ghassen Rjab <rjab.ghassen@gmail.com> | 2017-07-08 13:23:33 +0100 |
commit | 3f4c2855513646fbd826d0473b6304dbad1f3b16 (patch) | |
tree | cb9ba1943eed0e66989370992e69981bce68eb09 /client | |
parent | 61b2c91ffed53a616eeab0cee4e8b0c4eb7f764e (diff) | |
download | wekan-3f4c2855513646fbd826d0473b6304dbad1f3b16.tar.gz wekan-3f4c2855513646fbd826d0473b6304dbad1f3b16.tar.bz2 wekan-3f4c2855513646fbd826d0473b6304dbad1f3b16.zip |
Add import Wekan board feature
Diffstat (limited to 'client')
-rw-r--r-- | client/components/boards/boardHeader.jade | 8 | ||||
-rw-r--r-- | client/components/boards/boardHeader.js | 7 | ||||
-rw-r--r-- | client/components/import/import.jade | 4 | ||||
-rw-r--r-- | client/components/import/import.js | 48 | ||||
-rw-r--r-- | client/components/import/trelloMembersMapper.js | 14 | ||||
-rw-r--r-- | client/components/import/wekanMembersMapper.js | 24 |
6 files changed, 86 insertions, 19 deletions
diff --git a/client/components/boards/boardHeader.jade b/client/components/boards/boardHeader.jade index e61aea35..b965e917 100644 --- a/client/components/boards/boardHeader.jade +++ b/client/components/boards/boardHeader.jade @@ -191,8 +191,14 @@ template(name="createBoard") input.primary.wide(type="submit" value="{{_ 'create'}}") span.quiet | {{_ 'or'}} - a(href="{{pathFor 'import'}}") {{_ 'import-board'}} + a.js-import-board {{_ 'import-board'}} +template(name="chooseBoardSource") + ul + li + a(href="{{pathFor 'import/trello'}}") {{_ 'from-trello'}} + li + a(href="{{pathFor 'import/wekan'}}") {{_ 'from-wekan'}} template(name="boardChangeTitlePopup") form diff --git a/client/components/boards/boardHeader.js b/client/components/boards/boardHeader.js index 06defbfa..c8b44824 100644 --- a/client/components/boards/boardHeader.js +++ b/client/components/boards/boardHeader.js @@ -174,10 +174,17 @@ const CreateBoard = BlazeComponent.extendComponent({ 'click .js-change-visibility': this.toggleVisibilityMenu, 'click .js-import': Popup.open('boardImportBoard'), submit: this.onSubmit, + 'click .js-import-board': Popup.open('chooseBoardSource'), }]; }, }).register('createBoardPopup'); +BlazeComponent.extendComponent({ + template() { + return 'chooseBoardSource'; + }, +}).register('chooseBoardSourcePopup'); + (class HeaderBarCreateBoard extends CreateBoard { onSubmit(evt) { super.onSubmit(evt); diff --git a/client/components/import/import.jade b/client/components/import/import.jade index d4def7d8..d1b3489a 100644 --- a/client/components/import/import.jade +++ b/client/components/import/import.jade @@ -2,7 +2,7 @@ template(name="importHeaderBar") h1 a.back-btn(href="{{pathFor 'home'}}") i.fa.fa-chevron-left - | {{_ 'import-board-title'}} + | {{_ title}} template(name="import") .wrapper @@ -12,7 +12,7 @@ template(name="import") template(name="importTextarea") form - p: label(for='import-textarea') {{_ 'import-board-trello-instruction'}} + p: label(for='import-textarea') {{_ instruction}} textarea.js-import-json(placeholder="{{_ 'import-json-placeholder'}}" autofocus) | {{jsonText}} input.primary.wide(type="submit" value="{{_ 'import'}}") diff --git a/client/components/import/import.js b/client/components/import/import.js index 11a5308a..d02637d6 100644 --- a/client/components/import/import.js +++ b/client/components/import/import.js @@ -1,3 +1,12 @@ +import trelloMembersMapper from './trelloMembersMapper'; +import wekanMembersMapper from './wekanMembersMapper'; + +BlazeComponent.extendComponent({ + title() { + return `import-board-title-${Session.get('importSource')}!`; + }, +}).register('importHeaderBar'); + BlazeComponent.extendComponent({ onCreated() { this.error = new ReactiveVar(''); @@ -5,6 +14,7 @@ BlazeComponent.extendComponent({ this._currentStepIndex = new ReactiveVar(0); this.importedData = new ReactiveVar(); this.membersToMap = new ReactiveVar([]); + this.importSource = Session.get('importSource'); }, currentTemplate() { @@ -27,7 +37,10 @@ BlazeComponent.extendComponent({ const dataObject = JSON.parse(dataJson); this.setError(''); this.importedData.set(dataObject); - this._prepareAdditionalData(dataObject); + const membersToMap = this._prepareAdditionalData(dataObject); + // store members data and mapping in Session + // (we go deep and 2-way, so storing in data context is not a viable option) + this.membersToMap.set(membersToMap); this.nextStep(); } catch (e) { this.setError('error-json-malformed'); @@ -51,7 +64,10 @@ BlazeComponent.extendComponent({ additionalData.membersMapping = mappingById; } this.membersToMap.set([]); - Meteor.call('importTrelloBoard', this.importedData.get(), additionalData, + Meteor.call('importBoard', + this.importedData.get(), + additionalData, + this.importSource, (err, res) => { if (err) { this.setError(err.error); @@ -63,20 +79,16 @@ BlazeComponent.extendComponent({ }, _prepareAdditionalData(dataObject) { - // we will work on the list itself (an ordered array of objects) when a - // mapping is done, we add a 'wekan' field to the object representing the - // imported member - const membersToMap = dataObject.members; - // auto-map based on username - membersToMap.forEach((importedMember) => { - const wekanUser = Users.findOne({ username: importedMember.username }); - if (wekanUser) { - importedMember.wekanId = wekanUser._id; - } - }); - // store members data and mapping in Session - // (we go deep and 2-way, so storing in data context is not a viable option) - this.membersToMap.set(membersToMap); + const importSource = Session.get('importSource'); + let membersToMap; + switch (importSource) { + case 'trello': + membersToMap = trelloMembersMapper.getMembersToMap(dataObject); + break; + case 'wekan': + membersToMap = wekanMembersMapper.getMembersToMap(dataObject); + break; + } return membersToMap; }, @@ -90,6 +102,10 @@ BlazeComponent.extendComponent({ return 'importTextarea'; }, + instruction() { + return `import-board-instruction-${Session.get('importSource')}!`; + }, + events() { return [{ submit(evt) { diff --git a/client/components/import/trelloMembersMapper.js b/client/components/import/trelloMembersMapper.js new file mode 100644 index 00000000..0f353bf1 --- /dev/null +++ b/client/components/import/trelloMembersMapper.js @@ -0,0 +1,14 @@ +export function getMembersToMap(data) { + // we will work on the list itself (an ordered array of objects) when a + // mapping is done, we add a 'wekan' field to the object representing the + // imported member + const membersToMap = data.members; + // auto-map based on username + membersToMap.forEach((importedMember) => { + const wekanUser = Users.findOne({ username: importedMember.username }); + if (wekanUser) { + importedMember.wekanId = wekanUser._id; + } + }); + return membersToMap; +} diff --git a/client/components/import/wekanMembersMapper.js b/client/components/import/wekanMembersMapper.js new file mode 100644 index 00000000..f4c110f7 --- /dev/null +++ b/client/components/import/wekanMembersMapper.js @@ -0,0 +1,24 @@ +export function getMembersToMap(data) { + // we will work on the list itself (an ordered array of objects) when a + // mapping is done, we add a 'wekan' field to the object representing the + // imported member + const membersToMap = data.members; + const users = data.users; + // auto-map based on username + membersToMap.forEach((importedMember) => { + importedMember.id = importedMember.userId; + delete importedMember.userId; + const user = users.filter((user) => { + return user._id === importedMember.id; + })[0]; + if (user.profile && user.profile.fullname) { + importedMember.fullName = user.profile.fullname; + } + importedMember.username = user.username; + const wekanUser = Users.findOne({ username: importedMember.username }); + if (wekanUser) { + importedMember.wekanId = wekanUser._id; + } + }); + return membersToMap; +} |