From c952798e66a219e9a5a5580f9ea9492711181efe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Hru=C5=A1ka?= Date: Fri, 10 Aug 2018 22:06:30 +0200 Subject: [PATCH] comments and cleaning in TableEditController --- app/Http/Controllers/TableEditController.php | 40 ++++++++++++++++---- 1 file changed, 33 insertions(+), 7 deletions(-) diff --git a/app/Http/Controllers/TableEditController.php b/app/Http/Controllers/TableEditController.php index 7829546..e35777b 100644 --- a/app/Http/Controllers/TableEditController.php +++ b/app/Http/Controllers/TableEditController.php @@ -34,9 +34,14 @@ class TableEditController extends Controller }); } - private function storeChangeset(Changeset $chs) + /** + * Store the changeset to session + * + * @param Changeset $changeset + */ + private function storeChangeset(Changeset $changeset) { - session()->put($chs->table->draftSessionKey, $chs); + session()->put($changeset->table->draftSessionKey, $changeset); } /** @@ -53,6 +58,16 @@ class TableEditController extends Controller return redirect($tableModel->viewRoute); } + #region Draft tabs + + /** + * Show the table edit view with tabs + * + * @param User $user - table owner + * @param string $table - table name + * @param string|null $tab - page tab name, kebab-case + * @return \Illuminate\View\View; + */ public function draft(User $user, string $table, $tab = null) { /** @var Table $tableModel */ @@ -61,7 +76,7 @@ class TableEditController extends Controller if ($tab == null) $tab = 'edit-rows'; - $method = camel_case($tab); + $method = camel_case('tab-'.$tab); if (!method_exists($this, $method)) abort(404, "No such tab: $tab"); $changeset = $this->getChangeset($tableModel); @@ -74,7 +89,7 @@ class TableEditController extends Controller } /** @noinspection PhpUnusedPrivateMethodInspection */ - private function editRows(Changeset $changeset) + private function tabEditRows(Changeset $changeset) { $revision = $changeset->revision; $columns = $changeset->fetchAndTransformColumns(); @@ -89,7 +104,7 @@ class TableEditController extends Controller } /** @noinspection PhpUnusedPrivateMethodInspection */ - private function addRows(Changeset $changeset) + private function tabAddRows(Changeset $changeset) { $columns = $changeset->fetchAndTransformColumns(); $rows = $changeset->getAddedRows(25); @@ -103,7 +118,7 @@ class TableEditController extends Controller } /** @noinspection PhpUnusedPrivateMethodInspection */ - private function addRowsCsv(Changeset $changeset) + private function tabAddRowsCsv(Changeset $changeset) { $columns = $changeset->fetchAndTransformColumns(); @@ -115,7 +130,7 @@ class TableEditController extends Controller } /** @noinspection PhpUnusedPrivateMethodInspection */ - private function manageColumns(Changeset $changeset) + private function tabManageColumns(Changeset $changeset) { $columns = $changeset->fetchAndTransformColumns(); @@ -126,6 +141,17 @@ class TableEditController extends Controller ]); } + #endregion + + /** + * API hook called by AJAX or via forms. + * Generally applies modifications to the Changeset stored in session. + * + * @param Request $request + * @param User $user + * @param string $table + * @return \Symfony\Component\HttpFoundation\Response + */ public function draftUpdate(Request $request, User $user, string $table) { /** @var Table $tableModel */