From 8ff10904ce189965070f18d996123fcaec782f6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Hru=C5=A1ka?= Date: Sun, 29 Jul 2018 18:26:59 +0200 Subject: [PATCH] implemented table metadata editing page --- app/Http/Controllers/TableController.php | 29 +++++++++++++++-- resources/views/table/conf.blade.php | 41 ++++++++++++++++++++++-- routes/web.php | 1 + 3 files changed, 66 insertions(+), 5 deletions(-) diff --git a/app/Http/Controllers/TableController.php b/app/Http/Controllers/TableController.php index 6b04aba..43718b4 100644 --- a/app/Http/Controllers/TableController.php +++ b/app/Http/Controllers/TableController.php @@ -22,7 +22,6 @@ class TableController extends Controller /** @var Table $tableModel */ $tableModel = $user->tables()->withCount(['favourites', 'forks', 'revisions', 'comments', 'proposals']) ->where('name', $table)->first(); - if ($tableModel === null) abort(404, "No such table."); // make it possible to show other revisions @@ -71,7 +70,6 @@ class TableController extends Controller /** @var Table $tableModel */ $tableModel = $user->tables()->where('name', $table)->first(); if ($tableModel === null) abort(404, "No such table."); - $this->authorize('edit', $tableModel); 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) { /** @var User $u */ diff --git a/resources/views/table/conf.blade.php b/resources/views/table/conf.blade.php index 399281e..775b728 100644 --- a/resources/views/table/conf.blade.php +++ b/resources/views/table/conf.blade.php @@ -24,8 +24,43 @@ -
- lalala -
{{-- End of row --}} +
+ @csrf +
+ @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.') !!} + +
+
+ +
+
+
+
@endsection diff --git a/routes/web.php b/routes/web.php index 6f32303..0bb7d7b 100644 --- a/routes/web.php +++ b/routes/web.php @@ -55,6 +55,7 @@ Route::group(['middleware' => 'auth'], function () { }); 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