Skip to content

Commit

Permalink
Evarisk#984 [Dashboard] add: move position + change sort algorithm
Browse files Browse the repository at this point in the history
  • Loading branch information
evarisk-francois committed Jun 24, 2024
1 parent 8e6e6a1 commit 9e8ad4c
Show file tree
Hide file tree
Showing 2 changed files with 108 additions and 83 deletions.
188 changes: 107 additions & 81 deletions class/saturnedashboard.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,29 @@ public function load_dashboard(?array $moreParams = []): array
$dashboardInfos['graphs'][$key] = $dashboardData['graphs'];
}
}

$positions = [];
foreach ($dashboardInfos['graphs'] as $key => $dashboardGraph) {
foreach ($dashboardGraph as $keyElement => $graph) {
$positions[$key . '-' . $graph['title'] . '-' . $graph['position']] = $graph;
}
}

uasort($positions, function ($a, $b) {
return $a['position'] <=> $b['position'];
});

$positionsKeys = array_keys($positions);
$index = 0;
foreach ($dashboardInfos['graphs'] as $key => $databoardGraphs) {
foreach ($databoardGraphs as $keyElement => $dashboardGraph) {
$positionKey = $positionsKeys[$index];
$dashboardInfos['graphs'][$key][$keyElement] = $positions[$positionKey];
$index++;
}
}
}

return $dashboardInfos;
}

Expand All @@ -103,16 +125,16 @@ public function show_dashboard(?array $moreParams = [])

$dashboards = $this->load_dashboard($moreParams);

$dashboardGraphsArray = [];
foreach ($dashboards['graphs'] as $key => $graph) {
foreach ($graph as $keyElement => $dashboardGraph) {
array_push($dashboardGraphsArray, $dashboardGraph);
}
}
// $dashboardGraphsArray = [];
// foreach ($dashboards['graphs'] as $key => $graph) {
// foreach ($graph as $keyElement => $dashboardGraph) {
// array_push($dashboardGraphsArray, $dashboardGraph);
// }
// }

usort($dashboardGraphsArray, function ($a, $b) {
return $a['position'] <=> $b['position'];
});
// usort($dashboardGraphsArray, function ($a, $b) {
// return $a['position'] <=> $b['position'];
// });

print '<form method="POST" action="' . $_SERVER['PHP_SELF'] . '" class="dashboard" id="dashBoardForm">';
print '<input type="hidden" name="token" value="' . newToken() . '">';
Expand Down Expand Up @@ -196,85 +218,89 @@ public function show_dashboard(?array $moreParams = [])

print '<div class="graph-dashboard wpeo-grid grid-2">';

if (is_array($dashboardGraphsArray) && !empty($dashboardGraphsArray)) {
foreach ($dashboardGraphsArray as $dashboardGraph) {
$nbDataset = 0;
$uniqueKey = strip_tags($dashboardGraph['title']) . $keyElement;
if (is_array($dashboardGraph['data']) && !empty($dashboardGraph['data'])) {
if ($dashboardGraph['dataset'] >= 2) {
foreach ($dashboardGraph['data'] as $dashboardGraphDatasets) {
unset($dashboardGraphDatasets[0]);
foreach ($dashboardGraphDatasets as $dashboardGraphDataset) {
if (!empty($dashboardGraphDataset)) {
$nbDataset = 1;
if (is_array($dashboards['graphs']) && !empty($dashboards['graphs'])) {
foreach ($dashboards['graphs'] as $dashboardGraphs) {
if (is_array($dashboardGraphs) && !empty($dashboardGraphs)) {
foreach ($dashboardGraphs as $keyElement => $dashboardGraph) {
$nbDataset = 0;
$uniqueKey = strip_tags($dashboardGraph['title']) . $keyElement;
if (is_array($dashboardGraph['data']) && !empty($dashboardGraph['data'])) {
if ($dashboardGraph['dataset'] >= 2) {
foreach ($dashboardGraph['data'] as $dashboardGraphDatasets) {
unset($dashboardGraphDatasets[0]);
foreach ($dashboardGraphDatasets as $dashboardGraphDataset) {
if (!empty($dashboardGraphDataset)) {
$nbDataset = 1;
}
}
}
} else {
foreach ($dashboardGraph['data'] as $dashboardGraphDatasets) {
$nbDataset += $dashboardGraphDatasets;
}
}
}
} else {
foreach ($dashboardGraph['data'] as $dashboardGraphDatasets) {
$nbDataset += $dashboardGraphDatasets;
}
}
if ($nbDataset > 0) {
if (is_array($dashboardGraph['labels']) && !empty($dashboardGraph['labels'])) {
foreach ($dashboardGraph['labels'] as $key => $dashboardGraphLabel) {
$dashboardGraphLegend[$uniqueKey][] = $dashboardGraphLabel['label'];
if (isset($dashboardGraphLabel['color'])) {
if (dol_strlen($dashboardGraphLabel['color']) > 0) {
$dashboardGraphColor[$uniqueKey][] = $dashboardGraphLabel['color'];
if ($nbDataset > 0) {
if (is_array($dashboardGraph['labels']) && !empty($dashboardGraph['labels'])) {
foreach ($dashboardGraph['labels'] as $key => $dashboardGraphLabel) {
$dashboardGraphLegend[$uniqueKey][] = $dashboardGraphLabel['label'];
if (isset($dashboardGraphLabel['color'])) {
if (dol_strlen($dashboardGraphLabel['color']) > 0) {
$dashboardGraphColor[$uniqueKey][] = $dashboardGraphLabel['color'];
} else {
// If only one color is defined in category, the others will be black
// If no color is defined, all the colors will be defined by global $theme_datacolor
// To avoid black color we better define a color instead of empty
$dashboardGraphColor[$uniqueKey][] = $this->getColorRange($key);
}
}
}
}

$arrayKeys = array_keys($dashboardGraph['data']);
foreach ($arrayKeys as $key) {
if ($dashboardGraph['dataset'] >= 2) {
$graphData[$uniqueKey][] = $dashboardGraph['data'][$key];
} else {
// If only one color is defined in category, the others will be black
// If no color is defined, all the colors will be defined by global $theme_datacolor
// To avoid black color we better define a color instead of empty
$dashboardGraphColor[$uniqueKey][] = $this->getColorRange($key);
$graphData[$uniqueKey][] = [
0 => $dashboardGraph['labels'][$key]['label'],
1 => $dashboardGraph['data'][$key]
];
}
}

$fileName[$uniqueKey] = $uniqueKey . '.png';
$fileUrl[$uniqueKey] = DOL_URL_ROOT . '/viewimage.php?modulepart=' . $moduleNameLowerCase . '&file=' . $uniqueKey . '.png';

$graph = new DolGraph();
$graph->SetData($graphData[$uniqueKey]);

if ($dashboardGraph['dataset'] >= 2) {
$graph->SetLegend($dashboardGraphLegend[$uniqueKey]);
}
if (isset($dashboardGraphColor[$uniqueKey])) {
$graph->SetDataColor($dashboardGraphColor[$uniqueKey]);
}
$graph->SetType([$dashboardGraph['type'] ?? 'pie']);
$graph->SetWidth($dashboardGraph['width'] ?? $width);
$graph->SetHeight($dashboardGraph['height'] ?? $height);
$graph->setShowLegend($dashboardGraph['showlegend'] ?? 2);
$graph->draw($fileName[$uniqueKey], $fileUrl[$uniqueKey]);
print '<div class="' . $dashboardGraph['moreCSS'] . '">';

$downloadCSV = '<form method="POST" action="' . $_SERVER['PHP_SELF'] . (GETPOSTISSET('id') ? '?id=' . GETPOST('id') : '') . '">';
$downloadCSV .= '<input type="hidden" name="token" value="' . newToken() . '">';
$downloadCSV .= '<input type="hidden" name="action" value="generate_csv">';
$downloadCSV .= '<input type="hidden" name="graph" value="' . http_build_query($dashboardGraph) . '">';
$downloadCSV .= '<button class="wpeo-button no-load button-grey">';
$downloadCSV .= img_picto('ExportCSV', 'fontawesome_file-csv_fas_#31AD29_15px');
$downloadCSV .= '</button></form>';
$dashboardGraph['morehtmlright'] .= $downloadCSV;

print load_fiche_titre($dashboardGraph['title'], $dashboardGraph['morehtmlright'], $dashboardGraph['picto']);
print $graph->show();
print '</div>';
}
}

$arrayKeys = array_keys($dashboardGraph['data']);
foreach ($arrayKeys as $key) {
if ($dashboardGraph['dataset'] >= 2) {
$graphData[$uniqueKey][] = $dashboardGraph['data'][$key];
} else {
$graphData[$uniqueKey][] = [
0 => $dashboardGraph['labels'][$key]['label'],
1 => $dashboardGraph['data'][$key]
];
}
}

$fileName[$uniqueKey] = $uniqueKey . '.png';
$fileUrl[$uniqueKey] = DOL_URL_ROOT . '/viewimage.php?modulepart=' . $moduleNameLowerCase . '&file=' . $uniqueKey . '.png';

$graph = new DolGraph();
$graph->SetData($graphData[$uniqueKey]);

if ($dashboardGraph['dataset'] >= 2) {
$graph->SetLegend($dashboardGraphLegend[$uniqueKey]);
}
if (isset($dashboardGraphColor[$uniqueKey])) {
$graph->SetDataColor($dashboardGraphColor[$uniqueKey]);
}
$graph->SetType([$dashboardGraph['type'] ?? 'pie']);
$graph->SetWidth($dashboardGraph['width'] ?? $width);
$graph->SetHeight($dashboardGraph['height'] ?? $height);
$graph->setShowLegend($dashboardGraph['showlegend'] ?? 2);
$graph->draw($fileName[$uniqueKey], $fileUrl[$uniqueKey]);
print '<div class="' . $dashboardGraph['moreCSS'] . '">';

$downloadCSV = '<form method="POST" action="' . $_SERVER['PHP_SELF'] . (GETPOSTISSET('id') ? '?id=' . GETPOST('id') : '') . '">';
$downloadCSV .= '<input type="hidden" name="token" value="' . newToken() . '">';
$downloadCSV .= '<input type="hidden" name="action" value="generate_csv">';
$downloadCSV .= '<input type="hidden" name="graph" value="' . http_build_query($dashboardGraph) . '">';
$downloadCSV .= '<button class="wpeo-button no-load button-grey">';
$downloadCSV .= img_picto('ExportCSV', 'fontawesome_file-csv_fas_#31AD29_15px');
$downloadCSV .= '</button></form>';
$dashboardGraph['morehtmlright'] .= $downloadCSV;

print load_fiche_titre($dashboardGraph['title'], $dashboardGraph['morehtmlright'], $dashboardGraph['picto']);
print $graph->show();
print '</div>';
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions class/task/saturnetask.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,6 @@ public function load_dashboard($projectId): array
{
$arrayTasksByProgress = $this->getTasksByProgress($projectId);

$arrayTasksByProgress['position'] = 10;

$array['graphs'] = [$arrayTasksByProgress];

return $array;
Expand Down Expand Up @@ -116,6 +114,7 @@ public function getTasksByProgress($projectId = 0)
$array['type'] = 'pie';
$array['showlegend'] = $conf->browser->layout == 'phone' ? 1 : 2;
$array['dataset'] = 1;
$array['position'] = 150;

$array['labels'] = [
0 => [
Expand Down

0 comments on commit 9e8ad4c

Please sign in to comment.