new export options

This commit is contained in:
2018-07-29 22:07:21 +02:00
parent 8047a0487f
commit 8f76ce3569
7 changed files with 137 additions and 7 deletions
+16 -2
View File
@@ -6,12 +6,20 @@ namespace App\Tables;
class JsonExporter extends BaseExporter
{
private $fullJsDoc = false;
public function withJsWrapper()
{
$this->fullJsDoc = true;
return $this;
}
/**
* @return string - mime type for the downloaded file
*/
protected function getMimeType()
{
return 'application/json';
return $this->fullJsDoc ? 'application/javascript' : 'application/json';
}
/**
@@ -27,6 +35,12 @@ class JsonExporter extends BaseExporter
*/
protected function writeDocument()
{
if ($this->fullJsDoc) {
echo "/*\n" . $this->getHeaderComment(' ') . "*/\n\n";
echo 'module.exports = ';
}
echo "[\n";
$first = true;
@@ -36,7 +50,7 @@ class JsonExporter extends BaseExporter
} else {
echo ",\n";
}
echo json_encode($row, JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES);
echo ' '.json_encode($row, JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES);
}
echo "\n]\n";