[IMP] web_tour: add tour 'disabled' option
This commit changes the way tours are automatically disabled when in demo data. Previously, an override of the assets_common template was applied by a file loaded in the web_tour demo data, ensuring that the tours are disabled when demo data are loaded in the database. Now, a "tour_disable" boolean will be given to the session_info object to determine whether the tour manager must be disabled, meaning that it will automatically consume all registered tours. This has been done to improve consistency in asset bundles declarations by reducing them to the simplest possible templates. Part of task: 2352566 Co-authored-by: Julien Mougenot <jum@odoo.com> Co-authored-by: Simon Genin <ges@odoo.com>
This commit is contained in:
co-authored by
Simon Genin
parent
f1a0e164ea
commit
e0efbb08a4
@@ -1,11 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo>
|
||||
|
||||
<!-- Disable tours if Odoo installed with demo data. -->
|
||||
<template id="assets_common_disable_tour" name="disable tour" inherit_id="web.assets_common">
|
||||
<xpath expr="." position="inside">
|
||||
<script type="text/javascript" src="/web_tour/static/src/js/tour_disable.js"></script>
|
||||
</xpath>
|
||||
</template>
|
||||
|
||||
</odoo>
|
||||
@@ -9,7 +9,9 @@ class Http(models.AbstractModel):
|
||||
_inherit = 'ir.http'
|
||||
|
||||
def session_info(self):
|
||||
result = super(Http, self).session_info()
|
||||
result = super().session_info()
|
||||
if result['is_admin']:
|
||||
demo_modules_count = self.env['ir.module.module'].search_count([('demo', '=', True)])
|
||||
result['web_tours'] = request.env['web_tour.tour'].get_consumed_tours()
|
||||
result['tour_disable'] = demo_modules_count > 0
|
||||
return result
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
odoo.define('web_tour.DisableTour', function (require) {
|
||||
"use strict";
|
||||
|
||||
var local_storage = require('web.local_storage');
|
||||
var TourManager = require('web_tour.TourManager');
|
||||
var utils = require('web_tour.utils');
|
||||
|
||||
var get_debugging_key = utils.get_debugging_key;
|
||||
|
||||
TourManager.include({
|
||||
/**
|
||||
* Disables tours if Odoo installed with demo data.
|
||||
*
|
||||
* @override
|
||||
*/
|
||||
_register: function (do_update, tour, name) {
|
||||
// Consuming tours which are not run by test case nor currently being debugged
|
||||
if (!this.running_tour && !local_storage.getItem(get_debugging_key(name))) {
|
||||
this.consumed_tours.push(name);
|
||||
}
|
||||
return this._super.apply(this, arguments);
|
||||
},
|
||||
});
|
||||
|
||||
});
|
||||
@@ -26,7 +26,7 @@ var do_before_unload = utils.do_before_unload;
|
||||
var get_jquery_element_from_selector = utils.get_jquery_element_from_selector;
|
||||
|
||||
return core.Class.extend(mixins.EventDispatcherMixin, ServicesMixin, {
|
||||
init: function(parent, consumed_tours) {
|
||||
init: function(parent, consumed_tours, disabled = false) {
|
||||
mixins.EventDispatcherMixin.init.call(this);
|
||||
this.setParent(parent);
|
||||
|
||||
@@ -37,6 +37,7 @@ return core.Class.extend(mixins.EventDispatcherMixin, ServicesMixin, {
|
||||
this.consumed_tours = (consumed_tours || []).filter(tourName => {
|
||||
return !local_storage.getItem(get_debugging_key(tourName));
|
||||
});
|
||||
this.disabled = disabled;
|
||||
this.running_tour = local_storage.getItem(get_running_key());
|
||||
this.running_step_delay = parseInt(local_storage.getItem(get_running_delay_key()), 10) || 0;
|
||||
this.edition = (_.last(session.server_version_info) === 'e') ? 'enterprise' : 'community';
|
||||
@@ -128,6 +129,11 @@ return core.Class.extend(mixins.EventDispatcherMixin, ServicesMixin, {
|
||||
});
|
||||
},
|
||||
_register: function (do_update, tour, name) {
|
||||
const debuggingTour = local_storage.getItem(get_debugging_key(name));
|
||||
if (this.disabled && !this.running_tour && !debuggingTour) {
|
||||
this.consumed_tours.push(name);
|
||||
}
|
||||
|
||||
if (tour.ready) return Promise.resolve();
|
||||
|
||||
const tour_is_consumed = this._isTourConsumed(name);
|
||||
@@ -146,7 +152,6 @@ return core.Class.extend(mixins.EventDispatcherMixin, ServicesMixin, {
|
||||
|
||||
tour.ready = true;
|
||||
|
||||
const debuggingTour = local_storage.getItem(get_debugging_key(name));
|
||||
if (debuggingTour ||
|
||||
(do_update && (this.running_tour === name ||
|
||||
(!this.running_tour && !tour.test && !tour_is_consumed)))) {
|
||||
@@ -156,7 +161,7 @@ return core.Class.extend(mixins.EventDispatcherMixin, ServicesMixin, {
|
||||
},
|
||||
/**
|
||||
* Resets the given tour to its initial step, and prevent it from being
|
||||
* marked as consumed at reload, by the include in tour_disable.js
|
||||
* marked as consumed at reload.
|
||||
*
|
||||
* @param {string} tourName
|
||||
*/
|
||||
|
||||
@@ -5,6 +5,7 @@ var rootWidget = require('root.widget');
|
||||
var rpc = require('web.rpc');
|
||||
var session = require('web.session');
|
||||
var TourManager = require('web_tour.TourManager');
|
||||
const { device } = require('web.config');
|
||||
|
||||
const untrackedClassnames = ["o_tooltip", "o_tooltip_content", "o_tooltip_overlay"];
|
||||
|
||||
@@ -32,7 +33,8 @@ return session.is_bound.then(function () {
|
||||
}
|
||||
return Promise.all(defs).then(function (results) {
|
||||
var consumed_tours = session.is_frontend ? results[0] : session.web_tours;
|
||||
var tour_manager = new TourManager(rootWidget, consumed_tours);
|
||||
const disabled = session.tour_disable || device.isMobile;
|
||||
var tour_manager = new TourManager(rootWidget, consumed_tours, disabled);
|
||||
|
||||
function _isTrackedNode(node) {
|
||||
if (node.classList) {
|
||||
|
||||
@@ -18,12 +18,13 @@ odoo.define('web_tour.tour_manager_tests', async function (require) {
|
||||
* @param {Object} params
|
||||
* @param {string[]} [params.consumed_tours]
|
||||
* @param {boolean} [params.debug]
|
||||
* @param {boolean} [params.disabled]
|
||||
* @param {string} params.template inner HTML content of the widget
|
||||
* @param {Object[]} params.tours { {string} name, {Object} option, {Object[]} steps }
|
||||
*/
|
||||
async function createTourManager({ consumed_tours, debug, template, tours }) {
|
||||
async function createTourManager({ consumed_tours, debug, disabled, template, tours }) {
|
||||
const parent = await testUtils.createParent({ debug });
|
||||
const tourManager = new TourManager(parent, consumed_tours);
|
||||
const tourManager = new TourManager(parent, consumed_tours, disabled);
|
||||
tourManager.running_step_delay = 0;
|
||||
for (const { name, options, steps } of tours) {
|
||||
tourManager.register(name, options, steps);
|
||||
@@ -35,23 +36,13 @@ odoo.define('web_tour.tour_manager_tests', async function (require) {
|
||||
};
|
||||
await parent.prependTo(testUtils.prepareTarget(debug));
|
||||
parent.el.innerHTML = template;
|
||||
testUtils.mock.patch(TourManager, {
|
||||
// Since the `tour_disable.js` script automatically sets tours as consumed
|
||||
// as soon as they are registered, we override the "is consumed" to
|
||||
// assert that the tour is in the `consumed_tours` param key.
|
||||
_isTourConsumed: name => (consumed_tours || []).includes(name),
|
||||
});
|
||||
await tourManager._register_all(true);
|
||||
// Wait for possible tooltips to be loaded and appended.
|
||||
await testUtils.nextTick();
|
||||
return tourManager;
|
||||
}
|
||||
|
||||
QUnit.module("Tours", {
|
||||
afterEach() {
|
||||
testUtils.mock.unpatch(TourManager);
|
||||
},
|
||||
}, function () {
|
||||
QUnit.module("Tours", function () {
|
||||
|
||||
QUnit.module("Tour manager");
|
||||
|
||||
@@ -201,5 +192,26 @@ odoo.define('web_tour.tour_manager_tests', async function (require) {
|
||||
kanban.destroy();
|
||||
tourManager.destroy();
|
||||
});
|
||||
|
||||
QUnit.test("Automatic tour disabling", async function (assert) {
|
||||
assert.expect(2);
|
||||
|
||||
const options = {
|
||||
template: `<button class="btn anchor">Anchor</button>`,
|
||||
tours: [{ name: "Tour", options: {}, steps: [{ trigger: '.anchor' }] }],
|
||||
};
|
||||
|
||||
const enabledTM = await createTourManager({ disabled: false, ...options });
|
||||
|
||||
assert.containsOnce(document.body, '.o_tooltip:visible');
|
||||
|
||||
enabledTM.destroy();
|
||||
|
||||
const disabledTM = await createTourManager({ disabled: true, ...options });
|
||||
|
||||
assert.containsNone(document.body, '.o_tooltip:visible');
|
||||
|
||||
disabledTM.destroy();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user