fix #I947I0 16版本的app_odoo_customize增加功能,可对菜单信息显示debug

This commit is contained in:
Chill
2024-02-28 16:34:00 +08:00
parent 570318b441
commit 1a2072d91e
5 changed files with 162 additions and 2 deletions

View File

@@ -0,0 +1,90 @@
/** @odoo-module **/
import {NavBar} from '@web/webclient/navbar/navbar';
import {useEffect, useRef} from '@odoo/owl';
import {patch} from 'web.utils';
import config from 'web.config';
import {qweb} from 'web.core';
patch(NavBar.components.MenuDropdown.prototype, 'app_odoo_customize/static/src/js/menu_dropdown.js', {
setup() {
this._super();
useEffect(() => this.addDebugTooltip());
},
addDebugTooltip() {
if (config.isDebug()) {
let dropdownDebugData = this.getDebugData()
$(this.rootRef.el).find('.dropdown-toggle')
.removeAttr('title')
.tooltip(this.getDebugTooltip(dropdownDebugData));
var self = this;
_.each($(this.rootRef.el).find('.dropdown-menu_group'), function (menuGroup, index) {
let $menuGroup = $(menuGroup);
let menuGroupDebugData = self.getMenuGroupDebugData($menuGroup);
$menuGroup.tooltip(self.getDebugTooltip(menuGroupDebugData));
})
}
},
getDebugData() {
return {
title: this.props.payload.name,
xmlid: this.props.payload.xmlid,
sequence: this.props.payload.sequence,
}
},
getMenuGroupDebugData($menuGroup) {
return {
title: $menuGroup.data('name'),
xmlid: $menuGroup.data('xmlid'),
sequence: $menuGroup.data('sequence'),
}
},
getDebugTooltip(debugData) {
return {
template: '<div class="tooltip tooltip-field-info" role="tooltip"><div class="arrow"></div><div class="tooltip-inner"></div></div>',
title: qweb.render('Menu.tooltip', debugData),
};
}
})
NavBar.components.MenuDropdown.props.payload = {
type: Object,
optional: true,
};
patch(NavBar.components.DropdownItem.prototype, 'app_odoo_customize/static/src/js/menu_item.js', {
setup() {
this._super();
useEffect(() => this.addDebugTooltip());
},
addDebugTooltip() {
if (config.isDebug()) {
let menuDebugData = this.getDebugData();
if (!menuDebugData) {
return;
}
$(`.dropdown-item[data-menu-xmlid="${menuDebugData.xmlid}"], .dropdown-item[data-section="${menuDebugData.id}"]`)
.removeAttr('title')
.tooltip(this.getDebugTooltip(menuDebugData));
}
},
getDebugData() {
if (!this.props.payload) {
return null;
}
return {
id: this.props.payload.id,
title: this.props.payload.name,
xmlid: this.props.payload.xmlid,
sequence: this.props.payload.sequence,
}
},
getDebugTooltip(debugData) {
return {
template: '<div class="tooltip tooltip-field-info" role="tooltip"><div class="arrow"></div><div class="tooltip-inner"></div></div>',
title: qweb.render('Menu.tooltip', debugData),
};
}
})
NavBar.components.DropdownItem.props.payload = {
type: Object,
optional: true,
};

View File

@@ -0,0 +1,58 @@
<?xml version="1.0" encoding="UTF-8"?>
<templates xml:space="preserve">
<t t-inherit="web.NavBar" t-inherit-mode="extension" owl="1">
<xpath expr="//DropdownItem" position="attributes">
<attribute name="payload">currentApp</attribute>
</xpath>
</t>
<t t-inherit="web.NavBar.AppsMenu" t-inherit-mode="extension" owl="1">
<xpath expr="//DropdownItem" position="attributes">
<attribute name="payload">app</attribute>
</xpath>
</t>
<t t-inherit="web.NavBar.SectionsMenu" t-inherit-mode="extension" owl="1">
<xpath expr="//DropdownItem" position="attributes">
<attribute name="payload">section</attribute>
</xpath>
<xpath expr="//MenuDropdown" position="attributes">
<attribute name="payload">section</attribute>
</xpath>
</t>
<t t-inherit="web.NavBar.SectionsMenu.Dropdown.MenuSlot" t-inherit-mode="extension" owl="1">
<xpath expr="//DropdownItem" position="attributes">
<attribute name="payload">item</attribute>
</xpath>
<xpath expr="//div[hasclass('dropdown-menu_group')]" position="attributes">
<attribute name="t-att-data-name">item.name</attribute>
<attribute name="t-att-data-xmlid">item.xmlid</attribute>
<attribute name="t-att-data-sequence">item.sequence</attribute>
</xpath>
</t>
<t t-inherit="web.NavBar.SectionsMenu.MoreDropdown" t-inherit-mode="extension" owl="1">
<xpath expr="//DropdownItem" position="attributes">
<attribute name="payload">section</attribute>
</xpath>
</t>
<t t-name="Menu.tooltip">
<div class="oe_tooltip_string" if="title" role="tooltip">
<t t-esc="title"/>
</div>
<ul class="oe_tooltip_technical" role="tooltip">
<li t-if="xmlid">
<span class="oe_tooltip_technical_title">XMLID:</span>
<t t-esc="xmlid"/>
</li>
<li t-if="typeof sequence === 'number'">
<span class="oe_tooltip_technical_title">Sequence:</span>
<t t-esc="sequence"/>
</li>
</ul>
</t>
</templates>