Browse Source

[IMP] kpi_dashboard: Compute on fly, allow to refresh data on fly

12.0
Enric Tobella 4 years ago
parent
commit
593f7dc7a4
No known key found for this signature in database GPG Key ID: D76663C0B4023597
  1. 16
      kpi_dashboard/models/kpi_dashboard.py
  2. 22
      kpi_dashboard/static/src/js/dashboard_controller.js
  3. 13
      kpi_dashboard/static/src/js/dashboard_renderer.js
  4. 3
      kpi_dashboard/views/kpi_dashboard.xml

16
kpi_dashboard/models/kpi_dashboard.py

@ -16,6 +16,10 @@ class KpiDashboard(models.Model):
"kpi.dashboard.item", inverse_name="dashboard_id", copy=True,
)
number_of_columns = fields.Integer(default=5, required=True)
compute_on_fly_refresh = fields.Integer(
default=0,
help="Seconds to refresh on fly elements"
)
width = fields.Integer(compute="_compute_width")
margin_y = fields.Integer(default=10, required=True)
margin_x = fields.Integer(default=10, required=True)
@ -43,6 +47,15 @@ class KpiDashboard(models.Model):
+ rec.widget_dimension_x * rec.number_of_columns
)
def read_dashboard_on_fly(self):
self.ensure_one()
result = []
for item in self.item_ids:
if not item.kpi_id.compute_on_fly:
continue
result.append(item._read_dashboard())
return result
def read_dashboard(self):
self.ensure_one()
result = {
@ -52,6 +65,7 @@ class KpiDashboard(models.Model):
"max_cols": self.number_of_columns,
"margin_x": self.margin_x,
"margin_y": self.margin_y,
"compute_on_fly_refresh": self.compute_on_fly_refresh,
"widget_dimension_x": self.widget_dimension_x,
"widget_dimension_y": self.widget_dimension_y,
"background_color": self.background_color,
@ -167,7 +181,7 @@ class KpiDashboardItem(models.Model):
"kpi_id": self.kpi_id.id,
"suffix": self.kpi_id.suffix or "",
"prefix": self.kpi_id.prefix or "",
"compute_on_fly": self.kpi_id.compute_on_fly or "",
"compute_on_fly": self.kpi_id.compute_on_fly,
}
)
if self.kpi_id.compute_on_fly:

22
kpi_dashboard/static/src/js/dashboard_controller.js

@ -10,7 +10,29 @@ odoo.define('kpi_dashboard.DashboardController', function (require) {
var DashboardController = BasicController.extend({
custom_events: _.extend({}, BasicController.prototype.custom_events, {
addDashboard: '_addDashboard',
refresh_on_fly: '_refreshOnFly',
}),
_refreshOnFly: function (event) {
var self = this;
this._rpc({
model: this.modelName,
method: 'read_dashboard_on_fly',
args: [[this.renderer.state.res_id]],
context: _.extend(
{},
this.model.get(this.handle, {raw: true}).getContext(),
{bin_size: true}
),
}).then(function (data) {
_.each(data, function (item) {
// We will follow the same logic used on Bus Notifications
self.renderer._onNotification([[
"kpi_dashboard_" + self.renderer.state.res_id,
item
]])
});
});
},
renderPager: function ($node, options) {
options = _.extend({}, options, {
validate: this.canBeDiscarded.bind(this),

13
kpi_dashboard/static/src/js/dashboard_renderer.js

@ -53,8 +53,21 @@ odoo.define('kpi_dashboard.DashboardRenderer', function (require) {
'bus_service', 'onNotification',
this, this._onNotification
);
if (this.state.specialData.compute_on_fly_refresh > 0) {
// Setting the refresh interval
this.on_fly_interval = setInterval(function () {
self.trigger_up('refresh_on_fly');
}, this.state.specialData.compute_on_fly_refresh *1000);
};
return $.when();
},
on_detach_callback: function () {
// We want to clear the refresh interval once we exit the view
if (this.on_fly_interval) {
clearInterval(this.on_fly_interval)
}
this._super.apply(this, arguments);
},
_onNotification: function (notifications) {
var self = this;
_.each(notifications, function (notification) {

3
kpi_dashboard/views/kpi_dashboard.xml

@ -54,6 +54,9 @@
<group name="color">
<field name="background_color" widget="color"/>
</group>
<group name="config">
<field name="compute_on_fly_refresh"/>
</group>
</group>
</page>
<page name="group" string="Groups">

Loading…
Cancel
Save