activities.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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) return;
  25. this.subscribe('activities', mode, searchId, limit, hideSystem, () => {
  26. this.loadNextPageLocked = false;
  27. // If the sibear peak hasn't increased, that mean that there are no more
  28. // activities, and we can stop calling new subscriptions.
  29. // XXX This is hacky! We need to know excatly and reactively how many
  30. // activities there are, we probably want to denormalize this number
  31. // dirrectly into card and board documents.
  32. const nextPeakBefore = sidebar.callFirstWith(null, 'getNextPeak');
  33. sidebar.calculateNextPeak();
  34. const nextPeakAfter = sidebar.callFirstWith(null, 'getNextPeak');
  35. if (nextPeakBefore === nextPeakAfter) {
  36. sidebar.callFirstWith(null, 'resetNextPeak');
  37. }
  38. });
  39. });
  40. },
  41. loadNextPage() {
  42. if (this.loadNextPageLocked === false) {
  43. this.page.set(this.page.get() + 1);
  44. this.loadNextPageLocked = true;
  45. }
  46. },
  47. checkItem() {
  48. const checkItemId = this.currentData().checklistItemId;
  49. const checkItem = ChecklistItems.findOne({ _id: checkItemId });
  50. return checkItem.title;
  51. },
  52. boardLabel() {
  53. return TAPi18n.__('this-board');
  54. },
  55. cardLabel() {
  56. return TAPi18n.__('this-card');
  57. },
  58. cardLink() {
  59. const card = this.currentData().card();
  60. return (
  61. card &&
  62. Blaze.toHTML(
  63. HTML.A(
  64. {
  65. href: card.absoluteUrl(),
  66. class: 'action-card',
  67. },
  68. card.title,
  69. ),
  70. )
  71. );
  72. },
  73. lastLabel() {
  74. const lastLabelId = this.currentData().labelId;
  75. if (!lastLabelId) return null;
  76. const lastLabel = Boards.findOne(Session.get('currentBoard')).getLabelById(
  77. lastLabelId,
  78. );
  79. if (lastLabel.name === undefined || lastLabel.name === '') {
  80. return lastLabel.color;
  81. } else {
  82. return lastLabel.name;
  83. }
  84. },
  85. lastCustomField() {
  86. const lastCustomField = CustomFields.findOne(
  87. this.currentData().customFieldId,
  88. );
  89. if (!lastCustomField) return null;
  90. return lastCustomField.name;
  91. },
  92. lastCustomFieldValue() {
  93. const lastCustomField = CustomFields.findOne(
  94. this.currentData().customFieldId,
  95. );
  96. if (!lastCustomField) return null;
  97. const value = this.currentData().value;
  98. if (
  99. lastCustomField.settings.dropdownItems &&
  100. lastCustomField.settings.dropdownItems.length > 0
  101. ) {
  102. const dropDownValue = _.find(
  103. lastCustomField.settings.dropdownItems,
  104. item => {
  105. return item._id === value;
  106. },
  107. );
  108. if (dropDownValue) return dropDownValue.name;
  109. }
  110. return value;
  111. },
  112. listLabel() {
  113. return this.currentData().list().title;
  114. },
  115. sourceLink() {
  116. const source = this.currentData().source;
  117. if (source) {
  118. if (source.url) {
  119. return Blaze.toHTML(
  120. HTML.A(
  121. {
  122. href: source.url,
  123. },
  124. source.system,
  125. ),
  126. );
  127. } else {
  128. return source.system;
  129. }
  130. }
  131. return null;
  132. },
  133. memberLink() {
  134. return Blaze.toHTMLWithData(Template.memberName, {
  135. user: this.currentData().member(),
  136. });
  137. },
  138. attachmentLink() {
  139. const attachment = this.currentData().attachment();
  140. // trying to display url before file is stored generates js errors
  141. return (
  142. attachment &&
  143. attachment.url({ download: true }) &&
  144. Blaze.toHTML(
  145. HTML.A(
  146. {
  147. href: attachment.url({ download: true }),
  148. target: '_blank',
  149. },
  150. attachment.name(),
  151. ),
  152. )
  153. );
  154. },
  155. customField() {
  156. const customField = this.currentData().customField();
  157. if (!customField) return null;
  158. return customField.name;
  159. },
  160. events() {
  161. return [
  162. {
  163. // XXX We should use Popup.afterConfirmation here
  164. 'click .js-delete-comment'() {
  165. const commentId = this.currentData().commentId;
  166. CardComments.remove(commentId);
  167. },
  168. 'submit .js-edit-comment'(evt) {
  169. evt.preventDefault();
  170. const commentText = this.currentComponent()
  171. .getValue()
  172. .trim();
  173. const commentId = Template.parentData().commentId;
  174. if (commentText) {
  175. CardComments.update(commentId, {
  176. $set: {
  177. text: commentText,
  178. },
  179. });
  180. }
  181. },
  182. },
  183. ];
  184. },
  185. }).register('activities');