boardsList.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. const subManager = new SubsManager();
  2. BlazeComponent.extendComponent({
  3. onCreated() {
  4. // Here is the only place that boards data needed, all boards data will stop sync when leaving this template.
  5. Meteor.subscribe('boards');
  6. Meteor.subscribe('setting');
  7. },
  8. boards() {
  9. return Boards.find({
  10. archived: false,
  11. 'members.userId': Meteor.userId(),
  12. }, {
  13. sort: ['title'],
  14. });
  15. },
  16. isStarred() {
  17. const user = Meteor.user();
  18. return user && user.hasStarred(this.currentData()._id);
  19. },
  20. hasOvertimeCards() {
  21. subManager.subscribe('board', this.currentData()._id);
  22. return this.currentData().hasOvertimeCards();
  23. },
  24. hasSpentTimeCards() {
  25. subManager.subscribe('board', this.currentData()._id);
  26. return this.currentData().hasSpentTimeCards();
  27. },
  28. isInvited() {
  29. const user = Meteor.user();
  30. return user && user.isInvitedTo(this.currentData()._id);
  31. },
  32. events() {
  33. return [{
  34. 'click .js-add-board': Popup.open('createBoard'),
  35. 'click .js-star-board'(evt) {
  36. const boardId = this.currentData()._id;
  37. Meteor.user().toggleBoardStar(boardId);
  38. evt.preventDefault();
  39. },
  40. 'click .js-accept-invite'() {
  41. const boardId = this.currentData()._id;
  42. Meteor.user().removeInvite(boardId);
  43. },
  44. 'click .js-decline-invite'() {
  45. const boardId = this.currentData()._id;
  46. Meteor.call('quitBoard', boardId, (err, ret) => {
  47. if (!err && ret) {
  48. Meteor.user().removeInvite(boardId);
  49. FlowRouter.go('home');
  50. }
  51. });
  52. },
  53. }];
  54. },
  55. }).register('boardList');