From 36882a45c739632c9b2731dae77fb1768735f53d Mon Sep 17 00:00:00 2001 From: Julien Castiaux Date: Thu, 19 Oct 2023 14:47:20 +0200 Subject: [PATCH] [FIX] survey: missing vote count on top of bars Start the a live session, I used Burger Quizz, answer a question. On the manager side, the current vote count for each choice should be visible on top of each bar in the chart. That vote count is missing. During the migration of chartjs from v2 to v4, the datalabel plugin was updated from v0.7 to v2.2 in the same time. Using the new version of the datalabel plugin, the plugin is not automatically loaded anymore, one must explicitely loads it. We also removed the datalabel plugin from the bundle to load it explicitelly instead. The JS framework finds it cleaner this way. Task-3537480 Reference-to: 7e3c1ecdb861 ([REF] *: Update Chart.js to V4.3) Part-of: odoo/odoo#139204 Co-authored-by: Pierre Pulinckx --- addons/survey/__manifest__.py | 1 - addons/survey/static/src/js/survey_session_chart.js | 8 +++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/addons/survey/__manifest__.py b/addons/survey/__manifest__.py index 00ae4f3a3e1..18077d28f1a 100644 --- a/addons/survey/__manifest__.py +++ b/addons/survey/__manifest__.py @@ -80,7 +80,6 @@ sent mails with personal token for the invitation of the survey. 'survey/static/src/xml/survey_breadcrumb_templates.xml', ], 'survey.survey_user_input_session_assets': [ - 'survey/static/src/js/libs/chartjs-plugin-datalabels.js', 'survey/static/src/js/survey_session_colors.js', 'survey/static/src/js/survey_session_chart.js', 'survey/static/src/js/survey_session_text_answers.js', diff --git a/addons/survey/static/src/js/survey_session_chart.js b/addons/survey/static/src/js/survey_session_chart.js index 898a739ee49..e370bcbfcf8 100644 --- a/addons/survey/static/src/js/survey_session_chart.js +++ b/addons/survey/static/src/js/survey_session_chart.js @@ -1,5 +1,7 @@ /** @odoo-module **/ +/* global ChartDataLabels */ +import { loadJS } from "@web/core/assets"; import publicWidget from "@web/legacy/js/public/public_widget"; import SESSION_CHART_COLORS from "@survey/js/survey_session_colors"; @@ -22,6 +24,10 @@ publicWidget.registry.SurveySessionChart = publicWidget.Widget.extend({ }); }, + willStart: async function () { + await loadJS("/survey/static/src/js/libs/chartjs-plugin-datalabels.js"); + }, + //-------------------------------------------------------------------------- // Public //-------------------------------------------------------------------------- @@ -167,7 +173,7 @@ publicWidget.registry.SurveySessionChart = publicWidget.Widget.extend({ } } }, - plugins: [{ + plugins: [ChartDataLabels, { /** * The way it works is each label is an array of words. * eg.: if we have a chart label: "this is an example of a label"