Add server descriptions, closes #338 🐖

🐷 https://s3.kelp.in/D0n2Z.png
This commit is contained in:
Dane Everitt 2017-03-31 23:07:19 -04:00
parent 660cdca940
commit edaa270a33
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
7 changed files with 103 additions and 51 deletions

View file

@ -251,7 +251,7 @@ class ServersController extends Controller
$repo = new ServerRepository;
try {
$repo->updateDetails($id, $request->intersect([
'owner_id', 'name', 'reset_token',
'owner_id', 'name', 'description', 'reset_token',
]));
Alert::success('Server details were successfully updated.')->flash();

View file

@ -89,6 +89,7 @@ class ServerRepository
$validator = Validator::make($data, [
'user_id' => 'required|exists:users,id',
'name' => 'required|regex:/^([\w .-]{1,200})$/',
'description' => 'sometimes|nullable|string',
'memory' => 'required|numeric|min:0',
'swap' => 'required|numeric|min:-1',
'io' => 'required|numeric|min:10|max:1000',
@ -363,6 +364,7 @@ class ServerRepository
$validator = Validator::make($data, [
'owner_id' => 'sometimes|required|integer|exists:users,id',
'name' => 'sometimes|required|regex:([\w .-]{1,200})',
'description' => 'sometimes|required|string',
'reset_token' => 'sometimes|required|accepted',
]);
@ -384,24 +386,12 @@ class ServerRepository
$resetDaemonKey = true;
}
// Update Server Owner if it was passed.
if (isset($data['owner_id']) && (int) $data['owner_id'] !== $server->user->id) {
$server->owner_id = $data['owner_id'];
}
// Update Server Name if it was passed.
if (isset($data['name'])) {
$server->name = $data['name'];
}
// Save our changes
$server->save();
$server->fill($data)->save();
// Do we need to update? If not, return successful.
if (! $resetDaemonKey) {
DB::commit();
return true;
return DB::commit();
}
$res = $server->node->guzzleClient([
@ -418,16 +408,13 @@ class ServerRepository
]);
if ($res->getStatusCode() === 204) {
DB::commit();
return true;
return DB::commit();
} else {
throw new DisplayException('Daemon returned a a non HTTP/204 error code. HTTP/' + $res->getStatusCode());
}
} catch (\Exception $ex) {
DB::rollBack();
Log::error($ex);
throw new DisplayException('An error occured while attempting to update this server\'s information.');
throw $ex;
}
}

View file

@ -0,0 +1,32 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class AddServerDescriptionColumn extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('servers', function (Blueprint $table) {
$table->text('description')->after('name');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('servers', function (Blueprint $table) {
$table->dropColumn('description');
});
}
}

View file

@ -280,3 +280,12 @@ span[aria-labelledby="select2-pUserId-container"] {
.strong {
font-weight: bold !important;
}
.server-description > td {
padding-top: 0 !important;
border-top: 0 !important;
}
tr:hover + tr.server-description {
background-color: #f5f5f5 !important;
}

View file

@ -41,16 +41,23 @@
<h3 class="box-title">Core Details</h3>
</div>
<div class="box-body row">
<div class="form-group col-sm-6">
<div class="col-md-6">
<div class="form-group">
<label for="pName">Server Name</label>
<input type="text" class="form-control" id="pName" name="name" value="{{ old('name') }}" placeholder="Server Name">
<p class="small text-muted no-margin">Character limits: <code>a-z A-Z 0-9 _ - .</code> and <code>[Space]</code> (max 200 characters).</p>
</div>
<div class="form-group col-sm-6">
<div class="form-group">
<label for="pUserId">Server Owner</label>
<select class="form-control" style="padding-left:0;" name="user_id" id="pUserId"></select>
</div>
</div>
<div class="form-group col-md-6">
<label for="description" class="control-label">Server Description</label>
<textarea name="description" rows="3" class="form-control">{{ old('description') }}</textarea>
<p class="text-muted small">A brief description of this server.</p>
</div>
</div>
</div>
</div>
</div>

View file

@ -71,6 +71,11 @@
</select>
<p class="text-muted small">You can change the owner of this server by changing this field to an email matching another use on this system. If you do this a new daemon security token will be generated automatically.</p>
</div>
<div class="form-group">
<label for="description" class="control-label">Server Description</label>
<textarea name="description" rows="3" class="form-control">{{ old('description', $server->description) }}</textarea>
<p class="text-muted small">A brief description of this server.</p>
</div>
<div class="form-group">
<label for="name" class="control-label">Daemon Secret Token</label>
<input type="text" disabled value="{{ $server->daemonSecret }}" class="form-control" />

View file

@ -61,7 +61,7 @@
</tr>
@foreach($servers as $server)
<tr class="dynamic-update" data-server="{{ $server->uuidShort }}">
<td><code>{{ $server->uuidShort }}</code></td>
<td @if(! empty($server->description)) rowspan="2" @endif><code>{{ $server->uuidShort }}</code></td>
<td><a href="{{ route('server.index', $server->uuidShort) }}">{{ $server->name }}</a></td>
<td>{{ $server->node->name }}</td>
<td><code>{{ $server->allocation->alias }}:{{ $server->allocation->port }}</code></td>
@ -84,6 +84,11 @@
@endif
</td>
</tr>
@if (! empty($server->description))
<tr class="server-description">
<td colspan="7"><p class="text-muted small no-margin">{{ str_limit($server->description, 400) }}</p></td>
</tr>
@endif
@endforeach
</tbody>
</table>
@ -100,5 +105,12 @@
@section('footer-scripts')
@parent
<script>
$('tr.server-description').on('mouseenter mouseleave', function (event) {
$(this).prev('tr').css({
'background-color': (event.type === 'mouseenter') ? '#f5f5f5' : '',
});
});
</script>
{!! Theme::js('js/frontend/serverlist.js') !!}
@endsection