diff --git a/app/Http/Controllers/ServerController.php b/app/Http/Controllers/ServerController.php index 8a7a3fcb9ab7d0976c3059154978a29ad011b2ed..07ad995b1c88dd00a24a88b8f94929e3dd12f44c 100644 --- a/app/Http/Controllers/ServerController.php +++ b/app/Http/Controllers/ServerController.php @@ -21,7 +21,9 @@ class ServerController extends Controller return [ 'name' => 'required|string|regex:/^[a-zA-Z0-9\s\-\.]+$/|max:255', "organization_id" => Rule::in(Auth::user()->organizations->modelKeys()), - "description" => 'nullable|string']; + "description" => 'nullable|string', + "size" => "nullable|int|min:0|max:48", + "position" => "nullable|int|min:0|max:48"]; } /** @@ -90,6 +92,8 @@ class ServerController extends Controller $server->name = $request->name; $server->organization_id = $request->organization_id; $server->description = $request->description; + $server->size = $request->size; + $server->position = $request->position; $server->save(); return redirect(action("ServerController@show", ["server" => $server])); diff --git a/app/Server.php b/app/Server.php index 96e22279e4cd33d2d30a0efc19894e42d5e9c00e..df4267431c5a31ebc5351abbfafd0c353d1ae354 100644 --- a/app/Server.php +++ b/app/Server.php @@ -17,6 +17,8 @@ use Illuminate\Support\Collection; * @property \Illuminate\Support\Carbon|null $updated_at * @property string $name * @property string $description + * @property int $size rack size, expressed in "U" + * @property int $position position in rack, expressed in "U", starting from the bottom * @property string $token * @property string $read_token * @property \App\Organization $organization diff --git a/database/migrations/2024_03_27_192615_servers_add_rack_information.php b/database/migrations/2024_03_27_192615_servers_add_rack_information.php new file mode 100644 index 0000000000000000000000000000000000000000..d5be04a141cb2ab225ccb0f69c0bb3a7027de556 --- /dev/null +++ b/database/migrations/2024_03_27_192615_servers_add_rack_information.php @@ -0,0 +1,37 @@ +<?php + +use Illuminate\Database\Migrations\Migration; +use Illuminate\Database\Schema\Blueprint; +use Illuminate\Support\Facades\Schema; + +class ServersAddRackInformation extends Migration +{ + /** + * Run the migrations. + * + * @return void + */ + public function up() + { + Schema::table('servers', function (Blueprint $table) { + // expressed in "U" + $table->unsignedInteger("size")->default(0); + + // expressed in "U", starting from the bottom + $table->unsignedInteger("position")->default(0); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('servers', function (Blueprint $table) { + $table->dropColumn("size"); + $table->dropColumn("position"); + }); + } +} diff --git a/resources/views/organization/rack.blade.php b/resources/views/organization/rack.blade.php index 6eb07885e89cf948491911dbca65fba224583e69..838eee545487a4c2a422538984861cab826573a0 100644 --- a/resources/views/organization/rack.blade.php +++ b/resources/views/organization/rack.blade.php @@ -2,6 +2,12 @@ @section('content') <style> + div.rack { + position: relative; + width: 100%; + border: 1px solid rgba(0, 0, 0, 0.1); + } + div.server { position: absolute; width: 100%; @@ -15,30 +21,54 @@ border: 1px solid rgba(0, 0, 0, 0.1); } - div.1u { + div.size-1u { height: 2rem; } - div.2u { + div.size-2u { height: 4rem; } + + div.size-48u { + height: 96rem + } + + div.slot { + position: absolute; + width: 100%; + height: 2rem; + + padding: 0.2rem; + + display: flex; + flex-direction: column; + word-wrap: break-word; + background-color: rgba(0, 0, 0, 0.01); + border: 1px solid rgba(0, 0, 0, 0.05); + } </style> <div class="container"> - - <h1>{{ $organization->name }}</h1> - - <div style="position: relative; width: 100%; height: 96rem"> - - <div class="server 1u" - style="bottom: 2rem;"> - Server 02 - </div> + <div class="rack size-48u"> + @for ($i = 0; $i < 48; $i++) + <div class="slot" style="bottom: {{ 2*$i }}rem"></div> + @endfor - <div class="server 1u" - style="bottom: 0rem;"> - Server 01 + @foreach ($organization->servers as $server) + @if ($server->size == 0) + @continue + @endif + <div class="server size-{{ $server->size }}u" + style="bottom: {{ 2*$server->position }}rem;"> + <p> + <a href="{{ $server->getUrlAttribute() }}" + class="text-decoration-none"> + {{ $server->name }} + </a> + {!! $server->status()->badge() !!} + </p> </div> + @endforeach </div> </div> diff --git a/resources/views/organization/show.blade.php b/resources/views/organization/show.blade.php index 240ed8e5af406ab049ae7e24795b5c411b03ea2f..12e51f90bd62c03260db35954955f5b17c3c7146 100644 --- a/resources/views/organization/show.blade.php +++ b/resources/views/organization/show.blade.php @@ -28,6 +28,11 @@ "organization" => $organization]) }}"> <i class="fas fa-redo-alt"></i> Reset dashboard token </a> + + <a class="btn btn-primary btn-sm" + href="{{ action("OrganizationController@rack", ["organization" => $organization]) }}"> + <i class="fas fa-server"></i> Rack view + </a> </p> <table class="table table-striped my-5"> diff --git a/resources/views/server/edit.blade.php b/resources/views/server/edit.blade.php index 7d7d7c069e8ce025ad9d9b983a50be76f5fd22ad..9781e8b0f72fef3a41b6b0f69a60d65cfd87fe0d 100644 --- a/resources/views/server/edit.blade.php +++ b/resources/views/server/edit.blade.php @@ -68,6 +68,48 @@ </span> @endif </div> + + <div class="form-group"> + <label for="size">Form factor</label> + + <div class="input-group"> + <input id="size" + type="number" min="0" max="48" step="1" + class="form-control{{ $errors->has('size') ? ' is-invalid' : '' }}" + name="size" + value="{{ old('size', $server->size) }}"> + <div class="input-group-append"> + <div class="input-group-text">u</div> + </div> + </div> + + @if ($errors->has('size')) + <span class="invalid-feedback"> + <strong>{{ $errors->first('size') }}</strong> + </span> + @endif + </div> + + <div class="form-group"> + <label for="position">Position (from bottom)</label> + + <div class="input-group"> + <input id="position" + type="number" min="0" max="48" step="1" + class="form-control{{ $errors->has('position') ? ' is-invalid' : '' }}" + name="position" + value="{{ old('position', $server->position) }}"> + <div class="input-group-append"> + <div class="input-group-text">u</div> + </div> + </div> + + @if ($errors->has('position')) + <span class="invalid-feedback"> + <strong>{{ $errors->first('position') }}</strong> + </span> + @endif + </div> <div class="form-group"> <button type="submit" class="btn btn-primary">