From 56dda82a5f865ff1110fbb0d9f1330ddf04e57d9 Mon Sep 17 00:00:00 2001 From: "Lucas Perais (lpe)" Date: Mon, 20 Sep 2021 12:52:25 +0000 Subject: [PATCH] [REF] web, *: legacy: lazy loading of legacy reporting views Since commit 0134495ba55bea16c2d11d5eb5d832edad575694 the reporting views pivot, graph, cohort are written in full new framework. Some applications still need the legacy ones, so this commit just implements the lazy loading of those views. In stock, report_stock_forecasted has been adapted in order to avoid having a GraphView override: we now modify the canvas' height in pure JS. *: board, stock closes odoo/odoo#76931 Related: odoo/enterprise#21054 Signed-off-by: Aaron Bohy (aab) --- .../board/static/src/legacy/js/board_view.js | 7 ++++ .../static/src/js/report_stock_forecasted.js | 34 ++++++++++++------- .../src/xml/report_stock_forecasted.xml | 6 ---- addons/web/__manifest__.py | 15 ++++++++ .../src/legacy/js/views/graph/graph_view.js | 2 ++ .../src/legacy/js/views/pivot/pivot_view.js | 2 ++ .../src/legacy/js/views/view_registry.js | 5 --- .../static/src/legacy/js/widgets/pie_chart.js | 7 ++-- addons/web/static/src/legacy/legacy_views.js | 13 +++++++ .../web/static/tests/helpers/mock_server.js | 3 ++ .../tests/legacy/helpers/mock_server.js | 3 ++ .../static/tests/legacy/views/form_tests.js | 9 ++++- addons/web/views/lazy_assets.xml | 8 +++++ 13 files changed, 87 insertions(+), 27 deletions(-) create mode 100644 addons/web/views/lazy_assets.xml diff --git a/addons/board/static/src/legacy/js/board_view.js b/addons/board/static/src/legacy/js/board_view.js index d0cb35da927..e1125a2bd29 100644 --- a/addons/board/static/src/legacy/js/board_view.js +++ b/addons/board/static/src/legacy/js/board_view.js @@ -13,6 +13,7 @@ var FormView = require('web.FormView'); var pyUtils = require('web.py_utils'); var session = require('web.session'); var viewRegistry = require('web.view_registry'); +const { loadLegacyViews } = require("@web/legacy/legacy_views"); var _t = core._t; var _lt = core._lt; @@ -34,6 +35,12 @@ var BoardController = FormController.extend({ this.customViewID = params.customViewID; }, + async willStart() { + const _super = this._super.bind(this, ...arguments); + await loadLegacyViews({ rpc: this._rpc.bind(this) }); + return _super(); + }, + //-------------------------------------------------------------------------- // Public //-------------------------------------------------------------------------- diff --git a/addons/stock/static/src/js/report_stock_forecasted.js b/addons/stock/static/src/js/report_stock_forecasted.js index 017fb1e5332..4258c6c027d 100644 --- a/addons/stock/static/src/js/report_stock_forecasted.js +++ b/addons/stock/static/src/js/report_stock_forecasted.js @@ -1,24 +1,16 @@ odoo.define('stock.ReplenishReport', function (require) { "use strict"; +const { loadLegacyViews } = require("@web/legacy/legacy_views"); + const clientAction = require('report.client_action'); const core = require('web.core'); const dom = require('web.dom'); -const GraphRenderer = require("web/static/src/js/views/graph/graph_renderer"); -const GraphView = require('web.GraphView'); const qweb = core.qweb; const _t = core._t; -class StockReportGraphRenderer extends GraphRenderer {} - -StockReportGraphRenderer.template = "stock.GraphRenderer"; - -const StockReportGraphView = GraphView.extend({ - config: Object.assign({}, GraphView.prototype.config, { - Renderer: StockReportGraphRenderer, - }), -}); +const viewRegistry = require("web.view_registry"); const ReplenishReport = clientAction.extend({ /** @@ -56,7 +48,8 @@ const ReplenishReport = clientAction.extend({ }); return Promise.all([ this._super.apply(this, arguments), - loadWarehouses + loadWarehouses, + loadLegacyViews({ rpc: this._rpc.bind(this) }), ]); }, @@ -125,9 +118,24 @@ const ReplenishReport = clientAction.extend({ noContentHelp: _t("Try to add some incoming or outgoing transfers."), withControlPanel: false, }; - const graphView = new StockReportGraphView(viewInfo, params); + const GraphView = viewRegistry.get("graph"); + const graphView = new GraphView(viewInfo, params); const graphController = await graphView.getController(this); await graphController.appendTo(document.createDocumentFragment()); + + // Since we render the container in a fragment, we may endup in this case: + // https://github.com/chartjs/Chart.js/issues/2210#issuecomment-204984449 + // so, the canvas won't be resizing when it is relocated in the iframe. + // Also, since the iframe's position is absolute, chartJS reiszing may not work + // (https://www.chartjs.org/docs/2.9.4/general/responsive.html -- #Important Note) + // Finally, we do want to set a height for the canvas rendering in chartJS. + // We do this via the chartJS API, that is legacy/graph_renderer.js:@_prepareOptions + // (maintainAspectRatio = false) and with the *attribute* height (not the style). + // (https://www.chartjs.org/docs/2.9.4/general/responsive.html -- #Responsive Charts) + // Luckily, the chartJS is not fully rendered, so changing the height here is relevant. + // It wouldn't be if we were after GraphRenderer@mounted. + graphController.el.querySelector(".o_graph_canvas_container canvas").height = "300"; + return graphController; }, diff --git a/addons/stock/static/src/xml/report_stock_forecasted.xml b/addons/stock/static/src/xml/report_stock_forecasted.xml index 8f8110cc3d2..2c294cf4b09 100644 --- a/addons/stock/static/src/xml/report_stock_forecasted.xml +++ b/addons/stock/static/src/xml/report_stock_forecasted.xml @@ -1,12 +1,6 @@ - - - 300 - - -