activities.js 5.0 KB

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