[IMP] web: allow to use favorite in Knowledge embedded view
Purpose ======= Allow to use favorite in Knowledge embedded view. For that purpose, we need to hook some function in the web module (because favorites are stored in view arc and not using ir.filters records). Task-3251129 closes odoo/odoo#117188 Related: odoo/enterprise#39057 Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
This commit is contained in:
@@ -8,7 +8,7 @@
|
||||
<span class="o_dropdown_title">Favorites</span>
|
||||
</t>
|
||||
<t t-set="currentGroup" t-value="null"/>
|
||||
<t t-foreach="items" t-as="item" t-key="item.id or item.key">
|
||||
<t t-foreach="this.items" t-as="item" t-key="item.id or item.key">
|
||||
<t t-if="currentGroup !== null and currentGroup !== item.groupNumber">
|
||||
<div role="separator" class="dropdown-divider"/>
|
||||
</t>
|
||||
@@ -28,7 +28,7 @@
|
||||
</SearchDropdownItem>
|
||||
</t>
|
||||
<t t-else="">
|
||||
<t t-component="item.Component"/>
|
||||
<t t-component="item.Component" t-props="item.props"/>
|
||||
</t>
|
||||
<t t-set="currentGroup" t-value="item.groupNumber"/>
|
||||
</t>
|
||||
|
||||
@@ -154,10 +154,10 @@ const FAVORITE_PRIVATE_GROUP = 1;
|
||||
const FAVORITE_SHARED_GROUP = 2;
|
||||
|
||||
export class SearchModel extends EventBus {
|
||||
constructor(env, services) {
|
||||
constructor(env, services, args) {
|
||||
super();
|
||||
this.env = env;
|
||||
this.setup(services);
|
||||
this.setup(services, args);
|
||||
}
|
||||
/**
|
||||
* @override
|
||||
@@ -593,8 +593,7 @@ export class SearchModel extends EventBus {
|
||||
*/
|
||||
async createNewFavorite(params) {
|
||||
const { preFavorite, irFilter } = this._getIrFilterDescription(params);
|
||||
const serverSideId = await this.orm.call("ir.filters", "create_or_replace", [irFilter]);
|
||||
this.env.bus.trigger("CLEAR-CACHES");
|
||||
const serverSideId = await this._createIrFilters(irFilter);
|
||||
|
||||
// before the filter cache was cleared!
|
||||
this.blockNotification = true;
|
||||
@@ -616,6 +615,12 @@ export class SearchModel extends EventBus {
|
||||
this._notify();
|
||||
}
|
||||
|
||||
async _createIrFilters(irFilter) {
|
||||
const serverSideId = await this.orm.call("ir.filters", "create_or_replace", [irFilter]);
|
||||
this.env.bus.trigger("CLEAR-CACHES");
|
||||
return serverSideId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create new search items of type 'filter' and activate them.
|
||||
* A new group containing only those filters is created.
|
||||
@@ -702,9 +707,7 @@ export class SearchModel extends EventBus {
|
||||
if (searchItem.type !== "favorite") {
|
||||
return;
|
||||
}
|
||||
const { serverSideId } = searchItem;
|
||||
await this.orm.unlink("ir.filters", [serverSideId]);
|
||||
this.env.bus.trigger("CLEAR-CACHES");
|
||||
await this._deleteIrFilters(searchItem);
|
||||
const index = this.query.findIndex((queryElem) => queryElem.searchItemId === favoriteId);
|
||||
delete this.searchItems[favoriteId];
|
||||
if (index >= 0) {
|
||||
@@ -713,6 +716,12 @@ export class SearchModel extends EventBus {
|
||||
this._notify();
|
||||
}
|
||||
|
||||
async _deleteIrFilters(searchItem) {
|
||||
const { serverSideId } = searchItem;
|
||||
await this.orm.unlink("ir.filters", [serverSideId]);
|
||||
this.env.bus.trigger("CLEAR-CACHES");
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {Object}
|
||||
*/
|
||||
|
||||
@@ -18,11 +18,15 @@ export class WithSearch extends Component {
|
||||
}
|
||||
|
||||
const SearchModelClass = this.props.SearchModel || SearchModel;
|
||||
this.searchModel = new SearchModelClass(this.env, {
|
||||
user: useService("user"),
|
||||
orm: useService("orm"),
|
||||
view: useService("view"),
|
||||
});
|
||||
this.searchModel = new SearchModelClass(
|
||||
this.env,
|
||||
{
|
||||
user: useService("user"),
|
||||
orm: useService("orm"),
|
||||
view: useService("view"),
|
||||
},
|
||||
this.props.searchModelArgs
|
||||
);
|
||||
|
||||
useSubEnv({ searchModel: this.searchModel });
|
||||
|
||||
@@ -64,6 +68,7 @@ WithSearch.props = {
|
||||
resModel: String,
|
||||
|
||||
globalState: { type: Object, optional: true },
|
||||
searchModelArgs: { type: Object, optional: true },
|
||||
|
||||
display: { type: Object, optional: true },
|
||||
|
||||
|
||||
Reference in New Issue
Block a user