sidebarArchives.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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. {
  32. archived: true,
  33. boardId: Session.get('currentBoard'),
  34. },
  35. {
  36. sort: { archivedAt: -1, modifiedAt: -1 },
  37. },
  38. );
  39. },
  40. archivedLists() {
  41. return Lists.find(
  42. {
  43. archived: true,
  44. boardId: Session.get('currentBoard'),
  45. },
  46. {
  47. sort: { archivedAt: -1, modifiedAt: -1 },
  48. },
  49. );
  50. },
  51. archivedSwimlanes() {
  52. return Swimlanes.find(
  53. {
  54. archived: true,
  55. boardId: Session.get('currentBoard'),
  56. },
  57. {
  58. sort: { archivedAt: -1, modifiedAt: -1 },
  59. },
  60. );
  61. },
  62. cardIsInArchivedList() {
  63. return this.currentData().list().archived;
  64. },
  65. onRendered() {
  66. // XXX We should support dragging a card from the sidebar to the board
  67. },
  68. events() {
  69. return [
  70. {
  71. 'click .js-restore-card'() {
  72. const card = this.currentData();
  73. if (card.canBeRestored()) {
  74. card.restore();
  75. }
  76. },
  77. 'click .js-restore-all-cards'() {
  78. this.archivedCards().forEach(card => {
  79. if (card.canBeRestored()) {
  80. card.restore();
  81. }
  82. });
  83. },
  84. 'click .js-delete-card': Popup.afterConfirm('cardDelete', function() {
  85. const cardId = this._id;
  86. Cards.remove(cardId);
  87. Popup.back();
  88. }),
  89. 'click .js-delete-all-cards': Popup.afterConfirm('cardDelete', () => {
  90. this.archivedCards().forEach(card => {
  91. Cards.remove(card._id);
  92. });
  93. Popup.back();
  94. }),
  95. 'click .js-restore-list'() {
  96. const list = this.currentData();
  97. list.restore();
  98. },
  99. 'click .js-restore-all-lists'() {
  100. this.archivedLists().forEach(list => {
  101. list.restore();
  102. });
  103. },
  104. 'click .js-delete-list': Popup.afterConfirm('listDelete', function() {
  105. this.remove();
  106. Popup.back();
  107. }),
  108. 'click .js-delete-all-lists': Popup.afterConfirm('listDelete', () => {
  109. this.archivedLists().forEach(list => {
  110. list.remove();
  111. });
  112. Popup.back();
  113. }),
  114. 'click .js-restore-swimlane'() {
  115. const swimlane = this.currentData();
  116. swimlane.restore();
  117. },
  118. 'click .js-restore-all-swimlanes'() {
  119. this.archivedSwimlanes().forEach(swimlane => {
  120. swimlane.restore();
  121. });
  122. },
  123. 'click .js-delete-swimlane': Popup.afterConfirm(
  124. 'swimlaneDelete',
  125. function() {
  126. this.remove();
  127. Popup.back();
  128. },
  129. ),
  130. 'click .js-delete-all-swimlanes': Popup.afterConfirm(
  131. 'swimlaneDelete',
  132. () => {
  133. this.archivedSwimlanes().forEach(swimlane => {
  134. swimlane.remove();
  135. });
  136. Popup.back();
  137. },
  138. ),
  139. },
  140. ];
  141. },
  142. }).register('archivesSidebar');
  143. Template.archivesSidebar.helpers({
  144. isBoardAdmin() {
  145. return Meteor.user().isBoardAdmin();
  146. },
  147. isWorker() {
  148. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  149. return (
  150. !currentBoard.hasAdmin(this.userId) && currentBoard.hasWorker(this.userId)
  151. );
  152. },
  153. });