New models for node and location admin pages.
This commit is contained in:
parent
96d3aa767f
commit
09d23deed6
10 changed files with 152 additions and 78 deletions
|
@ -45,8 +45,8 @@ class LocationsController extends Controller
|
|||
return view('admin.locations.index', [
|
||||
'locations' => Models\Location::select(
|
||||
'locations.*',
|
||||
DB::raw('(SELECT COUNT(*) FROM nodes WHERE nodes.location = locations.id) as a_nodeCount'),
|
||||
DB::raw('(SELECT COUNT(*) FROM servers WHERE servers.node_id IN (SELECT nodes.id FROM nodes WHERE nodes.location = locations.id)) as a_serverCount')
|
||||
DB::raw('(SELECT COUNT(*) FROM nodes WHERE nodes.location_id = locations.id) as a_nodeCount'),
|
||||
DB::raw('(SELECT COUNT(*) FROM servers WHERE servers.node_id IN (SELECT nodes.id FROM nodes WHERE nodes.location_id = locations.id)) as a_serverCount')
|
||||
)->paginate(20),
|
||||
]);
|
||||
}
|
||||
|
@ -55,8 +55,8 @@ class LocationsController extends Controller
|
|||
{
|
||||
$model = Models\Location::select(
|
||||
'locations.id',
|
||||
DB::raw('(SELECT COUNT(*) FROM nodes WHERE nodes.location = locations.id) as a_nodeCount'),
|
||||
DB::raw('(SELECT COUNT(*) FROM servers WHERE servers.node_id IN (SELECT nodes.id FROM nodes WHERE nodes.location = locations.id)) as a_serverCount')
|
||||
DB::raw('(SELECT COUNT(*) FROM nodes WHERE nodes.location_id = locations.id) as a_nodeCount'),
|
||||
DB::raw('(SELECT COUNT(*) FROM servers WHERE servers.node_id IN (SELECT nodes.id FROM nodes WHERE nodes.location_id = locations.id)) as a_serverCount')
|
||||
)->where('id', $id)->first();
|
||||
|
||||
if (! $model) {
|
||||
|
@ -80,12 +80,12 @@ class LocationsController extends Controller
|
|||
{
|
||||
try {
|
||||
$location = new LocationRepository;
|
||||
$location->edit($id, $request->all());
|
||||
$location->edit($id, $request->only(['long', 'short']));
|
||||
|
||||
return response('', 204);
|
||||
} catch (DisplayValidationException $ex) {
|
||||
return response()->json([
|
||||
'error' => 'There was a validation error while processing this request. Location descriptions must be between 1 and 255 characters, and the location code must be between 1 and 10 characters with no spaces or special characters.',
|
||||
'error' => 'There was a validation error while processing this request. Location descriptions must be between 1 and 255 characters, and the location code must be between 1 and 20 characters with no spaces or special characters.',
|
||||
], 422);
|
||||
} catch (\Exception $ex) {
|
||||
// This gets caught and processed into JSON anyways.
|
||||
|
@ -97,9 +97,7 @@ class LocationsController extends Controller
|
|||
{
|
||||
try {
|
||||
$location = new LocationRepository;
|
||||
$id = $location->create($request->except([
|
||||
'_token',
|
||||
]));
|
||||
$id = $location->create($request->only(['long', 'short']));
|
||||
Alert::success('New location successfully added.')->flash();
|
||||
|
||||
return redirect()->route('admin.locations');
|
||||
|
|
|
@ -48,17 +48,15 @@ class NodesController extends Controller
|
|||
|
||||
public function getScript(Request $request, $id)
|
||||
{
|
||||
return response()->view('admin.nodes.remote.deploy', ['node' => Models\Node::findOrFail($id)])->header('Content-Type', 'text/plain');
|
||||
return response()->view('admin.nodes.remote.deploy', [
|
||||
'node' => Models\Node::findOrFail($id),
|
||||
])->header('Content-Type', 'text/plain');
|
||||
}
|
||||
|
||||
public function getIndex(Request $request)
|
||||
{
|
||||
return view('admin.nodes.index', [
|
||||
'nodes' => Models\Node::select(
|
||||
'nodes.*',
|
||||
'locations.long as a_locationName',
|
||||
DB::raw('(SELECT COUNT(*) FROM servers WHERE servers.node_id = nodes.id) as a_serverCount')
|
||||
)->join('locations', 'nodes.location', '=', 'locations.id')->paginate(20),
|
||||
'nodes' => Models\Node::with('location')->withCount('servers')->paginate(20),
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -78,15 +76,25 @@ class NodesController extends Controller
|
|||
public function postNew(Request $request)
|
||||
{
|
||||
try {
|
||||
$node = new NodeRepository;
|
||||
$new = $node->create($request->except([
|
||||
'_token',
|
||||
$repo = new NodeRepository;
|
||||
$node = $repo->create($request->only([
|
||||
'name',
|
||||
'location',
|
||||
'public',
|
||||
'fqdn',
|
||||
'scheme',
|
||||
'memory',
|
||||
'memory_overallocate',
|
||||
'disk',
|
||||
'disk_overallocate',
|
||||
'daemonBase',
|
||||
'daemonSFTP',
|
||||
'daemonListen',
|
||||
]));
|
||||
Alert::success('Successfully created new node. <strong>Before you can add any servers you need to first assign some IP addresses and ports.</strong>')->flash();
|
||||
Alert::info('<strong>To simplify the node setup you can generate a token on the configuration tab.</strong>')->flash();
|
||||
Alert::success('Successfully created new node that can be configured automatically on your remote machine by visiting the configuration tab. <strong>Before you can add any servers you need to first assign some IP addresses and ports.</strong>')->flash();
|
||||
|
||||
return redirect()->route('admin.nodes.view', [
|
||||
'id' => $new,
|
||||
'id' => $node->id,
|
||||
'tab' => 'tab_allocation',
|
||||
]);
|
||||
} catch (DisplayValidationException $e) {
|
||||
|
@ -103,26 +111,18 @@ class NodesController extends Controller
|
|||
|
||||
public function getView(Request $request, $id)
|
||||
{
|
||||
$node = Models\Node::findOrFail($id);
|
||||
$node = Models\Node::with(
|
||||
'servers.user',
|
||||
'servers.service',
|
||||
'servers.allocations',
|
||||
'location'
|
||||
)->findOrFail($id);
|
||||
$node->setRelation('allocations', $node->allocations()->paginate(40));
|
||||
|
||||
return view('admin.nodes.view', [
|
||||
'node' => $node,
|
||||
'servers' => Models\Server::select('servers.*', 'users.email as a_ownerEmail', 'services.name as a_serviceName')
|
||||
->join('users', 'users.id', '=', 'servers.owner_id')
|
||||
->join('services', 'services.id', '=', 'servers.service_id')
|
||||
->where('node_id', $id)->paginate(10, ['*'], 'servers'),
|
||||
'stats' => Models\Server::select(DB::raw('SUM(memory) as memory, SUM(disk) as disk'))->where('node_id', $node->id)->first(),
|
||||
'locations' => Models\Location::all(),
|
||||
'allocations' => Models\Allocation::select('allocations.*', 'servers.name as assigned_to_name')
|
||||
->where('allocations.node', $node->id)
|
||||
->leftJoin('servers', 'servers.id', '=', 'allocations.assigned_to')
|
||||
->orderBy('allocations.ip', 'asc')
|
||||
->orderBy('allocations.port', 'asc')
|
||||
->paginate(20, ['*'], 'allocations'),
|
||||
'allocation_ips' => Models\Allocation::select('id', 'ip')
|
||||
->where('node', $node->id)
|
||||
->groupBy('ip')
|
||||
->get(),
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -130,8 +130,21 @@ class NodesController extends Controller
|
|||
{
|
||||
try {
|
||||
$node = new NodeRepository;
|
||||
$node->update($id, $request->except([
|
||||
'_token',
|
||||
$node->update($id, $request->only([
|
||||
'name',
|
||||
'location',
|
||||
'public',
|
||||
'fqdn',
|
||||
'scheme',
|
||||
'memory',
|
||||
'memory_overallocate',
|
||||
'disk',
|
||||
'disk_overallocate',
|
||||
'upload_size',
|
||||
'daemonBase',
|
||||
'daemonSFTP',
|
||||
'daemonListen',
|
||||
'reset_secret',
|
||||
]));
|
||||
Alert::success('Successfully update this node\'s information. If you changed any daemon settings you will need to restart it now.')->flash();
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue