Complete new service, option, and variable management interface in Admin CP
This commit is contained in:
parent
bccbb309b2
commit
d7682bb7c9
16 changed files with 698 additions and 925 deletions
|
@ -27,15 +27,63 @@ namespace Pterodactyl\Http\Controllers\Admin;
|
|||
use Log;
|
||||
use Alert;
|
||||
use Storage;
|
||||
use Pterodactyl\Models;
|
||||
use Javascript;
|
||||
use Illuminate\Http\Request;
|
||||
use Pterodactyl\Models\Service;
|
||||
use Pterodactyl\Models\ServiceOption;
|
||||
use Pterodactyl\Exceptions\DisplayException;
|
||||
use Pterodactyl\Http\Controllers\Controller;
|
||||
use Pterodactyl\Repositories\OptionRepository;
|
||||
use Pterodactyl\Repositories\VariableRepository;
|
||||
use Pterodactyl\Exceptions\DisplayValidationException;
|
||||
|
||||
class OptionController extends Controller
|
||||
{
|
||||
/**
|
||||
* Handles request to view page for adding new option.
|
||||
*
|
||||
* @param Request $request
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function new(Request $request)
|
||||
{
|
||||
$services = Service::with('options')->get();
|
||||
Javascript::put(['services' => $services->keyBy('id')]);
|
||||
|
||||
return view('admin.services.options.new', ['services' => $services]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles POST request to create a new option.
|
||||
|
||||
* @param Request $request
|
||||
* @return \Illuminate\Response\RedirectResponse
|
||||
*/
|
||||
public function create(Request $request)
|
||||
{
|
||||
$repo = new OptionRepository;
|
||||
|
||||
try {
|
||||
$option = $repo->create($request->intersect([
|
||||
'service_id', 'name', 'description', 'tag',
|
||||
'docker_image', 'startup', 'config_from', 'config_startup',
|
||||
'config_logs', 'config_files', 'config_stop'
|
||||
]));
|
||||
Alert::success('Successfully created new service option.')->flash();
|
||||
|
||||
return redirect()->route('admin.services.option.view', $option->id);
|
||||
} catch (DisplayValidationException $ex) {
|
||||
return redirect()->route('admin.services.option.new')->withErrors(json_decode($ex->getMessage()))->withInput();
|
||||
} catch (DisplayException $ex) {
|
||||
Alert::danger($ex->getMessage())->flash();
|
||||
} catch (\Exception $ex) {
|
||||
Log::error($ex);
|
||||
Alert::danger('An unhandled exception occurred while attempting to create this service. This error has been logged.')->flash();
|
||||
}
|
||||
|
||||
return redirect()->route('admin.services.option.new')->withInput();
|
||||
}
|
||||
|
||||
/**
|
||||
* Display option overview page.
|
||||
*
|
||||
|
@ -45,27 +93,89 @@ class OptionController extends Controller
|
|||
*/
|
||||
public function viewConfiguration(Request $request, $id)
|
||||
{
|
||||
return view('admin.services.options.view', ['option' => Models\ServiceOption::findOrFail($id)]);
|
||||
return view('admin.services.options.view', ['option' => ServiceOption::findOrFail($id)]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display variable overview page for a service option.
|
||||
*
|
||||
* @param Request $request
|
||||
* @param int $id
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function viewVariables(Request $request, $id)
|
||||
{
|
||||
return view('admin.services.options.variables', ['option' => ServiceOption::with('variables')->findOrFail($id)]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles POST when editing a configration for a service option.
|
||||
*
|
||||
* @param Request $request
|
||||
* @return \Illuminate\Response\RedirectResponse
|
||||
*/
|
||||
public function editConfiguration(Request $request, $id)
|
||||
{
|
||||
$repo = new OptionRepository;
|
||||
|
||||
try {
|
||||
$repo->update($id, $request->intersect([
|
||||
'name', 'description', 'tag', 'docker_image', 'startup',
|
||||
'config_from', 'config_stop', 'config_logs', 'config_files', 'config_startup',
|
||||
]));
|
||||
if ($request->input('action') !== 'delete') {
|
||||
$repo->update($id, $request->intersect([
|
||||
'name', 'description', 'tag', 'docker_image', 'startup',
|
||||
'config_from', 'config_stop', 'config_logs', 'config_files', 'config_startup',
|
||||
]));
|
||||
Alert::success('Service option configuration has been successfully updated.')->flash();
|
||||
} else {
|
||||
$option = ServiceOption::with('service')->where('id', $id)->first();
|
||||
$repo->delete($id);
|
||||
Alert::success('Successfully deleted service option from the system.')->flash();
|
||||
|
||||
Alert::success('Service option configuration has been successfully updated.')->flash();
|
||||
return redirect()->route('admin.services.view', $option->service_id);
|
||||
}
|
||||
} catch (DisplayValidationException $ex) {
|
||||
return redirect()->route('admin.services.option.view', $id)->withErrors(json_decode($ex->getMessage()));
|
||||
} catch (DisplayException $ex) {
|
||||
Alert::danger($ex->getMessage())->flash();
|
||||
} catch (\Exception $ex) {
|
||||
Log::error($ex);
|
||||
Alert::danger('An unhandled exception occurred while attempting to update this service option. This error has been logged.')->flash();
|
||||
Alert::danger('An unhandled exception occurred while attempting to perform that action. This error has been logged.')->flash();
|
||||
}
|
||||
|
||||
return redirect()->route('admin.services.option.view', $id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles POST when editing a configration for a service option.
|
||||
*
|
||||
* @param Request $request
|
||||
* @param int $option
|
||||
* @param int $variable
|
||||
* @return \Illuminate\Response\RedirectResponse
|
||||
*/
|
||||
public function editVariable(Request $request, $option, $variable)
|
||||
{
|
||||
$repo = new VariableRepository;
|
||||
|
||||
try {
|
||||
if ($request->input('action') !== 'delete') {
|
||||
$variable = $repo->update($variable, $request->only([
|
||||
'name', 'description', 'env_variable',
|
||||
'default_value', 'options', 'rules',
|
||||
]));
|
||||
Alert::success("The service variable '{$variable->name}' has been updated.")->flash();
|
||||
} else {
|
||||
$repo->delete($variable);
|
||||
Alert::success("That service variable has been deleted.")->flash();
|
||||
}
|
||||
} catch (DisplayValidationException $ex) {
|
||||
return redirect()->route('admin.services.option.variables', $option)->withErrors(json_decode($ex->getMessage()));
|
||||
} catch (DisplayException $ex) {
|
||||
Alert::danger($ex->getMessage())->flash();
|
||||
} catch (\Exception $ex) {
|
||||
Log::error($ex);
|
||||
Alert::danger('An unhandled exception was encountered while attempting to process that request. This error has been logged.')->flash();
|
||||
}
|
||||
|
||||
return redirect()->route('admin.services.option.variables', $option);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -103,32 +103,6 @@ class ServiceController extends Controller
|
|||
return redirect()->route('admin.services.new')->withInput();
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a service from the system.
|
||||
*
|
||||
* @param Request $request
|
||||
* @param int $id
|
||||
* @return \Illuminate\Response\RedirectResponse
|
||||
*/
|
||||
public function delete(Request $request, $id)
|
||||
{
|
||||
$repo = new ServiceRepository;
|
||||
|
||||
try {
|
||||
$repo->delete($id);
|
||||
Alert::success('Successfully deleted service.')->flash();
|
||||
|
||||
return redirect()->route('admin.services');
|
||||
} catch (DisplayException $ex) {
|
||||
Alert::danger($ex->getMessage())->flash();
|
||||
} catch (\Exception $ex) {
|
||||
Log::error($ex);
|
||||
Alert::danger('An error was encountered while attempting to delete that service. This error has been logged')->flash();
|
||||
}
|
||||
|
||||
return redirect()->route('admin.services.view', $id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Edits configuration for a specific service.
|
||||
*
|
||||
|
@ -141,10 +115,17 @@ class ServiceController extends Controller
|
|||
$repo = new ServiceRepository;
|
||||
|
||||
try {
|
||||
$repo->update($id, $request->intersect([
|
||||
'name', 'description', 'folder', 'startup',
|
||||
]));
|
||||
Alert::success('Service has been updated successfully.')->flash();
|
||||
if ($request->input('action') !== 'delete') {
|
||||
$repo->update($id, $request->intersect([
|
||||
'name', 'description', 'folder', 'startup',
|
||||
]));
|
||||
Alert::success('Service has been updated successfully.')->flash();
|
||||
} else {
|
||||
$repo->delete($id);
|
||||
Alert::success('Successfully deleted service from the system.')->flash();
|
||||
|
||||
return redirect()->route('admin.services');
|
||||
}
|
||||
} catch (DisplayValidationException $ex) {
|
||||
return redirect()->route('admin.services.view', $id)->withErrors(json_decode($ex->getMessage()))->withInput();
|
||||
} catch (DisplayException $ex) {
|
||||
|
|
|
@ -419,20 +419,25 @@ class AdminRoutes
|
|||
'uses' => 'Admin\OptionController@new',
|
||||
]);
|
||||
|
||||
$router->post('/option/new', 'Admin\OptionController@create');
|
||||
|
||||
$router->get('/option/{id}', [
|
||||
'as' => 'admin.services.option.view',
|
||||
'uses' => 'Admin\OptionController@viewConfiguration',
|
||||
]);
|
||||
|
||||
$router->get('/option/{id}/variables', [
|
||||
'as' => 'admin.services.option.view.variables',
|
||||
'as' => 'admin.services.option.variables',
|
||||
'uses' => 'Admin\OptionController@viewVariables',
|
||||
]);
|
||||
|
||||
$router->post('/option/{id}', [
|
||||
'uses' => 'Admin\OptionController@editConfiguration',
|
||||
$router->post('/option/{id}/variables/{variable}', [
|
||||
'as' => 'admin.services.option.variables.edit',
|
||||
'uses' => 'Admin\OptionController@editVariable',
|
||||
]);
|
||||
|
||||
$router->post('/option/{id}', 'Admin\OptionController@editConfiguration');
|
||||
|
||||
});
|
||||
|
||||
// Service Packs
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue