Add Trello attached links to the card description

reviewable/pr3669/r1
John R. Supplee 4 years ago
parent df54863e72
commit 1083a92816
  1. 3
      i18n/en.i18n.json
  2. 77
      models/trelloCreator.js

@ -981,5 +981,6 @@
"due-date": "Due Date", "due-date": "Due Date",
"title-alphabetically": "Title (Alphabetically)", "title-alphabetically": "Title (Alphabetically)",
"created-at-newest-first": "Created At (Newest First)", "created-at-newest-first": "Created At (Newest First)",
"created-at-oldest-first": "Created At (Oldest First)" "created-at-oldest-first": "Created At (Oldest First)",
"links-heading": "Links"
} }

@ -416,39 +416,62 @@ export class TrelloCreator {
const attachments = this.attachments[card.id]; const attachments = this.attachments[card.id];
const trelloCoverId = card.idAttachmentCover; const trelloCoverId = card.idAttachmentCover;
if (attachments) { if (attachments) {
const links = [];
attachments.forEach(att => { attachments.forEach(att => {
const file = new FS.File(); // if the attachment `name` and `url` are the same, then the
// Simulating file.attachData on the client generates multiple errors // attachment is an attached link
// - HEAD returns null, which causes exception down the line if (att.name === att.url) {
// - the template then tries to display the url to the attachment which causes other errors links.push(att.url);
// so we make it server only, and let UI catch up once it is done, forget about latency comp. } else {
const self = this; const file = new FS.File();
if (Meteor.isServer) { // Simulating file.attachData on the client generates multiple errors
file.attachData(att.url, function(error) { // - HEAD returns null, which causes exception down the line
file.boardId = boardId; // - the template then tries to display the url to the attachment which causes other errors
file.cardId = cardId; // so we make it server only, and let UI catch up once it is done, forget about latency comp.
file.userId = self._user(att.idMemberCreator); const self = this;
// The field source will only be used to prevent adding if (Meteor.isServer) {
// attachments' related activities automatically file.attachData(att.url, function(error) {
file.source = 'import'; file.boardId = boardId;
if (error) { file.cardId = cardId;
throw error; file.userId = self._user(att.idMemberCreator);
} else { // The field source will only be used to prevent adding
const wekanAtt = Attachments.insert(file, () => { // attachments' related activities automatically
// we do nothing file.source = 'import';
}); if (error) {
self.attachmentIds[att.id] = wekanAtt._id; throw error;
// } else {
if (trelloCoverId === att.id) { const wekanAtt = Attachments.insert(file, () => {
Cards.direct.update(cardId, { // we do nothing
$set: { coverId: wekanAtt._id },
}); });
self.attachmentIds[att.id] = wekanAtt._id;
//
if (trelloCoverId === att.id) {
Cards.direct.update(cardId, {
$set: { coverId: wekanAtt._id },
});
}
} }
} });
}); }
} }
// todo XXX set cover - if need be // todo XXX set cover - if need be
}); });
if (links.length) {
let desc = cardToCreate.description.trim();
if (desc) {
desc += '\n\n';
}
desc += `## ${TAPi18n.__('links-heading')}\n`;
links.forEach(link => {
desc += `* ${link}\n`;
});
Cards.direct.update(cardId, {
$set: {
description: desc,
},
});
}
} }
result.push(cardId); result.push(cardId);
}); });

Loading…
Cancel
Save