mirror of
https://github.com/OCA/web.git
synced 2025-02-22 13:21:25 +02:00
[16.0][MIG] Migration to v16.0
This commit is contained in:
42
web_widget_plotly_chart/static/src/js/widget_plotly.esm.js
Normal file
42
web_widget_plotly_chart/static/src/js/widget_plotly.esm.js
Normal file
@@ -0,0 +1,42 @@
|
||||
/** @odoo-module **/
|
||||
|
||||
import {loadJS} from "@web/core/assets";
|
||||
import {registry} from "@web/core/registry";
|
||||
|
||||
import {Component, onPatched, onWillStart, useEffect, useRef} from "@odoo/owl";
|
||||
|
||||
export class PlotlyChartWidgetField extends Component {
|
||||
setup() {
|
||||
this.divRef = useRef("plotly");
|
||||
|
||||
onWillStart(async () => {
|
||||
await loadJS(
|
||||
"/web_widget_plotly_chart/static/src/lib/plotly/plotly-2.18.2.min.js"
|
||||
);
|
||||
this.updatePlotly(this.props.value);
|
||||
});
|
||||
|
||||
onPatched(() => {
|
||||
this.updatePlotly(this.props.value);
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
this.updatePlotly(this.props.value);
|
||||
});
|
||||
}
|
||||
updatePlotly(value) {
|
||||
const value_html = $(value);
|
||||
const div = value_html.find(".plotly-graph-div").get(0).outerHTML || "";
|
||||
const script = value_html.find("script").get(0).textContent || "";
|
||||
|
||||
if (this.divRef.el) {
|
||||
this.divRef.el.innerHTML = div;
|
||||
new Function(script)();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
PlotlyChartWidgetField.template = "web_widget_plotly_chart.PlotlyChartWidgetField";
|
||||
PlotlyChartWidgetField.supportedTypes = ["char", "text"];
|
||||
|
||||
registry.category("fields").add("plotly_chart", PlotlyChartWidgetField);
|
||||
@@ -1,17 +0,0 @@
|
||||
odoo.define("web_widget_plotly_chart", function (require) {
|
||||
"use strict";
|
||||
|
||||
var fieldRegistry = require("web.field_registry");
|
||||
var AbstractField = require("web.AbstractField");
|
||||
|
||||
var PlotlyChartWidget = AbstractField.extend({
|
||||
_renderReadonly: function () {
|
||||
var val = this.value;
|
||||
this.$el.html(val);
|
||||
},
|
||||
});
|
||||
fieldRegistry.add("plotly_chart", PlotlyChartWidget);
|
||||
return {
|
||||
PlotlyChartWidget: PlotlyChartWidget,
|
||||
};
|
||||
});
|
||||
8
web_widget_plotly_chart/static/src/js/widget_plotly.xml
Normal file
8
web_widget_plotly_chart/static/src/js/widget_plotly.xml
Normal file
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<templates xml:space="preserve">
|
||||
|
||||
<t t-name="web_widget_plotly_chart.PlotlyChartWidgetField" owl="1">
|
||||
<div t-ref="plotly" />
|
||||
</t>
|
||||
|
||||
</templates>
|
||||
8
web_widget_plotly_chart/static/src/lib/plotly/plotly-2.18.2.min.js
vendored
Normal file
8
web_widget_plotly_chart/static/src/lib/plotly/plotly-2.18.2.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user