sidebarArchives.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. archivedRequested = false;
  2. const subManager = new SubsManager();
  3. BlazeComponent.extendComponent({
  4. onCreated() {
  5. this.isArchiveReady = new ReactiveVar(false);
  6. // The pattern we use to manually handle data loading is described here:
  7. // https://kadira.io/academy/meteor-routing-guide/content/subscriptions-and-data-management/using-subs-manager
  8. // XXX The boardId should be readed from some sort the component "props",
  9. // unfortunatly, Blaze doesn't have this notion.
  10. this.autorun(() => {
  11. const currentBoardId = Session.get('currentBoard');
  12. if (!currentBoardId) return;
  13. const handle = subManager.subscribe('board', currentBoardId, true);
  14. archivedRequested = true;
  15. Tracker.nonreactive(() => {
  16. Tracker.autorun(() => {
  17. this.isArchiveReady.set(handle.ready());
  18. });
  19. });
  20. });
  21. },
  22. tabs() {
  23. return [
  24. { name: TAPi18n.__('cards'), slug: 'cards' },
  25. { name: TAPi18n.__('lists'), slug: 'lists' },
  26. { name: TAPi18n.__('swimlanes'), slug: 'swimlanes' },
  27. ];
  28. },
  29. archivedCards() {
  30. return Cards.find({
  31. archived: true,
  32. boardId: Session.get('currentBoard'),
  33. }, {
  34. sort: { archivedAt: -1, modifiedAt: -1 },
  35. });
  36. },
  37. archivedLists() {
  38. return Lists.find({
  39. archived: true,
  40. boardId: Session.get('currentBoard'),
  41. }, {
  42. sort: { archivedAt: -1, modifiedAt: -1 },
  43. });
  44. },
  45. archivedSwimlanes() {
  46. return Swimlanes.find({
  47. archived: true,
  48. boardId: Session.get('currentBoard'),
  49. }, {
  50. sort: { archivedAt: -1, modifiedAt: -1 },
  51. });
  52. },
  53. cardIsInArchivedList() {
  54. return this.currentData().list().archived;
  55. },
  56. onRendered() {
  57. // XXX We should support dragging a card from the sidebar to the board
  58. },
  59. events() {
  60. return [
  61. {
  62. 'click .js-restore-card'() {
  63. const card = this.currentData();
  64. if (card.canBeRestored()) {
  65. card.restore();
  66. }
  67. },
  68. 'click .js-restore-all-cards'() {
  69. this.archivedCards().forEach(card => {
  70. if (card.canBeRestored()) {
  71. card.restore();
  72. }
  73. });
  74. },
  75. 'click .js-delete-card': Popup.afterConfirm('cardDelete', function() {
  76. const cardId = this._id;
  77. Cards.remove(cardId);
  78. Popup.close();
  79. }),
  80. 'click .js-delete-all-cards': Popup.afterConfirm('cardDelete', () => {
  81. this.archivedCards().forEach(card => {
  82. Cards.remove(card._id);
  83. });
  84. Popup.close();
  85. }),
  86. 'click .js-restore-list'() {
  87. const list = this.currentData();
  88. list.restore();
  89. },
  90. 'click .js-restore-all-lists'() {
  91. this.archivedLists().forEach(list => {
  92. list.restore();
  93. });
  94. },
  95. 'click .js-delete-list': Popup.afterConfirm('listDelete', function() {
  96. this.remove();
  97. Popup.close();
  98. }),
  99. 'click .js-delete-all-lists': Popup.afterConfirm('listDelete', () => {
  100. this.archivedLists().forEach(list => {
  101. list.remove();
  102. });
  103. Popup.close();
  104. }),
  105. 'click .js-restore-swimlane'() {
  106. const swimlane = this.currentData();
  107. swimlane.restore();
  108. },
  109. 'click .js-restore-all-swimlanes'() {
  110. this.archivedSwimlanes().forEach(swimlane => {
  111. swimlane.restore();
  112. });
  113. },
  114. 'click .js-delete-swimlane': Popup.afterConfirm(
  115. 'swimlaneDelete',
  116. function() {
  117. this.remove();
  118. Popup.close();
  119. },
  120. ),
  121. 'click .js-delete-all-swimlanes': Popup.afterConfirm(
  122. 'swimlaneDelete',
  123. () => {
  124. this.archivedSwimlanes().forEach(swimlane => {
  125. swimlane.remove();
  126. });
  127. Popup.close();
  128. },
  129. ),
  130. },
  131. ];
  132. },
  133. }).register('archivesSidebar');
  134. Template.archivesSidebar.helpers({
  135. isBoardAdmin() {
  136. return Meteor.user().isBoardAdmin();
  137. },
  138. isWorker() {
  139. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  140. return (
  141. !currentBoard.hasAdmin(this.userId) && currentBoard.hasWorker(this.userId)
  142. );
  143. },
  144. });