activities.js 3.4 KB

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