Browse Source
Merge pull request #212 from hbrunn/8.0-web_menu_navbar_needaction
Merge pull request #212 from hbrunn/8.0-web_menu_navbar_needaction
[ADD] web_menu_navbar_needactionpull/215/head
Guewen Baconnier
9 years ago
12 changed files with 320 additions and 0 deletions
-
58web_menu_navbar_needaction/README.rst
-
20web_menu_navbar_needaction/__init__.py
-
37web_menu_navbar_needaction/__openerp__.py
-
9web_menu_navbar_needaction/data/ir_config_parameter.xml
-
20web_menu_navbar_needaction/models/__init__.py
-
36web_menu_navbar_needaction/models/ir_ui_menu.py
-
BINweb_menu_navbar_needaction/static/description/icon.png
-
4web_menu_navbar_needaction/static/src/css/web_menu_navbar_needaction.css
-
78web_menu_navbar_needaction/static/src/js/web_menu_navbar_needaction.js
-
20web_menu_navbar_needaction/tests/__init__.py
-
27web_menu_navbar_needaction/tests/test_web_menu_navbar_needaction.py
-
11web_menu_navbar_needaction/views/templates.xml
@ -0,0 +1,58 @@ |
|||||
|
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg |
||||
|
:alt: License: AGPL-3 |
||||
|
================================ |
||||
|
Needaction counters in main menu |
||||
|
================================ |
||||
|
|
||||
|
This module shows the sum of all submenus' needaction counters in main menus. This way, users get visual feedback where there's still work to do without having to open the respective menu beforehand. |
||||
|
|
||||
|
The counters are updated periodically, so users will also be notified if there are new records that require attention. |
||||
|
|
||||
|
Configuration |
||||
|
============= |
||||
|
|
||||
|
To configure the update frequency, set the configuration parameter `web_menu_navbar_needaction.refresh_timeout` to the amount of milliseconds after which the counters should be updated. Don't do this too often, as this will cause a lot of queries to the database. The default it 600000, which is equivalent to 10 minutes. |
||||
|
|
||||
|
To disable updates, set the parameter to 0. |
||||
|
|
||||
|
Usage |
||||
|
===== |
||||
|
|
||||
|
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas |
||||
|
:alt: Try me on Runbot |
||||
|
:target: https://runbot.odoo-community.org/runbot/162/8.0 |
||||
|
|
||||
|
For further information, please visit: |
||||
|
|
||||
|
* https://www.odoo.com/forum/help-1 |
||||
|
|
||||
|
Bug Tracker |
||||
|
=========== |
||||
|
|
||||
|
Bugs are tracked on `GitHub Issues <https://github.com/OCA/web/issues>`_. |
||||
|
In case of trouble, please check there if your issue has already been reported. |
||||
|
If you spotted it first, help us smashing it by providing a detailed and welcomed feedback |
||||
|
`here <https://github.com/OCA/web/issues/new?body=module:%20web_menu_navbar_needaction%0Aversion:%208.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_. |
||||
|
|
||||
|
Credits |
||||
|
======= |
||||
|
|
||||
|
Contributors |
||||
|
------------ |
||||
|
|
||||
|
* Holger Brunn <hbrunn@therp.nl> |
||||
|
|
||||
|
Maintainer |
||||
|
---------- |
||||
|
|
||||
|
.. image:: https://odoo-community.org/logo.png |
||||
|
:alt: Odoo Community Association |
||||
|
:target: https://odoo-community.org |
||||
|
|
||||
|
This module is maintained by the OCA. |
||||
|
|
||||
|
OCA, or the Odoo Community Association, is a nonprofit organization whose |
||||
|
mission is to support the collaborative development of Odoo features and |
||||
|
promote its widespread use. |
||||
|
|
||||
|
To contribute to this module, please visit http://odoo-community.org. |
@ -0,0 +1,20 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
############################################################################## |
||||
|
# |
||||
|
# This module copyright (C) 2015 Therp BV <http://therp.nl>. |
||||
|
# |
||||
|
# This program is free software: you can redistribute it and/or modify |
||||
|
# it under the terms of the GNU Affero General Public License as |
||||
|
# published by the Free Software Foundation, either version 3 of the |
||||
|
# License, or (at your option) any later version. |
||||
|
# |
||||
|
# This program is distributed in the hope that it will be useful, |
||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
|
# GNU Affero General Public License for more details. |
||||
|
# |
||||
|
# You should have received a copy of the GNU Affero General Public License |
||||
|
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
||||
|
# |
||||
|
############################################################################## |
||||
|
from . import models |
@ -0,0 +1,37 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
############################################################################## |
||||
|
# |
||||
|
# This module copyright (C) 2015 Therp BV <http://therp.nl>. |
||||
|
# |
||||
|
# This program is free software: you can redistribute it and/or modify |
||||
|
# it under the terms of the GNU Affero General Public License as |
||||
|
# published by the Free Software Foundation, either version 3 of the |
||||
|
# License, or (at your option) any later version. |
||||
|
# |
||||
|
# This program is distributed in the hope that it will be useful, |
||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
|
# GNU Affero General Public License for more details. |
||||
|
# |
||||
|
# You should have received a copy of the GNU Affero General Public License |
||||
|
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
||||
|
# |
||||
|
############################################################################## |
||||
|
{ |
||||
|
"name": "Needaction counters in main menu", |
||||
|
"version": "8.0.1.0.0", |
||||
|
"author": "Therp BV,Odoo Community Association (OCA)", |
||||
|
"license": "AGPL-3", |
||||
|
"category": "Usability", |
||||
|
"summary": "Show the sum of submenus' needaction counters in main menu", |
||||
|
"depends": [ |
||||
|
'web', |
||||
|
], |
||||
|
"data": [ |
||||
|
"data/ir_config_parameter.xml", |
||||
|
'views/templates.xml', |
||||
|
], |
||||
|
"auto_install": False, |
||||
|
"installable": True, |
||||
|
"application": False, |
||||
|
} |
@ -0,0 +1,9 @@ |
|||||
|
<?xml version="1.0" encoding="UTF-8"?> |
||||
|
<openerp> |
||||
|
<data noupdate="1"> |
||||
|
<record id="ir_config_parameter_refresh_timeout" model="ir.config_parameter"> |
||||
|
<field name="key">web_menu_navbar_needaction.refresh_timeout</field> |
||||
|
<field name="value">600000</field> |
||||
|
</record> |
||||
|
</data> |
||||
|
</openerp> |
@ -0,0 +1,20 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
############################################################################## |
||||
|
# |
||||
|
# This module copyright (C) 2015 Therp BV <http://therp.nl>. |
||||
|
# |
||||
|
# This program is free software: you can redistribute it and/or modify |
||||
|
# it under the terms of the GNU Affero General Public License as |
||||
|
# published by the Free Software Foundation, either version 3 of the |
||||
|
# License, or (at your option) any later version. |
||||
|
# |
||||
|
# This program is distributed in the hope that it will be useful, |
||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
|
# GNU Affero General Public License for more details. |
||||
|
# |
||||
|
# You should have received a copy of the GNU Affero General Public License |
||||
|
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
||||
|
# |
||||
|
############################################################################## |
||||
|
from . import ir_ui_menu |
@ -0,0 +1,36 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
############################################################################## |
||||
|
# |
||||
|
# This module copyright (C) 2015 Therp BV (<http://therp.nl>). |
||||
|
# |
||||
|
# This program is free software: you can redistribute it and/or modify |
||||
|
# it under the terms of the GNU Affero General Public License as |
||||
|
# published by the Free Software Foundation, either version 3 of the |
||||
|
# License, or (at your option) any later version. |
||||
|
# |
||||
|
# This program is distributed in the hope that it will be useful, |
||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
|
# GNU Affero General Public License for more details. |
||||
|
# |
||||
|
# You should have received a copy of the GNU Affero General Public License |
||||
|
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
||||
|
# |
||||
|
############################################################################## |
||||
|
from openerp import models, api |
||||
|
|
||||
|
|
||||
|
class IrUiMenu(models.Model): |
||||
|
_inherit = 'ir.ui.menu' |
||||
|
|
||||
|
@api.multi |
||||
|
def get_navbar_needaction_data(self): |
||||
|
result = {} |
||||
|
for this in self: |
||||
|
result[this.id] = sum(map( |
||||
|
lambda x: x['needaction_counter'], |
||||
|
self.search([('id', 'child_of', this.ids)]) |
||||
|
._filter_visible_menus().get_needaction_data() |
||||
|
.itervalues()) |
||||
|
) |
||||
|
return result |
After Width: 80 | Height: 80 | Size: 1.1 KiB |
@ -0,0 +1,4 @@ |
|||||
|
#oe_main_menu_navbar .badge |
||||
|
{ |
||||
|
margin-left: .3em; |
||||
|
} |
@ -0,0 +1,78 @@ |
|||||
|
//-*- coding: utf-8 -*-
|
||||
|
//############################################################################
|
||||
|
//
|
||||
|
// This module copyright (C) 2015 Therp BV <http://therp.nl>.
|
||||
|
//
|
||||
|
// This program is free software: you can redistribute it and/or modify
|
||||
|
// it under the terms of the GNU Affero General Public License as
|
||||
|
// published by the Free Software Foundation, either version 3 of the
|
||||
|
// License, or (at your option) any later version.
|
||||
|
//
|
||||
|
// This program is distributed in the hope that it will be useful,
|
||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
|
// GNU Affero General Public License for more details.
|
||||
|
//
|
||||
|
// You should have received a copy of the GNU Affero General Public License
|
||||
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
//
|
||||
|
//############################################################################
|
||||
|
|
||||
|
openerp.web_menu_navbar_needaction = function(instance) |
||||
|
{ |
||||
|
instance.web.Menu.include({ |
||||
|
init: function() |
||||
|
{ |
||||
|
var self = this, |
||||
|
result = this._super.apply(this, arguments); |
||||
|
this.on('menu_bound', this, function() |
||||
|
{ |
||||
|
new instance.web.Model('ir.config_parameter') |
||||
|
.call('get_param', |
||||
|
['web_menu_navbar_needaction.refresh_timeout']) |
||||
|
.then(self.proxy(self.refresh_navbar_needaction)) |
||||
|
}); |
||||
|
return result; |
||||
|
}, |
||||
|
refresh_navbar_needaction: function(timeout) |
||||
|
{ |
||||
|
if(timeout) |
||||
|
{ |
||||
|
setTimeout(this.proxy(this.refresh_navbar_needaction), timeout, timeout); |
||||
|
} |
||||
|
return this.load_navbar_needaction(); |
||||
|
}, |
||||
|
load_navbar_needaction: function() |
||||
|
{ |
||||
|
this.navbar_menu_ids = this.$el.parents('body') |
||||
|
.find('#oe_main_menu_navbar a[data-menu]') |
||||
|
.filter(function() { return parseInt(jQuery(this).attr('data-menu')); }) |
||||
|
.map(function() { return parseInt(jQuery(this).attr('data-menu')); }) |
||||
|
.get(); |
||||
|
return new instance.web.Model('ir.ui.menu') |
||||
|
.call('get_navbar_needaction_data', [this.navbar_menu_ids]) |
||||
|
.then(this.proxy(this.process_navbar_needaction)); |
||||
|
}, |
||||
|
process_navbar_needaction: function(data) |
||||
|
{ |
||||
|
var self = this; |
||||
|
_.each(data, function (needaction_count, menu_id) |
||||
|
{ |
||||
|
var $item = self.$el.parents('body').find( |
||||
|
_.str.sprintf('#oe_main_menu_navbar a[data-menu="%s"]', |
||||
|
menu_id)); |
||||
|
if(!$item.length) |
||||
|
{ |
||||
|
return; |
||||
|
} |
||||
|
$item.find('.badge').remove(); |
||||
|
if(needaction_count) |
||||
|
{ |
||||
|
$item.append( |
||||
|
instance.web.qweb.render("Menu.needaction_counter", |
||||
|
{widget : {needaction_counter: needaction_count}})); |
||||
|
} |
||||
|
}); |
||||
|
}, |
||||
|
}) |
||||
|
} |
@ -0,0 +1,20 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
############################################################################## |
||||
|
# |
||||
|
# This module copyright (C) 2015 Therp BV <http://therp.nl>. |
||||
|
# |
||||
|
# This program is free software: you can redistribute it and/or modify |
||||
|
# it under the terms of the GNU Affero General Public License as |
||||
|
# published by the Free Software Foundation, either version 3 of the |
||||
|
# License, or (at your option) any later version. |
||||
|
# |
||||
|
# This program is distributed in the hope that it will be useful, |
||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
|
# GNU Affero General Public License for more details. |
||||
|
# |
||||
|
# You should have received a copy of the GNU Affero General Public License |
||||
|
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
||||
|
# |
||||
|
############################################################################## |
||||
|
from . import test_web_menu_navbar_needaction |
@ -0,0 +1,27 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
############################################################################## |
||||
|
# |
||||
|
# This module copyright (C) 2015 Therp BV <http://therp.nl>. |
||||
|
# |
||||
|
# This program is free software: you can redistribute it and/or modify |
||||
|
# it under the terms of the GNU Affero General Public License as |
||||
|
# published by the Free Software Foundation, either version 3 of the |
||||
|
# License, or (at your option) any later version. |
||||
|
# |
||||
|
# This program is distributed in the hope that it will be useful, |
||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
|
# GNU Affero General Public License for more details. |
||||
|
# |
||||
|
# You should have received a copy of the GNU Affero General Public License |
||||
|
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
||||
|
# |
||||
|
############################################################################## |
||||
|
from openerp.tests.common import TransactionCase |
||||
|
|
||||
|
|
||||
|
class TestWebMenuNavbarNeedaction(TransactionCase): |
||||
|
def test_web_menu_navbar_needaction(self): |
||||
|
main_menus = self.env['ir.ui.menu'].search([('parent_id', '=', False)]) |
||||
|
data = main_menus.get_navbar_needaction_data() |
||||
|
self.assertEqual(len(main_menus), len(data)) |
@ -0,0 +1,11 @@ |
|||||
|
<?xml version="1.0" encoding="UTF-8"?> |
||||
|
<openerp> |
||||
|
<data> |
||||
|
<template id="assets_backend" name="web_menu_navbar_needaction assets" inherit_id="web.assets_backend"> |
||||
|
<xpath expr="." position="inside"> |
||||
|
<script type="text/javascript" src="/web_menu_navbar_needaction/static/src/js/web_menu_navbar_needaction.js"></script> |
||||
|
<link rel="stylesheet" href="/web_menu_navbar_needaction/static/src/css/web_menu_navbar_needaction.css"/> |
||||
|
</xpath> |
||||
|
</template> |
||||
|
</data> |
||||
|
</openerp> |
Write
Preview
Loading…
Cancel
Save
Reference in new issue