boardsList.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. isAdministrable() {
  41. const user = Meteor.user();
  42. return user && user.isBoardAdmin(this.currentData()._id);
  43. },
  44. hasOvertimeCards() {
  45. subManager.subscribe('board', this.currentData()._id, false);
  46. return this.currentData().hasOvertimeCards();
  47. },
  48. hasSpentTimeCards() {
  49. subManager.subscribe('board', this.currentData()._id, false);
  50. return this.currentData().hasSpentTimeCards();
  51. },
  52. isInvited() {
  53. const user = Meteor.user();
  54. return user && user.isInvitedTo(this.currentData()._id);
  55. },
  56. events() {
  57. return [
  58. {
  59. 'click .js-add-board': Popup.open('createBoard'),
  60. 'click .js-star-board'(evt) {
  61. const boardId = this.currentData()._id;
  62. Meteor.user().toggleBoardStar(boardId);
  63. evt.preventDefault();
  64. },
  65. 'click .js-clone-board'(evt) {
  66. Meteor.call(
  67. 'cloneBoard',
  68. this.currentData()._id,
  69. Session.get('fromBoard'),
  70. (err, res) => {
  71. if (err) {
  72. this.setError(err.error);
  73. } else {
  74. Session.set('fromBoard', null);
  75. Utils.goBoardId(res);
  76. }
  77. },
  78. );
  79. evt.preventDefault();
  80. },
  81. 'click .js-archive-board'(evt) {
  82. const boardId = this.currentData()._id;
  83. Meteor.call('archiveBoard', boardId);
  84. evt.preventDefault();
  85. },
  86. 'click .js-accept-invite'() {
  87. const boardId = this.currentData()._id;
  88. Meteor.call('acceptInvite', boardId);
  89. },
  90. 'click .js-decline-invite'() {
  91. const boardId = this.currentData()._id;
  92. Meteor.call('quitBoard', boardId, (err, ret) => {
  93. if (!err && ret) {
  94. Meteor.call('acceptInvite', boardId);
  95. FlowRouter.go('home');
  96. }
  97. });
  98. },
  99. },
  100. ];
  101. },
  102. }).register('boardList');