diff --git a/app/Http/Controllers/TableController.php b/app/Http/Controllers/TableController.php index 14206b5..a0dd03b 100644 --- a/app/Http/Controllers/TableController.php +++ b/app/Http/Controllers/TableController.php @@ -23,6 +23,14 @@ use MightyPork\Utils\Utils; class TableController extends Controller { + private function resolveTable(Request $request, User $user, string $table) + { + /** @var Table $tableModel */ + $tableModel = $user->tables()->where('name', $table)->first(); + if ($tableModel === null) abort(404, "No such table."); + return $tableModel; + } + public function view(Request $request, User $user, string $table) { $input = $this->validate($request, [ @@ -35,9 +43,10 @@ class TableController extends Controller if ($tableModel === null) abort(404, "No such table."); // option to show other revisions + $revisionNum = $tableModel->revisions_count; if ($input->has('rev')) { - $rev = (int)$input->rev; - $revision = $tableModel->revisions()->orderBy('created_at')->skip($rev - 1)->first(); + $revisionNum = (int)$input->rev; + $revision = $tableModel->revisions()->orderBy('created_at')->skip($revisionNum - 1)->first(); if ($revision === null) abort(404, "No such revision"); } else { $revision = $tableModel->revision; @@ -54,6 +63,7 @@ class TableController extends Controller return view('table.view', [ 'table' => $tableModel, 'revision' => $revision, + 'revisionNum' => $revisionNum, 'proposals_count' => $tableModel->proposals()->unmerged($tableModel)->count(), 'columns' => $columns, 'rows' => $rows, @@ -63,8 +73,7 @@ class TableController extends Controller public function delete(Request $request, User $user, string $table) { /** @var Table $tableModel */ - $tableModel = $user->tables()->where('name', $table)->first(); - if ($tableModel === null) abort(404, "No such table."); + $tableModel = $this->resolveTable($request, $user, $table); $this->authorize('delete', $tableModel); if ($request->get('table-name', null) !== $table) { @@ -84,16 +93,9 @@ class TableController extends Controller public function create() { $exampleData = ""; -// "Mercenaria mercenaria,hard clam,40\n" . -// "Magallana gigas,pacific oyster,30\n" . -// "Patella vulgata,common limpet,20"; $columns = Column::columnsFromJson([ - // fake 'id' to satisfy the check in Column constructor ['id' => 1, 'name' => 'column_1', 'type' => 'string', 'title' => 'First Column'], -// ['id' => 1, 'name' => 'latin', 'type' => 'string', 'title' => 'Latin Name'], -// ['id' => 2, 'name' => 'common', 'type' => 'string', 'title' => 'Common Name'], -// ['id' => 3, 'name' => 'lifespan', 'type' => 'int', 'title' => 'Lifespan (years)'] ]); return view('table.create', [ @@ -108,9 +110,7 @@ class TableController extends Controller */ public function settings(Request $request, User $user, string $table) { - /** @var Table $tableModel */ - $tableModel = $user->tables()->where('name', $table)->first(); - if ($tableModel === null) abort(404, "No such table."); + $tableModel = $this->resolveTable($request, $user, $table); $this->authorize('edit', $tableModel); return view('table.conf', [ @@ -123,9 +123,7 @@ class TableController extends Controller */ public function storeSettings(Request $request, User $user, string $table) { - /** @var Table $tableModel */ - $tableModel = $user->tables()->where('name', $table)->first(); - if ($tableModel === null) abort(404, "No such table."); + $tableModel = $this->resolveTable($request, $user, $table); $this->authorize('edit', $tableModel); $input = $this->validate($request, [ @@ -152,6 +150,18 @@ class TableController extends Controller return redirect($tableModel->viewRoute); // the route now changed } + public function viewRevisions(Request $request, User $user, string $table) + { + $tableModel = $this->resolveTable($request, $user, $table); + + $revisions = $tableModel->revisions()->orderBy('created_at', 'desc')->get(); + + return view('table.revisions', [ + 'table' => $tableModel, + 'revisions' => $revisions, + ]); + } + public function storeNew(Request $request) { /** @var User $u */ @@ -334,9 +344,7 @@ class TableController extends Controller */ public function export(Request $request, User $user, string $table) { - /** @var Table $tableModel */ - $tableModel = $user->tables()->where('name', $table)->first(); - if ($tableModel === null) abort(404, "No such table."); + $tableModel = $this->resolveTable($request, $user, $table); $exporter = null; diff --git a/app/Models/Table.php b/app/Models/Table.php index 7f8e637..c0e83ea 100644 --- a/app/Models/Table.php +++ b/app/Models/Table.php @@ -29,6 +29,7 @@ use Illuminate\Database\Eloquent\Collection; * @property-read string $draftDiscardRoute * @property-read string $draftUpdateRoute * @property-read string $draftSubmitRoute + * @property-read string $revisionsRoute * @property-read User $owner * @property-read Table $parentTable * @property-read Table[]|Collection $forks @@ -143,6 +144,7 @@ class Table extends BaseModel case 'draftDiscardRoute': return route('table.draft-discard', $arg); case 'draftUpdateRoute': return route('table.draft-update', $arg); case 'draftSubmitRoute': return route('table.draft-submit', $arg); + case 'revisionsRoute': return route('table.revisions', $arg); } } diff --git a/resources/assets/sass/app.scss b/resources/assets/sass/app.scss index 199fd62..09235bf 100644 --- a/resources/assets/sass/app.scss +++ b/resources/assets/sass/app.scss @@ -30,6 +30,7 @@ dt { @import "bootstrap-customizations/typography"; @import "bootstrap-customizations/nav"; @import "bootstrap-customizations/table"; +@import "bootstrap-customizations/notification"; @import "infobox"; @import "funding"; diff --git a/resources/assets/sass/bootstrap-customizations/_notification.scss b/resources/assets/sass/bootstrap-customizations/_notification.scss new file mode 100644 index 0000000..3cbc28a --- /dev/null +++ b/resources/assets/sass/bootstrap-customizations/_notification.scss @@ -0,0 +1,3 @@ +.alert-warning { + border-color: #d8c99a; +} diff --git a/resources/views/table/_header-handle.blade.php b/resources/views/table/_header-handle.blade.php new file mode 100644 index 0000000..9bc7603 --- /dev/null +++ b/resources/views/table/_header-handle.blade.php @@ -0,0 +1,5 @@ + + {{ $table->owner->handle }}{{-- + --}}/{{-- + --}}{{ $table->name }} + diff --git a/resources/views/table/_panel-metadata.blade.php b/resources/views/table/_panel-metadata.blade.php index 10fa31d..e1f2f92 100644 --- a/resources/views/table/_panel-metadata.blade.php +++ b/resources/views/table/_panel-metadata.blade.php @@ -3,7 +3,6 @@ --}}