Skip to content

update 12.0/bugfixes branch - #378

Merged
btry merged 2 commits into
pluginsGLPI:12.0/bugfixesfrom
btry:12.0/bugfixes
Oct 9, 2026
Merged

btry merged 2 commits into
pluginsGLPI:12.0/bugfixesfrom
btry:12.0/bugfixes

Conversation

@btry

@btry btry commented Oct 8, 2026 •

Copy link
Copy Markdown
Collaborator

Remove ApexCharts library, and use eCharts instead.

echarts is available in GLPI core, saving 1 library from the project
@@ -1,3 +1,5 @@
<?php

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file has actually NOT been renamed. This is a false positive from renaming detection feature.

@btry
btry requested a review from Rom1-B October 8, 2026 12:59

@Rom1-B Rom1-B left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some fixes on top of this port (they also apply to develop):

  • setup.php: echarts is not loaded when the environmental impact tab is opened from another tab (ReferenceError: echarts is not defined); use the core sector-based JS loading instead.
  • src/Dashboard/Grid.php: the card still declares apex_radar, so radar is hidden in the widget edit form.
  • apex_radar.html.twig renamed to radar.html.twig.
  • Migration test for the apex_radar to radar card conversion.
diff --git a/setup.php b/setup.php
index 01541e7..8e88770 100644
--- a/setup.php
+++ b/setup.php
@@ -108,13 +108,7 @@ function plugin_init_carbon()
 
     $CFG_GLPI['javascript']['tools'][strtolower(Report::class)] = ['dashboard'];
     foreach (PLUGIN_CARBON_TYPES as $itemtype) {
-        $form_url = $itemtype::getFormURL();
-        if (strpos($_SERVER['REQUEST_URI'] ?? '', $form_url) !== false) {
-            continue;
-        }
-        if (($_SESSION['glpi_tabs'][strtolower($itemtype)] ?? '') == 'GlpiPlugin\Carbon\UsageInfo$1') {
-            Html::requireJs('charts');
-        }
+        $CFG_GLPI['javascript']['assets'][strtolower($itemtype)][] = 'charts';
     }
     $proxy_exclusions = $CFG_GLPI['possible_proxy_exclusions'];
     $proxy_exclusions->addExclusion(new ProxyExclusion(
diff --git a/src/Dashboard/Grid.php b/src/Dashboard/Grid.php
index a4569e7..5180276 100644
--- a/src/Dashboard/Grid.php
+++ b/src/Dashboard/Grid.php
@@ -74,7 +74,7 @@ class Grid
         $group = __('Carbon', 'carbon');
         $cards += [
             'plugin_carbon_assets_completeness_ratio' => [
-                'widgettype'   => ['apex_radar', 'multipleNumber'],
+                'widgettype'   => ['radar', 'multipleNumber'],
                 'group'        => $group,
                 'label'        => __('Handled assets ratio', 'carbon'),
                 'provider'     => Provider::class . '::getHandledAssetsRatio',
diff --git a/src/Dashboard/Widget.php b/src/Dashboard/Widget.php
index 32c0c19..7c03c95 100644
--- a/src/Dashboard/Widget.php
+++ b/src/Dashboard/Widget.php
@@ -827,7 +827,7 @@ class Widget extends GlpiDashboardWidget
             ],
         ];
 
-        $output = TemplateRenderer::getInstance()->render('@carbon/dashboard/apex_radar.html.twig', [
+        $output = TemplateRenderer::getInstance()->render('@carbon/dashboard/radar.html.twig', [
             'chart_id' => $chart_id,
             'class'    => $class,
             'color' => $p['color'],
diff --git a/templates/dashboard/apex_radar.html.twig b/templates/dashboard/radar.html.twig
similarity index 100%
rename from templates/dashboard/apex_radar.html.twig
rename to templates/dashboard/radar.html.twig
diff --git a/tests/migration/migration_to_1_4_1_Test.php b/tests/migration/migration_to_1_4_1_Test.php
new file mode 100644
index 0000000..29c53dd
--- /dev/null
+++ b/tests/migration/migration_to_1_4_1_Test.php
@@ -0,0 +1,101 @@
+<?php
+
+/**
+ * -------------------------------------------------------------------------
+ * Carbon plugin for GLPI
+ *
+ * @copyright Copyright (C) 2024-2025 Teclib' and contributors.
+ * @license   https://www.gnu.org/licenses/gpl-3.0.txt GPLv3+
+ * @link      https://github.com/pluginsGLPI/carbon
+ *
+ * -------------------------------------------------------------------------
+ *
+ * LICENSE
+ *
+ * This file is part of Carbon plugin for GLPI.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
+ *
+ * -------------------------------------------------------------------------
+ */
+
+
+namespace GlpiPlugin\Carbon\Tests;
+
+use DBmysql;
+use GlpiPlugin\Carbon\Install;
+use Migration;
+
+use function Safe\json_decode;
+use function Safe\json_encode;
+
+class migration_to_1_4_1_Test extends CommonTestCase
+{
+    public function testUpdateHandledRatioCard()
+    {
+        /** @var DBmysql $DB */
+        global $DB;
+
+        require_once(__DIR__ . '/../../install/Install.php');
+
+        $DB->insert('glpi_dashboards_dashboards', [
+            'key'  => 'plugin_carbon_migration_test',
+            'name' => 'plugin_carbon_migration_test',
+        ]);
+        $dashboard_id = $DB->insertId();
+        $cards = [
+            'radar_card' => [
+                'card_id' => 'plugin_carbon_assets_completeness_ratio',
+                'widgettype' => 'apex_radar',
+            ],
+            'number_card' => [
+                'card_id' => 'plugin_carbon_assets_completeness_ratio',
+                'widgettype' => 'multipleNumber',
+            ],
+            'other_card' => [
+                'card_id' => 'plugin_carbon_assets_completeness',
+                'widgettype' => 'apex_radar',
+            ],
+        ];
+        $ids = [];
+        foreach ($cards as $key => $card) {
+            $DB->insert('glpi_dashboards_items', [
+                'dashboards_dashboards_id' => $dashboard_id,
+                'gridstack_id' => $card['card_id'] . '_' . $key,
+                'card_id'      => $card['card_id'],
+                'card_options' => json_encode(['color' => '#FAFAFA', 'widgettype' => $card['widgettype']]),
+            ]);
+            $ids[$key] = $DB->insertId();
+        }
+
+        $install = new Install(new Migration('1.4.1'));
+        $migrations = $install->getMigrationsToDo('1.4.0');
+        $install->upgradeOneVersion(key($migrations), current($migrations));
+
+        $expected = [
+            'radar_card'  => 'radar',
+            'number_card' => 'multipleNumber',
+            'other_card'  => 'apex_radar',
+        ];
+        foreach ($expected as $key => $widgettype) {
+            $row = $DB->request([
+                'FROM'  => 'glpi_dashboards_items',
+                'WHERE' => ['id' => $ids[$key]],
+            ])->current();
+            $card_options = json_decode($row['card_options'], true);
+            $this->assertSame($widgettype, $card_options['widgettype']);
+            $this->assertSame('#FAFAFA', $card_options['color']);
+        }
+    }
+}

@btry
btry requested a review from Rom1-B October 9, 2026 06:49
@@ -1,3 +1,5 @@
<?php

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file has actually NOT been renamed. This is a false positive from renaming detection feature.

@btry
btry merged commit 1143f29 into pluginsGLPI:12.0/bugfixes Oct 9, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants