boardsList.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. const subManager = new SubsManager();
  2. Template.boardListHeaderBar.events({
  3. 'click .js-open-archived-board'() {
  4. Modal.open('archivedBoards');
  5. },
  6. });
  7. Template.boardListHeaderBar.helpers({
  8. title(){
  9. return FlowRouter.getRouteName() == 'home' ? 'my-boards' :'public';
  10. },
  11. templatesBoardId() {
  12. return Meteor.user() && Meteor.user().getTemplatesBoardId();
  13. },
  14. templatesBoardSlug() {
  15. return Meteor.user() && Meteor.user().getTemplatesBoardSlug();
  16. },
  17. });
  18. BlazeComponent.extendComponent({
  19. onCreated() {
  20. Meteor.subscribe('setting');
  21. },
  22. boards() {
  23. let query = {
  24. archived: false,
  25. type: 'board',
  26. }
  27. if (FlowRouter.getRouteName() == 'home')
  28. query['members.userId'] = Meteor.userId()
  29. else
  30. query.permission = 'public'
  31. return Boards.find(
  32. query,
  33. { sort: ['title'] },
  34. );
  35. },
  36. isStarred() {
  37. const user = Meteor.user();
  38. return user && user.hasStarred(this.currentData()._id);
  39. },
  40. hasOvertimeCards() {
  41. subManager.subscribe('board', this.currentData()._id, false);
  42. return this.currentData().hasOvertimeCards();
  43. },
  44. hasSpentTimeCards() {
  45. subManager.subscribe('board', this.currentData()._id, false);
  46. return this.currentData().hasSpentTimeCards();
  47. },
  48. isInvited() {
  49. const user = Meteor.user();
  50. return user && user.isInvitedTo(this.currentData()._id);
  51. },
  52. events() {
  53. return [
  54. {
  55. 'click .js-add-board': Popup.open('createBoard'),
  56. 'click .js-star-board'(evt) {
  57. const boardId = this.currentData()._id;
  58. Meteor.user().toggleBoardStar(boardId);
  59. evt.preventDefault();
  60. },
  61. 'click .js-clone-board'(evt) {
  62. Meteor.call(
  63. 'cloneBoard',
  64. this.currentData()._id,
  65. Session.get('fromBoard'),
  66. (err, res) => {
  67. if (err) {
  68. this.setError(err.error);
  69. } else {
  70. Session.set('fromBoard', null);
  71. Utils.goBoardId(res);
  72. }
  73. },
  74. );
  75. evt.preventDefault();
  76. },
  77. 'click .js-archive-board'(evt) {
  78. const boardId = this.currentData()._id;
  79. Meteor.call('archiveBoard', boardId);
  80. evt.preventDefault();
  81. },
  82. 'click .js-accept-invite'() {
  83. const boardId = this.currentData()._id;
  84. Meteor.call('acceptInvite', boardId);
  85. },
  86. 'click .js-decline-invite'() {
  87. const boardId = this.currentData()._id;
  88. Meteor.call('quitBoard', boardId, (err, ret) => {
  89. if (!err && ret) {
  90. Meteor.call('acceptInvite', boardId);
  91. FlowRouter.go('home');
  92. }
  93. });
  94. },
  95. },
  96. ];
  97. },
  98. }).register('boardList');