|
|
|
@ -22,8 +22,19 @@ use MightyPork\Exceptions\NotApplicableException; |
|
|
|
|
use MightyPork\Exceptions\SimpleValidationException; |
|
|
|
|
use MightyPork\Utils\Utils; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Table view, creation, settings |
|
|
|
|
*/ |
|
|
|
|
class TableController extends Controller |
|
|
|
|
{ |
|
|
|
|
/** |
|
|
|
|
* Helper to fetch a table by user and table name |
|
|
|
|
* |
|
|
|
|
* @param Request $request |
|
|
|
|
* @param User $user |
|
|
|
|
* @param string $table |
|
|
|
|
* @return Table |
|
|
|
|
*/ |
|
|
|
|
private function resolveTable(Request $request, User $user, string $table) |
|
|
|
|
{ |
|
|
|
|
/** @var Table $tableModel */ |
|
|
|
@ -32,6 +43,29 @@ class TableController extends Controller |
|
|
|
|
return $tableModel; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Favourite a table |
|
|
|
|
*/ |
|
|
|
|
public function favouriteTable(Request $request, User $user, string $table) |
|
|
|
|
{ |
|
|
|
|
$tableModel = $this->resolveTable($request, $user, $table); |
|
|
|
|
\user()->favouriteTables()->attach($tableModel); |
|
|
|
|
return redirect($tableModel->viewRoute); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Un-favourite a table |
|
|
|
|
*/ |
|
|
|
|
public function unfavouriteTable(Request $request, User $user, string $table) |
|
|
|
|
{ |
|
|
|
|
$tableModel = $this->resolveTable($request, $user, $table); |
|
|
|
|
\user()->favouriteTables()->detach($tableModel); |
|
|
|
|
return redirect($tableModel->viewRoute); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Switch table's current revision |
|
|
|
|
*/ |
|
|
|
|
public function revertTo(Request $request, User $user, string $table) |
|
|
|
|
{ |
|
|
|
|
$input = $this->validate($request, [ |
|
|
|
@ -51,6 +85,9 @@ class TableController extends Controller |
|
|
|
|
return redirect($tableModel->revisionsRoute); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Show a table |
|
|
|
|
*/ |
|
|
|
|
public function view(Request $request, User $user, string $table) |
|
|
|
|
{ |
|
|
|
|
$input = $this->validate($request, [ |
|
|
|
@ -91,6 +128,9 @@ class TableController extends Controller |
|
|
|
|
]); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Delete a table |
|
|
|
|
*/ |
|
|
|
|
public function delete(Request $request, User $user, string $table) |
|
|
|
|
{ |
|
|
|
|
$tableModel = $this->resolveTable($request, $user, $table); |
|
|
|
@ -106,9 +146,7 @@ class TableController extends Controller |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* SHow a form for creating a new table |
|
|
|
|
* |
|
|
|
|
* @return \Illuminate\Http\Response |
|
|
|
|
* Show a form for creating a new table |
|
|
|
|
*/ |
|
|
|
|
public function create() |
|
|
|
|
{ |
|
|
|
@ -170,6 +208,9 @@ class TableController extends Controller |
|
|
|
|
return redirect($tableModel->viewRoute); // the route now changed |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* List of table revisions |
|
|
|
|
*/ |
|
|
|
|
public function viewRevisions(Request $request, User $user, string $table) |
|
|
|
|
{ |
|
|
|
|
$tableModel = $this->resolveTable($request, $user, $table); |
|
|
|
@ -182,6 +223,24 @@ class TableController extends Controller |
|
|
|
|
]); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* List of table favouriting users |
|
|
|
|
*/ |
|
|
|
|
public function viewFavourites(Request $request, User $user, string $table) |
|
|
|
|
{ |
|
|
|
|
$tableModel = $this->resolveTable($request, $user, $table); |
|
|
|
|
|
|
|
|
|
$users = $tableModel->favouritingUsers()->orderBy('title')->get(); |
|
|
|
|
|
|
|
|
|
return view('table.favourites', [ |
|
|
|
|
'table' => $tableModel, |
|
|
|
|
'users' => $users, |
|
|
|
|
]); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Store a newly created table (save form) |
|
|
|
|
*/ |
|
|
|
|
public function storeNew(Request $request) |
|
|
|
|
{ |
|
|
|
|
/** @var User $u */ |
|
|
|
|