sidebarArchives.js 4.0 KB

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