Merge pull request #574 from ok236449/development-2
Resource checks on server creation and upgrade
This commit is contained in:
commit
1c389c85c0
4 changed files with 30 additions and 7 deletions
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Classes\Pterodactyl;
|
||||
use App\Models\Egg;
|
||||
use App\Models\Location;
|
||||
use App\Models\Node;
|
||||
|
@ -55,6 +56,10 @@ class ProductController extends Controller
|
|||
public function getLocationsBasedOnEgg(Request $request, Egg $egg)
|
||||
{
|
||||
$nodes = $this->getNodesBasedOnEgg($request, $egg);
|
||||
foreach($nodes as $key => $node){
|
||||
$pteroNode = Pterodactyl::getNode($node->id);
|
||||
if($pteroNode['allocated_resources']['memory']>=($pteroNode['memory']*($pteroNode['memory_overallocate']+100)/100)||$pteroNode['allocated_resources']['disk']>=($pteroNode['disk']*($pteroNode['disk_overallocate']+100)/100)) $nodes->forget($key);
|
||||
}
|
||||
$locations = collect();
|
||||
|
||||
//locations
|
||||
|
@ -87,7 +92,7 @@ class ProductController extends Controller
|
|||
{
|
||||
if (is_null($egg->id) || is_null($node->id)) return response()->json('node and egg id is required', '400');
|
||||
|
||||
return Product::query()
|
||||
$products = Product::query()
|
||||
->where('disabled', '=', false)
|
||||
->whereHas('nodes', function (Builder $builder) use ($node) {
|
||||
$builder->where('id', '=', $node->id);
|
||||
|
@ -96,5 +101,12 @@ class ProductController extends Controller
|
|||
$builder->where('id', '=', $egg->id);
|
||||
})
|
||||
->get();
|
||||
|
||||
$pteroNode = Pterodactyl::getNode($node->id);
|
||||
foreach($products as $key => $product){
|
||||
if($product->memory>($pteroNode['memory']*($pteroNode['memory_overallocate']+100)/100)-$pteroNode['allocated_resources']['memory']||$product->disk>($pteroNode['disk']*($pteroNode['disk_overallocate']+100)/100)-$pteroNode['allocated_resources']['disk']) $product->doesNotFit = true;
|
||||
}
|
||||
|
||||
return $products;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -241,6 +241,9 @@ class ServerController extends Controller
|
|||
$serverRelationships = $serverAttributes['relationships'];
|
||||
$serverLocationAttributes = $serverRelationships['location']['attributes'];
|
||||
|
||||
//Get current product
|
||||
$currentProduct = Product::where('id', $server->product_id)->first();
|
||||
|
||||
//Set server infos
|
||||
$server->location = $serverLocationAttributes['long'] ?
|
||||
$serverLocationAttributes['long'] :
|
||||
|
@ -249,11 +252,19 @@ class ServerController extends Controller
|
|||
$server->node = $serverRelationships['node']['attributes']['name'];
|
||||
$server->name = $serverAttributes['name'];
|
||||
$server->egg = $serverRelationships['egg']['attributes']['name'];
|
||||
$products = Product::orderBy("created_at")->get();
|
||||
|
||||
$pteroNode = Pterodactyl::getNode($serverRelationships['node']['attributes']['id']);
|
||||
|
||||
$products = Product::orderBy("created_at")
|
||||
->whereHas('nodes', function (Builder $builder) use ($serverRelationships) { //Only show products for that node
|
||||
$builder->where('id', '=', $serverRelationships['node']['attributes']['id']);
|
||||
})
|
||||
->get();
|
||||
|
||||
// Set the each product eggs array to just contain the eggs name
|
||||
foreach ($products as $product) {
|
||||
$product->eggs = $product->eggs->pluck('name')->toArray();
|
||||
if($product->memory-$currentProduct->memory>($pteroNode['memory']*($pteroNode['memory_overallocate']+100)/100)-$pteroNode['allocated_resources']['memory']||$product->disk-$currentProduct->disk>($pteroNode['disk']*($pteroNode['disk_overallocate']+100)/100)-$pteroNode['allocated_resources']['disk']) $product->doesNotFit = true;
|
||||
}
|
||||
|
||||
return view('servers.settings')->with([
|
||||
|
|
|
@ -218,10 +218,10 @@
|
|||
</div>
|
||||
</div>
|
||||
<button type="submit" x-model="selectedProduct" name="product"
|
||||
:disabled="product.minimum_credits > user.credits"
|
||||
:disabled="product.minimum_credits > user.credits||product.doesNotFit == true"
|
||||
:class="product.minimum_credits > user.credits ? 'disabled' : ''"
|
||||
class="btn btn-primary btn-block mt-2" @click="setProduct(product.id)"
|
||||
x-text=" product.minimum_credits > user.credits ? '{{ __('Not enough') }} {{ CREDITS_DISPLAY_NAME }}!' : '{{ __('Create server') }}'">
|
||||
x-text=" product.doesNotFit == true? '{{ __('Server can´t fit on this node') }}' : (product.minimum_credits > user.credits ? '{{ __('Not enough') }} {{ CREDITS_DISPLAY_NAME }}!' : '{{ __('Create server') }}')">
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -255,13 +255,13 @@
|
|||
<option value="">{{__("Select the product")}}</option>
|
||||
@foreach($products as $product)
|
||||
@if(in_array($server->egg, $product->eggs) && $product->id != $server->product->id && $product->disabled == false)
|
||||
<option value="{{ $product->id }}">{{ $product->name }} [ {{ CREDITS_DISPLAY_NAME }} {{ $product->price }} @if($product->minimum_credits!=-1) /
|
||||
{{__("Required")}}: {{$product->minimum_credits}} {{ CREDITS_DISPLAY_NAME }}@endif ]</option>
|
||||
<option value="{{ $product->id }}" @if($product->doesNotFit)disabled @endif>{{ $product->name }} [ {{ CREDITS_DISPLAY_NAME }} {{ $product->price }} @if($product->doesNotFit)] {{__('Server can´t fit on this node')}} @else @if($product->minimum_credits!=-1) /
|
||||
{{__("Required")}}: {{$product->minimum_credits}} {{ CREDITS_DISPLAY_NAME }}@endif ] @endif</option>
|
||||
@endif
|
||||
@endforeach
|
||||
</select>
|
||||
<br> {{__("Once the Upgrade button is pressed, we will automatically deduct the amount for the first hour according to the new product from your credits")}}. <br>
|
||||
<br> {{_("Server will be automatically restarted once upgraded")}}
|
||||
<br> {{__("Server will be automatically restarted once upgraded")}}
|
||||
</div>
|
||||
<div class="modal-footer card-body">
|
||||
<button type="submit" class="btn btn-primary upgrade-once" style="width: 100%"><strong>{{__("Change Product")}}</strong></button>
|
||||
|
|
Loading…
Reference in a new issue