activities.js 3.7 KB

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