implemented table metadata editing page

pull/26/head
Ondřej Hruška 6 years ago
parent c1bc5a6677
commit 8ff10904ce
Signed by: MightyPork
GPG Key ID: 2C5FD5035250423D
  1. 29
      app/Http/Controllers/TableController.php
  2. 41
      resources/views/table/conf.blade.php
  3. 1
      routes/web.php

@ -22,7 +22,6 @@ class TableController extends Controller
/** @var Table $tableModel */ /** @var Table $tableModel */
$tableModel = $user->tables()->withCount(['favourites', 'forks', 'revisions', 'comments', 'proposals']) $tableModel = $user->tables()->withCount(['favourites', 'forks', 'revisions', 'comments', 'proposals'])
->where('name', $table)->first(); ->where('name', $table)->first();
if ($tableModel === null) abort(404, "No such table."); if ($tableModel === null) abort(404, "No such table.");
// make it possible to show other revisions // make it possible to show other revisions
@ -71,7 +70,6 @@ class TableController extends Controller
/** @var Table $tableModel */ /** @var Table $tableModel */
$tableModel = $user->tables()->where('name', $table)->first(); $tableModel = $user->tables()->where('name', $table)->first();
if ($tableModel === null) abort(404, "No such table."); if ($tableModel === null) abort(404, "No such table.");
$this->authorize('edit', $tableModel); $this->authorize('edit', $tableModel);
return view('table.conf', [ return view('table.conf', [
@ -79,6 +77,33 @@ 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.");
$this->authorize('edit', $tableModel);
$input = $this->validate($request, [
'name' => [
'required',
VALI_NAME,
Rule::unique('tables')->ignoreModel($tableModel),
],
'title' => ['required', VALI_LINE],
'description' => ['nullable', VALI_TEXT],
'license' => ['nullable', VALI_TEXT],
'origin' => ['nullable', VALI_TEXT],
]);
$tableModel->fill($input->all());
$tableModel->save();
flash()->success('Table settings saved');
return redirect($tableModel->viewRoute); // the route now changed
}
public function storeNew(Request $request) public function storeNew(Request $request)
{ {
/** @var User $u */ /** @var User $u */

@ -24,8 +24,43 @@
</div> </div>
</div> </div>
<div class="row mx-auto col-md-12 justify-content-center mb-1 border rounded px-0 py-2 box-shadow mb-3"> <form method="POST" action="{{$table->settingsRoute}}" class="row justify-content-center"
lalala aria-label="New Table">
</div>{{-- End of row --}}
@csrf
<div class="col-md-10">
@php(Widget::setLayout(3, 7))
{!! Widget::header(2, 'Table Metadata') !!}
{!! Widget::text('title', 'Title')->value($table->title)
->help('Unique among your tables') !!}
{!! Widget::par('Changing table name will change its URL, possibly breaking external links or bookmarks!') !!}
{!! Widget::text('name', 'Name')->value($table->name)->prepend(user()->handle.' /')
->help('Unique among your tables, and part of the URL; only letters, digits and
some symbols are allowed.') !!}
{!! Widget::textarea('description', 'Description')->value($table->description)
->height('8em')
->help('Description of the table. URLs in a full format will be clickable.') !!}
{!! Widget::text('license', 'License')->value($table->license)
->help('License applicable to the table\'s data, if any. By default, all
tables are CC0 or Public Domain.') !!}
{!! Widget::text('origin', 'Adapted from')->value($table->origin)
->help('If you took the data from some external site, a book, etc., write it here.
URLs in a full format will be clickable.') !!}
<div class="row form-group">
<div class="col-md-7 offset-md-3">
<button type="submit" class="btn btn-primary">
@icon(fa-save fa-pr)Save Changes
</button>
</div>
</div>
</div>
</form>
@endsection @endsection

@ -55,6 +55,7 @@ Route::group(['middleware' => 'auth'], function () {
}); });
Route::get('@{user}/{table}/settings', 'TableController@settings')->name('table.conf'); Route::get('@{user}/{table}/settings', 'TableController@settings')->name('table.conf');
Route::post('@{user}/{table}/settings', 'TableController@storeSettings')->name('table.storeConf');
}); });
// Table resource - located at the end to work as a fallback // Table resource - located at the end to work as a fallback

Loading…
Cancel
Save