sidebarArchives.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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)
  12. return;
  13. const handle = subManager.subscribe('board', currentBoardId, true);
  14. Tracker.nonreactive(() => {
  15. Tracker.autorun(() => {
  16. this.isArchiveReady.set( handle.ready() );
  17. });
  18. });
  19. });
  20. },
  21. tabs() {
  22. return [
  23. { name: TAPi18n.__('cards'), slug: 'cards' },
  24. { name: TAPi18n.__('lists'), slug: 'lists' },
  25. { name: TAPi18n.__('swimlanes'), slug: 'swimlanes' },
  26. ];
  27. },
  28. archivedCards() {
  29. return Cards.find({
  30. archived: true,
  31. boardId: Session.get('currentBoard'),
  32. });
  33. },
  34. archivedLists() {
  35. return Lists.find({
  36. archived: true,
  37. boardId: Session.get('currentBoard'),
  38. });
  39. },
  40. archivedSwimlanes() {
  41. return Swimlanes.find({
  42. archived: true,
  43. boardId: Session.get('currentBoard'),
  44. });
  45. },
  46. cardIsInArchivedList() {
  47. return this.currentData().list().archived;
  48. },
  49. onRendered() {
  50. // XXX We should support dragging a card from the sidebar to the board
  51. },
  52. events() {
  53. return [{
  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('swimlaneDelete', function() {
  107. this.remove();
  108. Popup.close();
  109. }),
  110. 'click .js-delete-all-swimlanes': Popup.afterConfirm('swimlaneDelete', () => {
  111. this.archivedSwimlanes().forEach((swimlane) => {
  112. swimlane.remove();
  113. });
  114. Popup.close();
  115. }),
  116. }];
  117. },
  118. }).register('archivesSidebar');