activities.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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.parentComponent(); // 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. listLabel() {
  55. return this.currentData().list().title;
  56. },
  57. sourceLink() {
  58. const source = this.currentData().source;
  59. if(source) {
  60. if(source.url) {
  61. return Blaze.toHTML(HTML.A({
  62. href: source.url,
  63. }, source.system));
  64. } else {
  65. return source.system;
  66. }
  67. }
  68. return null;
  69. },
  70. memberLink() {
  71. return Blaze.toHTMLWithData(Template.memberName, {
  72. user: this.currentData().member(),
  73. });
  74. },
  75. attachmentLink() {
  76. const attachment = this.currentData().attachment();
  77. // trying to display url before file is stored generates js errors
  78. return attachment && attachment.url({ download: true }) && Blaze.toHTML(HTML.A({
  79. href: FlowRouter.path(attachment.url({ download: true })),
  80. target: '_blank',
  81. }, attachment.name()));
  82. },
  83. events() {
  84. return [{
  85. // XXX We should use Popup.afterConfirmation here
  86. 'click .js-delete-comment'() {
  87. const commentId = this.currentData().commentId;
  88. CardComments.remove(commentId);
  89. },
  90. 'submit .js-edit-comment'(evt) {
  91. evt.preventDefault();
  92. const commentText = this.currentComponent().getValue().trim();
  93. const commentId = Template.parentData().commentId;
  94. if (commentText) {
  95. CardComments.update(commentId, {
  96. $set: {
  97. text: commentText,
  98. },
  99. });
  100. }
  101. },
  102. }];
  103. },
  104. }).register('activities');