[IMP] web_refresher: Be able to refresh from report views

pull/2800/head
Carlos Roca 2024-04-09 10:22:49 +02:00
parent bc43787c65
commit b842cf4e39
2 changed files with 24 additions and 15 deletions

View File

@ -6,6 +6,7 @@
import {Component} from "@odoo/owl"; import {Component} from "@odoo/owl";
import {useDebounced} from "@web/core/utils/timing"; import {useDebounced} from "@web/core/utils/timing";
import {useService} from "@web/core/utils/hooks";
export function useRefreshAnimation(timeout) { export function useRefreshAnimation(timeout) {
const refreshClass = "o_content__refresh"; const refreshClass = "o_content__refresh";
@ -41,19 +42,11 @@ export function useRefreshAnimation(timeout) {
export class Refresher extends Component { export class Refresher extends Component {
setup() { setup() {
super.setup(); super.setup();
this.action = useService("action");
this.refreshAnimation = useRefreshAnimation(1000); this.refreshAnimation = useRefreshAnimation(1000);
this.onClickRefresh = useDebounced(this.onClickRefresh, 200); this.onClickRefresh = useDebounced(this.onClickRefresh, 200);
} }
/**
* @returns {Boolean}
*/
get displayButton() {
const {searchModel, pagerProps} = this.props;
const hasSearchModel = searchModel && searchModel.search;
return Boolean(hasSearchModel || (pagerProps && pagerProps.onUpdate));
}
/** /**
* @returns {Boolean} * @returns {Boolean}
* @private * @private
@ -92,7 +85,28 @@ export class Refresher extends Component {
return updated; return updated;
} }
/**
* Function to refresh the views that has not the props
* required by the refresher, like ir.actions.report or
* ir.actions.client.
*/
async refreshReport() {
const viewAction = this.action.currentController.action;
const options = {};
if (this.env.config.breadcrumbs.length > 1) {
const breadcrumb = this.env.config.breadcrumbs.slice(-1);
await this.action.restore(breadcrumb.jsId);
} else {
options.clearBreadcrumbs = true;
}
this.action.doAction(viewAction, options);
}
async onClickRefresh() { async onClickRefresh() {
const {searchModel, pagerProps} = this.props;
if (!searchModel && !pagerProps) {
return this.refreshReport();
}
const updated = await this.refresh(); const updated = await this.refresh();
if (updated) { if (updated) {
this.refreshAnimation(); this.refreshAnimation();

View File

@ -4,12 +4,7 @@
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). --> License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
<template> <template>
<t t-name="web_refresher.Button"> <t t-name="web_refresher.Button">
<nav <nav class="oe_refresher" aria-label="Refresher" aria-atomic="true">
class="oe_refresher"
aria-label="Refresher"
aria-atomic="true"
t-if="displayButton"
>
<button <button
class="fa fa-refresh btn btn-icon oe_pager_refresh" class="fa fa-refresh btn btn-icon oe_pager_refresh"
aria-label="Refresh" aria-label="Refresh"