Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ jobs:
run: "npm install"
- name: "Check generated assets are present"
run: |
for file in public/lib/apexcharts.js public/lib/carbon.js public/lib/carbon.css; do
for file in public/lib/carbon.js public/lib/carbon.css; do
if [ ! -s "$file" ]; then
echo "::error::Missing or empty build asset: $file"
exit 1
Expand Down
81 changes: 81 additions & 0 deletions install/migration/update_1.4.0_to_1.4.1.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?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/>.
*
* -------------------------------------------------------------------------
*/

use Safe\Exceptions\FilesystemException;

use function Safe\preg_match;
use function Safe\scandir;

function update140to141(Migration $migration)
{
/** @var DBmysql $DB */
global $DB;

$updateresult = true;
$from_version = '1.4.0';
$to_version = '1.4.1';
$update_dir = __DIR__ . "/update_{$from_version}_to_{$to_version}/";

//TRANS: %s is the number of new version
$migration->addInfoMessage(sprintf(__('Update to %s'), $to_version));
$migration->setVersion($to_version);

// New tables from enpty.sql file after the migration
// If a script requires a new table, it may create it by itself

$update_scripts = scandir($update_dir);
natcasesort($update_scripts);
foreach ($update_scripts as $update_script) {
if (preg_match('/\.php$/', $update_script) !== 1) {
continue;
}
require $update_dir . $update_script;
}

$dbFile = plugin_carbon_getSchemaPath($to_version);
if ($dbFile === null) {
$migration->addWarningMessage("Error creating tables : " . $DB->error());
$updateresult = false;
}
try {
$DB->runFile($dbFile);
} catch (RuntimeException|FilesystemException $e) {
$migration->addWarningMessage("Error creating tables : " . $e->getMessage());
$updateresult = false;
}


// ************ Keep it at the end **************
$migration->executeMigration();

return $updateresult;
}
Original file line number Diff line number Diff line change
@@ -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.

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.


/**
* -------------------------------------------------------------------------
* Carbon plugin for GLPI
Expand Down Expand Up @@ -28,5 +30,28 @@
* -------------------------------------------------------------------------
*/

import ApexCharts from "apexcharts";
window.ApexCharts = ApexCharts;
use Glpi\Dashboard\Item as DashboardItem;

use function Safe\json_decode;
use function Safe\json_encode;

/** @var DBmysql $DB */
/** @var Migration $migration */

$dashboard_item = new DashboardItem();
$rows = $dashboard_item->find([
'card_id' => 'plugin_carbon_assets_completeness_ratio',
]);

foreach ($rows as $row) {
$card_options = json_decode($row['card_options'], true);
if (!is_array($card_options) || ($card_options['widgettype'] ?? null) !== 'apex_radar') {
continue;
}

$card_options['widgettype'] = 'radar';
$dashboard_item->update([
'id' => $row['id'],
'card_options' => json_encode($card_options),
]);
}
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
"node": ">= 18.12.0"
},
"dependencies": {
"apexcharts": "^7.0"
},
"scripts": {
"build": "webpack --config .webpack.config.js",
Expand Down
4 changes: 3 additions & 1 deletion setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ function plugin_init_carbon()
plugin_carbon_registerClasses();

$CFG_GLPI['javascript']['tools'][strtolower(Report::class)] = ['dashboard'];
foreach (PLUGIN_CARBON_TYPES as $itemtype) {
$CFG_GLPI['javascript']['assets'][strtolower($itemtype)][] = 'charts';
}
$proxy_exclusions = $CFG_GLPI['possible_proxy_exclusions'];
$proxy_exclusions->addExclusion(new ProxyExclusion(
Config::class,
Expand Down Expand Up @@ -163,7 +166,6 @@ function plugin_carbon_setupHooks()
$PLUGIN_HOOKS[Hooks::PRE_ITEM_UPDATE]['carbon'][GlpiProfile::class] = 'plugin_carbon_profileUpdate';
$PLUGIN_HOOKS[Hooks::PRE_ITEM_ADD]['carbon'][GlpiProfile::class] = 'plugin_carbon_profileAdd';

$PLUGIN_HOOKS[Hooks::ADD_JAVASCRIPT]['carbon'][] = 'lib/apexcharts.js';
$PLUGIN_HOOKS[Hooks::ADD_JAVASCRIPT]['carbon'][] = 'lib/carbon.js';

// Import CSS
Expand Down
37 changes: 37 additions & 0 deletions src/Dashboard/DemoProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,10 @@ public static function getSumUsageEmissionsPerModel(array $params = [], array $w
],
'url' => [
'',
'',
'',
'',
'',
],
'unit' => 'g CO₂eq',
];
Expand Down Expand Up @@ -481,4 +485,37 @@ public static function getImpactOfEmbodiedAndUsageCriteria(string $impact_type,
'doc_url' => Type::getCriteriaInfoLink($impact_type),
];
}

public static function getHandledAssetsRatio(array $params = [])
{
$default_params = [
'label' => __('handled assets ratio', 'carbon'),
'icon' => '',
];
$params = array_merge($default_params, $params);

$data = [];

$data[] = [
'number' => 83,
'url' => '',
'label' => Computer::getTypeName(Session::getPluralNumber()),
];
$data[] = [
'number' => 71,
'url' => '',
'label' => Monitor::getTypeName(Session::getPluralNumber()),
];
$data[] = [
'number' => 90,
'url' => '',
'label' => NetworkEquipment::getTypeName(Session::getPluralNumber()),
];

return [
'data' => $data,
'label' => $params['label'],
'icon' => $params['icon'],
];
}
}
2 changes: 1 addition & 1 deletion src/Dashboard/Grid.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public static function getDashboardCards(?array $cards = null): array
$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',
Expand Down
Loading
Loading