From 34e432fe872eaf0a4d7dd75699557da91b912347 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Hru=C5=A1ka?= Date: Thu, 16 Aug 2018 21:17:32 +0200 Subject: [PATCH] added a revisions page --- app/Http/Controllers/TableController.php | 48 ++++++---- app/Models/Table.php | 2 + resources/assets/sass/app.scss | 1 + .../_notification.scss | 3 + .../views/table/_header-handle.blade.php | 5 + .../views/table/_panel-metadata.blade.php | 6 +- .../views/table/propose/layout.blade.php | 8 +- resources/views/table/revisions.blade.php | 91 +++++++++++++++++++ resources/views/table/view.blade.php | 22 +++-- routes/login.php | 2 +- routes/web.php | 1 + 11 files changed, 154 insertions(+), 35 deletions(-) create mode 100644 resources/assets/sass/bootstrap-customizations/_notification.scss create mode 100644 resources/views/table/_header-handle.blade.php create mode 100644 resources/views/table/revisions.blade.php 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 @@ --}}
- {{-- Description field --}}
Description @@ -67,7 +66,10 @@ Revisions - {{ $table->revisions_count }} + + {{ $table->revisions_count }} + (see changes) + diff --git a/resources/views/table/propose/layout.blade.php b/resources/views/table/propose/layout.blade.php index 14235bb..de47e77 100644 --- a/resources/views/table/propose/layout.blade.php +++ b/resources/views/table/propose/layout.blade.php @@ -11,13 +11,9 @@ if (!isset($tab) || $tab == '') $tab = 'edit-rows'; @section('content')
- - {{ $table->owner->handle }}{{-- - --}}/{{-- - --}}{{ $table->name }} - + @include('table._header-handle') -

+

{{ $table->title }}

diff --git a/resources/views/table/revisions.blade.php b/resources/views/table/revisions.blade.php new file mode 100644 index 0000000..322f3a6 --- /dev/null +++ b/resources/views/table/revisions.blade.php @@ -0,0 +1,91 @@ +{{-- List of table revisions --}} + +@extends('layouts.app') + +@php +/** @var \App\Models\Table $table */ +/** @var \App\Models\Revision[]|\Illuminate\Support\Collection $revisions */ +@endphp + +@section('content') + + +
+
+

Table Revisions

+ + @php + $revIds = $revisions->pluck('id'); + @endphp + + @foreach($revisions as $i => $revision) + @php + $num = count($revisions) - $i; + @endphp +
+
+
+ #{{$num}} + – {{ $revision->created_at->format('Y-m-d, G:i:s') }} + @if($i == 0) + (current) + @else + + (see table in this revision) + + @endif +
+
+ @if($revision->ancestor_id) + @if ($revIds->contains($revision->ancestor_id)) + Show parent + @else + Forked from elsewhere + @endif + @endif +
+
+ +
+
+ {{ $revision->note }} +
+
+
+ @endforeach +
+
+ +@endsection + +@push('scripts') + + + +@endpush diff --git a/resources/views/table/view.blade.php b/resources/views/table/view.blade.php index 15812f2..62a205f 100644 --- a/resources/views/table/view.blade.php +++ b/resources/views/table/view.blade.php @@ -6,17 +6,14 @@ /** @var \App\Models\Table $table */ @endphp + @section('content') +
- - {{ $table->owner->handle }}{{-- - --}}/{{-- - --}}{{ $table->name }} - + @include('table._header-handle')

{{ $table->title }}

- @include('table._view-action-buttons')
@@ -65,6 +62,19 @@
{{-- End of row --}} +@if($table->revisions_count != $revisionNum) + +@endif +