sidebarArchives.js 4.3 KB

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