Basic allocation information

Allows deleting ports, nothing else yet
This commit is contained in:
Dane Everitt 2016-01-08 20:01:18 -05:00
parent 2160613163
commit 54bef1e7d5
3 changed files with 114 additions and 1 deletions

View file

@ -67,6 +67,23 @@ class NodesController extends Controller
public function getView(Request $request, $id)
{
$node = Models\Node::findOrFail($id);
$allocations = [];
$alloc = Models\Allocation::select('ip', 'port', 'assigned_to')->where('node', $node->id)->get();
if ($alloc) {
foreach($alloc as &$alloc) {
if (!array_key_exists($alloc->ip, $allocations)) {
$allocations[$alloc->ip] = [[
'port' => $alloc->port,
'assigned_to' => $alloc->assigned_to
]];
} else {
array_push($allocations[$alloc->ip], [
'port' => $alloc->port,
'assigned_to' => $alloc->assigned_to
]);
}
}
}
return view('admin.nodes.view', [
'node' => $node,
'servers' => Models\Server::select('servers.*', 'users.email as a_ownerEmail', 'services.name as a_serviceName')
@ -75,6 +92,7 @@ class NodesController extends Controller
->where('node', $id)->paginate(10),
'stats' => Models\Server::select(DB::raw('SUM(memory) as memory, SUM(disk) as disk'))->where('node', $node->id)->first(),
'locations' => Models\Location::all(),
'allocations' => json_decode(json_encode($allocations), false),
]);
}
@ -104,4 +122,16 @@ class NodesController extends Controller
])->withInput();
}
public function deletePortAllocation(Request $request, $id, $ip, $port)
{
$allocation = Models\Allocation::where('node', $id)->whereNull('assigned_to')->where('ip', $ip)->where('port', $port)->first();
if (!$allocation) {
return response()->json([
'error' => 'Unable to find an allocation matching those details to delete.'
], 400);
}
$allocation->delete();
return response('', 204);
}
}

View file

@ -172,6 +172,10 @@ class AdminRoutes {
'uses' => 'Admin\NodesController@postView'
]);
$router->delete('/view/{id}/allocation/{ip}/{port}', [
'uses' => 'Admin\NodesController@deletePortAllocation'
]);
});
}

View file

@ -285,7 +285,42 @@
<div class="panel panel-default">
<div class="panel-heading"></div>
<div class="panel-body">
Allocations
<table class="table table-striped table-bordered table-hover">
<thead>
<td>IP Address</td>
<td>Ports</td>
<td></td>
</thead>
<tbody>
@foreach($allocations as $ip => $ports)
<tr>
<td>{{ $ip }}</td>
<td>
@foreach($ports as $id => $allocation)
@if (($id % 2) === 0)
@if($allocation->assigned_to === null)
<span style="cursor:pointer" data-action="delete" data-ip="{{ $ip }}" data-port="{{ $allocation->port }}"><i class="fa fa-fw fa-square-o"></i> {{ $allocation->port }} <br /></span>
@else
<i class="fa fa-fw fa-check-square-o"></i> {{ $allocation->port }} <br />
@endif
@endif
@endforeach
</td>
<td>
@foreach($ports as $id => $allocation)
@if (($id % 2) === 1)
@if($allocation->assigned_to === null)
<span style="cursor:pointer" data-action="delete" data-ip="{{ $ip }}" data-port="{{ $allocation->port }}"><i class="fa fa-fw fa-square-o"></i> {{ $allocation->port }} <br /></span>
@else
<i class="fa fa-fw fa-check-square-o"></i> {{ $allocation->port }} <br />
@endif
@endif
@endforeach
</td>
</tr>
@endforeach
</tbody>
</table>
</div>
</div>
</div>
@ -600,6 +635,50 @@ $(document).ready(function () {
});
});
$('span[data-action="delete"]').hover(function() {
$(this).find('i').css('color', '#d9534f').removeClass('fa-square-o').addClass('fa-minus-square');
}, function () {
$(this).find('i').css('color', 'inherit').addClass('fa-square-o').removeClass('fa-minus-square');
});
$('span[data-action="delete"]').click(function (event) {
event.preventDefault();
var element = $(this);
var deleteIp = $(this).data('ip');
var deletePort = $(this).data('port');
swal({
title: '',
text: 'Are you sure you want to delete this port?',
type: 'warning',
showCancelButton: true,
allowOutsideClick: true,
closeOnConfirm: false,
confirmButtonText: 'Delete',
confirmButtonColor: '#d9534f',
showLoaderOnConfirm: true
}, function () {
$.ajax({
method: 'DELETE',
url: '{{ route('admin.nodes.view', $node->id) }}/allocation/' + deleteIp + '/' + deletePort,
headers: {
'X-CSRF-TOKEN': '{{ csrf_token() }}'
}
}).done(function (data) {
swal({
type: 'success',
title: 'Port Deleted!',
});
}).fail(function (jqXHR) {
console.error(jqXHR);
swal({
title: 'Whoops!',
text: jqXHR.responseJSON.error,
type: 'error'
});
});
});
});
});
</script>
@endsection