mirror of
https://github.com/wekan/wekan.git
synced 2025-12-16 07:20:12 +01:00
Add import Wekan board feature
This commit is contained in:
parent
61b2c91ffe
commit
3f4c285551
11 changed files with 1096 additions and 529 deletions
|
|
@ -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'}}")
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
14
client/components/import/trelloMembersMapper.js
Normal file
14
client/components/import/trelloMembersMapper.js
Normal file
|
|
@ -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;
|
||||
}
|
||||
24
client/components/import/wekanMembersMapper.js
Normal file
24
client/components/import/wekanMembersMapper.js
Normal file
|
|
@ -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;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue