mirror of
https://github.com/wekan/wekan.git
synced 2026-02-26 09:54:08 +01:00
Fix mentions and notifications drawer.
Thanks to xet7 ! Fixes #6062, fixes #6003, fixes #5996, fixes #5720, fixes #5911, fixes #5792, fixes #5163, fixes #4431, fixes #4126, fixes #3363, fixes #3150
This commit is contained in:
parent
0d5dd3082c
commit
20b5e2ab8f
14 changed files with 225 additions and 72 deletions
|
|
@ -14,41 +14,83 @@ Template.notificationsDrawer.onCreated(function() {
|
|||
});
|
||||
|
||||
Template.notificationsDrawer.helpers({
|
||||
notifications() {
|
||||
const user = ReactiveCache.getCurrentUser();
|
||||
return user ? user.notifications() : [];
|
||||
},
|
||||
transformedProfile() {
|
||||
return ReactiveCache.getCurrentUser();
|
||||
},
|
||||
readNotifications() {
|
||||
const readNotifications = _.filter(
|
||||
ReactiveCache.getCurrentUser().profile.notifications,
|
||||
v => !!v.read,
|
||||
);
|
||||
const user = ReactiveCache.getCurrentUser();
|
||||
const list = user ? user.notifications() : [];
|
||||
const readNotifications = _.filter(list, v => !!v.read);
|
||||
return readNotifications.length;
|
||||
},
|
||||
});
|
||||
|
||||
Template.notificationsDrawer.events({
|
||||
'click .all-read'() {
|
||||
const notifications = ReactiveCache.getCurrentUser().profile.notifications;
|
||||
for (const index in notifications) {
|
||||
if (notifications.hasOwnProperty(index) && !notifications[index].read) {
|
||||
const update = {};
|
||||
update[`profile.notifications.${index}.read`] = Date.now();
|
||||
Users.update(Meteor.userId(), { $set: update });
|
||||
'click .notification-menu-toggle'(event) {
|
||||
event.stopPropagation();
|
||||
Session.set('showNotificationMenu', !Session.get('showNotificationMenu'));
|
||||
},
|
||||
'click .notification-menu .menu-item'(event) {
|
||||
const target = event.currentTarget;
|
||||
|
||||
if (target.classList.contains('mark-all-read')) {
|
||||
const notifications = ReactiveCache.getCurrentUser().profile.notifications;
|
||||
for (const index in notifications) {
|
||||
if (notifications.hasOwnProperty(index) && !notifications[index].read) {
|
||||
const update = {};
|
||||
update[`profile.notifications.${index}.read`] = Date.now();
|
||||
Users.update(Meteor.userId(), { $set: update });
|
||||
}
|
||||
}
|
||||
Session.set('showNotificationMenu', false);
|
||||
} else if (target.classList.contains('mark-all-unread')) {
|
||||
const notifications = ReactiveCache.getCurrentUser().profile.notifications;
|
||||
for (const index in notifications) {
|
||||
if (notifications.hasOwnProperty(index) && notifications[index].read) {
|
||||
const update = {};
|
||||
update[`profile.notifications.${index}.read`] = null;
|
||||
Users.update(Meteor.userId(), { $set: update });
|
||||
}
|
||||
}
|
||||
Session.set('showNotificationMenu', false);
|
||||
} else if (target.classList.contains('delete-read')) {
|
||||
const user = ReactiveCache.getCurrentUser();
|
||||
for (const notification of user.profile.notifications) {
|
||||
if (notification.read) {
|
||||
user.removeNotification(notification.activity);
|
||||
}
|
||||
}
|
||||
Session.set('showNotificationMenu', false);
|
||||
} else if (target.classList.contains('delete-all')) {
|
||||
if (confirm(TAPi18n.__('delete-all-notifications-confirm'))) {
|
||||
const user = ReactiveCache.getCurrentUser();
|
||||
const notificationsCopy = [...user.profile.notifications];
|
||||
for (const notification of notificationsCopy) {
|
||||
user.removeNotification(notification.activity);
|
||||
}
|
||||
}
|
||||
Session.set('showNotificationMenu', false);
|
||||
} else if (target.classList.contains('selected')) {
|
||||
// Already selected, do nothing
|
||||
Session.set('showNotificationMenu', false);
|
||||
} else {
|
||||
// Toggle view
|
||||
Session.set('showReadNotifications', !Session.get('showReadNotifications'));
|
||||
Session.set('showNotificationMenu', false);
|
||||
}
|
||||
},
|
||||
'click .close'() {
|
||||
Session.set('showNotificationMenu', false);
|
||||
toggleNotificationsDrawer();
|
||||
},
|
||||
'click .toggle-read'() {
|
||||
Session.set('showReadNotifications', !Session.get('showReadNotifications'));
|
||||
},
|
||||
'click .remove-read'() {
|
||||
const user = ReactiveCache.getCurrentUser();
|
||||
for (const notification of user.profile.notifications) {
|
||||
if (notification.read) {
|
||||
user.removeNotification(notification.activity);
|
||||
}
|
||||
'click'(event) {
|
||||
// Close menu when clicking outside
|
||||
if (!event.target.closest('.notification-menu') && !event.target.closest('.notification-menu-toggle')) {
|
||||
Session.set('showNotificationMenu', false);
|
||||
}
|
||||
},
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue