Skip to content

Commit

Permalink
Merge pull request #540 from dbarzin/dev
Browse files Browse the repository at this point in the history
Work on clusters
  • Loading branch information
dbarzin authored Nov 7, 2023
2 parents 551663f + 81e2af2 commit d1f756e
Show file tree
Hide file tree
Showing 8 changed files with 212 additions and 44 deletions.
42 changes: 31 additions & 11 deletions app/Http/Controllers/Admin/PhysicalServerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@

use App\Bay;
use App\Building;
use App\LogicalServer;
use App\MApplication;
use App\PhysicalServer;
use App\Site;
use App\Cluster;
// Laravel
use App\Http\Controllers\Controller;
use App\Http\Requests\MassDestroyPhysicalServerRequest;
use App\Http\Requests\StorePhysicalServerRequest;
use App\Http\Requests\UpdatePhysicalServerRequest;
use App\MApplication;
use App\PhysicalServer;
use App\Site;
use Gate;
use Symfony\Component\HttpFoundation\Response;

Expand All @@ -29,27 +32,38 @@ public function create()
{
abort_if(Gate::denies('physical_server_create'), Response::HTTP_FORBIDDEN, '403 Forbidden');

$sites = Site::all()->sortBy('name')->pluck('name', 'id')->prepend(trans('global.pleaseSelect'), '');
$buildings = Building::all()->sortBy('name')->pluck('name', 'id')->prepend(trans('global.pleaseSelect'), '');
$bays = Bay::all()->sortBy('name')->pluck('name', 'id')->prepend(trans('global.pleaseSelect'), '');
// $applications = MApplication::select('id','name')->sortBy('name')->prepend(trans('global.pleaseSelect'), '');
$sites = Site::all()->sortBy('name')->pluck('name', 'id');
$buildings = Building::all()->sortBy('name')->pluck('name', 'id');
$bays = Bay::all()->sortBy('name')->pluck('name', 'id');
$clusters = Cluster::all()->sortBy('name')->pluck('name', 'id');

// List
$application_list = MApplication::orderBy('name')->pluck('name', 'id');
$operating_system_list = PhysicalServer::select('operating_system')->where('operating_system', '<>', null)->distinct()->orderBy('operating_system')->pluck('operating_system');
$responsible_list = PhysicalServer::select('responsible')->where('responsible', '<>', null)->distinct()->orderBy('responsible')->pluck('responsible');
$type_list = PhysicalServer::select('type')->where('type', '<>', null)->distinct()->orderBy('type')->pluck('type');
$logical_server_list = LogicalServer::orderBy('name')->pluck('name', 'id');

return view(
'admin.physicalServers.create',
compact('sites', 'buildings', 'bays', 'application_list', 'operating_system_list', 'responsible_list', 'type_list')
compact(
'sites',
'buildings',
'bays',
'clusters',
'application_list',
'operating_system_list',
'responsible_list',
'type_list',
'logical_server_list')
);
}

public function store(StorePhysicalServerRequest $request)
{
$physicalServer = PhysicalServer::create($request->all());
$physicalServer->applications()->sync($request->input('applications', []));
$physicalServer->serversLogicalServers()->sync($request->input('logicalServers', []));

return redirect()->route('admin.physical-servers.index');
}
Expand All @@ -58,14 +72,17 @@ public function edit(PhysicalServer $physicalServer)
{
abort_if(Gate::denies('physical_server_edit'), Response::HTTP_FORBIDDEN, '403 Forbidden');

$sites = Site::all()->sortBy('name')->pluck('name', 'id')->prepend(trans('global.pleaseSelect'), '');
$buildings = Building::all()->sortBy('name')->pluck('name', 'id')->prepend(trans('global.pleaseSelect'), '');
$bays = Bay::all()->sortBy('name')->pluck('name', 'id')->prepend(trans('global.pleaseSelect'), '');
$sites = Site::all()->sortBy('name')->pluck('name', 'id');
$buildings = Building::all()->sortBy('name')->pluck('name', 'id');
$bays = Bay::all()->sortBy('name')->pluck('name', 'id');
$clusters = Cluster::all()->sortBy('name')->pluck('name', 'id');

// List
$operating_system_list = PhysicalServer::select('operating_system')->where('operating_system', '<>', null)->distinct()->orderBy('operating_system')->pluck('operating_system');
$responsible_list = PhysicalServer::select('responsible')->where('responsible', '<>', null)->distinct()->orderBy('responsible')->pluck('responsible');
$type_list = PhysicalServer::select('type')->where('type', '<>', null)->distinct()->orderBy('type')->pluck('type');
$application_list = MApplication::orderBy('name')->pluck('name', 'id');
$logical_server_list = LogicalServer::orderBy('name')->pluck('name', 'id');

$physicalServer->load('site', 'building', 'bay');

Expand All @@ -75,7 +92,9 @@ public function edit(PhysicalServer $physicalServer)
'sites',
'buildings',
'bays',
'clusters',
'application_list',
'logical_server_list',
'responsible_list',
'operating_system_list',
'type_list',
Expand All @@ -88,6 +107,7 @@ public function update(UpdatePhysicalServerRequest $request, PhysicalServer $phy
{
$physicalServer->update($request->all());
$physicalServer->applications()->sync($request->input('applications', []));
$physicalServer->serversLogicalServers()->sync($request->input('logicalServers', []));

return redirect()->route('admin.physical-servers.index');
}
Expand Down
7 changes: 5 additions & 2 deletions app/Http/Controllers/Admin/ReportController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2291,7 +2291,8 @@ public function logicalServerConfigs()
trans('cruds.logicalServer.fields.configuration'), // K
trans('cruds.logicalServer.fields.applications'), // L
trans('cruds.application.fields.application_block'), // M
trans('cruds.logicalServer.fields.servers'), // N
trans('cruds.logicalServer.fields.cluster'), // N
trans('cruds.logicalServer.fields.servers'), // O
];

$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet();
Expand All @@ -2316,6 +2317,7 @@ public function logicalServerConfigs()
$sheet->getColumnDimension('L')->setAutoSize(true);
$sheet->getColumnDimension('M')->setAutoSize(true);
$sheet->getColumnDimension('N')->setAutoSize(true);
$sheet->getColumnDimension('O')->setAutoSize(true);

// center (CPU, Men, Disk)
$sheet->getStyle('F')->getAlignment()->setHorizontal(\PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_CENTER);
Expand All @@ -2342,7 +2344,8 @@ public function logicalServerConfigs()
$sheet->setCellValue("L{$row}", $logicalServer->applications->implode('name', ', '));
$sheet->setCellValue("M{$row}", $logicalServer->applications->first() !== null ?
($logicalServer->applications->first()->application_block !== null ? $logicalServer->applications->first()->application_block->name : '') : '');
$sheet->setCellValue("N{$row}", $logicalServer->servers->implode('name', ', '));
$sheet->setCellValue("N{$row}", $logicalServer->cluster->name ?? "");
$sheet->setCellValue("O{$row}", $logicalServer->servers->implode('name', ', '));

$row++;
}
Expand Down
1 change: 1 addition & 0 deletions app/PhysicalServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class PhysicalServer extends Model
'site_id',
'building_id',
'bay_id',
'cluster_id',
'responsible',
'created_at',
'updated_at',
Expand Down
69 changes: 54 additions & 15 deletions mercator_data.sql

Large diffs are not rendered by default.

25 changes: 18 additions & 7 deletions resources/views/admin/logicalServers/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
{{ trans('cruds.logicalServer.fields.applications') }}
</th>
<th>
{{ trans('cruds.logicalServer.fields.cluster') }} /
{{ trans('cruds.logicalServer.fields.servers') }}
</th>
<th>
Expand Down Expand Up @@ -83,14 +84,24 @@ class="table-warning"
@endforeach
</td>
<td>
@foreach($logicalServer->servers as $server)
<a href="{{ route('admin.physical-servers.show', $server->id) }}">
{{ $server->name }}
@if ($logicalServer->cluster_id!==null)
<a href="{{ route('admin.clusters.show', $logicalServer->cluster_id) }}">
{{ $logicalServer->cluster->name }}
</a>
@if(!$loop->last)
,
@endif
@endforeach
@endif
@if(count($logicalServer->servers)>0)
@if ($logicalServer->cluster_id!==null)
/
@endif
@foreach($logicalServer->servers as $server)
<a href="{{ route('admin.physical-servers.show', $server->id) }}">
{{ $server->name }}
</a>
@if(!$loop->last)
,
@endif
@endforeach
@endif
</td>
<td>
@can('logical_server_show')
Expand Down
42 changes: 42 additions & 0 deletions resources/views/admin/physicalServers/create.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,45 @@
</div>
</div>
</div>

<div class="row">

<div class="col-md-4">
<div class="form-group">
<label for="site_id">{{ trans('cruds.physicalServer.fields.cluster') }}</label>
<select class="form-control select2 {{ $errors->has('cluster') ? 'is-invalid' : '' }}" name="cluster_id" id="cluster_id">
<option></option>
@foreach($clusters as $id => $cluster)
<option value="{{ $id }}" {{ old('cluster_id') == $id ? 'selected' : '' }}>{{ $cluster }}</option>
@endforeach
</select>
@if($errors->has('cluster'))
<div class="invalid-feedback">
{{ $errors->first('cluster') }}
</div>
@endif
<span class="help-block">{{ trans('cruds.physicalServer.fields.cluster_helper') }}</span>
</div>
</div>

<div class="col-md-8">
<div class="form-group">
<label for="applications">{{ trans('cruds.physicalServer.fields.logical_servers') }}</label>
<select class="form-control select2 {{ $errors->has('logicalServers') ? 'is-invalid' : '' }}" name="logicalServers[]" id="logicalServers" multiple>
@foreach($logical_server_list as $id => $name)
<option value="{{ $id }}" {{ in_array($id, old('logical_servers', [])) ? 'selected' : '' }}>{{ $name }}</option>
@endforeach
</select>
@if($errors->has('logical_servers'))
<div class="invalid-feedback">
{{ $errors->first('logical_servers') }}
</div>
@endif
<span class="help-block">{{ trans('cruds.physicalServer.fields.logical_servers_helper') }}</span>
</div>
</div>
</div>

</div>
<!---------------------------------------------------------------------------------------------------->
<div class="card-header">
Expand Down Expand Up @@ -240,6 +279,7 @@
<div class="form-group">
<label for="site_id">{{ trans('cruds.physicalServer.fields.site') }}</label>
<select class="form-control select2 {{ $errors->has('site') ? 'is-invalid' : '' }}" name="site_id" id="site_id">
<option></option>
@foreach($sites as $id => $site)
<option value="{{ $id }}" {{ old('site_id') == $id ? 'selected' : '' }}>{{ $site }}</option>
@endforeach
Expand All @@ -256,6 +296,7 @@
<div class="form-group">
<label for="building_id">{{ trans('cruds.physicalServer.fields.building') }}</label>
<select class="form-control select2 {{ $errors->has('building') ? 'is-invalid' : '' }}" name="building_id" id="building_id">
<option></option>
@foreach($buildings as $id => $building)
<option value="{{ $id }}" {{ old('building_id') == $id ? 'selected' : '' }}>{{ $building }}</option>
@endforeach
Expand All @@ -272,6 +313,7 @@
<div class="form-group">
<label for="bay_id">{{ trans('cruds.physicalServer.fields.bay') }}</label>
<select class="form-control select2 {{ $errors->has('bay') ? 'is-invalid' : '' }}" name="bay_id" id="bay_id">
<option></option>
@foreach($bays as $id => $bay)
<option value="{{ $id }}" {{ old('bay_id') == $id ? 'selected' : '' }}>{{ $bay }}</option>
@endforeach
Expand Down
39 changes: 39 additions & 0 deletions resources/views/admin/physicalServers/edit.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,42 @@
</div>
</div>
</div>
<div class="row">
<div class="col-lg-4">
<div class="form-group">
<label for="cluster_id">{{ trans('cruds.physicalServer.fields.cluster') }}</label>
<select class="form-control select2 {{ $errors->has('site') ? 'is-invalid' : '' }}" name="cluster_id" id="cluster_id">
<option></option>
@foreach($clusters as $id => $name)
<option value="{{ $id }}" {{ ($physicalServer->cluster ? $physicalServer->cluster->id : old('cluster_id')) == $id ? 'selected' : '' }}>{{ $name }}</option>
@endforeach
</select>
@if($errors->has('cluster'))
<div class="invalid-feedback">
{{ $errors->first('cluster') }}
</div>
@endif
<span class="help-block">{{ trans('cruds.physicalServer.fields.cluster_helper') }}</span>
</div>
</div>
<div class="col-lg-8">
<div class="form-group">
<label for="applications">{{ trans('cruds.physicalServer.fields.logical_servers') }}</label>
<select class="form-control select2 {{ $errors->has('logicalServers') ? 'is-invalid' : '' }}" name="logicalServers[]" id="logicalServers" multiple>
@foreach($logical_server_list as $id => $name)
<option value="{{ $id }}" {{ (in_array($id, old('logicalServers', [])) || $physicalServer->serversLogicalServers->contains($id)) ? 'selected' : '' }}>{{ $name }}</option>
@endforeach
</select>
@if($errors->has('logicalServers'))
<div class="invalid-feedback">
{{ $errors->first('logicalServers') }}
</div>
@endif
<span class="help-block">{{ trans('cruds.physicalServer.fields.logical_servers_helper') }}</span>
</div>
</div>
</div>

</div>
<!---------------------------------------------------------------------------------------------------->
<div class="card-header">
Expand All @@ -240,6 +276,7 @@
<div class="form-group">
<label for="site_id">{{ trans('cruds.physicalServer.fields.site') }}</label>
<select class="form-control select2 {{ $errors->has('site') ? 'is-invalid' : '' }}" name="site_id" id="site_id">
<option></option>
@foreach($sites as $id => $site)
<option value="{{ $id }}" {{ ($physicalServer->site ? $physicalServer->site->id : old('site_id')) == $id ? 'selected' : '' }}>{{ $site }}</option>
@endforeach
Expand All @@ -256,6 +293,7 @@
<div class="form-group">
<label for="building_id">{{ trans('cruds.physicalServer.fields.building') }}</label>
<select class="form-control select2 {{ $errors->has('building') ? 'is-invalid' : '' }}" name="building_id" id="building_id">
<option></option>
@foreach($buildings as $id => $building)
<option value="{{ $id }}" {{ ($physicalServer->building ? $physicalServer->building->id : old('building_id')) == $id ? 'selected' : '' }}>{{ $building }}</option>
@endforeach
Expand All @@ -272,6 +310,7 @@
<div class="form-group">
<label for="bay_id">{{ trans('cruds.physicalServer.fields.bay') }}</label>
<select class="form-control select2 {{ $errors->has('bay') ? 'is-invalid' : '' }}" name="bay_id" id="bay_id">
<option></option>
@foreach($bays as $id => $bay)
<option value="{{ $id }}" {{ ($physicalServer->bay ? $physicalServer->bay->id : old('bay_id')) == $id ? 'selected' : '' }}>{{ $bay }}</option>
@endforeach
Expand Down
31 changes: 22 additions & 9 deletions resources/views/admin/physicalServers/show.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
<div class="card-body">
<div class="row">
<div class="col-lg">
<b>{{ trans('cruds.physicalServer.fields.applications') }}</b> :
<b>{{ trans('cruds.physicalServer.fields.applications') }}</b>
@foreach($physicalServer->applications as $application)
<a href="{{ route('admin.applications.show', $application->id) }}">
{{ $application->name }}
Expand Down Expand Up @@ -121,14 +121,6 @@
</div>
</div>
<div class="row">
<div class="col-sm-4">
<b>{{ trans('cruds.physicalServer.fields.cluster') }}</b>
@if ($physicalServer->cluster!=null)
<a href="{{ route('admin.clusters.show', $physicalServer->cluster_id) }}">
{!! $physicalServer->cluster->name ?? "" !!}
</a>
@endif
</div>
<div class="col-sm-4">
<b>{{ trans('cruds.physicalServer.fields.address_ip') }}</b>
{{ $physicalServer->address_ip }}
Expand All @@ -140,6 +132,27 @@
{{ $physicalServer->responsible }}
</div>
</div>
<div class="row">
<div class="col-sm-4">
<b>{{ trans('cruds.physicalServer.fields.cluster') }}</b>
@if ($physicalServer->cluster!==null)
<a href="{{ route('admin.clusters.show', $physicalServer->cluster_id) }}">
{!! $physicalServer->cluster->name !!}
</a>
@endif
</div>
<div class="col-sm-8">
<b>{{ trans('cruds.physicalServer.fields.logical_servers') }}</b>
@foreach($physicalServer->serversLogicalServers as $logicalServer)
<a href="{{ route('admin.logical-servers.show', $logicalServer->id) }}">
{!! $logicalServer->name !!}
</a>
@if (!$loop->last)
,
@endif
@endforeach
</div>
</div>
</div>
<!---------------------------------------------------------------------------------------------------->
<div class="card-header">
Expand Down

0 comments on commit d1f756e

Please sign in to comment.