boardsList.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. Meteor.subscribe('user-admin');
  8. },
  9. boards() {
  10. return Boards.find({
  11. archived: false,
  12. 'members.userId': Meteor.userId(),
  13. }, {
  14. sort: ['title'],
  15. });
  16. },
  17. isStarred() {
  18. const user = Meteor.user();
  19. return user && user.hasStarred(this.currentData()._id);
  20. },
  21. hasOvertimeCards() {
  22. subManager.subscribe('board', this.currentData()._id);
  23. return this.currentData().hasOvertimeCards();
  24. },
  25. hasSpentTimeCards() {
  26. subManager.subscribe('board', this.currentData()._id);
  27. return this.currentData().hasSpentTimeCards();
  28. },
  29. isInvited() {
  30. const user = Meteor.user();
  31. return user && user.isInvitedTo(this.currentData()._id);
  32. },
  33. events() {
  34. return [{
  35. 'click .js-add-board': Popup.open('createBoard'),
  36. 'click .js-star-board'(evt) {
  37. const boardId = this.currentData()._id;
  38. Meteor.user().toggleBoardStar(boardId);
  39. evt.preventDefault();
  40. },
  41. 'click .js-accept-invite'() {
  42. const boardId = this.currentData()._id;
  43. Meteor.user().removeInvite(boardId);
  44. },
  45. 'click .js-decline-invite'() {
  46. const boardId = this.currentData()._id;
  47. Meteor.call('quitBoard', boardId, (err, ret) => {
  48. if (!err && ret) {
  49. Meteor.user().removeInvite(boardId);
  50. FlowRouter.go('home');
  51. }
  52. });
  53. },
  54. }];
  55. },
  56. }).register('boardList');