mirror of https://github.com/OCA/web.git
[IMP] web_refresher: Be able to refresh from report views
parent
8ffee9f78e
commit
6dc79241ed
|
@ -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,6 +42,7 @@ 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);
|
||||||
}
|
}
|
||||||
|
@ -49,9 +51,11 @@ export class Refresher extends Component {
|
||||||
* @returns {Boolean}
|
* @returns {Boolean}
|
||||||
*/
|
*/
|
||||||
get displayButton() {
|
get displayButton() {
|
||||||
const {searchModel, pagerProps} = this.props;
|
const {searchModel, pagerProps, refresherReport} = this.props;
|
||||||
const hasSearchModel = searchModel && searchModel.search;
|
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;
|
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() {
|
||||||
|
if (this.props.refresherReport) {
|
||||||
|
return this.refreshReport();
|
||||||
|
}
|
||||||
const updated = await this.refresh();
|
const updated = await this.refresh();
|
||||||
if (updated) {
|
if (updated) {
|
||||||
this.refreshAnimation();
|
this.refreshAnimation();
|
||||||
|
@ -105,5 +129,6 @@ Object.assign(Refresher, {
|
||||||
props: {
|
props: {
|
||||||
searchModel: {type: Object, optional: true},
|
searchModel: {type: Object, optional: true},
|
||||||
pagerProps: {type: Object, optional: true},
|
pagerProps: {type: Object, optional: true},
|
||||||
|
refresherReport: {type: Boolean, optional: true},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
|
@ -13,6 +13,16 @@
|
||||||
<Refresher t-props="refresherProps" />
|
<Refresher t-props="refresherProps" />
|
||||||
</div>
|
</div>
|
||||||
</xpath>
|
</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
|
<t
|
||||||
t-name="web_refresher.ControlPanel.Small"
|
t-name="web_refresher.ControlPanel.Small"
|
||||||
|
@ -25,6 +35,16 @@
|
||||||
<Refresher t-props="refresherProps" />
|
<Refresher t-props="refresherProps" />
|
||||||
</div>
|
</div>
|
||||||
</xpath>
|
</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
|
<t
|
||||||
t-name="web_refresher.FormControlPanel"
|
t-name="web_refresher.FormControlPanel"
|
||||||
|
@ -37,5 +57,15 @@
|
||||||
<Refresher t-props="refresherProps" />
|
<Refresher t-props="refresherProps" />
|
||||||
</div>
|
</div>
|
||||||
</xpath>
|
</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>
|
||||||
</template>
|
</template>
|
||||||
|
|
Loading…
Reference in New Issue