trelloCreator.js 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789
  1. import { ReactiveCache } from '/imports/reactiveCache';
  2. import { TAPi18n } from '/imports/i18n';
  3. import {
  4. formatDateTime,
  5. formatDate,
  6. formatTime,
  7. getISOWeek,
  8. isValidDate,
  9. isBefore,
  10. isAfter,
  11. isSame,
  12. add,
  13. subtract,
  14. startOf,
  15. endOf,
  16. format,
  17. parseDate,
  18. now,
  19. createDate,
  20. fromNow,
  21. calendar
  22. } from '/imports/lib/dateUtils';
  23. const DateString = Match.Where(function(dateAsString) {
  24. check(dateAsString, String);
  25. return isValidDate(new Date(dateAsString));
  26. });
  27. export class TrelloCreator {
  28. constructor(data) {
  29. // we log current date, to use the same timestamp for all our actions.
  30. // this helps to retrieve all elements performed by the same import.
  31. this._nowDate = new Date();
  32. // The object creation dates, indexed by Trello id
  33. // (so we only parse actions once!)
  34. this.createdAt = {
  35. board: null,
  36. cards: {},
  37. lists: {},
  38. };
  39. // The object creator Trello Id, indexed by the object Trello id
  40. // (so we only parse actions once!)
  41. this.createdBy = {
  42. cards: {}, // only cards have a field for that
  43. };
  44. // Map of labels Trello ID => Wekan ID
  45. this.labels = {};
  46. // Default swimlane
  47. this.swimlane = null;
  48. // Map of lists Trello ID => Wekan ID
  49. this.lists = {};
  50. // Map of cards Trello ID => Wekan ID
  51. this.cards = {};
  52. // Map of attachments Wekan ID => Wekan ID
  53. this.attachmentIds = {};
  54. // Map of checklists Wekan ID => Wekan ID
  55. this.checklists = {};
  56. // The comments, indexed by Trello card id (to map when importing cards)
  57. this.comments = {};
  58. // the members, indexed by Trello member id => Wekan user ID
  59. this.members = data.membersMapping ? data.membersMapping : {};
  60. // maps a trelloCardId to an array of trelloAttachments
  61. this.attachments = {};
  62. this.customFields = {};
  63. }
  64. /**
  65. * If dateString is provided,
  66. * return the Date it represents.
  67. * If not, will return the date when it was first called.
  68. * This is useful for us, as we want all import operations to
  69. * have the exact same date for easier later retrieval.
  70. *
  71. * @param {String} dateString a properly formatted Date
  72. */
  73. _now(dateString) {
  74. if (dateString) {
  75. return new Date(dateString);
  76. }
  77. if (!this._nowDate) {
  78. this._nowDate = new Date();
  79. }
  80. return this._nowDate;
  81. }
  82. /**
  83. * if trelloUserId is provided and we have a mapping,
  84. * return it.
  85. * Otherwise return current logged user.
  86. * @param trelloUserId
  87. * @private
  88. */
  89. _user(trelloUserId) {
  90. if (trelloUserId && this.members[trelloUserId]) {
  91. return this.members[trelloUserId];
  92. }
  93. return Meteor.userId();
  94. }
  95. checkActions(trelloActions) {
  96. check(trelloActions, [
  97. Match.ObjectIncluding({
  98. data: Object,
  99. date: DateString,
  100. type: String,
  101. }),
  102. ]);
  103. // XXX we could perform more thorough checks based on action type
  104. }
  105. checkBoard(trelloBoard) {
  106. check(
  107. trelloBoard,
  108. Match.ObjectIncluding({
  109. // closed: Boolean, // issue #3840, should import closed Trello boards
  110. name: String,
  111. prefs: Match.ObjectIncluding({
  112. // XXX refine control by validating 'background' against a list of
  113. // allowed values (is it worth the maintenance?)
  114. background: String,
  115. permissionLevel: Match.Where(value => {
  116. return ['org', 'private', 'public'].indexOf(value) >= 0;
  117. }),
  118. }),
  119. }),
  120. );
  121. }
  122. checkCards(trelloCards) {
  123. check(trelloCards, [
  124. Match.ObjectIncluding({
  125. closed: Boolean,
  126. dateLastActivity: DateString,
  127. desc: String,
  128. idLabels: [String],
  129. idMembers: [String],
  130. name: String,
  131. pos: Number,
  132. }),
  133. ]);
  134. }
  135. checkLabels(trelloLabels) {
  136. check(trelloLabels, [
  137. Match.ObjectIncluding({
  138. // XXX refine control by validating 'color' against a list of allowed
  139. // values (is it worth the maintenance?)
  140. name: String,
  141. }),
  142. ]);
  143. }
  144. checkLists(trelloLists) {
  145. check(trelloLists, [
  146. Match.ObjectIncluding({
  147. closed: Boolean,
  148. name: String,
  149. }),
  150. ]);
  151. }
  152. checkChecklists(trelloChecklists) {
  153. check(trelloChecklists, [
  154. Match.ObjectIncluding({
  155. idBoard: String,
  156. idCard: String,
  157. name: String,
  158. checkItems: [
  159. Match.ObjectIncluding({
  160. state: String,
  161. name: String,
  162. }),
  163. ],
  164. }),
  165. ]);
  166. }
  167. // You must call parseActions before calling this one.
  168. createBoardAndLabels(trelloBoard) {
  169. let color = 'blue';
  170. if (this.getColor(trelloBoard.prefs.background) !== undefined) {
  171. color = this.getColor(trelloBoard.prefs.background);
  172. }
  173. const boardToCreate = {
  174. archived: trelloBoard.closed,
  175. color: color,
  176. // very old boards won't have a creation activity so no creation date
  177. createdAt: this._now(this.createdAt.board),
  178. labels: [],
  179. customFields: [],
  180. members: [
  181. {
  182. userId: Meteor.userId(),
  183. isAdmin: true,
  184. isActive: true,
  185. isNoComments: false,
  186. isCommentOnly: false,
  187. swimlaneId: false,
  188. },
  189. ],
  190. permission: this.getPermission(trelloBoard.prefs.permissionLevel),
  191. slug: getSlug(trelloBoard.name) || 'board',
  192. stars: 0,
  193. title: Boards.uniqueTitle(trelloBoard.name),
  194. };
  195. // now add other members
  196. if (trelloBoard.memberships) {
  197. trelloBoard.memberships.forEach(trelloMembership => {
  198. const trelloId = trelloMembership.idMember;
  199. // do we have a mapping?
  200. if (this.members[trelloId]) {
  201. const wekanId = this.members[trelloId];
  202. // do we already have it in our list?
  203. const wekanMember = boardToCreate.members.find(
  204. wekanMember => wekanMember.userId === wekanId,
  205. );
  206. if (wekanMember) {
  207. // we're already mapped, but maybe with lower rights
  208. if (!wekanMember.isAdmin) {
  209. wekanMember.isAdmin = this.getAdmin(trelloMembership.memberType);
  210. }
  211. } else {
  212. boardToCreate.members.push({
  213. userId: wekanId,
  214. isAdmin: this.getAdmin(trelloMembership.memberType),
  215. isActive: true,
  216. isNoComments: false,
  217. isCommentOnly: false,
  218. swimlaneId: false,
  219. });
  220. }
  221. }
  222. });
  223. }
  224. if (trelloBoard.labels) {
  225. trelloBoard.labels.forEach(label => {
  226. const labelToCreate = {
  227. _id: Random.id(6),
  228. color: label.color ? label.color : 'black',
  229. name: label.name,
  230. };
  231. // We need to remember them by Trello ID, as this is the only ref we have
  232. // when importing cards.
  233. this.labels[label.id] = labelToCreate._id;
  234. boardToCreate.labels.push(labelToCreate);
  235. });
  236. }
  237. const boardId = Boards.direct.insert(boardToCreate);
  238. Boards.direct.update(boardId, { $set: { modifiedAt: this._now() } });
  239. // log activity
  240. Activities.direct.insert({
  241. activityType: 'importBoard',
  242. boardId,
  243. createdAt: this._now(),
  244. source: {
  245. id: trelloBoard.id,
  246. system: 'Trello',
  247. url: trelloBoard.url,
  248. },
  249. // We attribute the import to current user,
  250. // not the author from the original object.
  251. userId: this._user(),
  252. });
  253. if (trelloBoard.customFields) {
  254. trelloBoard.customFields.forEach(field => {
  255. const fieldToCreate = {
  256. // trelloId: field.id,
  257. name: field.name,
  258. showOnCard: field.display.cardFront,
  259. showLabelOnMiniCard: field.display.cardFront,
  260. automaticallyOnCard: true,
  261. alwaysOnCard: false,
  262. type: field.type,
  263. boardIds: [boardId],
  264. settings: {},
  265. };
  266. if (field.type === 'list') {
  267. fieldToCreate.type = 'dropdown';
  268. fieldToCreate.settings = {
  269. dropdownItems: field.options.map(opt => {
  270. return {
  271. _id: opt.id,
  272. name: opt.value.text,
  273. };
  274. }),
  275. };
  276. }
  277. // We need to remember them by Trello ID, as this is the only ref we have
  278. // when importing cards.
  279. this.customFields[field.id] = CustomFields.direct.insert(fieldToCreate);
  280. });
  281. }
  282. return boardId;
  283. }
  284. /**
  285. * Create the Wekan cards corresponding to the supplied Trello cards,
  286. * as well as all linked data: activities, comments, and attachments
  287. * @param trelloCards
  288. * @param boardId
  289. * @returns {Array}
  290. */
  291. createCards(trelloCards, boardId) {
  292. const result = [];
  293. trelloCards.forEach(card => {
  294. const cardToCreate = {
  295. archived: card.closed,
  296. boardId,
  297. // very old boards won't have a creation activity so no creation date
  298. createdAt: this._now(this.createdAt.cards[card.id]),
  299. dateLastActivity: this._now(),
  300. description: card.desc,
  301. listId: this.lists[card.idList],
  302. swimlaneId: this.swimlane,
  303. sort: card.pos,
  304. title: card.name,
  305. // we attribute the card to its creator if available
  306. userId: this._user(this.createdBy.cards[card.id]),
  307. dueAt: card.due ? this._now(card.due) : null,
  308. };
  309. // add labels
  310. if (card.idLabels) {
  311. cardToCreate.labelIds = card.idLabels.map(trelloId => {
  312. return this.labels[trelloId];
  313. });
  314. }
  315. // add members {
  316. if (card.idMembers) {
  317. const wekanMembers = [];
  318. // we can't just map, as some members may not have been mapped
  319. card.idMembers.forEach(trelloId => {
  320. if (this.members[trelloId]) {
  321. const wekanId = this.members[trelloId];
  322. // we may map multiple Trello members to the same wekan user
  323. // in which case we risk adding the same user multiple times
  324. if (!wekanMembers.find(wId => wId === wekanId)) {
  325. wekanMembers.push(wekanId);
  326. }
  327. }
  328. return true;
  329. });
  330. if (wekanMembers.length > 0) {
  331. cardToCreate.members = wekanMembers;
  332. }
  333. }
  334. // add vote
  335. if (card.idMembersVoted) {
  336. // Trello only know's positive votes
  337. const positiveVotes = [];
  338. card.idMembersVoted.forEach(trelloId => {
  339. if (this.members[trelloId]) {
  340. const wekanId = this.members[trelloId];
  341. // we may map multiple Trello members to the same wekan user
  342. // in which case we risk adding the same user multiple times
  343. if (!positiveVotes.find(wId => wId === wekanId)) {
  344. positiveVotes.push(wekanId);
  345. }
  346. }
  347. return true;
  348. });
  349. if (positiveVotes.length > 0) {
  350. cardToCreate.vote = {
  351. question: cardToCreate.title,
  352. public: true,
  353. positive: positiveVotes,
  354. };
  355. }
  356. }
  357. if (card.customFieldItems) {
  358. cardToCreate.customFields = [];
  359. card.customFieldItems.forEach(item => {
  360. const custom = {
  361. _id: this.customFields[item.idCustomField],
  362. };
  363. if (item.idValue) {
  364. custom.value = item.idValue;
  365. } else if (item.value.hasOwnProperty('checked')) {
  366. custom.value = item.value.checked === 'true';
  367. } else if (item.value.hasOwnProperty('text')) {
  368. custom.value = item.value.text;
  369. } else if (item.value.hasOwnProperty('date')) {
  370. custom.value = item.value.date;
  371. } else if (item.value.hasOwnProperty('number')) {
  372. custom.value = item.value.number;
  373. }
  374. cardToCreate.customFields.push(custom);
  375. });
  376. }
  377. // insert card
  378. const cardId = Cards.direct.insert(cardToCreate);
  379. // keep track of Trello id => Wekan id
  380. this.cards[card.id] = cardId;
  381. // log activity
  382. // Activities.direct.insert({
  383. // activityType: 'importCard',
  384. // boardId,
  385. // cardId,
  386. // createdAt: this._now(),
  387. // listId: cardToCreate.listId,
  388. // source: {
  389. // id: card.id,
  390. // system: 'Trello',
  391. // url: card.url,
  392. // },
  393. // // we attribute the import to current user,
  394. // // not the author of the original card
  395. // userId: this._user(),
  396. // });
  397. // add comments
  398. const comments = this.comments[card.id];
  399. if (comments) {
  400. comments.forEach(comment => {
  401. const commentToCreate = {
  402. boardId,
  403. cardId,
  404. createdAt: this._now(comment.date),
  405. text: comment.data.text,
  406. // we attribute the comment to the original author, default to current user
  407. userId: this._user(comment.idMemberCreator),
  408. };
  409. // dateLastActivity will be set from activity insert, no need to
  410. // update it ourselves
  411. const commentId = CardComments.direct.insert(commentToCreate);
  412. // We need to keep adding comment activities this way with Trello
  413. // because it doesn't provide a comment ID
  414. Activities.direct.insert({
  415. activityType: 'addComment',
  416. boardId: commentToCreate.boardId,
  417. cardId: commentToCreate.cardId,
  418. commentId,
  419. createdAt: this._now(comment.date),
  420. // we attribute the addComment (not the import)
  421. // to the original author - it is needed by some UI elements.
  422. userId: commentToCreate.userId,
  423. });
  424. });
  425. }
  426. const attachments = this.attachments[card.id];
  427. const trelloCoverId = card.idAttachmentCover;
  428. if (attachments && Meteor.isServer) {
  429. attachments.forEach(att => {
  430. const self = this;
  431. const opts = {
  432. type: att.type ? att.type : undefined,
  433. userId: self._user(att.userId),
  434. meta: {
  435. boardId,
  436. cardId,
  437. source: 'import',
  438. },
  439. };
  440. const cb = (error, fileObj) => {
  441. if (error) {
  442. throw error;
  443. }
  444. self.attachmentIds[att._id] = fileObj._id;
  445. if (trelloCoverId === att._id) {
  446. Cards.direct.update(cardId, {
  447. $set: { coverId: fileObj._id },
  448. });
  449. }
  450. };
  451. if (att.url) {
  452. Attachments.load(att.url, opts, cb, true);
  453. } else if (att.file) {
  454. Attachments.insert(att.file, opts, cb, true);
  455. }
  456. });
  457. if (links) {
  458. if (links.length) {
  459. let desc = cardToCreate.description.trim();
  460. if (desc) {
  461. desc += '\n\n';
  462. }
  463. desc += `## ${TAPi18n.__('links-heading')}\n`;
  464. links.forEach(link => {
  465. desc += `* ${link}\n`;
  466. });
  467. Cards.direct.update(cardId, {
  468. $set: {
  469. description: desc,
  470. },
  471. });
  472. }
  473. }
  474. }
  475. result.push(cardId);
  476. });
  477. return result;
  478. }
  479. // Create labels if they do not exist and load this.labels.
  480. createLabels(trelloLabels, board) {
  481. trelloLabels.forEach(label => {
  482. const color = label.color;
  483. const name = label.name;
  484. const existingLabel = board.getLabel(name, color);
  485. if (existingLabel) {
  486. this.labels[label.id] = existingLabel._id;
  487. } else {
  488. const idLabelCreated = board.pushLabel(name, color);
  489. this.labels[label.id] = idLabelCreated;
  490. }
  491. });
  492. }
  493. createLists(trelloLists, boardId) {
  494. trelloLists.forEach(list => {
  495. const listToCreate = {
  496. archived: list.closed,
  497. boardId,
  498. // We are being defensing here by providing a default date (now) if the
  499. // creation date wasn't found on the action log. This happen on old
  500. // Trello boards (eg from 2013) that didn't log the 'createList' action
  501. // we require.
  502. createdAt: this._now(this.createdAt.lists[list.id]),
  503. title: list.name,
  504. sort: list.pos,
  505. };
  506. const listId = Lists.direct.insert(listToCreate);
  507. Lists.direct.update(listId, { $set: { updatedAt: this._now() } });
  508. this.lists[list.id] = listId;
  509. // log activity
  510. // Activities.direct.insert({
  511. // activityType: 'importList',
  512. // boardId,
  513. // createdAt: this._now(),
  514. // listId,
  515. // source: {
  516. // id: list.id,
  517. // system: 'Trello',
  518. // },
  519. // // We attribute the import to current user,
  520. // // not the creator of the original object
  521. // userId: this._user(),
  522. // });
  523. });
  524. }
  525. createSwimlanes(boardId) {
  526. const swimlaneToCreate = {
  527. archived: false,
  528. boardId,
  529. // We are being defensing here by providing a default date (now) if the
  530. // creation date wasn't found on the action log. This happen on old
  531. // Wekan boards (eg from 2013) that didn't log the 'createList' action
  532. // we require.
  533. createdAt: this._now(),
  534. title: 'Default',
  535. sort: 1,
  536. };
  537. const swimlaneId = Swimlanes.direct.insert(swimlaneToCreate);
  538. Swimlanes.direct.update(swimlaneId, { $set: { updatedAt: this._now() } });
  539. this.swimlane = swimlaneId;
  540. }
  541. createChecklists(trelloChecklists) {
  542. trelloChecklists.forEach(checklist => {
  543. if (this.cards[checklist.idCard]) {
  544. // Create the checklist
  545. const checklistToCreate = {
  546. cardId: this.cards[checklist.idCard],
  547. title: checklist.name,
  548. createdAt: this._now(),
  549. sort: checklist.pos,
  550. };
  551. const checklistId = Checklists.direct.insert(checklistToCreate);
  552. // keep track of Trello id => Wekan id
  553. this.checklists[checklist.id] = checklistId;
  554. // Now add the items to the checklistItems
  555. let counter = 0;
  556. checklist.checkItems.forEach(item => {
  557. counter++;
  558. const checklistItemTocreate = {
  559. _id: checklistId + counter,
  560. title: item.name,
  561. checklistId: this.checklists[checklist.id],
  562. cardId: this.cards[checklist.idCard],
  563. sort: item.pos,
  564. isFinished: item.state === 'complete',
  565. };
  566. ChecklistItems.direct.insert(checklistItemTocreate);
  567. });
  568. }
  569. });
  570. }
  571. getAdmin(trelloMemberType) {
  572. return trelloMemberType === 'admin';
  573. }
  574. getColor(trelloColorCode) {
  575. // trello color name => wekan color
  576. const mapColors = {
  577. blue: 'belize',
  578. orange: 'pumpkin',
  579. green: 'nephritis',
  580. red: 'pomegranate',
  581. purple: 'wisteria',
  582. pink: 'moderatepink',
  583. lime: 'limegreen',
  584. sky: 'strongcyan',
  585. grey: 'midnight',
  586. };
  587. const wekanColor = mapColors[trelloColorCode];
  588. return wekanColor || Boards.simpleSchema()._schema.color.allowedValues[0];
  589. }
  590. getPermission(trelloPermissionCode) {
  591. if (trelloPermissionCode === 'public') {
  592. return 'public';
  593. }
  594. // Wekan does NOT have organization level, so we default both 'private' and
  595. // 'org' to private.
  596. return 'private';
  597. }
  598. parseActions(trelloActions) {
  599. trelloActions.forEach(action => {
  600. if (action.type === 'addAttachmentToCard') {
  601. // We have to be cautious, because the attachment could have been removed later.
  602. // In that case Trello still reports its addition, but removes its 'url' field.
  603. // So we test for that
  604. const trelloAttachment = action.data.attachment;
  605. // We need the idMemberCreator
  606. trelloAttachment.idMemberCreator = action.idMemberCreator;
  607. if (trelloAttachment.url) {
  608. // we cannot actually create the Wekan attachment, because we don't yet
  609. // have the cards to attach it to, so we store it in the instance variable.
  610. const trelloCardId = action.data.card.id;
  611. if (!this.attachments[trelloCardId]) {
  612. this.attachments[trelloCardId] = [];
  613. }
  614. this.attachments[trelloCardId].push(trelloAttachment);
  615. }
  616. } else if (action.type === 'commentCard') {
  617. const id = action.data.card.id;
  618. if (this.comments[id]) {
  619. this.comments[id].push(action);
  620. } else {
  621. this.comments[id] = [action];
  622. }
  623. } else if (action.type === 'createBoard') {
  624. this.createdAt.board = action.date;
  625. } else if (action.type === 'createCard') {
  626. const cardId = action.data.card.id;
  627. this.createdAt.cards[cardId] = action.date;
  628. this.createdBy.cards[cardId] = action.idMemberCreator;
  629. } else if (action.type === 'createList') {
  630. const listId = action.data.list.id;
  631. this.createdAt.lists[listId] = action.date;
  632. }
  633. });
  634. }
  635. importActions(actions, boardId) {
  636. actions.forEach(action => {
  637. switch (action.type) {
  638. // Board related actions
  639. // TODO: addBoardMember, removeBoardMember
  640. case 'createBoard': {
  641. Activities.direct.insert({
  642. userId: this._user(action.idMemberCreator),
  643. type: 'board',
  644. activityTypeId: boardId,
  645. activityType: 'createBoard',
  646. boardId,
  647. createdAt: this._now(action.date),
  648. });
  649. break;
  650. }
  651. // List related activities
  652. // TODO: removeList, archivedList
  653. case 'createList': {
  654. Activities.direct.insert({
  655. userId: this._user(action.idMemberCreator),
  656. type: 'list',
  657. activityType: 'createList',
  658. listId: this.lists[action.data.list.id],
  659. boardId,
  660. createdAt: this._now(action.date),
  661. });
  662. break;
  663. }
  664. // Card related activities
  665. // TODO: archivedCard, restoredCard, joinMember, unjoinMember
  666. case 'createCard': {
  667. Activities.direct.insert({
  668. userId: this._user(action.idMemberCreator),
  669. activityType: 'createCard',
  670. listId: this.lists[action.data.list.id],
  671. cardId: this.cards[action.data.card.id],
  672. boardId,
  673. createdAt: this._now(action.date),
  674. });
  675. break;
  676. }
  677. case 'updateCard': {
  678. if (action.data.old.idList) {
  679. Activities.direct.insert({
  680. userId: this._user(action.idMemberCreator),
  681. oldListId: this.lists[action.data.old.idList],
  682. activityType: 'moveCard',
  683. listId: this.lists[action.data.listAfter.id],
  684. cardId: this.cards[action.data.card.id],
  685. boardId,
  686. createdAt: this._now(action.date),
  687. });
  688. }
  689. break;
  690. }
  691. // Comment related activities
  692. // Trello doesn't export the comment id
  693. // Attachment related activities
  694. case 'addAttachmentToCard': {
  695. Activities.direct.insert({
  696. userId: this._user(action.idMemberCreator),
  697. type: 'card',
  698. activityType: 'addAttachment',
  699. attachmentId: this.attachmentIds[action.data.attachment.id],
  700. cardId: this.cards[action.data.card.id],
  701. boardId,
  702. createdAt: this._now(action.date),
  703. });
  704. break;
  705. }
  706. // Checklist related activities
  707. case 'addChecklistToCard': {
  708. Activities.direct.insert({
  709. userId: this._user(action.idMemberCreator),
  710. activityType: 'addChecklist',
  711. cardId: this.cards[action.data.card.id],
  712. checklistId: this.checklists[action.data.checklist.id],
  713. boardId,
  714. createdAt: this._now(action.date),
  715. });
  716. break;
  717. }
  718. }
  719. // Trello doesn't have an add checklist item action
  720. });
  721. }
  722. check(board) {
  723. try {
  724. // check(data, {
  725. // membersMapping: Match.Optional(Object),
  726. // });
  727. this.checkActions(board.actions);
  728. this.checkBoard(board);
  729. this.checkLabels(board.labels);
  730. this.checkLists(board.lists);
  731. this.checkCards(board.cards);
  732. this.checkChecklists(board.checklists);
  733. } catch (e) {
  734. throw new Meteor.Error('error-json-schema');
  735. }
  736. }
  737. create(board, currentBoardId) {
  738. // TODO : Make isSandstorm variable global
  739. const isSandstorm =
  740. Meteor.settings &&
  741. Meteor.settings.public &&
  742. Meteor.settings.public.sandstorm;
  743. if (isSandstorm && currentBoardId) {
  744. const currentBoard = ReactiveCache.getBoard(currentBoardId);
  745. currentBoard.archive();
  746. }
  747. this.parseActions(board.actions);
  748. const boardId = this.createBoardAndLabels(board);
  749. this.createLists(board.lists, boardId);
  750. this.createSwimlanes(boardId);
  751. this.createCards(board.cards, boardId);
  752. this.createChecklists(board.checklists);
  753. this.importActions(board.actions, boardId);
  754. // XXX add members
  755. return boardId;
  756. }
  757. }