mirror of https://github.com/OCA/web.git
[IMP] web_refresher: Be able to refresh from report views
parent
bc43787c65
commit
b842cf4e39
|
@ -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();
|
||||||
|
|
|
@ -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"
|
||||||
|
|
Loading…
Reference in New Issue