activities.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. var activitiesPerPage = 20;
  2. BlazeComponent.extendComponent({
  3. template: function() {
  4. return 'activities';
  5. },
  6. onCreated: function() {
  7. var self = this;
  8. // XXX Should we use ReactiveNumber?
  9. self.page = new ReactiveVar(1);
  10. self.loadNextPageLocked = false;
  11. var sidebar = self.componentParent(); // XXX for some reason not working
  12. sidebar.callFirstWith(null, 'resetNextPeak');
  13. self.autorun(function() {
  14. var mode = self.data().mode;
  15. var capitalizedMode = Utils.capitalize(mode);
  16. var id = Session.get('current' + capitalizedMode);
  17. var limit = self.page.get() * activitiesPerPage;
  18. if (id === null)
  19. return;
  20. self.subscribe('activities', mode, id, limit, function() {
  21. self.loadNextPageLocked = false;
  22. // If the sibear peak hasn't increased, that mean that there are no more
  23. // activities, and we can stop calling new subscriptions.
  24. // XXX This is hacky! We need to know excatly and reactively how many
  25. // activities there are, we probably want to denormalize this number
  26. // dirrectly into card and board documents.
  27. var a = sidebar.callFirstWith(null, 'getNextPeak');
  28. sidebar.calculateNextPeak();
  29. var b = sidebar.callFirstWith(null, 'getNextPeak');
  30. if (a === b) {
  31. sidebar.callFirstWith(null, 'resetNextPeak');
  32. }
  33. });
  34. });
  35. },
  36. loadNextPage: function() {
  37. if (this.loadNextPageLocked === false) {
  38. this.page.set(this.page.get() + 1);
  39. this.loadNextPageLocked = true;
  40. }
  41. },
  42. boardLabel: function() {
  43. return TAPi18n.__('this-board');
  44. },
  45. cardLabel: function() {
  46. return TAPi18n.__('this-card');
  47. },
  48. cardLink: function() {
  49. var card = this.currentData().card();
  50. return Blaze.toHTML(HTML.A({
  51. href: card.absoluteUrl(),
  52. 'class': 'action-card'
  53. }, card.title));
  54. },
  55. memberLink: function() {
  56. return Blaze.toHTMLWithData(Template.memberName, {
  57. user: this.currentData().member()
  58. });
  59. },
  60. attachmentLink: function() {
  61. var attachment = this.currentData().attachment();
  62. return Blaze.toHTML(HTML.A({
  63. href: attachment.url(),
  64. 'class': 'js-open-attachment-viewer'
  65. }, attachment.name()));
  66. }
  67. }).register('activities');