sidebarArchives.js 4.4 KB

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