comments and cleaning in TableEditController

pull/35/head
Ondřej Hruška 6 years ago
parent 23f27e6f34
commit c952798e66
Signed by: MightyPork
GPG Key ID: 2C5FD5035250423D
  1. 40
      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); 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) public function draft(User $user, string $table, $tab = null)
{ {
/** @var Table $tableModel */ /** @var Table $tableModel */
@ -61,7 +76,7 @@ class TableEditController extends Controller
if ($tab == null) $tab = 'edit-rows'; 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"); if (!method_exists($this, $method)) abort(404, "No such tab: $tab");
$changeset = $this->getChangeset($tableModel); $changeset = $this->getChangeset($tableModel);
@ -74,7 +89,7 @@ class TableEditController extends Controller
} }
/** @noinspection PhpUnusedPrivateMethodInspection */ /** @noinspection PhpUnusedPrivateMethodInspection */
private function editRows(Changeset $changeset) private function tabEditRows(Changeset $changeset)
{ {
$revision = $changeset->revision; $revision = $changeset->revision;
$columns = $changeset->fetchAndTransformColumns(); $columns = $changeset->fetchAndTransformColumns();
@ -89,7 +104,7 @@ class TableEditController extends Controller
} }
/** @noinspection PhpUnusedPrivateMethodInspection */ /** @noinspection PhpUnusedPrivateMethodInspection */
private function addRows(Changeset $changeset) private function tabAddRows(Changeset $changeset)
{ {
$columns = $changeset->fetchAndTransformColumns(); $columns = $changeset->fetchAndTransformColumns();
$rows = $changeset->getAddedRows(25); $rows = $changeset->getAddedRows(25);
@ -103,7 +118,7 @@ class TableEditController extends Controller
} }
/** @noinspection PhpUnusedPrivateMethodInspection */ /** @noinspection PhpUnusedPrivateMethodInspection */
private function addRowsCsv(Changeset $changeset) private function tabAddRowsCsv(Changeset $changeset)
{ {
$columns = $changeset->fetchAndTransformColumns(); $columns = $changeset->fetchAndTransformColumns();
@ -115,7 +130,7 @@ class TableEditController extends Controller
} }
/** @noinspection PhpUnusedPrivateMethodInspection */ /** @noinspection PhpUnusedPrivateMethodInspection */
private function manageColumns(Changeset $changeset) private function tabManageColumns(Changeset $changeset)
{ {
$columns = $changeset->fetchAndTransformColumns(); $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) public function draftUpdate(Request $request, User $user, string $table)
{ {
/** @var Table $tableModel */ /** @var Table $tableModel */

Loading…
Cancel
Save