mirror of
https://github.com/OCA/web.git
synced 2025-02-22 13:21:25 +02:00
[MIG] web_advanced_search: Migration to 16.0
This commit is contained in:
committed by
Raf Ven
parent
1681eef37f
commit
c77f504757
@@ -6,7 +6,7 @@
|
||||
{
|
||||
"name": "Advanced search",
|
||||
"summary": "Easier and more powerful searching tools",
|
||||
"version": "15.0.1.1.1",
|
||||
"version": "16.0.1.0.0",
|
||||
"author": "Therp BV, Tecnativa, Camptocamp, Odoo Community Association (OCA)",
|
||||
"website": "https://github.com/OCA/web",
|
||||
"maintainers": ["ivantodorovich"],
|
||||
@@ -15,10 +15,9 @@
|
||||
"depends": ["web"],
|
||||
"assets": {
|
||||
"web.assets_backend": [
|
||||
"web_advanced_search/static/src/js/**/*.js",
|
||||
],
|
||||
"web.assets_qweb": [
|
||||
"web_advanced_search/static/src/xml/**/*.xml",
|
||||
],
|
||||
"web_advanced_search/static/src/js/**/*",
|
||||
"web_advanced_search/static/src/legacy/**/*",
|
||||
"web_advanced_search/static/src/search/**/*",
|
||||
]
|
||||
},
|
||||
}
|
||||
|
||||
@@ -2,12 +2,29 @@
|
||||
|
||||
import BasicModel from "web.BasicModel";
|
||||
import {ComponentAdapter} from "web.OwlCompatibility";
|
||||
import {FieldMany2One} from "web.relational_fields";
|
||||
import {Dropdown} from "@web/core/dropdown/dropdown";
|
||||
import FieldManagerMixin from "web.FieldManagerMixin";
|
||||
import {FieldMany2One} from "web.relational_fields";
|
||||
import {SelectCreateDialog} from "web.view_dialogs";
|
||||
import {patch} from "@web/core/utils/patch";
|
||||
import {session} from "@web/session";
|
||||
|
||||
const {Component} = owl;
|
||||
const {xml} = owl.tags;
|
||||
const {Component, xml} = owl;
|
||||
|
||||
patch(Dropdown.prototype, "dropdown", {
|
||||
onWindowClicked(ev) {
|
||||
// This patch is created to prevent the closing of the Filter menu
|
||||
// when a selection is made in the RecordPicker
|
||||
if (
|
||||
$(ev.target.closest("ul.dropdown-menu")).attr("id") !== undefined &&
|
||||
$(ev.target.closest("ul.dropdown-menu")).attr("id") ===
|
||||
$("body > ul.dropdown-menu").attr("id")
|
||||
) {
|
||||
return;
|
||||
}
|
||||
this._super(ev);
|
||||
},
|
||||
});
|
||||
|
||||
export const FakeMany2oneFieldWidget = FieldMany2One.extend(FieldManagerMixin, {
|
||||
/**
|
||||
@@ -55,6 +72,7 @@ export const FakeMany2oneFieldWidget = FieldMany2One.extend(FieldManagerMixin, {
|
||||
* Get record
|
||||
*
|
||||
* @param {BasicModel} model
|
||||
* @returns {String}
|
||||
*/
|
||||
_get_record: function (model) {
|
||||
return model.get(this.dataPointID);
|
||||
@@ -67,16 +85,6 @@ export const FakeMany2oneFieldWidget = FieldMany2One.extend(FieldManagerMixin, {
|
||||
this.dataPointID = id;
|
||||
return this.reset(this._get_record(this.model), event);
|
||||
},
|
||||
/**
|
||||
* Stop propagation of the autocompleteselect event.
|
||||
* Otherwise, the filter's dropdown will be closed after a selection.
|
||||
*
|
||||
* @override to stop propagating autocompleteselect event
|
||||
*/
|
||||
start: function () {
|
||||
this._super(...arguments);
|
||||
this.$input.on("autocompleteselect", (event) => event.stopPropagation());
|
||||
},
|
||||
/**
|
||||
* Stop propagation of the 'Search more..' dialog click event.
|
||||
* Otherwise, the filter's dropdown will be closed after a selection.
|
||||
@@ -102,17 +110,56 @@ export const FakeMany2oneFieldWidget = FieldMany2One.extend(FieldManagerMixin, {
|
||||
);
|
||||
return dialog.open();
|
||||
},
|
||||
_onFieldChanged: function (event) {
|
||||
const self = this;
|
||||
event.stopPropagation();
|
||||
if (event.data.changes.dummy.display_name === undefined) {
|
||||
return this._rpc({
|
||||
model: this.field.relation,
|
||||
method: "name_get",
|
||||
args: [event.data.changes.dummy.id],
|
||||
context: session.user_context,
|
||||
}).then(function (result) {
|
||||
event.data.changes.dummy.display_name = result[0][1];
|
||||
return (
|
||||
self
|
||||
._applyChanges(
|
||||
event.data.dataPointID,
|
||||
event.data.changes,
|
||||
event
|
||||
)
|
||||
// eslint-disable-next-line no-empty-function
|
||||
.then(event.data.onSuccess || function () {})
|
||||
// eslint-disable-next-line no-empty-function
|
||||
.guardedCatch(event.data.onFailure || function () {})
|
||||
);
|
||||
});
|
||||
}
|
||||
return (
|
||||
this._applyChanges(event.data.dataPointID, event.data.changes, event)
|
||||
// eslint-disable-next-line no-empty-function
|
||||
.then(event.data.onSuccess || function () {})
|
||||
// eslint-disable-next-line no-empty-function
|
||||
.guardedCatch(event.data.onFailure || function () {})
|
||||
);
|
||||
},
|
||||
});
|
||||
|
||||
export class FakeMany2oneFieldWidgetAdapter extends ComponentAdapter {
|
||||
setup() {
|
||||
this.env = owl.Component.env;
|
||||
constructor() {
|
||||
super(...arguments);
|
||||
this.env = Component.env;
|
||||
}
|
||||
async updateWidget() {
|
||||
/* eslint-disable no-empty-function */
|
||||
|
||||
renderWidget() {
|
||||
this.widget._render();
|
||||
}
|
||||
async renderWidget() {
|
||||
/* eslint-disable no-empty-function */
|
||||
|
||||
get widgetArgs() {
|
||||
if (this.props.widgetArgs) {
|
||||
return this.props.widgetArgs;
|
||||
}
|
||||
return [this.props.attrs];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
*/
|
||||
|
||||
import {_t} from "web.core";
|
||||
|
||||
const JOIN_MAPPING = {
|
||||
"&": _t(" and "),
|
||||
"|": _t(" or "),
|
||||
@@ -39,8 +38,8 @@ const HUMAN_DOMAIN_METHODS = {
|
||||
for (let x = 0; x < len; ++x) {
|
||||
const element = chain_splitted[x];
|
||||
chain.push(
|
||||
_.findWhere(this.fieldSelector.pages[x], {name: element}).string ||
|
||||
element
|
||||
_.findWhere(this.fieldSelector.popover.pages[x], {name: element})
|
||||
.string || element
|
||||
);
|
||||
}
|
||||
// Special beautiness for some values
|
||||
|
||||
@@ -1,23 +1,21 @@
|
||||
/** @odoo-module **/
|
||||
|
||||
import {getHumanDomain} from "../utils.esm";
|
||||
|
||||
import config from "web.config";
|
||||
import DomainSelectorDialog from "web.DomainSelectorDialog";
|
||||
import Domain from "web.Domain";
|
||||
import DomainSelectorDialog from "web.DomainSelectorDialog";
|
||||
import config from "web.config";
|
||||
import {getHumanDomain} from "../../../js/utils.esm";
|
||||
import {standaloneAdapter} from "web.OwlCompatibility";
|
||||
import {useModel} from "web.Model";
|
||||
const {Component, useRef} = owl;
|
||||
|
||||
const {Component, hooks} = owl;
|
||||
const {useRef} = hooks;
|
||||
|
||||
export default class AdvancedFilterItem extends Component {
|
||||
class AdvancedFilterItem extends Component {
|
||||
setup() {
|
||||
this.itemRef = useRef("dropdown-item");
|
||||
this.model = useModel("searchModel");
|
||||
}
|
||||
/**
|
||||
* Prevent propagation of dropdown-item-selected event, so that it
|
||||
* doesn't reaches the FilterMenu onFilterSelected event handler.
|
||||
* doesn't reach the FilterMenu onFilterSelected event handler.
|
||||
*/
|
||||
mounted() {
|
||||
$(this.itemRef.el).on("dropdown-item-selected", (event) =>
|
||||
@@ -30,8 +28,9 @@ export default class AdvancedFilterItem extends Component {
|
||||
* @returns {DomainSelectorDialog} The opened dialog itself.
|
||||
*/
|
||||
onClick() {
|
||||
const adapterParent = standaloneAdapter({Component});
|
||||
const dialog = new DomainSelectorDialog(
|
||||
this,
|
||||
adapterParent,
|
||||
this.model.config.modelName,
|
||||
"[]",
|
||||
{
|
||||
@@ -52,17 +51,9 @@ export default class AdvancedFilterItem extends Component {
|
||||
});
|
||||
return dialog.open();
|
||||
}
|
||||
/**
|
||||
* Mocks _trigger_up to redirect Odoo legacy events to OWL events.
|
||||
*
|
||||
* @private
|
||||
* @param {OdooEvent} event
|
||||
*/
|
||||
_trigger_up(event) {
|
||||
const {name, data} = event;
|
||||
data.__targetWidget = event.target;
|
||||
this.trigger(name.replace(/_/g, "-"), data);
|
||||
}
|
||||
}
|
||||
|
||||
AdvancedFilterItem.components = {AdvancedFilterItem};
|
||||
|
||||
AdvancedFilterItem.template = "web_advanced_search.AdvancedFilterItem";
|
||||
export default AdvancedFilterItem;
|
||||
@@ -1,14 +1,14 @@
|
||||
/** @odoo-module **/
|
||||
|
||||
import {patch} from "@web/core/utils/patch";
|
||||
import CustomFilterItem from "web.CustomFilterItem";
|
||||
import {RecordPicker} from "../RecordPicker.esm";
|
||||
import {RecordPicker} from "../../../js/RecordPicker.esm";
|
||||
import {patch} from "@web/core/utils/patch";
|
||||
|
||||
/**
|
||||
* Patches the CustomFilterItem for legacy widgets.
|
||||
*
|
||||
* Tree views still use this old legacy widget, so we need to patch it.
|
||||
* This is likely to dissapear in 16.0
|
||||
* This is likely to disappear in 17.0
|
||||
*/
|
||||
patch(CustomFilterItem.prototype, "web_advanced_search.legacy.CustomFilterItem", {
|
||||
/**
|
||||
@@ -1,14 +1,14 @@
|
||||
/** @odoo-module **/
|
||||
|
||||
import {patch} from "@web/core/utils/patch";
|
||||
import AdvancedFilterItem from "./advanced_filter_item.esm";
|
||||
import FilterMenu from "web.FilterMenu";
|
||||
import AdvancedFilterItem from "./AdvancedFilterItem.esm";
|
||||
import {patch} from "@web/core/utils/patch";
|
||||
|
||||
/**
|
||||
* Patches the FilterMenu for legacy widgets.
|
||||
*
|
||||
* Tree views still use this old legacy widget, so we need to patch it.
|
||||
* This is likely to dissapear in 16.0
|
||||
* This is likely to disappear in 17.0
|
||||
*/
|
||||
patch(FilterMenu, "web_advanced_search.legacy.FilterMenu", {
|
||||
components: {
|
||||
@@ -1,22 +1,19 @@
|
||||
/** @odoo-module **/
|
||||
|
||||
import {getHumanDomain} from "../utils.esm";
|
||||
|
||||
import config from "web.config";
|
||||
import DomainSelectorDialog from "web.DomainSelectorDialog";
|
||||
import Domain from "web.Domain";
|
||||
import {ComponentAdapter} from "web.OwlCompatibility";
|
||||
import DomainSelectorDialog from "web.DomainSelectorDialog";
|
||||
import config from "web.config";
|
||||
import {getHumanDomain} from "../../js/utils.esm";
|
||||
import {standaloneAdapter} from "web.OwlCompatibility";
|
||||
const {Component, useRef} = owl;
|
||||
|
||||
const {Component, hooks} = owl;
|
||||
const {useRef} = hooks;
|
||||
|
||||
export default class AdvancedFilterItem extends Component {
|
||||
class AdvancedFilterItem extends Component {
|
||||
setup() {
|
||||
this.itemRef = useRef("dropdown-item");
|
||||
}
|
||||
/**
|
||||
* Prevent propagation of dropdown-item-selected event, so that it
|
||||
* doesn't reaches the FilterMenu onFilterSelected event handler.
|
||||
* doesn't reach the FilterMenu onFilterSelected event handler.
|
||||
*/
|
||||
mounted() {
|
||||
$(this.itemRef.el).on("dropdown-item-selected", (event) =>
|
||||
@@ -29,7 +26,7 @@ export default class AdvancedFilterItem extends Component {
|
||||
* @returns {DomainSelectorDialog} The opened dialog itself.
|
||||
*/
|
||||
onClick() {
|
||||
const adapterParent = new ComponentAdapter(null, {Component});
|
||||
const adapterParent = standaloneAdapter({Component});
|
||||
const dialog = new DomainSelectorDialog(
|
||||
adapterParent,
|
||||
this.env.searchModel.resModel,
|
||||
@@ -54,4 +51,7 @@ export default class AdvancedFilterItem extends Component {
|
||||
}
|
||||
}
|
||||
|
||||
AdvancedFilterItem.components = {AdvancedFilterItem};
|
||||
|
||||
AdvancedFilterItem.template = "web_advanced_search.AdvancedFilterItem";
|
||||
export default AdvancedFilterItem;
|
||||
@@ -6,12 +6,10 @@
|
||||
-->
|
||||
<templates>
|
||||
<t t-name="web_advanced_search.AdvancedFilterItem" owl="1">
|
||||
<DropdownItem
|
||||
t-ref="dropdown-item"
|
||||
<a
|
||||
role="menuitem"
|
||||
t-on-click="onClick"
|
||||
class="o_add_advanced_search"
|
||||
>
|
||||
Add Advanced Filter
|
||||
</DropdownItem>
|
||||
class=" dropdown-item o_add_advanced_search"
|
||||
> Add Advanced Filter </a>
|
||||
</t>
|
||||
</templates>
|
||||
@@ -1,15 +1,11 @@
|
||||
/** @odoo-module **/
|
||||
|
||||
import {patch} from "@web/core/utils/patch";
|
||||
import {CustomFilterItem} from "@web/search/filter_menu/custom_filter_item";
|
||||
import {RecordPicker} from "../RecordPicker.esm";
|
||||
import {RecordPicker} from "../../js/RecordPicker.esm";
|
||||
import {patch} from "@web/core/utils/patch";
|
||||
|
||||
/**
|
||||
* Patches the CustomFilterItem for owl widgets.
|
||||
*
|
||||
* Pivot and Graph views use this new owl widget, so we need to patch it.
|
||||
* Other views like Tree use the old legacy widget that will probably dissapear
|
||||
* in 16.0. Until then, we need to patch both.
|
||||
*/
|
||||
patch(CustomFilterItem.prototype, "web_advanced_search.CustomFilterItem", {
|
||||
/**
|
||||
@@ -51,12 +47,17 @@ patch(CustomFilterItem.prototype, "web_advanced_search.CustomFilterItem", {
|
||||
const idx = this.indexOf(condition);
|
||||
const preFilter = preFilters[idx];
|
||||
const operator = self.OPERATORS[type][condition.operator];
|
||||
const descriptionArray = [
|
||||
field.string,
|
||||
operator.description,
|
||||
`"${condition.displayedValue}"`,
|
||||
];
|
||||
preFilter.description = descriptionArray.join(" ");
|
||||
if (
|
||||
["=", "!="].includes(operator.symbol) &&
|
||||
operator.value === undefined
|
||||
) {
|
||||
const descriptionArray = [
|
||||
field.string,
|
||||
operator.description,
|
||||
`"${condition.displayedValue}"`,
|
||||
];
|
||||
preFilter.description = descriptionArray.join(" ");
|
||||
}
|
||||
}
|
||||
}
|
||||
return preFilters;
|
||||
@@ -77,6 +78,19 @@ patch(CustomFilterItem.prototype, "web_advanced_search.CustomFilterItem", {
|
||||
condition.displayedValue = ev.detail.display_name;
|
||||
}
|
||||
},
|
||||
onValueChange(condition, ev) {
|
||||
if (!ev.target.value) {
|
||||
return this.setDefaultValue(condition);
|
||||
}
|
||||
const field = this.fields[condition.field];
|
||||
const type = this.FIELD_TYPES[field.type];
|
||||
if (type === "relational") {
|
||||
condition.value = ev.target.value;
|
||||
condition.displayedValue = ev.target.value;
|
||||
} else {
|
||||
this._super.apply(this, arguments);
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
patch(CustomFilterItem, "web_advanced_search.CustomFilterItem", {
|
||||
@@ -14,7 +14,7 @@
|
||||
model="fields[condition.field].relation"
|
||||
string="fields[condition.field].string"
|
||||
context="fields[condition.field].context"
|
||||
t-on-change="onRelationalChanged(condition)"
|
||||
t-on-change="(ev) => this.onRelationalChanged(condition,ev)"
|
||||
/>
|
||||
</t>
|
||||
</xpath>
|
||||
@@ -1,15 +1,10 @@
|
||||
/** @odoo-module **/
|
||||
|
||||
import {patch} from "@web/core/utils/patch";
|
||||
import AdvancedFilterItem from "./advanced_filter_item.esm";
|
||||
import {FilterMenu} from "@web/search/filter_menu/filter_menu";
|
||||
import AdvancedFilterItem from "./AdvancedFilterItem.esm";
|
||||
|
||||
import {patch} from "@web/core/utils/patch";
|
||||
/**
|
||||
* Patches the FilterMenu for owl widgets.
|
||||
*
|
||||
* Pivot and Graph views use this new owl widget, so we need to patch it.
|
||||
* Other views like Tree use the old legacy widget that will probably dissapear
|
||||
* in 16.0. Until then, we need to patch both.
|
||||
*/
|
||||
patch(FilterMenu, "web_advanced_search.FilterMenu", {
|
||||
components: {
|
||||
Reference in New Issue
Block a user