From d7186bfd8f9a10bd48aa367714241c57205ce9fb Mon Sep 17 00:00:00 2001 From: jssuzanne Date: Fri, 11 Jul 2014 09:52:13 +0200 Subject: [PATCH] [REF] profiler: Many changes (see list below) - Refactor the import - Add player - Update display with css - Add access rule to show or hide the player --- profiler/__openerp__.py | 10 ++-- .../__init__.py => controllers.py} | 23 +++++++- profiler/controllers/main.py | 0 profiler/security/group.xml | 11 ++++ profiler/static/src/css/player.css | 21 ++++++++ profiler/static/src/js/boot.js | 3 -- profiler/static/src/js/player.js | 53 +++++++++++++++++++ profiler/static/src/js/profiler.js | 32 ----------- profiler/static/src/xml/player.xml | 18 +++++++ profiler/view/menu.xml | 50 ----------------- 10 files changed, 128 insertions(+), 93 deletions(-) rename profiler/{controllers/__init__.py => controllers.py} (67%) delete mode 100644 profiler/controllers/main.py create mode 100644 profiler/security/group.xml create mode 100644 profiler/static/src/css/player.css delete mode 100644 profiler/static/src/js/boot.js create mode 100644 profiler/static/src/js/player.js delete mode 100644 profiler/static/src/js/profiler.js create mode 100644 profiler/static/src/xml/player.xml delete mode 100644 profiler/view/menu.xml diff --git a/profiler/__openerp__.py b/profiler/__openerp__.py index f7716809e..256705f47 100644 --- a/profiler/__openerp__.py +++ b/profiler/__openerp__.py @@ -31,18 +31,16 @@ 'website': 'http://anybox.fr', 'depends': ['base', 'web'], 'data': [ - 'view/menu.xml', - ], - 'test': [ - ], - 'demo': [ + 'security/group.xml', ], 'js': [ - 'static/src/js/profiler.js', + 'static/src/js/player.js', ], 'qweb': [ + 'static/src/xml/player.xml', ], 'css': [ + 'static/src/css/player.css', ], 'installable': True, 'application': False, diff --git a/profiler/controllers/__init__.py b/profiler/controllers.py similarity index 67% rename from profiler/controllers/__init__.py rename to profiler/controllers.py index 4d40bab28..89568e6e6 100644 --- a/profiler/controllers/__init__.py +++ b/profiler/controllers.py @@ -3,7 +3,7 @@ import logging from datetime import datetime from tempfile import mkstemp import openerp.addons.web.http as openerpweb -from .. import core +from . import core logger = logging.getLogger(__name__) @@ -12,20 +12,31 @@ class ProfilerController(openerpweb.Controller): _cp_path = '/web/profiler' + player_state = 'profiler_player_clear' + """Indicate the state(css class) of the player: + + * profiler_player_clear + * profiler_player_enabled + * profiler_player_disabled + """ + @openerpweb.jsonrequest def enable(self, request): logger.info("Enabling") core.enabled = True + ProfilerController.player_state = 'profiler_player_enabled' @openerpweb.jsonrequest def disable(self, request): logger.info("Disabling") - core.disabled = True + core.enabled = False + ProfilerController.player_state = 'profiler_player_disabled' @openerpweb.jsonrequest def clear(self, request): core.profile.clear() logger.info("Cleared stats") + ProfilerController.player_state = 'profiler_player_clear' @openerpweb.httprequest def dump(self, request, token): @@ -48,3 +59,11 @@ class ProfilerController(openerpweb.Controller): ('Content-Disposition', 'attachment; filename="%s"' % filename), ('Content-Type', 'application/octet-stream') ], cookies={'fileToken': int(token)}) + + @openerpweb.jsonrequest + def initial_state(self, request): + user = request.session.model('res.users') + return { + 'has_player_group': user.has_group('profiler.group_profiler_player'), + 'player_state': ProfilerController.player_state, + } diff --git a/profiler/controllers/main.py b/profiler/controllers/main.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/profiler/security/group.xml b/profiler/security/group.xml new file mode 100644 index 000000000..a34c11293 --- /dev/null +++ b/profiler/security/group.xml @@ -0,0 +1,11 @@ + + + + + Profiling capability + + + + + + diff --git a/profiler/static/src/css/player.css b/profiler/static/src/css/player.css new file mode 100644 index 000000000..42bb978c8 --- /dev/null +++ b/profiler/static/src/css/player.css @@ -0,0 +1,21 @@ +.openerp .oe_topbar_item.profiler_player img { + cursor: pointer; +} +.openerp .oe_topbar_item.profiler_player.profiler_player_enabled img.profiler_enable { + display: None; +} +.openerp .oe_topbar_item.profiler_player.profiler_player_enabled img.profiler_dump { + display: None; +} +.openerp .oe_topbar_item.profiler_player.profiler_player_disabled img.profiler_disable { + display: None; +} +.openerp .oe_topbar_item.profiler_player.profiler_player_clear img.profiler_disable { + display: None; +} +.openerp .oe_topbar_item.profiler_player.profiler_player_clear img.profiler_clear { + display: None; +} +.openerp .oe_topbar_item.profiler_player.profiler_player_clear img.profiler_dump { + display: None; +} diff --git a/profiler/static/src/js/boot.js b/profiler/static/src/js/boot.js deleted file mode 100644 index 6cf1540a1..000000000 --- a/profiler/static/src/js/boot.js +++ /dev/null @@ -1,3 +0,0 @@ -openerp.profiler = function(instance) { - openerp.profiler.profiler_enable(); - }; diff --git a/profiler/static/src/js/player.js b/profiler/static/src/js/player.js new file mode 100644 index 000000000..dfa807442 --- /dev/null +++ b/profiler/static/src/js/player.js @@ -0,0 +1,53 @@ +openerp.profiler = function(instance) { + instance.profiler.Player = instance.web.Widget.extend({ + template: 'profiler.player', + events: { + "click .profiler_enable": "enable", + "click .profiler_disable": "disable", + "click .profiler_clear": "clear", + "click .profiler_dump": "dump", + }, + apply_class: function(css_class) { + console.log(css_class) + this.$el.removeClass('profiler_player_enabled'); + this.$el.removeClass('profiler_player_disabled'); + this.$el.removeClass('profiler_player_clear'); + this.$el.addClass(css_class); + }, + enable: function() { + this.rpc('/web/profiler/enable', {}); + this.apply_class('profiler_player_enabled'); + }, + disable: function() { + this.rpc('/web/profiler/disable', {}); + this.apply_class('profiler_player_disabled'); + }, + clear: function() { + this.rpc('/web/profiler/clear', {}); + this.apply_class('profiler_player_clear'); + }, + dump: function() { + $.blockUI(); + this.session.get_file({ + url: '/web/profiler/dump', + complete: $.unblockUI + }); + }, + }); + + instance.web.UserMenu.include({ + do_update: function () { + var self = this; + this.update_promise.done(function () { + self.rpc('/web/profiler/initial_state', {}).done(function(state) { + if (state.has_player_group) { + this.profiler_player = new instance.profiler.Player(this); + this.profiler_player.prependTo(instance.webclient.$('.oe_systray')); + this.profiler_player.apply_class(state.player_state); + } + }); + }); + return this._super(); + }, + }); +}; diff --git a/profiler/static/src/js/profiler.js b/profiler/static/src/js/profiler.js deleted file mode 100644 index 1e06a108f..000000000 --- a/profiler/static/src/js/profiler.js +++ /dev/null @@ -1,32 +0,0 @@ -openerp.profiler = function(instance) { - openerp.profiler.profiler_enable(instance); - }; - -openerp.profiler.profiler_enable = function(instance) { - instance.profiler.controllers = { - 'profiler.enable': 'enable', - 'profiler.disable': 'disable', - 'profiler.clear': 'clear', - }; - instance.profiler.simple_action = function(parent, action) { - console.info(action); - parent.session.rpc('/web/profiler/' + instance.profiler.controllers[action.tag], {}); - }; - - instance.profiler.dump = function(parent, action) { - $.blockUI(); - parent.session.get_file({ - url: '/web/profiler/dump', - complete: $.unblockUI - }); - - }; - instance.web.client_actions.add("profiler.enable", - "instance.profiler.simple_action"); - instance.web.client_actions.add("profiler.disable", - "instance.profiler.simple_action"); - instance.web.client_actions.add("profiler.clear", - "instance.profiler.simple_action"); - instance.web.client_actions.add("profiler.dump", - "instance.profiler.dump"); -}; diff --git a/profiler/static/src/xml/player.xml b/profiler/static/src/xml/player.xml new file mode 100644 index 000000000..36c51dceb --- /dev/null +++ b/profiler/static/src/xml/player.xml @@ -0,0 +1,18 @@ + + +
+ + + + +
+
+
diff --git a/profiler/view/menu.xml b/profiler/view/menu.xml deleted file mode 100644 index c3cdc211f..000000000 --- a/profiler/view/menu.xml +++ /dev/null @@ -1,50 +0,0 @@ - - - - - - - - Enable Profiler - profiler.enable - - - - - Disable Profiler - profiler.disable - - - - - Dump Stats - profiler.dump - - - - - Clear Stats - profiler.clear - - - -