1
1
mirror of https://github.com/pterodactyl/panel.git synced 2024-11-25 10:32:31 +01:00

Add support for adding new service option

This commit is contained in:
Dane Everitt 2016-02-20 16:45:13 -05:00
parent 177bd4ec9d
commit 1e9bf1c220
8 changed files with 186 additions and 4 deletions

View File

@ -47,7 +47,10 @@ class ServiceController extends Controller
public function getIndex(Request $request)
{
return view('admin.services.index', [
'services' => Models\Service::all()
'services' => Models\Service::select(
'services.*',
DB::raw('(SELECT COUNT(*) FROM servers WHERE servers.service = services.id) as c_servers')
)->get()
]);
}
@ -185,4 +188,29 @@ class ServiceController extends Controller
}
}
public function newOption(Request $request, $service)
{
return view('admin.services.options.new', [
'service' => Models\Service::findOrFail($service),
]);
}
public function postNewOption(Request $request, $service)
{
try {
$repo = new ServiceRepository\Option;
$id = $repo->create($service, $request->except([
'_token'
]));
Alert::success('Successfully created new service option.')->flash();
return redirect()->route('admin.services.option', $id);
} catch (DisplayValidationException $ex) {
return redirect()->route('admin.services.option.new', $service)->withErrors(json_decode($ex->getMessage()))->withInput();
} catch (\Exception $ex) {
Log::error($ex);
Alert::danger('An error occured while attempting to add this service option.')->flash();
}
return redirect()->route('admin.services.option.new', $service)->withInput();
}
}

View File

@ -370,6 +370,15 @@ class AdminRoutes {
'uses' => 'Admin\ServiceController@deleteService'
]);
$router->get('/option/new/{service}', [
'as' => 'admin.services.option.new',
'uses' => 'Admin\ServiceController@newOption'
]);
$router->post('/option/new/{service}', [
'uses' => 'Admin\ServiceController@postNewOption'
]);
$router->get('/option/{id}', [
'as' => 'admin.services.option',
'uses' => 'Admin\ServiceController@getOption'

View File

@ -40,6 +40,39 @@ class Option
//
}
public function create($service, array $data)
{
$service = Models\Service::findOrFail($service);
$validator = Validator::make($data, [
'name' => 'required|string|max:255',
'description' => 'required|string|min:1',
'tag' => 'required|string|max:255',
'executable' => 'sometimes|string|max:255',
'docker_image' => 'required|string|max:255',
'startup' => 'sometimes|string'
]);
if ($validator->fails()) {
throw new DisplayValidationException($validator->errors());
}
if (isset($data['executable']) && empty($data['executable'])) {
$data['executable'] = null;
}
if (isset($data['startup']) && empty($data['startup'])) {
$data['startup'] = null;
}
$option = new Models\ServiceOptions;
$option->parent_service = $service->id;
$option->fill($data);
$option->save();
return $option->id;
}
public function update($id, array $data)
{
$option = Models\ServiceOptions::findOrFail($id);

View File

@ -35,6 +35,7 @@
<tr>
<th>Service Type</th>
<th>Description</th>
<th class="text-center">Servers</th>
</tr>
</thead>
<tbody>
@ -42,8 +43,14 @@
<tr>
<td><a href="{{ route('admin.services.service', $service->id) }}">{{ $service->name }}</a></td>
<td>{!! $service->description !!}</td>
<td class="text-center">{{ $service->c_servers }}</td>
</tr>
@endforeach
<tr>
<td></td>
<td></td>
<td class="text-center"><a href="{{ route('admin.services.new') }}"><i class="fa fa-plus"></i></a></td>
</tr>
</tbody>
</table>
</div>

View File

@ -20,7 +20,7 @@
@extends('layouts.admin')
@section('title')
Manage Services
New Service
@endsection
@section('content')

View File

@ -0,0 +1,98 @@
{{-- Copyright (c) 2015 - 2016 Dane Everitt <dane@daneeveritt.com> --}}
{{-- Permission is hereby granted, free of charge, to any person obtaining a copy --}}
{{-- of this software and associated documentation files (the "Software"), to deal --}}
{{-- in the Software without restriction, including without limitation the rights --}}
{{-- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell --}}
{{-- copies of the Software, and to permit persons to whom the Software is --}}
{{-- furnished to do so, subject to the following conditions: --}}
{{-- The above copyright notice and this permission notice shall be included in all --}}
{{-- copies or substantial portions of the Software. --}}
{{-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR --}}
{{-- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, --}}
{{-- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE --}}
{{-- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER --}}
{{-- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, --}}
{{-- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE --}}
{{-- SOFTWARE. --}}
@extends('layouts.admin')
@section('title')
New Service Option for {{ $service->name }}
@endsection
@section('content')
<div class="col-md-12">
<ul class="breadcrumb">
<li><a href="/admin">Admin Control</a></li>
<li><a href="/admin/services">Services</a></li>
<li><a href="{{ route('admin.services.service', $service->id) }}">{{ $service->name }}</a></li>
<li class="active">New Service Option</li>
</ul>
<h3>Service Option Settings</h3><hr />
<form action="{{ route('admin.services.option.new', $service->id) }}" method="POST">
<div class="row">
<div class="col-md-6 form-group">
<label class="control-label">Name:</label>
<div>
<input type="text" name="name" value="{{ old('name') }}" class="form-control" />
</div>
</div>
<div class="col-md-6 form-group">
<label class="control-label">Description:</label>
<div>
<textarea name="description" class="form-control" rows="3">{{ old('description') }}</textarea>
</div>
</div>
</div>
<div class="row">
<div class="col-md-3 form-group">
<label class="control-label">Tag:</label>
<div>
<input type="text" name="tag" value="{{ old('tag') }}" class="form-control" />
</div>
</div>
<div class="col-md-3 form-group">
<label class="control-label">Executable:</label>
<div>
<input type="text" name="executable" value="{{ old('executable') }}" class="form-control" />
<p class="text-muted"><small>Leave blank to use parent executable.</small></p>
</div>
</div>
<div class="col-md-6 form-group">
<label class="control-label">Docker Image:</label>
<div>
<input type="text" name="docker_image" value="{{ old('docker_image') }}" class="form-control" />
</div>
</div>
</div>
<div class="row">
<div class="col-md-12 form-group">
<label class="control-label">Default Startup Command:</label>
<div>
<input type="text" name="startup" value="{{ old('startup') }}" class="form-control" />
<p class="text-muted"><small>To use the default startup of the parent service simply leave this field blank.</small></p>
</div>
</div>
</div>
<div class="well well-sm">
<div class="row">
<div class="col-md-12">
{!! csrf_field() !!}
<input type="submit" class="btn btn-sm btn-primary" value="Create Service Option" />
</div>
</div>
</div>
</form>
</div>
<script>
$(document).ready(function () {
$('#sidebar_links').find("a[href='/admin/services']").addClass('active');
$('#env_var').on('keyup', function () {
$(this).parent().find('code').html('&#123;&#123;' + escape($(this).val()) + '&#125;&#125;');
});
});
</script>
@endsection

View File

@ -20,7 +20,7 @@
@extends('layouts.admin')
@section('title')
Manage Services
Manage Service Option {{ $option->name }}
@endsection
@section('content')

View File

@ -20,7 +20,7 @@
@extends('layouts.admin')
@section('title')
Manage Services
Manage Service
@endsection
@section('content')
@ -51,6 +51,13 @@
<td class="text-center">{{ $option->c_servers }}</td>
</tr>
@endforeach
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td class="text-center"><a href="{{ route('admin.services.option.new', $service->id) }}"><i class="fa fa-plus"></i></a></td>
</tr>
</tbody>
</table>
<div class="well">