diff --git a/.env.example b/.env.example
index 355194e..bb9353a 100644
--- a/.env.example
+++ b/.env.example
@@ -38,8 +38,6 @@ MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
-PRETTY_JSON=true
-
OAUTH_GITHUB_ID=
OAUTH_GITHUB_SECRET=
OAUTH_GITHUB_REDIRECT=https://datatable.directory/auth/github/callback
diff --git a/app/Http/Controllers/TableController.php b/app/Http/Controllers/TableController.php
index 60e21d8..0a621c3 100644
--- a/app/Http/Controllers/TableController.php
+++ b/app/Http/Controllers/TableController.php
@@ -72,19 +72,22 @@ class TableController extends Controller
*/
public function create()
{
- $exampleColumns =
- "latin,string,Latin Name\n" .
- "common,string,Common Name\n" .
- "lifespan,int,Lifespan (years)";
-
$exampleData =
"Mercenaria mercenaria,hard clam,40\n" .
"Magallana gigas,pacific oyster,30\n" .
"Patella vulgata,common limpet,20";
- return view('table.create',
- compact('exampleColumns', 'exampleData')
- );
+ $columns = Column::columnsFromJson([
+ ['name' => 'latin', 'type' => 'string', 'title' => 'Latin Name'],
+ ['name' => 'common', 'type' => 'string', 'title' => 'Common Name'],
+ ['name' => 'lifespan', 'type' => 'int', 'title' => 'Lifespan (years)']
+ ]);
+
+ return view('table.create', [
+ 'exampleColumns' => '',
+ 'columns' => $columns,
+ 'exampleData' => $exampleData,
+ ]);
}
public function settings(Request $request, User $user, string $table)
@@ -141,7 +144,7 @@ class TableController extends Controller
'description' => ['nullable', VALI_TEXT],
'license' => ['nullable', VALI_TEXT],
'origin' => ['nullable', VALI_TEXT],
- 'columns' => 'required|string',
+ 'columns' => 'required|json',
'data' => 'string|nullable',
]);
@@ -156,28 +159,24 @@ class TableController extends Controller
/** @var Column[] $columns */
$columns = [];
$column_keys = []; // for checking duplicates
- $colTable = array_map('str_getcsv', explode("\n", $input->columns));
+ $colsArray = fromJSON($input->columns);
// prevent griefing via long list of columns
- if (count($colTable) > 100) return $this->backWithErrors(['columns' => "Too many columns"]);
+ if (count($colsArray) > 100) return $this->backWithErrors(['columns' => "Too many columns"]);
- foreach ($colTable as $col) {
- $col = array_map('trim', $col);
- if (count($col) < 2 || strlen($col[0])==0) {
+ foreach ($colsArray as $col) {
+ if (!isset($col->name) || !isset($col->type) || empty($col->name) || empty($col->type)) {
return $this->backWithErrors(['columns' => "All columns must have at least name and type."]);
}
try {
- if (in_array($col[0], $column_keys)) {
- return $this->backWithErrors(['columns' => "Duplicate column: $col[0]"]);
+ if (in_array($col->name, $column_keys)) {
+ return $this->backWithErrors(['columns' => "Duplicate column: $col->name"]);
}
- $column_keys[] = $col[0];
+ $column_keys[] = $col->name;
- $columns[] = new Column([
- 'name' => $col[0],
- 'type' => $col[1],
- 'title' => count($col) >= 3 ? $col[2] : $col[0], // title falls back to =name if not specified,
- ]);
+ if (!isset($col->title)) $col->title = $col->name;
+ $columns[] = new Column($col);
} catch (\Exception $e) {
return $this->backWithErrors(['columns' => $e->getMessage()]);
}
diff --git a/app/helpers.php b/app/helpers.php
index dacd548..178ffa1 100644
--- a/app/helpers.php
+++ b/app/helpers.php
@@ -67,3 +67,27 @@ function vali($arr) {
}
return $result;
}
+
+
+
+/**
+ * like old(), but decodes stringified json
+ *
+ * @param string $name
+ * @param object|array $default
+ * @return object|array
+ */
+function old_json($name, $default) {
+ $old = old($name, null);
+ if (is_string($old)) return json_decode($old);
+ return $default;
+}
+
+// Safe JSON funcs
+function toJSON($object) {
+ return \GuzzleHttp\json_encode($object, JSON_UNESCAPED_SLASHES + JSON_UNESCAPED_UNICODE);
+}
+
+function fromJSON($object, $assoc=false) {
+ return \GuzzleHttp\json_decode($object, $assoc);
+}
diff --git a/config/app.php b/config/app.php
index 13c3b78..692b7d2 100644
--- a/config/app.php
+++ b/config/app.php
@@ -222,7 +222,6 @@ return [
],
// -------------- added keys --------------
- 'pretty_json' => env('PRETTY_JSON', false),
'debug_blacklist' => [
'_COOKIE' => array_keys($_COOKIE),
diff --git a/porklib/Providers/BladeExtensionsProvider.php b/porklib/Providers/BladeExtensionsProvider.php
index 8aff1e5..a0c34cf 100644
--- a/porklib/Providers/BladeExtensionsProvider.php
+++ b/porklib/Providers/BladeExtensionsProvider.php
@@ -44,11 +44,7 @@ class BladeExtensionsProvider extends ServiceProvider
// json encode
Blade::directive('json', function ($x) {
- if (config('app.pretty_json')) {
- return "= json_encode(($x), JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES) ?>";
- } else {
- return "= json_encode(($x), JSON_UNESCAPED_SLASHES) ?>";
- }
+ return "= json_encode(($x), JSON_UNESCAPED_SLASHES) ?>";
});
// json encode, escaped
diff --git a/public/fonts/fa-dtbl-1-preview.html b/public/fonts/fa-dtbl-1-preview.html
index c171c3a..60afadf 100644
--- a/public/fonts/fa-dtbl-1-preview.html
+++ b/public/fonts/fa-dtbl-1-preview.html
@@ -166,6 +166,7 @@
.fa-code-fork:before,
.fa-comment:before,
.fa-download:before,
+.fa-exclamation-triangle:before,
.fa-eye:before,
.fa-facebook-square:before,
.fa-floppy-o:before,
@@ -178,6 +179,7 @@
.fa-key-modern:before,
.fa-link:before,
.fa-pencil:before,
+.fa-plus:before,
.fa-question-circle:before,
.fa-sign-in:before,
.fa-sign-out:before,
@@ -185,6 +187,7 @@
.fa-star-o:before,
.fa-table:before,
.fa-th-list:before,
+.fa-trash-o:before,
.fa-user:before,
.fa-user-circle-o:before,
.fa-user-plus:before,
@@ -209,30 +212,33 @@
.fa-code-fork:before { content: "\f102"; }
.fa-comment:before { content: "\f103"; }
.fa-download:before { content: "\f104"; }
-.fa-eye:before { content: "\f105"; }
-.fa-facebook-square:before { content: "\f106"; }
-.fa-floppy-o:before { content: "\f107"; }
-.fa-github:before { content: "\f108"; }
-.fa-globe:before { content: "\f109"; }
-.fa-google:before { content: "\f10a"; }
-.fa-history:before { content: "\f10b"; }
-.fa-home:before { content: "\f10c"; }
-.fa-inbox:before { content: "\f10d"; }
-.fa-key-modern:before { content: "\f10e"; }
-.fa-link:before { content: "\f10f"; }
-.fa-pencil:before { content: "\f110"; }
-.fa-question-circle:before { content: "\f111"; }
-.fa-sign-in:before { content: "\f112"; }
-.fa-sign-out:before { content: "\f113"; }
-.fa-star:before { content: "\f114"; }
-.fa-star-o:before { content: "\f115"; }
-.fa-table:before { content: "\f116"; }
-.fa-th-list:before { content: "\f117"; }
-.fa-user:before { content: "\f118"; }
-.fa-user-circle-o:before { content: "\f119"; }
-.fa-user-plus:before { content: "\f11a"; }
-.fa-users:before { content: "\f11b"; }
-.fa-wrench:before { content: "\f11c"; }
+.fa-exclamation-triangle:before { content: "\f105"; }
+.fa-eye:before { content: "\f106"; }
+.fa-facebook-square:before { content: "\f107"; }
+.fa-floppy-o:before { content: "\f108"; }
+.fa-github:before { content: "\f109"; }
+.fa-globe:before { content: "\f10a"; }
+.fa-google:before { content: "\f10b"; }
+.fa-history:before { content: "\f10c"; }
+.fa-home:before { content: "\f10d"; }
+.fa-inbox:before { content: "\f10e"; }
+.fa-key-modern:before { content: "\f10f"; }
+.fa-link:before { content: "\f110"; }
+.fa-pencil:before { content: "\f111"; }
+.fa-plus:before { content: "\f112"; }
+.fa-question-circle:before { content: "\f113"; }
+.fa-sign-in:before { content: "\f114"; }
+.fa-sign-out:before { content: "\f115"; }
+.fa-star:before { content: "\f116"; }
+.fa-star-o:before { content: "\f117"; }
+.fa-table:before { content: "\f118"; }
+.fa-th-list:before { content: "\f119"; }
+.fa-trash-o:before { content: "\f11a"; }
+.fa-user:before { content: "\f11b"; }
+.fa-user-circle-o:before { content: "\f11c"; }
+.fa-user-plus:before { content: "\f11d"; }
+.fa-users:before { content: "\f11e"; }
+.fa-wrench:before { content: "\f11f"; }
@@ -248,7 +254,7 @@
+
+
@@ -341,7 +361,7 @@
-
+
@@ -355,7 +375,7 @@
-
+
@@ -368,7 +388,7 @@
-
+
@@ -381,7 +401,7 @@
-
+
@@ -394,7 +414,7 @@
-
+
@@ -407,7 +427,7 @@
-
+
@@ -420,7 +440,7 @@
-
+
@@ -433,7 +453,7 @@
-
+
@@ -446,7 +466,7 @@
-
+
@@ -459,7 +479,7 @@
-
+
@@ -472,7 +492,20 @@
-
+
+
+
+
+
+
+ PpPpPpPpPpPpPpPpPpPp
+
+
+ 12141618212436486072
+
+
+
+
@@ -485,7 +518,7 @@
-
+
@@ -498,7 +531,7 @@
-
+
@@ -511,7 +544,7 @@
-
+
@@ -524,7 +557,7 @@
-
+
@@ -537,7 +570,7 @@
-
+
@@ -550,7 +583,7 @@
-
+
@@ -563,7 +596,20 @@
-
+
+
+
+
+
+
+ PpPpPpPpPpPpPpPpPpPp
+
+
+ 12141618212436486072
+
+
+
+
@@ -576,7 +622,7 @@
-
+
@@ -589,7 +635,7 @@
-
+
@@ -602,7 +648,7 @@
-
+
@@ -615,7 +661,7 @@
-
+
@@ -628,7 +674,7 @@
-
+
diff --git a/public/fonts/fa-dtbl-1.css b/public/fonts/fa-dtbl-1.css
index 134b96f..2a98041 100644
--- a/public/fonts/fa-dtbl-1.css
+++ b/public/fonts/fa-dtbl-1.css
@@ -43,27 +43,30 @@
.fa-code-fork::before { content: "\f102"; }
.fa-comment::before { content: "\f103"; }
.fa-download::before { content: "\f104"; }
-.fa-eye::before { content: "\f105"; }
-.fa-facebook-square::before { content: "\f106"; }
-.fa-floppy-o::before, .fa-save::before { content: "\f107"; }
-.fa-github::before { content: "\f108"; }
-.fa-globe::before { content: "\f109"; }
-.fa-google::before { content: "\f10a"; }
-.fa-history::before { content: "\f10b"; }
-.fa-home::before { content: "\f10c"; }
-.fa-inbox::before { content: "\f10d"; }
-.fa-key-modern::before { content: "\f10e"; }
-.fa-link::before { content: "\f10f"; }
-.fa-pencil::before { content: "\f110"; }
-.fa-question-circle::before { content: "\f111"; }
-.fa-sign-in::before { content: "\f112"; }
-.fa-sign-out::before { content: "\f113"; }
-.fa-star::before { content: "\f114"; }
-.fa-star-o::before { content: "\f115"; }
-.fa-table::before { content: "\f116"; }
-.fa-th-list::before { content: "\f117"; }
-.fa-user::before { content: "\f118"; }
-.fa-user-circle-o::before { content: "\f119"; }
-.fa-user-plus::before { content: "\f11a"; }
-.fa-users::before { content: "\f11b"; }
-.fa-wrench::before { content: "\f11c"; }
+.fa-exclamation-triangle::before, .fa-warning::before { content: "\f105"; }
+.fa-eye::before { content: "\f106"; }
+.fa-facebook-square::before { content: "\f107"; }
+.fa-floppy-o::before, .fa-save::before { content: "\f108"; }
+.fa-github::before { content: "\f109"; }
+.fa-globe::before { content: "\f10a"; }
+.fa-google::before { content: "\f10b"; }
+.fa-history::before { content: "\f10c"; }
+.fa-home::before { content: "\f10d"; }
+.fa-inbox::before { content: "\f10e"; }
+.fa-key-modern::before { content: "\f10f"; }
+.fa-link::before { content: "\f110"; }
+.fa-pencil::before { content: "\f111"; }
+.fa-plus::before { content: "\f112"; }
+.fa-question-circle::before { content: "\f113"; }
+.fa-sign-in::before { content: "\f114"; }
+.fa-sign-out::before { content: "\f115"; }
+.fa-star::before { content: "\f116"; }
+.fa-star-o::before { content: "\f117"; }
+.fa-table::before { content: "\f118"; }
+.fa-th-list::before { content: "\f119"; }
+.fa-trash-o::before { content: "\f11a"; }
+.fa-user::before { content: "\f11b"; }
+.fa-user-circle-o::before { content: "\f11c"; }
+.fa-user-plus::before { content: "\f11d"; }
+.fa-users::before { content: "\f11e"; }
+.fa-wrench::before { content: "\f11f"; }
diff --git a/public/fonts/fa-dtbl-1.eot b/public/fonts/fa-dtbl-1.eot
index 3083190..71ba15c 100644
Binary files a/public/fonts/fa-dtbl-1.eot and b/public/fonts/fa-dtbl-1.eot differ
diff --git a/public/fonts/fa-dtbl-1.svg b/public/fonts/fa-dtbl-1.svg
index d2153ea..3115101 100644
--- a/public/fonts/fa-dtbl-1.svg
+++ b/public/fonts/fa-dtbl-1.svg
@@ -1,11 +1,11 @@