notificationsDrawer.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import { toggleNotificationsDrawer } from './notifications.js';
  2. Template.notificationsDrawer.onCreated(function() {
  3. Meteor.subscribe('notificationActivities');
  4. Meteor.subscribe('notificationCards');
  5. Meteor.subscribe('notificationUsers');
  6. Meteor.subscribe('notificationsAttachments');
  7. Meteor.subscribe('notificationChecklistItems');
  8. Meteor.subscribe('notificationChecklists');
  9. Meteor.subscribe('notificationComments');
  10. Meteor.subscribe('notificationLists');
  11. Meteor.subscribe('notificationSwimlanes');
  12. });
  13. Template.notificationsDrawer.helpers({
  14. transformedProfile() {
  15. return Users.findOne(Meteor.userId());
  16. },
  17. readNotifications() {
  18. const readNotifications = _.filter(
  19. Meteor.user().profile.notifications,
  20. v => !!v.read,
  21. );
  22. return readNotifications.length;
  23. },
  24. });
  25. Template.notificationsDrawer.events({
  26. 'click .all-read'() {
  27. const notifications = Meteor.user().profile.notifications;
  28. for (const index in notifications) {
  29. if (notifications.hasOwnProperty(index) && !notifications[index].read) {
  30. const update = {};
  31. update[`profile.notifications.${index}.read`] = Date.now();
  32. Users.update(Meteor.userId(), { $set: update });
  33. }
  34. }
  35. },
  36. 'click .close'() {
  37. toggleNotificationsDrawer();
  38. },
  39. 'click .toggle-read'() {
  40. Session.set('showReadNotifications', !Session.get('showReadNotifications'));
  41. },
  42. 'click .remove-read'() {
  43. const user = Meteor.user();
  44. for (const notification of user.profile.notifications) {
  45. if (notification.read) {
  46. user.removeNotification(notification.activity);
  47. }
  48. }
  49. },
  50. });