diff --git a/app/Http/Controllers/TableController.php b/app/Http/Controllers/TableController.php index c2d0b17..cae1bc7 100644 --- a/app/Http/Controllers/TableController.php +++ b/app/Http/Controllers/TableController.php @@ -13,11 +13,22 @@ use MightyPork\Exceptions\NotApplicableException; class TableController extends Controller { - public function view(User $user, string $table) + public function view(Request $request, User $user, string $table) { + $input = $this->validate($request, [ + 'rev' => 'nullable|int' + ]); + /** @var Table $tableModel */ $tableModel = $user->tables()->where('name', $table)->first(); - $revision = $tableModel->revision; + + if ($input->has('rev')) { + $rev = (int)$input->rev; + $revision = $tableModel->revisions()->orderBy('created_at')->skip($rev)->first(); + if ($revision === null) abort(404, "No such revision"); + } else { + $revision = $tableModel->revision; + } return view('table.view', [ 'table' => $tableModel, @@ -113,6 +124,7 @@ class TableController extends Controller $rowsData = null; try { $rowsData = array_map(function ($row) use ($columns) { + if (count($row) == 0 || count($row)==1&&$row[0]=='') return null; if (count($row) != count($columns)) { throw new NotApplicableException("All rows must have " . count($columns) . " fields."); } @@ -129,8 +141,10 @@ class TableController extends Controller 'data' => json_encode($parsed), ]; }, $rowTable); + + $rowsData = array_filter($rowsData); } catch (\Exception $e) { - return $this->backWithErrors(['columns' => $e->getMessage()]); + return $this->backWithErrors(['data' => $e->getMessage()]); } $revisionFields = [ diff --git a/app/View/CollapsibleTextBoxWidget.php b/app/View/CollapsibleTextBoxWidget.php index adca77b..890a266 100644 --- a/app/View/CollapsibleTextBoxWidget.php +++ b/app/View/CollapsibleTextBoxWidget.php @@ -75,7 +75,7 @@ class CollapsibleTextBoxWidget if ($this->collapsing) { return '
Source
- {!! Widget::tryLink($table->origin) !!}
+ @icon(fa-link){!! Widget::tryLink($table->origin) !!}