activities.js 3.2 KB

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