-
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
229 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...tic/src/fields/automation_activity.esm.js → ...ation_activity/automation_activity.esm.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 104 additions & 0 deletions
104
automation_oca/static/src/fields/automation_graph/automation_graph.esm.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
/** @odoo-module **/ | ||
/* global Chart*/ | ||
|
||
import {loadJS} from "@web/core/assets"; | ||
import {registry} from "@web/core/registry"; | ||
import {standardFieldProps} from "@web/views/fields/standard_field_props"; | ||
|
||
const {Component, onWillStart, useEffect, useRef} = owl; | ||
|
||
export class AutomationGraph extends Component { | ||
setup() { | ||
this.chart = null; | ||
this.canvasRef = useRef("canvas"); | ||
onWillStart(() => loadJS("/web/static/lib/Chart/Chart.js")); | ||
useEffect(() => { | ||
this.renderChart(); | ||
return () => { | ||
if (this.chart) { | ||
this.chart.destroy(); | ||
} | ||
}; | ||
}); | ||
} | ||
_getChartConfig() { | ||
return { | ||
type: "line", | ||
data: { | ||
labels: this.props.value.done.map(function (pt) { | ||
return pt.x; | ||
}), | ||
datasets: [ | ||
{ | ||
backgroundColor: "#4CAF5080", | ||
borderColor: "#4CAF50", | ||
data: this.props.value.done, | ||
fill: "start", | ||
label: this.env._t("Done"), | ||
borderWidth: 2, | ||
}, | ||
{ | ||
backgroundColor: "#F4433680", | ||
borderColor: "#F44336", | ||
data: this.props.value.error, | ||
fill: "start", | ||
label: this.env._t("Error"), | ||
borderWidth: 2, | ||
}, | ||
], | ||
}, | ||
options: { | ||
legend: {display: false}, | ||
|
||
layout: { | ||
padding: {left: 10, right: 10, top: 10, bottom: 10}, | ||
}, | ||
scales: { | ||
yAxes: [ | ||
{ | ||
type: "linear", | ||
display: false, | ||
ticks: { | ||
beginAtZero: true, | ||
}, | ||
}, | ||
], | ||
xAxes: [ | ||
{ | ||
ticks: { | ||
maxRotation: 0, | ||
}, | ||
}, | ||
], | ||
}, | ||
maintainAspectRatio: false, | ||
elements: { | ||
line: { | ||
tension: 0.000001, | ||
}, | ||
}, | ||
tooltips: { | ||
intersect: false, | ||
position: "nearest", | ||
caretSize: 0, | ||
borderWidth: 2, | ||
}, | ||
}, | ||
}; | ||
} | ||
renderChart() { | ||
if (this.chart) { | ||
this.chart.destroy(); | ||
} | ||
var config = this._getChartConfig(); | ||
this.chart = new Chart(this.canvasRef.el, config); | ||
Chart.animationService.advance(); | ||
} | ||
} | ||
|
||
AutomationGraph.template = "automation_oca.AutomationGraph"; | ||
AutomationGraph.props = { | ||
...standardFieldProps, | ||
}; | ||
|
||
registry.category("fields").add("automation_graph", AutomationGraph); |
10 changes: 10 additions & 0 deletions
10
automation_oca/static/src/fields/automation_graph/automation_graph.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<templates id="template" xml:space="preserve"> | ||
|
||
<t t-name="automation_oca.AutomationGraph" owl="1"> | ||
<div class="o_automation_graph w-100" t-att-class="props.className"> | ||
<canvas t-ref="canvas" /> | ||
</div> | ||
</t> | ||
|
||
</templates> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters