activities.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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: FlowRouter.path(card.absoluteUrl()),
  51. 'class': 'action-card',
  52. }, card.title));
  53. },
  54. sourceLink() {
  55. const source = this.currentData().source;
  56. return source && Blaze.toHTML(HTML.A({
  57. href: source.url,
  58. }, source.system));
  59. },
  60. memberLink() {
  61. return Blaze.toHTMLWithData(Template.memberName, {
  62. user: this.currentData().member(),
  63. });
  64. },
  65. attachmentLink() {
  66. const attachment = this.currentData().attachment();
  67. return attachment && Blaze.toHTML(HTML.A({
  68. href: FlowRouter.path(attachment.url({ download: true })),
  69. target: '_blank',
  70. }, attachment.name()));
  71. },
  72. events() {
  73. return [{
  74. // XXX We should use Popup.afterConfirmation here
  75. 'click .js-delete-comment'() {
  76. const commentId = this.currentData().commentId;
  77. CardComments.remove(commentId);
  78. },
  79. 'submit .js-edit-comment'(evt) {
  80. evt.preventDefault();
  81. const commentText = this.currentComponent().getValue();
  82. const commentId = Template.parentData().commentId;
  83. if ($.trim(commentText)) {
  84. CardComments.update(commentId, {
  85. $set: {
  86. text: commentText,
  87. },
  88. });
  89. }
  90. },
  91. }];
  92. },
  93. }).register('activities');