mirror of
https://github.com/OCA/reporting-engine.git
synced 2025-02-16 16:30:38 +02:00
[MIG] kpi_dashboard: migration to 13.0
This commit is contained in:
@@ -1,3 +1,6 @@
|
||||
/*
|
||||
global py
|
||||
*/
|
||||
odoo.define("kpi_dashboard.DashboardController", function(require) {
|
||||
"use strict";
|
||||
|
||||
@@ -20,7 +23,7 @@ odoo.define("kpi_dashboard.DashboardController", function(require) {
|
||||
add_modify_color: "_addModifyColor",
|
||||
refresh_colors: "_refreshColors",
|
||||
}),
|
||||
_refreshOnFly: function(event) {
|
||||
_refreshOnFly: function() {
|
||||
var self = this;
|
||||
this._rpc({
|
||||
model: this.modelName,
|
||||
@@ -37,12 +40,14 @@ odoo.define("kpi_dashboard.DashboardController", function(require) {
|
||||
});
|
||||
},
|
||||
renderPager: function($node, options) {
|
||||
// eslint-disable-next-line no-param-reassign
|
||||
options = _.extend({}, options, {
|
||||
validate: this.canBeDiscarded.bind(this),
|
||||
});
|
||||
this._super($node, options);
|
||||
},
|
||||
_pushState: function(state) {
|
||||
// eslint-disable-next-line no-param-reassign
|
||||
state = state || {};
|
||||
var env = this.model.get(this.handle, {env: true});
|
||||
state.id = env.currentId;
|
||||
|
||||
@@ -4,7 +4,7 @@ odoo.define("kpi_dashboard.DashboardModel", function(require) {
|
||||
var BasicModel = require("web.BasicModel");
|
||||
|
||||
var DashboardModel = BasicModel.extend({
|
||||
_fetchRecord: function(record, options) {
|
||||
_fetchRecord: function(record) {
|
||||
return this._rpc({
|
||||
model: record.model,
|
||||
method: "read_dashboard",
|
||||
|
||||
@@ -4,7 +4,6 @@ odoo.define("kpi_dashboard.DashboardRenderer", function(require) {
|
||||
var BasicRenderer = require("web.BasicRenderer");
|
||||
var core = require("web.core");
|
||||
var registry = require("kpi_dashboard.widget_registry");
|
||||
var BusService = require("bus.BusService");
|
||||
var qweb = core.qweb;
|
||||
|
||||
var DashboardRenderer = BasicRenderer.extend({
|
||||
|
||||
50
kpi_dashboard/static/src/js/lib/nvd3.js
Normal file
50
kpi_dashboard/static/src/js/lib/nvd3.js
Normal file
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
global nv
|
||||
*/
|
||||
odoo.define("web.nvd3.extensions", function() {
|
||||
"use strict";
|
||||
|
||||
/**
|
||||
* The nvd3 library extensions and fixes should be done here to avoid patching
|
||||
* in place.
|
||||
*/
|
||||
|
||||
nv.dev = false;
|
||||
// Sets nvd3 library in production mode
|
||||
|
||||
// monkey patch nvd3 to allow removing eventhandler on windowresize events
|
||||
// see https://github.com/novus/nvd3/pull/396 for more details
|
||||
|
||||
// Adds a resize listener to the window.
|
||||
nv.utils.onWindowResize = function(fun) {
|
||||
if (fun === null) return;
|
||||
window.addEventListener("resize", fun);
|
||||
};
|
||||
|
||||
// Backwards compatibility with current API.
|
||||
nv.utils.windowResize = nv.utils.onWindowResize;
|
||||
|
||||
// Removes a resize listener from the window.
|
||||
nv.utils.offWindowResize = function(fun) {
|
||||
if (fun === null) return;
|
||||
window.removeEventListener("resize", fun);
|
||||
};
|
||||
|
||||
// Monkey patch nvd3 to prevent crashes when user changes view and nvd3
|
||||
// tries to remove tooltips after 500 ms... seriously nvd3, what were you
|
||||
// thinking?
|
||||
nv.tooltip.cleanup = function() {
|
||||
$(".nvtooltip").remove();
|
||||
};
|
||||
|
||||
// Monkey patch nvd3 to prevent it to display a tooltip (position: absolute)
|
||||
// with a negative `top`; with this patch the highest tooltip's position is
|
||||
// still in the graph
|
||||
var originalCalcTooltipPosition = nv.tooltip.calcTooltipPosition;
|
||||
nv.tooltip.calcTooltipPosition = function() {
|
||||
var container = originalCalcTooltipPosition.apply(this, arguments);
|
||||
container.style.top =
|
||||
container.style.top.split("px")[0] < 0 ? 0 + "px" : container.style.top;
|
||||
return container;
|
||||
};
|
||||
});
|
||||
@@ -7,9 +7,12 @@ odoo.define("kpi_dashboard.AbstractWidget", function(require) {
|
||||
var registry = require("kpi_dashboard.widget_registry");
|
||||
|
||||
var AbstractWidget = Widget.extend({
|
||||
template: "kpi_dashboard.base_widget", // Template used by the widget
|
||||
cssLibs: [], // Specific css of the widget
|
||||
jsLibs: [], // Specific Javascript libraries of the widget
|
||||
// Template used by the widget
|
||||
template: "kpi_dashboard.base_widget",
|
||||
// Specific css of the widget
|
||||
cssLibs: [],
|
||||
// Specific Javascript libraries of the widget
|
||||
jsLibs: [],
|
||||
events: {
|
||||
"click .o_kpi_dashboard_toggle_button": "_onClickToggleButton",
|
||||
"click .direct_action": "_onClickDirectAction",
|
||||
|
||||
@@ -3,7 +3,6 @@ odoo.define("kpi_dashboard.CounterWidget", function(require) {
|
||||
|
||||
var IntegerWidget = require("kpi_dashboard.IntegerWidget");
|
||||
var registry = require("kpi_dashboard.widget_registry");
|
||||
var field_utils = require("web.field_utils");
|
||||
|
||||
var CounterWidget = IntegerWidget.extend({
|
||||
shortList: [],
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
/*
|
||||
global nv, d3
|
||||
*/
|
||||
odoo.define("kpi_dashboard.GraphWidget", function(require) {
|
||||
"use strict";
|
||||
|
||||
@@ -9,11 +12,11 @@ odoo.define("kpi_dashboard.GraphWidget", function(require) {
|
||||
var GraphWidget = AbstractWidget.extend({
|
||||
template: "kpi_dashboard.graph",
|
||||
jsLibs: [
|
||||
"/web/static/lib/nvd3/d3.v3.js",
|
||||
"/web/static/lib/nvd3/nv.d3.js",
|
||||
"/web/static/src/js/libs/nvd3.js",
|
||||
"/kpi_dashboard/static/lib/nvd3/d3.v3.js",
|
||||
"/kpi_dashboard/static/lib/nvd3/nv.d3.js",
|
||||
"/kpi_dashboard/static/src/js/lib/nvd3.js",
|
||||
],
|
||||
cssLibs: ["/web/static/lib/nvd3/nv.d3.css"],
|
||||
cssLibs: ["/kpi_dashboard/static/lib/nvd3/nv.d3.css"],
|
||||
start: function() {
|
||||
this._onResize = this._onResize.bind(this);
|
||||
nv.utils.windowResize(this._onResize);
|
||||
@@ -28,7 +31,7 @@ odoo.define("kpi_dashboard.GraphWidget", function(require) {
|
||||
}
|
||||
this._super.apply(this, arguments);
|
||||
},
|
||||
_getChartOptions: function(values) {
|
||||
_getChartOptions: function() {
|
||||
return {
|
||||
x: function(d, u) {
|
||||
return u;
|
||||
|
||||
@@ -18,16 +18,17 @@ odoo.define("kpi_dashboard.IntegerWidget", function(require) {
|
||||
var suffix = "";
|
||||
var shortened = false;
|
||||
var digits = this.digits;
|
||||
var result = num;
|
||||
_.each(this.shortList, function(shortItem) {
|
||||
if (!shortened && Math.abs(num) >= shortItem[0]) {
|
||||
shortened = true;
|
||||
suffix = shortItem[1];
|
||||
num /= shortItem[0];
|
||||
result /= shortItem[0];
|
||||
digits = shortItem[2];
|
||||
}
|
||||
});
|
||||
return (
|
||||
field_utils.format.float(num, false, {
|
||||
field_utils.format.float(result, false, {
|
||||
digits: digits,
|
||||
}) + suffix
|
||||
);
|
||||
|
||||
@@ -21,8 +21,8 @@ odoo.define("kpi_dashboard.MeterWidget", function(require) {
|
||||
style: "Arch",
|
||||
width: 10,
|
||||
size: size,
|
||||
prepend: values.prefix !== undefined ? values.prefix : "",
|
||||
append: values.suffix !== undefined ? values.suffix : "",
|
||||
prepend: values.prefix === undefined ? "" : values.prefix,
|
||||
append: values.suffix === undefined ? "" : values.suffix,
|
||||
color: values.font_color,
|
||||
animate_text_colors: true,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user