activities.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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. checkItem(){
  49. const checkItemId = this.currentData().checklistItemId;
  50. const checkItem = ChecklistItems.findOne({_id:checkItemId});
  51. return checkItem.title;
  52. },
  53. boardLabel() {
  54. return TAPi18n.__('this-board');
  55. },
  56. cardLabel() {
  57. return TAPi18n.__('this-card');
  58. },
  59. cardLink() {
  60. const card = this.currentData().card();
  61. return card && Blaze.toHTML(HTML.A({
  62. href: card.absoluteUrl(),
  63. 'class': 'action-card',
  64. }, card.title));
  65. },
  66. lastLabel(){
  67. const lastLabelId = this.currentData().labelId;
  68. const lastLabel = Boards.findOne(Session.get('currentBoard')).getLabelById(lastLabelId);
  69. if(lastLabel.name === undefined || lastLabel.name === ''){
  70. return lastLabel.color;
  71. }else{
  72. return lastLabel.name;
  73. }
  74. },
  75. listLabel() {
  76. return this.currentData().list().title;
  77. },
  78. sourceLink() {
  79. const source = this.currentData().source;
  80. if(source) {
  81. if(source.url) {
  82. return Blaze.toHTML(HTML.A({
  83. href: source.url,
  84. }, source.system));
  85. } else {
  86. return source.system;
  87. }
  88. }
  89. return null;
  90. },
  91. memberLink() {
  92. return Blaze.toHTMLWithData(Template.memberName, {
  93. user: this.currentData().member(),
  94. });
  95. },
  96. attachmentLink() {
  97. const attachment = this.currentData().attachment();
  98. // trying to display url before file is stored generates js errors
  99. return attachment && attachment.url({ download: true }) && Blaze.toHTML(HTML.A({
  100. href: attachment.url({ download: true }),
  101. target: '_blank',
  102. }, attachment.name()));
  103. },
  104. customField() {
  105. const customField = this.currentData().customField();
  106. return customField.name;
  107. },
  108. events() {
  109. return [{
  110. // XXX We should use Popup.afterConfirmation here
  111. 'click .js-delete-comment'() {
  112. const commentId = this.currentData().commentId;
  113. CardComments.remove(commentId);
  114. },
  115. 'submit .js-edit-comment'(evt) {
  116. evt.preventDefault();
  117. const commentText = this.currentComponent().getValue().trim();
  118. const commentId = Template.parentData().commentId;
  119. if (commentText) {
  120. CardComments.update(commentId, {
  121. $set: {
  122. text: commentText,
  123. },
  124. });
  125. }
  126. },
  127. }];
  128. },
  129. }).register('activities');