From 73327db0656bfdd2bce2a69ca1c5c07ad3d3b763 Mon Sep 17 00:00:00 2001 From: Romain Derie Date: Mon, 3 Jun 2019 14:26:17 +0000 Subject: [PATCH] [IMP] *: add debug manager in frontend Now that the debug mode is stored in session, we need a clear indication that debug mode is activated. In backend, the 'fa-bug' is doing the trick but in frontend there is no visible clue that debug mode is enabled. This commit separate the debug manager code/feature so we can instanciate it in frontend only with usefull options (such as enable assets, leave debug mode..). Now, in frontend, people having access to the navbar (o_main_navbar) will see the same 'fa-bug' icon with minimal options as mentioned above. Also, in the footer, there will be another 'fa-bug' icon without any options. It will be usefull when the navbar is not shown, typically the case for public user, or for portal (without website installed)). Clicking on it will simply leave debug mode as hinted in tooltip. task-1934445 Comes with https://github.com/odoo/enterprise/pull/4281 Closes #33213 --- .../mail/static/src/js/tools/debug_manager.js | 4 +- .../views/unsubscribe_templates.xml | 1 + .../web/static/src/js/tools/debug_manager.js | 116 ++++++++++++ .../src/js/tools/debug_manager_backend.js | 168 ++---------------- addons/web/static/src/xml/base.xml | 104 ----------- addons/web/static/src/xml/debug.xml | 112 ++++++++++++ .../static/tests/helpers/test_utils_create.js | 2 +- addons/web/views/webclient_templates.xml | 15 +- .../web_tour/static/src/js/debug_manager.js | 4 +- .../web_tour/static/src/xml/debug_manager.xml | 2 +- .../static/src/js/menu/debug_manager.js | 20 +++ addons/website/views/website_templates.xml | 1 + 12 files changed, 281 insertions(+), 268 deletions(-) create mode 100644 addons/web/static/src/js/tools/debug_manager.js create mode 100644 addons/web/static/src/xml/debug.xml create mode 100644 addons/website/static/src/js/menu/debug_manager.js diff --git a/addons/mail/static/src/js/tools/debug_manager.js b/addons/mail/static/src/js/tools/debug_manager.js index 452a062806f..3a4c1d3c372 100644 --- a/addons/mail/static/src/js/tools/debug_manager.js +++ b/addons/mail/static/src/js/tools/debug_manager.js @@ -1,8 +1,8 @@ -odoo.define('mail.DebugManager', function (require) { +odoo.define('mail.DebugManager.Backend', function (require) { "use strict"; var core = require('web.core'); -var DebugManager = require('web.DebugManager'); +var DebugManager = require('web.DebugManager.Backend'); var _t = core._t; /** diff --git a/addons/mass_mailing/views/unsubscribe_templates.xml b/addons/mass_mailing/views/unsubscribe_templates.xml index bf7b4b54e84..793bb61034d 100644 --- a/addons/mass_mailing/views/unsubscribe_templates.xml +++ b/addons/mass_mailing/views/unsubscribe_templates.xml @@ -136,6 +136,7 @@ Odoo
+ Copyright © Company name
diff --git a/addons/web/static/src/js/tools/debug_manager.js b/addons/web/static/src/js/tools/debug_manager.js new file mode 100644 index 00000000000..db14dec2e36 --- /dev/null +++ b/addons/web/static/src/js/tools/debug_manager.js @@ -0,0 +1,116 @@ +odoo.define('web.DebugManager', function (require) { +"use strict"; + +var core = require('web.core'); +var session = require('web.session'); +var Widget = require('web.Widget'); + +var QWeb = core.qweb; + +/** + * DebugManager base + general features (applicable to any context) + */ +var DebugManager = Widget.extend({ + template: "WebClient.DebugManager", + xmlDependencies: ['/web/static/src/xml/debug.xml'], + events: { + "click a[data-action]": "perform_callback", + }, + init: function () { + this._super.apply(this, arguments); + this._events = null; + var debug = odoo.debug; + this.debug_mode = debug; + this.debug_mode_help = debug && debug !== '1' ? ' (' + debug + ')' : ''; + }, + start: function () { + core.bus.on('rpc:result', this, function (req, resp) { + this._debug_events(resp.debug); + }); + + this.$dropdown = this.$(".o_debug_dropdown"); + // whether the current user is an administrator + this._is_admin = session.is_system; + return Promise.resolve( + this._super() + ).then(function () { + return this.update(); + }.bind(this)); + }, + /** + * Calls the appropriate callback when clicking on a Debug option + */ + perform_callback: function (evt) { + evt.preventDefault(); + var params = $(evt.target).data(); + var callback = params.action; + + if (callback && this[callback]) { + // Perform the callback corresponding to the option + this[callback](params, evt); + } else { + console.warn("No handler for ", callback); + } + }, + + _debug_events: function (events) { + if (!this._events) { + return; + } + if (events && events.length) { + this._events.push(events); + } + this.trigger('update-stats', this._events); + }, + + /** + * Update the debug manager: reinserts all "universal" controls + */ + update: function () { + this.$dropdown + .empty() + .append(QWeb.render('WebClient.DebugManager.Global', { + manager: this, + })); + return Promise.resolve(); + }, + split_assets: function () { + window.location = $.param.querystring(window.location.href, 'debug=assets'); + }, + tests_assets: function () { + // Enable also 'assets' to see non minimized assets + window.location = $.param.querystring(window.location.href, 'debug=assets,tests'); + }, + /** + * Delete assets bundles to force their regeneration + * + * @returns {void} + */ + regenerateAssets: function () { + var self = this; + var domain = [ + ['res_model', '=', 'ir.ui.view'], + ['name', 'like', 'assets_'] + ]; + this._rpc({ + model: 'ir.attachment', + method: 'search', + args: [domain], + }).then(function (ids) { + self._rpc({ + model: 'ir.attachment', + method: 'unlink', + args: [ids], + }).then(window.location.reload()); + }); + }, + leave_debug_mode: function () { + var qs = $.deparam.querystring(); + qs.debug = ''; + window.location.search = '?' + $.param(qs); + }, +}); + +return DebugManager; + +}); diff --git a/addons/web/static/src/js/tools/debug_manager_backend.js b/addons/web/static/src/js/tools/debug_manager_backend.js index 29fe1123e1f..06cffa627bf 100644 --- a/addons/web/static/src/js/tools/debug_manager_backend.js +++ b/addons/web/static/src/js/tools/debug_manager_backend.js @@ -1,14 +1,13 @@ -odoo.define('web.DebugManager', function (require) { +odoo.define('web.DebugManager.Backend', function (require) { "use strict"; var ActionManager = require('web.ActionManager'); +var DebugManager = require('web.DebugManager'); var dialogs = require('web.view_dialogs'); var startClickEverywhere = require('web.clickEverywhere'); var config = require('web.config'); var core = require('web.core'); var Dialog = require('web.Dialog'); -var field_utils = require('web.field_utils'); -var session = require('web.session'); var SystrayMenu = require('web.SystrayMenu'); var utils = require('web.utils'); var WebClient = require('web.WebClient'); @@ -18,129 +17,16 @@ var QWeb = core.qweb; var _t = core._t; /** - * DebugManager base + general features (applicable to any context) + * DebugManager features depending on backend */ -var DebugManager = Widget.extend({ - template: "WebClient.DebugManager", - events: { - "click a[data-action]": "perform_callback", - "mouseover .o_debug_dropdowns > li:not(.show)": function(e) { - // Open other dropdowns on mouseover - var $opened = this.$('.o_debug_dropdowns > li.show'); - if($opened.length) { - $opened.removeClass('show'); - $(e.currentTarget).addClass('show').find('> a').focus(); - } - }, - }, - init: function () { - this._super.apply(this, arguments); - // 15 fps, only actually call after sequences of queries - this._update_stats = _.throttle( - this._update_stats.bind(this), - 1000/15, {leading: false}); - this._events = null; - if (document.querySelector('meta[name=debug]')) { - this._events = []; - } - }, - start: function () { - core.bus.on('rpc:result', this, function (req, resp) { - this._debug_events(resp.debug); - }); - this.on('update-stats', this, this._update_stats); - var init; - if ((init = document.querySelector('meta[name=debug]'))) { - this._debug_events(JSON.parse(init.getAttribute('value'))); - } - - this.$dropdown = this.$(".o_debug_dropdown"); - // falsy if can't write to user or couldn't find technical features - // group, otherwise features group id - this._features_group = null; - // whether group is currently enabled for current user - this._has_features = false; - // whether the current user is an administrator - this._is_admin = session.is_system; - return Promise.resolve( - this._rpc({ - model: 'res.users', - method: 'check_access_rights', - kwargs: {operation: 'write', raise_exception: false}, - }), - session.user_has_group('base.group_no_one'), - this._rpc({ - model: 'ir.model.data', - method: 'xmlid_to_res_id', - kwargs: {xmlid: 'base.group_no_one'}, - }), - this._super() - ).then(function (can_write_user, has_group_no_one, group_no_one_id) { - this._features_group = can_write_user && group_no_one_id; - this._has_features = has_group_no_one; - return this.update(); - }.bind(this)); - }, - leave_debug_mode: function () { - var qs = $.deparam.querystring(); - qs.debug = ''; - window.location.search = '?' + $.param(qs); - }, /** - * Calls the appropriate callback when clicking on a Debug option - */ - perform_callback: function (evt) { - evt.preventDefault(); - var params = $(evt.target).data(); - var callback = params.action; - - if (callback && this[callback]) { - // Perform the callback corresponding to the option - this[callback](params, evt); - } else { - console.warn("No handler for ", callback); - } - }, - - _debug_events: function (events) { - if (!this._events) { return; } - if (events && events.length) { - this._events.push(events); - } - this.trigger('update-stats', this._events); - }, +DebugManager.include({ requests_clear: function () { - if (!this._events) { return; } + if (!this._events) { + return; + } this._events = []; this.trigger('update-stats', this._events); }, - _update_stats: function (rqs) { - var requests = 0, rtime = 0, queries = 0, qtime = 0; - for(var r = 0; r < rqs.length; ++r) { - for (var i = 0; i < rqs[r].length; i++) { - var event = rqs[r][i]; - var query_start, request_start; - switch (event[0]) { - case 'request-start': - request_start = event[3] * 1e3; - break; - case 'request-end': - ++requests; - rtime += (event[3] * 1e3 - request_start) | 0; - break; - case 'sql-start': - query_start = event[3] * 1e3; - break; - case 'sql-end': - ++queries; - qtime += (event[3] * 1e3 - query_start) | 0; - break; - } - } - } - this.$('#debugmanager_requests_stats').text( - _.str.sprintf(_t("%d requests (%d ms) %d queries (%d ms)"), - requests, rtime, queries, qtime)); - }, show_timelines: function () { if (this._overlay) { this._overlay.destroy(); @@ -152,15 +38,14 @@ var DebugManager = Widget.extend({ }, /** - * Update the debug manager: reinserts all "universal" controls + * Updates current action (action descriptor) on tag = action, */ - update: function () { - this.$dropdown - .empty() - .append(QWeb.render('WebClient.DebugManager.Global', { + update: function (tag, descriptor) { + return this._super().then(function () { + this.$dropdown.find(".o_debug_split_assets").before(QWeb.render('WebClient.DebugManager.Backend', { manager: this, })); - return Promise.resolve(); + }.bind(this)); }, select_view: function () { var self = this; @@ -217,35 +102,6 @@ var DebugManager = Widget.extend({ $homeMenu.click(); startClickEverywhere(); }, - split_assets: function() { - window.location = $.param.querystring(window.location.href, 'debug=assets'); - }, - tests_assets: function () { - window.location = $.param.querystring(window.location.href, 'debug=tests'); - }, - /** - * Delete assets bundles to force their regeneration - * - * @returns {void} - */ - regenerateAssets: function () { - var self = this; - var domain = [ - ['res_model', '=', 'ir.ui.view'], - ['name', 'like', 'assets_'] - ]; - this._rpc({ - model: 'ir.attachment', - method: 'search', - args: [domain], - }).then(function (ids) { - self._rpc({ - model: 'ir.attachment', - method: 'unlink', - args: [ids], - }).then(self.do_action('reload')); - }); - } }); /** diff --git a/addons/web/static/src/xml/base.xml b/addons/web/static/src/xml/base.xml index 203d2326c3c..e34d017b1a4 100644 --- a/addons/web/static/src/xml/base.xml +++ b/addons/web/static/src/xml/base.xml @@ -218,110 +218,6 @@ - - - - - Run JS Tests - Run JS Mobile Tests - Run Click Everywhere Test - Open View - -