activities.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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. lastCustomField(){
  76. const lastCustomField = CustomFields.findOne(this.currentData().customFieldId);
  77. return lastCustomField.name;
  78. },
  79. lastCustomFieldValue(){
  80. const lastCustomField = CustomFields.findOne(this.currentData().customFieldId);
  81. const value = this.currentData().value;
  82. if (lastCustomField.settings.dropdownItems && lastCustomField.settings.dropdownItems.length > 0) {
  83. const dropDownValue = _.find(lastCustomField.settings.dropdownItems, (item) => {
  84. return item._id === value;
  85. });
  86. if (dropDownValue)
  87. return dropDownValue.name;
  88. }
  89. return value;
  90. },
  91. listLabel() {
  92. return this.currentData().list().title;
  93. },
  94. sourceLink() {
  95. const source = this.currentData().source;
  96. if(source) {
  97. if(source.url) {
  98. return Blaze.toHTML(HTML.A({
  99. href: source.url,
  100. }, source.system));
  101. } else {
  102. return source.system;
  103. }
  104. }
  105. return null;
  106. },
  107. memberLink() {
  108. return Blaze.toHTMLWithData(Template.memberName, {
  109. user: this.currentData().member(),
  110. });
  111. },
  112. attachmentLink() {
  113. const attachment = this.currentData().attachment();
  114. // trying to display url before file is stored generates js errors
  115. return attachment && attachment.url({ download: true }) && Blaze.toHTML(HTML.A({
  116. href: attachment.url({ download: true }),
  117. target: '_blank',
  118. }, attachment.name()));
  119. },
  120. customField() {
  121. const customField = this.currentData().customField();
  122. return customField.name;
  123. },
  124. events() {
  125. return [{
  126. // XXX We should use Popup.afterConfirmation here
  127. 'click .js-delete-comment'() {
  128. const commentId = this.currentData().commentId;
  129. CardComments.remove(commentId);
  130. },
  131. 'submit .js-edit-comment'(evt) {
  132. evt.preventDefault();
  133. const commentText = this.currentComponent().getValue().trim();
  134. const commentId = Template.parentData().commentId;
  135. if (commentText) {
  136. CardComments.update(commentId, {
  137. $set: {
  138. text: commentText,
  139. },
  140. });
  141. }
  142. },
  143. }];
  144. },
  145. }).register('activities');