notificationsDrawer.js 1.7 KB

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