From c5d3036674fdd4345876f85cb1009d76daaf56ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Tue, 27 Nov 2012 15:29:44 +0100 Subject: [PATCH 1/5] [IMP] Needaction: couters are not counter with the menu anymore. Web-side: a call to get_needaction_data is performed to have action counters. Menus are then updated synchronously with this value. bzr revid: tde@openerp.com-20121127142944-m17zo62er5rh2lvg --- addons/web/controllers/main.py | 27 ++++++++++++++++++++++++--- addons/web/static/src/js/chrome.js | 15 +++++++++++++++ addons/web/tests/test_menu.py | 4 ++-- 3 files changed, 41 insertions(+), 5 deletions(-) diff --git a/addons/web/controllers/main.py b/addons/web/controllers/main.py index ad5dd21d0d8..99cd6711d33 100644 --- a/addons/web/controllers/main.py +++ b/addons/web/controllers/main.py @@ -1034,6 +1034,10 @@ class Menu(openerpweb.Controller): def load(self, req): return {'data': self.do_load(req)} + @openerpweb.jsonrequest + def load_needaction(self, req, menu_ids): + return {'data': self.do_load_needaction(req, menu_ids)} + @openerpweb.jsonrequest def get_user_roots(self, req): return self.do_get_user_roots(req) @@ -1071,13 +1075,13 @@ class Menu(openerpweb.Controller): context = req.session.eval_context(req.context) Menus = req.session.model('ir.ui.menu') - menu_roots = Menus.read(self.do_get_user_roots(req), ['name', 'sequence', 'parent_id', 'action', 'needaction_enabled', 'needaction_counter'], context) - menu_root = {'id': False, 'name': 'root', 'parent_id': [-1, ''], 'children' : menu_roots} + menu_roots = Menus.read(self.do_get_user_roots(req), ['name', 'sequence', 'parent_id', 'action', 'needaction_enabled'], context) + menu_root = {'id': False, 'name': 'root', 'parent_id': [-1, ''], 'children': menu_roots} # menus are loaded fully unlike a regular tree view, cause there are a # limited number of items (752 when all 6.1 addons are installed) menu_ids = Menus.search([], 0, False, False, context) - menu_items = Menus.read(menu_ids, ['name', 'sequence', 'parent_id', 'action', 'needaction_enabled', 'needaction_counter'], context) + menu_items = Menus.read(menu_ids, ['name', 'sequence', 'parent_id', 'action', 'needaction_enabled'], context) # adds roots at the end of the sequence, so that they will overwrite # equivalent menu items from full menu read when put into id:item # mapping, resulting in children being correctly set on the roots. @@ -1101,6 +1105,23 @@ class Menu(openerpweb.Controller): return menu_root + def do_load_needaction(self, req, menu_ids=False): + """ Loads needaction counters for all or some specific menu ids. + + :param req: A request object, with an OpenERP session attribute + :type req: < session -> OpenERPSession > + :return: the menu root + :rtype: dict('children': menu_nodes) + """ + context = req.session.eval_context(req.context) + Menus = req.session.model('ir.ui.menu') + + if menu_ids == False: + menu_ids = Menus.search([('needaction_enabled', '=', True)], context=context) + + menu_needaction_data = Menus.get_needaction_data(menu_ids, context) + return menu_needaction_data + @openerpweb.jsonrequest def action(self, req, menu_id): actions = load_actions_from_ir_values(req,'action', 'tree_but_open', diff --git a/addons/web/static/src/js/chrome.js b/addons/web/static/src/js/chrome.js index 1bca6bf94cd..c1a506fd107 100644 --- a/addons/web/static/src/js/chrome.js +++ b/addons/web/static/src/js/chrome.js @@ -835,6 +835,21 @@ instance.web.Menu = instance.web.Widget.extend({ } this.trigger('menu_loaded', data); this.has_been_loaded.resolve(); + // Now launch the fetch of needaction counters, asynchronous + this.rpc("web/menu/load_needaction", {menu_ids: false}).done(function(r) { + self.on_needaction_loaded(r); + }); + }, + on_needaction_loaded: function(data) { + var self = this; + this.needaction_data = data; + _.each(this.needaction_data.data, function (item, menu_id) { + var $item = self.$secondary_menus.find('a[data-menu="' + menu_id + '"]'); + $item.remove('oe_menu_counter'); + if (item.needaction_counter && item.needaction_counter > 0) { + $item.append('
' + item.needaction_counter + '
'); + } + }); }, limit_entries: function() { var maximum_visible_links = this.maximum_visible_links; diff --git a/addons/web/tests/test_menu.py b/addons/web/tests/test_menu.py index c5e1b948b67..5e1d61708e1 100644 --- a/addons/web/tests/test_menu.py +++ b/addons/web/tests/test_menu.py @@ -43,7 +43,7 @@ class LoadTest(unittest2.TestCase): [], 0, False, False, self.request.session.eval_context()) self.MockMenus.read.assert_called_with( [], ['name', 'sequence', 'parent_id', - 'action', 'needaction_enabled', 'needaction_counter'], + 'action', 'needaction_enabled'], self.request.session.eval_context()) self.assertListEqual( @@ -62,7 +62,7 @@ class LoadTest(unittest2.TestCase): self.MockMenus.read.assert_called_with( [1, 2, 3], ['name', 'sequence', 'parent_id', - 'action', 'needaction_enabled', 'needaction_counter'], + 'action', 'needaction_enabled'], self.request.session.eval_context()) self.assertEqual( From 10ba4e5e606ace471ad8b43e9224c78cfcf033e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Wed, 28 Nov 2012 12:05:20 +0100 Subject: [PATCH 2/5] [IMP] [TMP] controller: search for all menus to have their needaction info, because currently needaction_enabled is not searchable (non stored function field). Revert this revision when the column is back as stored. bzr revid: tde@openerp.com-20121128110520-wijh1sr5qvsch7b8 --- addons/web/controllers/main.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/addons/web/controllers/main.py b/addons/web/controllers/main.py index 517ef242684..7658d3de0b8 100644 --- a/addons/web/controllers/main.py +++ b/addons/web/controllers/main.py @@ -1117,7 +1117,9 @@ class Menu(openerpweb.Controller): Menus = req.session.model('ir.ui.menu') if menu_ids == False: - menu_ids = Menus.search([('needaction_enabled', '=', True)], context=context) + menu_ids = Menus.search([], context=context) + # TDE FIXME: set needaction_enabled column to store, to enable this more limited search + # menu_ids = Menus.search([('needaction_enabled', '=', True)], context=context) menu_needaction_data = Menus.get_needaction_data(menu_ids, context) return menu_needaction_data From f0087538ac10b05126fd158c29f4b2132ca9edc6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Thu, 29 Nov 2012 16:58:01 +0100 Subject: [PATCH 3/5] [IMP] as ir_ui_menu.needaction_enabled is back as store=True, we can filter the initial search for needaction_counters. bzr revid: tde@openerp.com-20121129155801-0wxdogo9o9emk6i4 --- addons/web/controllers/main.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/addons/web/controllers/main.py b/addons/web/controllers/main.py index 23dd42e32e1..9da87631fe1 100644 --- a/addons/web/controllers/main.py +++ b/addons/web/controllers/main.py @@ -1013,9 +1013,7 @@ class Menu(openerpweb.Controller): Menus = req.session.model('ir.ui.menu') if menu_ids == False: - menu_ids = Menus.search([], context=req.context) - # TDE FIXME: set needaction_enabled column to store, to enable this more limited search - # menu_ids = Menus.search([('needaction_enabled', '=', True)], context=req.context) + menu_ids = Menus.search([('needaction_enabled', '=', True)], context=req.context) menu_needaction_data = Menus.get_needaction_data(menu_ids, req.context) return menu_needaction_data From 0de15c9bbf84e86cafa84c7ab025f853e4d987d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Thu, 29 Nov 2012 17:14:28 +0100 Subject: [PATCH 4/5] [CLEAN] Moved needaction html into a dedicated template. bzr revid: tde@openerp.com-20121129161428-usvgdoykg0g0etr7 --- addons/web/static/src/js/chrome.js | 2 +- addons/web/static/src/xml/base.xml | 12 +++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/addons/web/static/src/js/chrome.js b/addons/web/static/src/js/chrome.js index 072d3582159..68493b36701 100644 --- a/addons/web/static/src/js/chrome.js +++ b/addons/web/static/src/js/chrome.js @@ -847,7 +847,7 @@ instance.web.Menu = instance.web.Widget.extend({ var $item = self.$secondary_menus.find('a[data-menu="' + menu_id + '"]'); $item.remove('oe_menu_counter'); if (item.needaction_counter && item.needaction_counter > 0) { - $item.append('
' + item.needaction_counter + '
'); + $item.append(QWeb.render("Menu.needaction_counter", { widget : item })); } }); }, diff --git a/addons/web/static/src/xml/base.xml b/addons/web/static/src/xml/base.xml index 62d8a872f25..7421027315b 100644 --- a/addons/web/static/src/xml/base.xml +++ b/addons/web/static/src/xml/base.xml @@ -388,14 +388,16 @@ t-att-data-action-model="menu.action ? menu.action.split(',')[0] : ''" t-att-data-action-id="menu.action ? menu.action.split(',')[1] : ''"> - -
- 99+ -
-
+ +
+ 99+ + +
+
+ From a5ca416f055871fb2765567c2cf2f06445c1d2ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Thu, 29 Nov 2012 17:42:53 +0100 Subject: [PATCH 5/5] [IMP] needaction counters: moved rpc call on the trigger menu_loaded, to be able to reload the needaction counters through this trigger. bzr revid: tde@openerp.com-20121129164253-j2vol27w0libpdsd --- addons/web/static/src/js/chrome.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/addons/web/static/src/js/chrome.js b/addons/web/static/src/js/chrome.js index 68493b36701..c6d216d128c 100644 --- a/addons/web/static/src/js/chrome.js +++ b/addons/web/static/src/js/chrome.js @@ -799,10 +799,18 @@ instance.web.client_actions.add("change_password", "instance.web.ChangePassword" instance.web.Menu = instance.web.Widget.extend({ template: 'Menu', init: function() { + var self = this; this._super.apply(this, arguments); this.has_been_loaded = $.Deferred(); this.maximum_visible_links = 'auto'; // # of menu to show. 0 = do not crop, 'auto' = algo this.data = {data:{children:[]}}; + this.on("menu_loaded", this, function (e) { + // launch the fetch of needaction counters, asynchronous + this.rpc("/web/menu/load_needaction", {menu_ids: false}).done(function(r) { + self.on_needaction_loaded(r); + }); + }); + }, start: function() { this._super.apply(this, arguments); @@ -835,10 +843,6 @@ instance.web.Menu = instance.web.Widget.extend({ } this.trigger('menu_loaded', data); this.has_been_loaded.resolve(); - // Now launch the fetch of needaction counters, asynchronous - this.rpc("web/menu/load_needaction", {menu_ids: false}).done(function(r) { - self.on_needaction_loaded(r); - }); }, on_needaction_loaded: function(data) { var self = this;