activities.js 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. const activitiesPerPage = 20;
  2. BlazeComponent.extendComponent({
  3. template() {
  4. return 'activities';
  5. },
  6. onCreated() {
  7. // XXX Should we use ReactiveNumber?
  8. this.page = new ReactiveVar(1);
  9. this.loadNextPageLocked = false;
  10. const sidebar = this.componentParent(); // XXX for some reason not working
  11. sidebar.callFirstWith(null, 'resetNextPeak');
  12. this.autorun(() => {
  13. const mode = this.data().mode;
  14. const capitalizedMode = Utils.capitalize(mode);
  15. const id = Session.get(`current${capitalizedMode}`);
  16. const limit = this.page.get() * activitiesPerPage;
  17. if (id === null)
  18. return;
  19. this.subscribe('activities', mode, id, limit, () => {
  20. this.loadNextPageLocked = false;
  21. // If the sibear peak hasn't increased, that mean that there are no more
  22. // activities, and we can stop calling new subscriptions.
  23. // XXX This is hacky! We need to know excatly and reactively how many
  24. // activities there are, we probably want to denormalize this number
  25. // dirrectly into card and board documents.
  26. const nextPeakBefore = sidebar.callFirstWith(null, 'getNextPeak');
  27. sidebar.calculateNextPeak();
  28. const nextPeakAfter = sidebar.callFirstWith(null, 'getNextPeak');
  29. if (nextPeakBefore === nextPeakAfter) {
  30. sidebar.callFirstWith(null, 'resetNextPeak');
  31. }
  32. });
  33. });
  34. },
  35. loadNextPage() {
  36. if (this.loadNextPageLocked === false) {
  37. this.page.set(this.page.get() + 1);
  38. this.loadNextPageLocked = true;
  39. }
  40. },
  41. boardLabel() {
  42. return TAPi18n.__('this-board');
  43. },
  44. cardLabel() {
  45. return TAPi18n.__('this-card');
  46. },
  47. cardLink() {
  48. const card = this.currentData().card();
  49. return card && Blaze.toHTML(HTML.A({
  50. href: card.absoluteUrl(),
  51. 'class': 'action-card',
  52. }, card.title));
  53. },
  54. memberLink() {
  55. return Blaze.toHTMLWithData(Template.memberName, {
  56. user: this.currentData().member(),
  57. });
  58. },
  59. attachmentLink() {
  60. const attachment = this.currentData().attachment();
  61. return attachment && Blaze.toHTML(HTML.A({
  62. href: attachment.url(),
  63. 'class': 'js-open-attachment-viewer',
  64. }, attachment.name()));
  65. },
  66. events() {
  67. return [{
  68. // XXX We should use Popup.afterConfirmation here
  69. 'click .js-delete-comment'() {
  70. const commentId = this.currentData().commentId;
  71. CardComments.remove(commentId);
  72. },
  73. 'submit .js-edit-comment'(evt) {
  74. evt.preventDefault();
  75. const commentText = this.currentComponent().getValue();
  76. const commentId = Template.parentData().commentId;
  77. if ($.trim(commentText)) {
  78. CardComments.update(commentId, {
  79. $set: {
  80. text: commentText,
  81. },
  82. });
  83. }
  84. },
  85. }];
  86. },
  87. }).register('activities');