From ab8d00a5b756aa290acf104e1f52c597dac011cf Mon Sep 17 00:00:00 2001 From: prssanna Date: Fri, 8 Nov 2019 14:19:06 +0530 Subject: [PATCH] fix: make notification settings searchable --- .../notification_settings.json | 6 +-- .../frappe/ui/notifications/notifications.js | 37 +++++++++++++------ .../js/frappe/ui/toolbar/search_utils.js | 7 ++-- 3 files changed, 31 insertions(+), 19 deletions(-) diff --git a/frappe/desk/doctype/notification_settings/notification_settings.json b/frappe/desk/doctype/notification_settings/notification_settings.json index 68eec92125..c2f3633d63 100644 --- a/frappe/desk/doctype/notification_settings/notification_settings.json +++ b/frappe/desk/doctype/notification_settings/notification_settings.json @@ -72,15 +72,14 @@ "fieldname": "user", "fieldtype": "Link", "hidden": 1, - "in_list_view": 1, "label": "User", "options": "User", "read_only": 1 } ], "in_create": 1, - "modified": "2019-10-23 12:42:56.175928", - "modified_by": "Administrator", + "modified": "2019-11-08 14:11:35.619306", + "modified_by": "frappetestuser2@gmail.com", "module": "Desk", "name": "Notification Settings", "owner": "Administrator", @@ -97,7 +96,6 @@ "write": 1 } ], - "read_only": 1, "sort_field": "modified", "sort_order": "DESC", "track_changes": 1 diff --git a/frappe/public/js/frappe/ui/notifications/notifications.js b/frappe/public/js/frappe/ui/notifications/notifications.js index bce8e58fdf..3ccbc3318c 100644 --- a/frappe/public/js/frappe/ui/notifications/notifications.js +++ b/frappe/public/js/frappe/ui/notifications/notifications.js @@ -1,3 +1,5 @@ +frappe.provide('frappe.search'); + frappe.ui.Notifications = class Notifications { constructor() { frappe.model @@ -29,10 +31,30 @@ frappe.ui.Notifications = class Notifications { ); frappe.utils.bind_actions_with_object(this.$dropdown_list, this); + let me = this; + frappe.search.utils.make_function_searchable( + me.route_to_settings, + __('Notification Settings'), + [this.notifications_settings], + ) + this.setup_notifications(); this.bind_events(); } + route_to_settings(settings_doc) { + let method = + 'frappe.desk.doctype.notification_settings.notification_settings.create_notification_settings'; + + return Promise.resolve() + .then(() => { + if (!settings_doc) return frappe.call(method); + }) + .then(() => { + frappe.set_route(`#Form/Notification Settings/${frappe.session.user}`); + }); + } + setup_notifications() { this.get_notifications_list(this.max_length).then(list => { this.dropdown_items = list; @@ -249,7 +271,7 @@ frappe.ui.Notifications = class Notifications { } ); } - + mark_all_as_seen() { this.$dropdown_list.find('.unseen').removeClass('unseen'); let unseen_docnames = this.dropdown_items @@ -368,7 +390,7 @@ frappe.ui.Notifications = class Notifications { let mark_all_read_html = category.value === 'Notifications' ? ` - ${__('Mark All as Read')} + ${__('Mark all as Read')} ` : ''; let html = `
  • @@ -407,16 +429,7 @@ frappe.ui.Notifications = class Notifications { e.stopImmediatePropagation(); this.$dropdown.removeClass('open'); this.$dropdown.trigger('hide.bs.dropdown'); - let method = - 'frappe.desk.doctype.notification_settings.notification_settings.create_notification_settings'; - - return Promise.resolve() - .then(() => { - if (!this.notifications_settings) return frappe.call(method); - }) - .then(() => { - frappe.set_route(`#Form/Notification Settings/${frappe.session.user}`); - }); + this.route_to_settings(this.notifications_settings); } bind_events() { diff --git a/frappe/public/js/frappe/ui/toolbar/search_utils.js b/frappe/public/js/frappe/ui/toolbar/search_utils.js index c67c4b0b13..153a4dfa67 100644 --- a/frappe/public/js/frappe/ui/toolbar/search_utils.js +++ b/frappe/public/js/frappe/ui/toolbar/search_utils.js @@ -622,20 +622,21 @@ frappe.search.utils = { value: this.bolden_match_part(__(item.label), txt), index: this.fuzzy_search(txt, target), match: item.label, - onclick: item.action, + onclick: () => item.action.apply(this, item.args) }); } }); return results; }, - make_function_searchable(_function, label=null) { + make_function_searchable(_function, label=null, args=null) { if (typeof _function !== 'function') { throw new Error('First argument should be a function'); } this.searchable_functions.push({ 'label': label || _function.name, - 'action': _function + 'action': _function, + 'args': args, }); }, searchable_functions: [],