sidebarArchives.js 3.7 KB

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