added a revisions page

master
Ondřej Hruška 6 years ago
parent a69c3e6cf6
commit 34e432fe87
Signed by: MightyPork
GPG Key ID: 2C5FD5035250423D
  1. 48
      app/Http/Controllers/TableController.php
  2. 2
      app/Models/Table.php
  3. 1
      resources/assets/sass/app.scss
  4. 3
      resources/assets/sass/bootstrap-customizations/_notification.scss
  5. 5
      resources/views/table/_header-handle.blade.php
  6. 6
      resources/views/table/_panel-metadata.blade.php
  7. 8
      resources/views/table/propose/layout.blade.php
  8. 91
      resources/views/table/revisions.blade.php
  9. 22
      resources/views/table/view.blade.php
  10. 2
      routes/login.php
  11. 1
      routes/web.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;

@ -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);
}
}

@ -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";

@ -0,0 +1,3 @@
.alert-warning {
border-color: #d8c99a;
}

@ -0,0 +1,5 @@
<small class="flex-grow-1" style="font-size: 120%;" id="table-id">
<a href="{{ route('profile.view', $table->owner->name) }}" class="link-no-color">{{ $table->owner->handle }}</a>{{--
--}}<span class="px-1">/</span>{{--
--}}<b><a href="{{ $table->viewRoute }}" class="link-no-color">{{ $table->name }}</a></b>
</small>

@ -3,7 +3,6 @@
--}}
<div class="row">
{{-- Description field --}}
<div class="col-md-8 pl-md-0">
<b>Description</b>
@ -67,7 +66,10 @@
<tr>
<th class="text-right pr-2">Revisions</th>
<td>{{ $table->revisions_count }}</td>
<td>
{{ $table->revisions_count }}
<span class="text-muted ml-1">(<a class="link-no-color" href="{{ $table->revisionsRoute }}">see changes</a>)</span>
</td>
</tr>
<tr>

@ -11,13 +11,9 @@ if (!isset($tab) || $tab == '') $tab = 'edit-rows';
@section('content')
<div class="row justify-content-start px-3">
<div class="d-flex w-100 align-items-center">
<small class="flex-grow-1" style="font-size: 120%;">
<a href="{{ route('profile.view', $table->owner->name) }}" class="link-no-color">{{ $table->owner->handle }}</a>{{--
--}}<span class="px-1">/</span>{{--
--}}<b><a href="{{ $table->viewRoute }}" class="link-no-color">{{ $table->name }}</a></b>
</small>
@include('table._header-handle')
<h1 class="mx-3">
<h1 class="mx-3" id="table-title">
<a href="{{ $table->viewRoute }}" class="link-no-color">{{ $table->title }}</a>
</h1>
<a href="{{$table->draftDiscardRoute}}" class="btn btn-outline-danger mr-2 py-1 btn-sm">

@ -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')
<div class="row justify-content-start px-3">
<div class="d-flex w-100 align-items-center">
@include('table._header-handle')
<h1 class="mx-3" id="table-title">{{ $table->title }}</h1>
<a href="{{ $table->viewRoute }}" class="btn btn-outline-primary py-1 btn-sm" @tooltip(Back to Table)>
@icon(fa-reply, sr:Back to Table)
</a>
</div>
</div>
<div class="row px-3 border-top pt-3">
<div class="col-md-12">
<h2>Table Revisions</h2>
@php
$revIds = $revisions->pluck('id');
@endphp
@foreach($revisions as $i => $revision)
@php
$num = count($revisions) - $i;
@endphp
<div class="x-revision rounded border box-shadow mb-3 p-2" id="revision-{{$revision->id}}">
<div class="row">
<div class="col-md-8">
#{{$num}}
– {{ $revision->created_at->format('Y-m-d, G:i:s') }}
@if($i == 0)
<span class="text-muted ml-1">(current)</span>
@else
<span class="text-muted ml-1">
(<a class="link-no-color" href="{{ $table->viewRoute }}?rev={{$num}}">see table in this revision</a>)
</span>
@endif
</div>
<div class="col-md-4 text-right">
@if($revision->ancestor_id)
@if ($revIds->contains($revision->ancestor_id))
<span class="x-revision-link text-muted" data-id="{{$revision->ancestor_id}}">Show parent</span>
@else
<span class="text-muted">Forked from elsewhere</span>
@endif
@endif
</div>
</div>
<div class="row">
<div class="col-md-12" style="font-size:140%;">
{{ $revision->note }}
</div>
</div>
</div>
@endforeach
</div>
</div>
@endsection
@push('scripts')
<style>
.x-revision.highlight {
background: #a5d5ff;
border-color: #a5d5ff;
}
.x-revision-link {
cursor: pointer;
}
</style>
<script>
ready(function() {
$('.x-revision-link').on('mouseenter', function () {
$('#revision-'+$(this).data('id')).addClass('highlight');
}).on('mouseleave', function () {
$('#revision-'+$(this).data('id')).removeClass('highlight');
})
});
</script>
@endpush

@ -6,17 +6,14 @@
/** @var \App\Models\Table $table */
@endphp
@section('content')
<div class="row justify-content-start px-3">
<div class="d-flex w-100 align-items-center" id="table-title-container">
<small class="flex-grow-1" style="font-size: 120%;" id="table-id">
<a href="{{route('profile.view', $table->owner->name)}}" class="link-no-color">{{ $table->owner->handle }}</a>{{--
--}}<span class="px-1">/</span>{{--
--}}<b>{{ $table->name }}</b>
</small>
@include('table._header-handle')
<h1 class="mx-3" id="table-title">{{ $table->title }}</h1>
@include('table._view-action-buttons')
</div>
</div>
@ -65,6 +62,19 @@
</div>{{-- End of row --}}
@if($table->revisions_count != $revisionNum)
<div class="alert alert-warning alert-important" role="alert" >
<button type="button"
class="close"
data-dismiss="alert"
aria-hidden="true"
>&times;</button>
You're viewing an old table revision ({{$revisionNum}} out of {{ $table->revisions_count }}).
<a href="{{ $table->viewRoute }}">Go to current</a>
</div>
@endif
<div class="row justify-content-center mb-2">
<div class="col-md-12 d-flex">
<nav class="text-center" aria-label="Pages of the table">

@ -68,7 +68,7 @@ if (!function_exists('_loginVia')) {
}
if ($wasLoggedIn)
return redirect(route('profile.manage-oauth'));
return redirect(route('account.edit'));
else
return Redirect::intended();
}

@ -42,6 +42,7 @@ Route::get('/home', function () {
// Table resource
Route::get('@{user}', 'ProfileController@view')->name('profile.view');
Route::get('@{user}/{table}', 'TableController@view')->name('table.view');
Route::get('@{user}/{table}/revisions', 'TableController@viewRevisions')->name('table.revisions');
Route::get('@{user}/{table}/export', 'TableController@export')->name('table.export');

Loading…
Cancel
Save