Fixed when export csv in custom graph and only print one register and add label in export data, tiquet: #2755

This commit is contained in:
m-lopez-f 2015-09-28 16:17:30 +02:00
parent 15a1c1f27f
commit afef30bc75
3 changed files with 36 additions and 17 deletions

View File

@ -53,20 +53,23 @@ $output_csv = function ($data, $filename) {
header ('Content-Disposition: attachment; filename="'.$filename.'.csv"'); header ('Content-Disposition: attachment; filename="'.$filename.'.csv"');
// Header // Header
if (!isset($data['head']) || !isset($data['data']))
throw new Exception(__('An error occured exporting the data'));
$head_line = implode($separator, $data['head']);
echo $head_line . "\n";
// Item / data // Item / data
foreach ($data['data'] as $items) { foreach ($data as $items) {
$line = implode($separator, $items); if (!isset($items['head']) || !isset($items['data']))
throw new Exception(__('An error occured exporting the data'));
if ($excel_encoding)
echo mb_convert_encoding($line, 'UTF-16LE', 'UTF-8') . "\n"; $head_line = implode($separator, $items['head']);
else echo $head_line . "\n";
echo $line . "\n"; foreach ($items['data'] as $item) {
$line = implode($separator, $item);
if ($excel_encoding)
echo mb_convert_encoding($line, 'UTF-16LE', 'UTF-8') . "\n";
else
echo $line . "\n";
}
} }
}; };

View File

@ -1099,8 +1099,9 @@ function pandoraFlotArea(graph_id, values, labels, labels_long, legend,
* } * }
*/ */
if (type === 'csv') { if (type === 'csv') {
result = { result = {
head: ['date', 'value'], head: ['date', 'value','label'],
data: [] data: []
}; };
@ -1113,7 +1114,7 @@ function pandoraFlotArea(graph_id, values, labels, labels_long, legend,
else if (typeof labels[index] !== 'undefined') else if (typeof labels[index] !== 'undefined')
date = labels[index]; date = labels[index];
result.data.push([date, value]); result.data.push([date, value,dataObject.label]);
}); });
} }
/* [ /* [
@ -1150,7 +1151,8 @@ function pandoraFlotArea(graph_id, values, labels, labels_long, legend,
result.push({ result.push({
'date': date, 'date': date,
'value': value 'value': value,
'label': dataObject.label
}); });
}); });
} }
@ -1162,8 +1164,21 @@ function pandoraFlotArea(graph_id, values, labels, labels_long, legend,
} }
try { try {
dataObject = retrieveDataOject(dataObjects); var elements = [];
graphData = processDataObject(dataObject); var custom_graph = $('input:hidden[name=custom_graph]').value;
if (custom_graph) {
dataObject = retrieveDataOject(dataObjects);
dataObjects.forEach(function (element) {
elements.push(processDataObject(element));
});
graphData = elements;
}
else {
dataObject = retrieveDataOject(dataObjects);
elements.push(processDataObject(dataObject));
graphData = elements;
}
// Transform the object data into a string // Transform the object data into a string
// cause PHP has limitations in the number // cause PHP has limitations in the number

View File

@ -104,6 +104,7 @@ if ($view_graph) {
exit; exit;
} }
html_print_input_hidden ('lineWidhtGraph', $config['custom_graph_width']); html_print_input_hidden ('lineWidhtGraph', $config['custom_graph_width']);
html_print_input_hidden ('custom_graph', 1);
$url = "index.php?" . $url = "index.php?" .
"sec=reporting&" . "sec=reporting&" .
"sec2=operation/reporting/graph_viewer&" . "sec2=operation/reporting/graph_viewer&" .