activities.js 3.9 KB

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