sidebarArchives.js 4.4 KB

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