refactor: cleaner code closes #605

This commit is contained in:
IceToast 2023-01-18 23:54:37 +01:00
parent 3b2a851f4f
commit 1a75d63ba1

View file

@ -23,7 +23,7 @@
<!-- END CONTENT HEADER --> <!-- END CONTENT HEADER -->
<!-- MAIN CONTENT --> <!-- MAIN CONTENT -->
<section x-data="{ ...serverApp(), submitClicked: false }" class="content"> <section x-data="serverApp()" class="content">
<div class="container-xxl"> <div class="container-xxl">
<!-- FORM --> <!-- FORM -->
<form action="{{ route('servers.store') }}" x-on:submit="submitClicked = true" method="post" <form action="{{ route('servers.store') }}" x-on:submit="submitClicked = true" method="post"
@ -35,10 +35,10 @@
<div class="card-title"><i class="fas fa-cogs mr-2"></i>{{ __('Server configuration') }} <div class="card-title"><i class="fas fa-cogs mr-2"></i>{{ __('Server configuration') }}
</div> </div>
</div> </div>
@if (!config("SETTINGS::SYSTEM:CREATION_OF_NEW_SERVERS")) @if (!config('SETTINGS::SYSTEM:CREATION_OF_NEW_SERVERS'))
<div class="alert alert-warning p-2 m-2"> <div class="alert alert-warning p-2 m-2">
The creation of new servers has been disabled for regular users, enable it again The creation of new servers has been disabled for regular users, enable it again
<a href="{{route('admin.settings.system')}}">{{ __('here') }}</a>. <a href="{{ route('admin.settings.system') }}">{{ __('here') }}</a>.
</div> </div>
@endif @endif
@if ($productCount === 0 || $nodeCount === 0 || count($nests) === 0 || count($eggs) === 0) @if ($productCount === 0 || $nodeCount === 0 || count($nests) === 0 || count($eggs) === 0)
@ -48,7 +48,7 @@
@if (Auth::user()->role == 'admin') @if (Auth::user()->role == 'admin')
{{ __('Make sure to link your products to nodes and eggs.') }} <br> {{ __('Make sure to link your products to nodes and eggs.') }} <br>
{{ __('There has to be at least 1 valid product for server creation') }} {{ __('There has to be at least 1 valid product for server creation') }}
<a href="{{route('admin.overview.sync')}}">{{ __('Sync now') }}</a> <a href="{{ route('admin.overview.sync') }}">{{ __('Sync now') }}</a>
@endif @endif
</p> </p>
@ -103,8 +103,8 @@
<div class="col-md-6"> <div class="col-md-6">
<div class="form-group"> <div class="form-group">
<label for="nest">{{ __('Software / Games') }}</label> <label for="nest">{{ __('Software / Games') }}</label>
<select class="custom-select" required name="nest" id="nest" x-model="selectedNest" <select class="custom-select" required name="nest" id="nest"
@change="setEggs();"> x-model="selectedNest" @change="setEggs();">
<option selected disabled hidden value="null"> <option selected disabled hidden value="null">
{{ count($nests) > 0 ? __('Please select software ...') : __('---') }} {{ count($nests) > 0 ? __('Please select software ...') : __('---') }}
</option> </option>
@ -135,8 +135,8 @@
<div class="form-group"> <div class="form-group">
<label for="node">{{ __('Node') }}</label> <label for="node">{{ __('Node') }}</label>
<select name="node" required id="node" x-model="selectedNode" :disabled="!fetchedLocations" <select name="node" required id="node" x-model="selectedNode"
@change="fetchProducts();" class="custom-select"> :disabled="!fetchedLocations" @change="fetchProducts();" class="custom-select">
<option x-text="getNodeInputText()" disabled selected hidden value="null"> <option x-text="getNodeInputText()" disabled selected hidden value="null">
</option> </option>
@ -209,14 +209,17 @@
</li> </li>
<li class="d-flex justify-content-between"> <li class="d-flex justify-content-between">
<span class="d-inline-block"><i class="fa fa-coins"></i> <span class="d-inline-block"><i class="fa fa-coins"></i>
{{ __('Required') }} {{ CREDITS_DISPLAY_NAME }} {{ __('to create this server') }}</span> {{ __('Required') }} {{ CREDITS_DISPLAY_NAME }}
<span class="d-inline-block" x-text="product.minimum_credits === -1 ? {{ config('SETTINGS::USER:MINIMUM_REQUIRED_CREDITS_TO_MAKE_SERVER') }} : product.minimum_credit"></span> {{ __('to create this server') }}</span>
<span class="d-inline-block"
x-text="product.minimum_credits === -1 ? {{ config('SETTINGS::USER:MINIMUM_REQUIRED_CREDITS_TO_MAKE_SERVER') }} : product.minimum_credit"></span>
</li> </li>
</ul> </ul>
</div> </div>
<div class="mt-2 mb-2"> <div class="mt-2 mb-2">
<span class="card-text text-muted">{{ __('Description') }}</span> <span class="card-text text-muted">{{ __('Description') }}</span>
<p class="card-text" style="white-space:pre-wrap" x-text="product.description"></p> <p class="card-text" style="white-space:pre-wrap"
x-text="product.description"></p>
</div> </div>
</div> </div>
<div class="mt-auto border rounded border-secondary"> <div class="mt-auto border rounded border-secondary">
@ -285,6 +288,8 @@
locations: [], locations: [],
products: [], products: [],
submitClicked: false,
/** /**
* @description set available eggs based on the selected nest * @description set available eggs based on the selected nest
@ -368,7 +373,8 @@
this.fetchedProducts = true; this.fetchedProducts = true;
// TODO: Sortable by user chosen property (cpu, ram, disk...) // TODO: Sortable by user chosen property (cpu, ram, disk...)
this.products = response.data.sort((p1, p2) => parseInt(p1.price,10) > parseInt(p2.price,10) && 1 || -1) this.products = response.data.sort((p1, p2) => parseInt(p1.price, 10) > parseInt(p2.price, 10) &&
1 || -1)
//divide cpu by 100 for each product //divide cpu by 100 for each product
this.products.forEach(product => { this.products.forEach(product => {