Skip to content

Commit 228821a

Browse files
committed
Install: update reporting page configuration
1 parent 0d65672 commit 228821a

7 files changed

Lines changed: 41 additions & 30 deletions

File tree

install/data/report_dashboard.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,27 +77,27 @@
7777
"point_labels": "0"
7878
}
7979
},
80-
"plugin_carbon_report_embodied_abiotic_depletion": {
80+
"plugin_carbon_report_embodied_adp_impact": {
8181
"x": 5,
8282
"y": 3,
8383
"width": 5,
8484
"height": 3,
8585
"card_options": {
8686
"color": "#ffd966",
87-
"widgettype": "embodied_abiotic_depletion",
87+
"widgettype": "impact_criteria_number",
8888
"use_gradient": "0",
8989
"point_labels": "0",
9090
"limit": "7"
9191
}
9292
},
93-
"plugin_carbon_report_embodied_global_warming": {
93+
"plugin_carbon_report_embodied_gwp_impact": {
9494
"x": 10,
9595
"y": 0,
9696
"width": 5,
9797
"height": 3,
9898
"card_options": {
9999
"color": "#7a941e",
100-
"widgettype": "embodied_global_warming",
100+
"widgettype": "impact_criteria_number",
101101
"use_gradient": "0",
102102
"point_labels": "0",
103103
"limit": "7"
@@ -110,7 +110,7 @@
110110
"height": 3,
111111
"card_options": {
112112
"color": "#326319",
113-
"widgettype": "embodied_primary_energy",
113+
"widgettype": "impact_criteria_number",
114114
"use_gradient": "0",
115115
"point_labels": "0",
116116
"limit": "7"

install/migration/update_1.1.1_to_1.2.0/09_add_impact_criterias.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,14 @@
100100
'card_id' => 'plugin_carbon_report_embodied_gwp_impact'
101101
]);
102102
foreach ($rows as $row) {
103+
$card_options = json_decode($row['card_options'], true);
104+
if ($card_options['widgettype'] === 'embodied_global_warming') {
105+
$card_options['widgettype'] = 'impact_criteria_number';
106+
}
103107
$dashboard_item->update([
104108
'id' => $row['id'],
105109
'card_id' => 'plugin_carbon_report_embodied_gwp_impact',
110+
'card_options' => json_encode($card_options),
106111
]);
107112
}
108113

@@ -111,8 +116,29 @@
111116
'card_id' => 'plugin_carbon_report_embodied_abiotic_depletion'
112117
]);
113118
foreach ($rows as $row) {
119+
$card_options = json_decode($row['card_options'], true);
120+
if ($card_options['widgettype'] === 'embodied_abiotic_depletion') {
121+
$card_options['widgettype'] = 'impact_criteria_number';
122+
}
114123
$dashboard_item->update([
115124
'id' => $row['id'],
116125
'card_id' => 'plugin_carbon_report_embodied_adp_impact',
126+
'card_options' => json_encode($card_options),
127+
]);
128+
}
129+
130+
$dashboard_item = new DashboardItem();
131+
$rows = $dashboard_item->find([
132+
'card_id' => 'plugin_carbon_report_embodied_pe_impact'
133+
]);
134+
foreach ($rows as $row) {
135+
$card_options = json_decode($row['card_options'], true);
136+
if ($card_options['widgettype'] === 'embodied_primary_energy') {
137+
$card_options['widgettype'] = 'impact_criteria_number';
138+
}
139+
$dashboard_item->update([
140+
'id' => $row['id'],
141+
'card_id' => 'plugin_carbon_report_embodied_pe_impact',
142+
'card_options' => json_encode($card_options),
117143
]);
118144
}

src/Dashboard/Grid.php

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -309,18 +309,4 @@ protected static function getReportCards(): array
309309

310310
return $new_cards;
311311
}
312-
313-
private static function getWidgetForImpact(bool $embodied, string $type): string
314-
{
315-
switch (($embodied ? 'embodied' : 'usage') . ' ' . $type) {
316-
case 'embodied gwp':
317-
return 'impact_criteria_number';
318-
case 'embodied adp':
319-
return 'impact_criteria_number';
320-
case 'embodied pe':
321-
return 'impact_criteria_number';
322-
}
323-
324-
return 'bigNumber';
325-
}
326312
}

src/Dashboard/Provider.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@
5353
use GlpiPlugin\Carbon\UsageImpact;
5454
use Glpi\DBAL\QueryExpression;
5555
use Glpi\DBAL\QuerySubQuery;
56-
use GlpiPlugin\Carbon\Documentation;
5756
use GlpiPlugin\Carbon\Impact\Type;
5857
use Search;
5958
use Session;

src/Dashboard/Widget.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
use Glpi\Application\View\TemplateRenderer;
4141
use Glpi\Dashboard\Widget as GlpiDashboardWidget;
4242
use GlpiPlugin\Carbon\Documentation;
43+
use GlpiPlugin\Carbon\Impact\Type;
4344
use GlpiPlugin\Carbon\Report;
4445
use GlpiPlugin\Carbon\Toolbox;
4546
use Monitor;
@@ -744,7 +745,7 @@ public static function displayMonthlyCarbonEmission(array $params = []): string
744745
$last_month['series'][0]['unit']
745746
);
746747

747-
$url = Documentation::getInfoLink('carbon_emission');
748+
$url = Type::getCriteriaInfoLink('gwp');
748749
$tooltip = __('Evaluates the usage carbon emission in CO₂ equivalent during the last 2 months. %s More information %s', 'carbon');
749750
$tooltip = sprintf($tooltip, '<br /><a target="_blank" href="' . $url . '">', '</a>');
750751
$tooltip_html = Html::showToolTip($tooltip, [
@@ -810,7 +811,7 @@ public static function displayUsageCarbonEmissionYearToDate(array $params = []):
810811
break;
811812
}
812813

813-
$url = Documentation::getInfoLink('carbon_emission');
814+
$url = Type::getCriteriaInfoLink('gwp');
814815
$tooltip = __('Evaluates the usage carbon emission in CO₂ equivalent during the last 12 elapsed months. %s More information %s', 'carbon');
815816
$tooltip = sprintf($tooltip, '<br /><a target="_blank" href="' . $url . '">', '</a>');
816817
$tooltip_html = Html::showToolTip($tooltip, [
@@ -845,12 +846,11 @@ public static function displayImpactCriteriaNumber(array $params = []): string
845846
'alt' => '',
846847
'color' => '',
847848
'icon' => '',
848-
'id' => 'plugin_carbon_embodied_primary_energy_' . mt_rand(),
849+
'id' => 'plugin_carbon_impact_criteria_' . mt_rand(),
849850
'filters' => [], // TODO: Not implemented yet (is this useful ?)
850851
];
851852
$p = array_merge($default, $params);
852853

853-
$url = Documentation::getInfoLink('primary_energy_impact');
854854
$url = $p['doc_url'];
855855
$tooltip = $p['tooltip'];
856856
$tooltip .= '<br /><a target="_blank" href="' . $url . '">'
@@ -892,7 +892,7 @@ public static function displayUsageAbioticDepletion(array $params = []): string
892892
];
893893
$p = array_merge($default, $params);
894894

895-
$url = Documentation::getInfoLink('abiotic_depletion_impact');
895+
$url = Type::getCriteriaInfoLink('adp');
896896
$tooltip = __('Evaluates the consumption of non renewable resources in Antimony equivalent. %s More information %s', 'carbon');
897897
$tooltip = sprintf($tooltip, '<br /><a target="_blank" href="' . $url . '">', '</a>');
898898
$tooltip_html = Html::showToolTip($tooltip, [

src/Impact/Type.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535

3636
class Type
3737
{
38-
3938
private const BASE_URL = 'https://glpi-plugins.readthedocs.io/%s/latest/carbon';
4039

4140
const IMPACT_GWP = 1; // Global warming potential
@@ -344,7 +343,7 @@ public static function getCriteriaPictogram(string $type): string
344343
/**
345344
* Get external URL to a detailed description of the given path
346345
*
347-
* @param string $object_descriptor
346+
* @param string $impact_type
348347
* @return string
349348
*/
350349
public static function getCriteriaInfoLink(string $impact_type): string

src/UsageInfo.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
use Glpi\Application\View\TemplateRenderer;
4040
use GlpiPlugin\Carbon\Dashboard\Provider;
4141
use GlpiPlugin\Carbon\Dashboard\Widget;
42+
use GlpiPlugin\Carbon\Impact\Type;
4243
use Html;
4344
use Monitor;
4445
use NetworkEquipment;
@@ -214,15 +215,15 @@ public static function showCharts(CommonDBTM $asset)
214215
'items_id' => $asset->getID(),
215216
]);
216217

217-
$url = Documentation::getInfoLink('carbon_emission');
218+
$url = Type::getCriteriaInfoLink('gwp');
218219
$tooltip = __('Evaluates the carbon emission in CO₂ equivalent. %s More information %s', 'carbon');
219220
$tooltip = sprintf($tooltip, '<br /><a target="_blank" href="' . $url . '">', '</a>');
220221
$carbon_emission_tooltip_html = Html::showToolTip($tooltip, [
221222
'display' => false,
222223
'applyto' => 'carbon_emission_tip',
223224
]);
224225

225-
$url = Documentation::getInfoLink('abiotic_depletion_impact');
226+
$url = Type::getCriteriaInfoLink('adp');
226227
$tooltip = __('Evaluates the consumption of non renewable resources in Antimony equivalent. %s More information %s', 'carbon');
227228
$tooltip = sprintf($tooltip, '<br /><a target="_blank" href="' . $url . '">', '</a>');
228229
$usage_abiotic_depletion_tooltip_html = Html::showToolTip($tooltip, [
@@ -234,7 +235,7 @@ public static function showCharts(CommonDBTM $asset)
234235
'applyto' => 'embodied_abiotic_depletion_tip',
235236
]);
236237

237-
$url = Documentation::getInfoLink('primary_energy');
238+
$url = Type::getCriteriaInfoLink('pe');
238239
$tooltip = __('Evaluates the primary energy consumed. %s More information %s', 'carbon');
239240
$tooltip = sprintf($tooltip, '<br /><a target="_blank" href="' . $url . '">', '</a>');
240241
$embodied_primary_energy_tooltip_html = Html::showToolTip($tooltip, [

0 commit comments

Comments
 (0)