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

pull/2787/head
Carlos Roca 2024-04-09 10:22:49 +02:00
parent 8ffee9f78e
commit 6dc79241ed
2 changed files with 57 additions and 2 deletions

View File

@ -6,6 +6,7 @@
import {Component} from "@odoo/owl";
import {useDebounced} from "@web/core/utils/timing";
import {useService} from "@web/core/utils/hooks";
export function useRefreshAnimation(timeout) {
const refreshClass = "o_content__refresh";
@ -41,6 +42,7 @@ export function useRefreshAnimation(timeout) {
export class Refresher extends Component {
setup() {
super.setup();
this.action = useService("action");
this.refreshAnimation = useRefreshAnimation(1000);
this.onClickRefresh = useDebounced(this.onClickRefresh, 200);
}
@ -49,9 +51,11 @@ export class Refresher extends Component {
* @returns {Boolean}
*/
get displayButton() {
const {searchModel, pagerProps} = this.props;
const {searchModel, pagerProps, refresherReport} = this.props;
const hasSearchModel = searchModel && searchModel.search;
return Boolean(hasSearchModel || (pagerProps && pagerProps.onUpdate));
return Boolean(
refresherReport || hasSearchModel || (pagerProps && pagerProps.onUpdate)
);
}
/**
@ -92,7 +96,27 @@ export class Refresher extends Component {
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() {
if (this.props.refresherReport) {
return this.refreshReport();
}
const updated = await this.refresh();
if (updated) {
this.refreshAnimation();
@ -105,5 +129,6 @@ Object.assign(Refresher, {
props: {
searchModel: {type: Object, optional: true},
pagerProps: {type: Object, optional: true},
refresherReport: {type: Boolean, optional: true},
},
});

View File

@ -13,6 +13,16 @@
<Refresher t-props="refresherProps" />
</div>
</xpath>
<xpath expr="//div[hasclass('o_cp_bottom_right')]" position="before">
<div
t-if="!display['bottom-right']"
class="o_cp_bottom_right d-flex flex-row-reverse"
>
<div class="oe_cp_refresher" role="search" t-ref="refresher">
<Refresher refresherReport="true" />
</div>
</div>
</xpath>
</t>
<t
t-name="web_refresher.ControlPanel.Small"
@ -25,6 +35,16 @@
<Refresher t-props="refresherProps" />
</div>
</xpath>
<xpath expr="//div[hasclass('o_cp_bottom_right')]" position="before">
<div
t-if="!display['bottom-right']"
class="o_cp_bottom_right d-flex flex-row-reverse"
>
<div class="oe_cp_refresher" role="search" t-ref="refresher">
<Refresher refresherReport="true" />
</div>
</div>
</xpath>
</t>
<t
t-name="web_refresher.FormControlPanel"
@ -37,5 +57,15 @@
<Refresher t-props="refresherProps" />
</div>
</xpath>
<xpath expr="//div[hasclass('o_cp_bottom_right')]" position="before">
<div
t-if="!display['bottom-right']"
class="o_cp_bottom_right d-flex flex-row-reverse"
>
<div class="oe_cp_refresher" role="search" t-ref="refresher">
<Refresher refresherReport="true" />
</div>
</div>
</xpath>
</t>
</template>