fix: [dashboard:csvExport] Quote elements and correctly apply line break

pull/9247/head
Sami Mokaddem 2023-08-09 14:56:24 +02:00
parent 1f839d91c5
commit 3c097f8202
No known key found for this signature in database
GPG Key ID: 164C473F627A06FA
3 changed files with 11 additions and 6 deletions

View File

@ -33,7 +33,7 @@ class AppController extends Controller
public $helpers = array('OrgImg', 'FontAwesome', 'UserName');
private $__queryVersion = '154';
private $__queryVersion = '155';
public $pyMispVersion = '2.4.174';
public $phpmin = '7.2';
public $phprec = '7.4';

View File

@ -207,13 +207,16 @@ class DashboardsController extends AppController
$csv = array_map(function($row) {
$flattened = array_values(Hash::flatten($row));
$stringified = array_map('strval', $flattened);
return implode(',', $stringified);
$quotified = array_map(function($item) { return sprintf('"%s"', $item); }, $stringified);
return implode(',', $quotified);
}, $toConvert);
$rowKey = implode(',', array_map('strval', array_keys(Hash::flatten($toConvert[0]))));
$rowKey = implode(',', array_map(function ($item) {
return sprintf('"%s"', $item);
}, array_map('strval', array_keys(Hash::flatten($toConvert[0])))));
$csv = $rowKey . PHP_EOL . implode(PHP_EOL, array_values($csv));
}
}
return $this->RestResponse->viewData($csv, 'text/csv');
return $this->RestResponse->viewData($csv, 'text/csv', false, true);
}
$this->layout = false;

View File

@ -5527,8 +5527,10 @@ function resetDashboardGrid(grid, save = true) {
widget: $element.attr('widget')
},
success:function (data) {
data = JSON.stringify(data, null, 2);
var blob=new Blob([data], {type: 'application/json'});
if (export_type == 'json') {
data = JSON.stringify(data, null, 2);
}
var blob = new Blob([data], { type: (export_type == 'json' ? 'application/json' : 'text/csv') });
var link=window.document.createElement('a');
link.href=window.URL.createObjectURL(blob);
link.download=$element.attr('widget') + "_" + container_id + "_export." + export_type;