Skip to content

Commit e42547a

Browse files
committed
add support for editing service options
1 parent 4e60adc commit e42547a

File tree

3 files changed

+116
-23
lines changed

3 files changed

+116
-23
lines changed

app/Http/Controllers/Admin/ServiceController.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,19 @@ public function getOption(Request $request, $option)
107107

108108
public function postOption(Request $request, $option)
109109
{
110-
// editing option
110+
try {
111+
$repo = new ServiceRepository\Option;
112+
$repo->update($option, $request->except([
113+
'_token'
114+
]));
115+
Alert::success('Option settings successfully updated.')->flash();
116+
} catch (DisplayValidationException $ex) {
117+
return redirect()->route('admin.services.option', $option)->withErrors(json_decode($ex->getMessage()))->withInput();
118+
} catch (\Exception $ex) {
119+
Log::error($ex);
120+
Alert::danger('An error occured while attempting to modify this option.')->flash();
121+
}
122+
return redirect()->route('admin.services.option', $option)->withInput();
111123
}
112124

113125
public function postOptionVariable(Request $request, $option, $variable)

app/Repositories/ServiceRepository/Option.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,31 @@ public function __construct()
4242

4343
public function update($id, array $data)
4444
{
45+
$option = Models\ServiceOptions::findOrFail($id);
4546

47+
$validator = Validator::make($data, [
48+
'name' => 'sometimes|required|string|max:255',
49+
'description' => 'sometimes|required|string|min:1',
50+
'tag' => 'sometimes|required|string|max:255',
51+
'executable' => 'sometimes|string|max:255',
52+
'docker_image' => 'sometimes|required|string|max:255',
53+
'startup' => 'sometimes|string'
54+
]);
55+
56+
if ($validator->fails()) {
57+
throw new DisplayValidationException($validator->errors());
58+
}
59+
60+
if (isset($data['executable']) && empty($data['executable'])) {
61+
$data['executable'] = null;
62+
}
63+
64+
if (isset($data['startup']) && empty($data['startup'])) {
65+
$data['startup'] = null;
66+
}
67+
68+
$option->fill($data);
69+
$option->save();
4670
}
4771

4872
}

resources/views/admin/services/options/view.blade.php

Lines changed: 79 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -31,28 +31,64 @@
3131
<li><a href="{{ route('admin.services.service', $service->id) }}">{{ $service->name }}</a></li>
3232
<li class="active">{{ $option->name }}</li>
3333
</ul>
34-
<h3 class="nopad">Servers</h3>
35-
<table class="table table-bordered table-hover">
36-
<thead>
37-
<tr>
38-
<th>Name</th>
39-
<th>Owner</th>
40-
<th>Connection</th>
41-
<th>Updated</th>
42-
</tr>
43-
</thead>
44-
<tbody>
45-
@foreach ($servers as $server)
46-
<tr>
47-
<td><a href="{{ route('admin.servers.view', $server->id) }}">{{ $server->name }}</a></td>
48-
<td><a href="{{ route('admin.accounts.view', $server->owner) }}">{{ $server->a_ownerEmail }}</a></td>
49-
<td><code>{{ $server->ip }}:{{ $server->port }}</code></td>
50-
<td>{{ $server->updated_at }}</td>
51-
</tr>
52-
@endforeach
53-
</tbody>
54-
</table>
55-
<h3 class="nopad">Option Variables</h3><hr />
34+
<div class="alert alert-warning"><strong>Warning!</strong> This page contains advanced settings that the panel and daemon use to control servers. Modifying information on this page is not recommended unless you are absolutely sure of what you are doing.</div>
35+
<h3>Settings</h3><hr />
36+
<form action="{{ route('admin.services.option', $option->id) }}" method="POST">
37+
<div class="row">
38+
<div class="col-md-6 form-group">
39+
<label class="control-label">Name:</label>
40+
<div>
41+
<input type="text" name="name" value="{{ old('name', $option->name) }}" class="form-control" />
42+
</div>
43+
</div>
44+
<div class="col-md-6 form-group">
45+
<label class="control-label">Description:</label>
46+
<div>
47+
<textarea name="description" class="form-control" rows="3">{{ old('description', $option->description) }}</textarea>
48+
</div>
49+
</div>
50+
</div>
51+
<div class="row">
52+
<div class="col-md-3 form-group">
53+
<label class="control-label">Tag:</label>
54+
<div>
55+
<input type="text" name="tag" value="{{ old('tag', $option->tag) }}" class="form-control" />
56+
</div>
57+
</div>
58+
<div class="col-md-3 form-group">
59+
<label class="control-label">Executable:</label>
60+
<div>
61+
<input type="text" name="executable" value="{{ old('executable', $option->executable) }}" class="form-control" />
62+
<p class="text-muted"><small>Leave blank to use parent executable.</small></p>
63+
</div>
64+
</div>
65+
<div class="col-md-6 form-group">
66+
<label class="control-label">Docker Image:</label>
67+
<div>
68+
<input type="text" name="docker_image" value="{{ old('docker_image', $option->docker_image) }}" class="form-control" />
69+
<p class="text-muted"><small>Changing the docker image will only effect servers created or modified after this point.</small></p>
70+
</div>
71+
</div>
72+
</div>
73+
<div class="row">
74+
<div class="col-md-12 form-group">
75+
<label class="control-label">Default Startup Command:</label>
76+
<div>
77+
<input type="text" name="startup" value="{{ old('startup', $option->startup) }}" class="form-control" />
78+
<p class="text-muted"><small>To use the default startup of the parent service simply leave this field blank.</small></p>
79+
</div>
80+
</div>
81+
</div>
82+
<div class="well well-sm">
83+
<div class="row">
84+
<div class="col-md-12">
85+
{!! csrf_field() !!}
86+
<input type="submit" class="btn btn-sm btn-primary" value="Update Service Option" />
87+
</div>
88+
</div>
89+
</div>
90+
</form>
91+
<h3>Variables</h3><hr />
5692
@foreach($variables as $variable)
5793
<form action="{{ route('admin.services.option.variable', [ 'option' => $option->id, 'variable' => $variable->id ]) }}" method="POST">
5894
<div class="well">
@@ -128,6 +164,27 @@
128164
</div>
129165
</form>
130166
@endforeach
167+
<h3>Servers</h3><hr />
168+
<table class="table table-bordered table-hover">
169+
<thead>
170+
<tr>
171+
<th>Name</th>
172+
<th>Owner</th>
173+
<th>Connection</th>
174+
<th>Updated</th>
175+
</tr>
176+
</thead>
177+
<tbody>
178+
@foreach ($servers as $server)
179+
<tr>
180+
<td><a href="{{ route('admin.servers.view', $server->id) }}">{{ $server->name }}</a></td>
181+
<td><a href="{{ route('admin.accounts.view', $server->owner) }}">{{ $server->a_ownerEmail }}</a></td>
182+
<td><code>{{ $server->ip }}:{{ $server->port }}</code></td>
183+
<td>{{ $server->updated_at }}</td>
184+
</tr>
185+
@endforeach
186+
</tbody>
187+
</table>
131188
</div>
132189
<script>
133190
$(document).ready(function () {

0 commit comments

Comments
 (0)