2021-06-05 09:26:32 +00:00
|
|
|
@extends('layouts.main')
|
|
|
|
|
|
|
|
@section('content')
|
|
|
|
<!-- CONTENT HEADER -->
|
|
|
|
<section class="content-header">
|
|
|
|
<div class="container-fluid">
|
|
|
|
<div class="row mb-2">
|
|
|
|
<div class="col-sm-6">
|
2021-12-22 19:34:27 +00:00
|
|
|
<h1>{{ __('Servers') }}</h1>
|
2021-06-05 09:26:32 +00:00
|
|
|
</div>
|
|
|
|
<div class="col-sm-6">
|
|
|
|
<ol class="breadcrumb float-sm-right">
|
2021-12-22 19:34:27 +00:00
|
|
|
<li class="breadcrumb-item"><a href="{{ route('home') }}">{{ __('Dashboard') }}</a></li>
|
|
|
|
<li class="breadcrumb-item"><a href="{{ route('servers.index') }}">{{ __('Servers') }}</a>
|
2021-10-01 21:21:49 +00:00
|
|
|
<li class="breadcrumb-item"><a class="text-muted"
|
2021-12-22 19:34:27 +00:00
|
|
|
href="{{ route('servers.create') }}">{{ __('Create') }}</a>
|
2021-06-05 09:26:32 +00:00
|
|
|
</li>
|
|
|
|
</ol>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</section>
|
|
|
|
<!-- END CONTENT HEADER -->
|
|
|
|
|
|
|
|
<!-- MAIN CONTENT -->
|
2023-01-18 22:54:37 +00:00
|
|
|
<section x-data="serverApp()" class="content">
|
2021-11-25 15:16:03 +00:00
|
|
|
<div class="container-xxl">
|
2021-11-06 00:56:57 +00:00
|
|
|
<!-- FORM -->
|
2023-01-18 22:50:52 +00:00
|
|
|
<form action="{{ route('servers.store') }}" x-on:submit="submitClicked = true" method="post"
|
|
|
|
class="row justify-content-center">
|
2021-11-07 00:47:16 +00:00
|
|
|
@csrf
|
2021-11-25 21:21:06 +00:00
|
|
|
<div class="col-xl-6 col-lg-8 col-md-8 col-sm-10">
|
2021-11-06 00:56:57 +00:00
|
|
|
<div class="card">
|
|
|
|
<div class="card-header">
|
2021-11-20 22:38:44 +00:00
|
|
|
<div class="card-title"><i class="fas fa-cogs mr-2"></i>{{ __('Server configuration') }}
|
|
|
|
</div>
|
2021-11-06 00:56:57 +00:00
|
|
|
</div>
|
2023-01-18 22:54:37 +00:00
|
|
|
@if (!config('SETTINGS::SYSTEM:CREATION_OF_NEW_SERVERS'))
|
2022-11-04 19:15:48 +00:00
|
|
|
<div class="alert alert-warning p-2 m-2">
|
|
|
|
The creation of new servers has been disabled for regular users, enable it again
|
2023-01-18 22:54:37 +00:00
|
|
|
<a href="{{ route('admin.settings.system') }}">{{ __('here') }}</a>.
|
2022-11-04 19:15:48 +00:00
|
|
|
</div>
|
|
|
|
@endif
|
2021-11-20 22:38:44 +00:00
|
|
|
@if ($productCount === 0 || $nodeCount === 0 || count($nests) === 0 || count($eggs) === 0)
|
2021-11-06 00:56:57 +00:00
|
|
|
<div class="alert alert-danger p-2 m-2">
|
2021-11-20 22:38:44 +00:00
|
|
|
<h5><i class="icon fas fa-exclamation-circle"></i>{{ __('Error!') }}</h5>
|
2021-11-07 11:07:30 +00:00
|
|
|
<p class="pl-4">
|
2021-11-20 22:38:44 +00:00
|
|
|
@if (Auth::user()->role == 'admin')
|
|
|
|
{{ __('Make sure to link your products to nodes and eggs.') }} <br>
|
|
|
|
{{ __('There has to be at least 1 valid product for server creation') }}
|
2023-01-18 22:54:37 +00:00
|
|
|
<a href="{{ route('admin.overview.sync') }}">{{ __('Sync now') }}</a>
|
2021-11-07 15:39:29 +00:00
|
|
|
@endif
|
2022-01-07 11:46:45 +00:00
|
|
|
|
2021-11-07 11:07:30 +00:00
|
|
|
</p>
|
2021-11-06 00:56:57 +00:00
|
|
|
<ul>
|
2021-11-20 22:38:44 +00:00
|
|
|
@if ($productCount === 0)
|
|
|
|
<li> {{ __('No products available!') }}</li>
|
2021-11-06 00:56:57 +00:00
|
|
|
@endif
|
2021-06-05 09:26:32 +00:00
|
|
|
|
2021-11-20 22:38:44 +00:00
|
|
|
@if ($nodeCount === 0)
|
|
|
|
<li>{{ __('No nodes have been linked!') }}</li>
|
2021-11-06 00:56:57 +00:00
|
|
|
@endif
|
2021-06-05 09:26:32 +00:00
|
|
|
|
2021-11-20 22:38:44 +00:00
|
|
|
@if (count($nests) === 0)
|
|
|
|
<li>{{ __('No nests available!') }}</li>
|
2021-11-06 00:56:57 +00:00
|
|
|
@endif
|
2021-06-05 09:26:32 +00:00
|
|
|
|
2021-11-20 22:38:44 +00:00
|
|
|
@if (count($eggs) === 0)
|
|
|
|
<li>{{ __('No eggs have been linked!') }}</li>
|
2021-11-06 00:56:57 +00:00
|
|
|
@endif
|
|
|
|
</ul>
|
2021-06-05 09:26:32 +00:00
|
|
|
</div>
|
2021-11-06 00:56:57 +00:00
|
|
|
@endif
|
|
|
|
|
|
|
|
|
|
|
|
<div x-show="loading" class="overlay dark">
|
|
|
|
<i class="fas fa-2x fa-sync-alt"></i>
|
|
|
|
</div>
|
2021-11-07 00:47:16 +00:00
|
|
|
|
2021-11-20 22:38:44 +00:00
|
|
|
<div class="card-body">
|
2021-11-07 00:47:16 +00:00
|
|
|
@if ($errors->any())
|
|
|
|
<div class="alert alert-danger">
|
|
|
|
<ul class="list-group pl-3">
|
|
|
|
@foreach ($errors->all() as $error)
|
|
|
|
<li>{{ $error }}</li>
|
|
|
|
@endforeach
|
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
@endif
|
|
|
|
|
2021-06-05 09:26:32 +00:00
|
|
|
<div class="form-group">
|
2021-11-20 22:38:44 +00:00
|
|
|
<label for="name">{{ __('Name') }}</label>
|
2021-11-06 00:56:57 +00:00
|
|
|
<input x-model="name" id="name" name="name" type="text" required="required"
|
2021-11-20 22:38:44 +00:00
|
|
|
class="form-control @error('name') is-invalid @enderror">
|
2021-11-06 00:56:57 +00:00
|
|
|
@error('name')
|
2021-11-20 22:38:44 +00:00
|
|
|
<div class="invalid-feedback">
|
|
|
|
{{ $message }}
|
|
|
|
</div>
|
2021-06-05 09:26:32 +00:00
|
|
|
@enderror
|
|
|
|
</div>
|
|
|
|
|
2021-11-06 00:56:57 +00:00
|
|
|
<div class="row">
|
|
|
|
<div class="col-md-6">
|
|
|
|
<div class="form-group">
|
2021-11-20 22:38:44 +00:00
|
|
|
<label for="nest">{{ __('Software / Games') }}</label>
|
2023-01-18 22:54:37 +00:00
|
|
|
<select class="custom-select" required name="nest" id="nest"
|
|
|
|
x-model="selectedNest" @change="setEggs();">
|
2021-11-20 22:38:44 +00:00
|
|
|
<option selected disabled hidden value="null">
|
|
|
|
{{ count($nests) > 0 ? __('Please select software ...') : __('---') }}
|
|
|
|
</option>
|
2021-11-06 00:56:57 +00:00
|
|
|
@foreach ($nests as $nest)
|
|
|
|
<option value="{{ $nest->id }}">{{ $nest->name }}</option>
|
|
|
|
@endforeach
|
|
|
|
</select>
|
|
|
|
|
2021-10-01 21:21:49 +00:00
|
|
|
</div>
|
2021-06-05 09:26:32 +00:00
|
|
|
</div>
|
2021-11-06 00:56:57 +00:00
|
|
|
<div class="col-md-6">
|
|
|
|
<div class="form-group">
|
2021-11-20 22:38:44 +00:00
|
|
|
<label for="egg">{{ __('Specification ') }}</label>
|
2021-11-06 00:56:57 +00:00
|
|
|
<div>
|
2021-11-20 22:38:44 +00:00
|
|
|
<select id="egg" required name="egg" :disabled="eggs.length == 0"
|
|
|
|
x-model="selectedEgg" @change="fetchLocations();" required="required"
|
|
|
|
class="custom-select">
|
|
|
|
<option x-text="getEggInputText()" selected disabled hidden value="null">
|
|
|
|
</option>
|
2021-11-06 00:56:57 +00:00
|
|
|
<template x-for="egg in eggs" :key="egg.id">
|
|
|
|
<option x-text="egg.name" :value="egg.id"></option>
|
|
|
|
</template>
|
|
|
|
</select>
|
|
|
|
</div>
|
2021-10-01 21:21:49 +00:00
|
|
|
</div>
|
2021-11-06 00:56:57 +00:00
|
|
|
</div>
|
2021-06-05 09:26:32 +00:00
|
|
|
</div>
|
2021-11-06 00:56:57 +00:00
|
|
|
|
|
|
|
<div class="form-group">
|
2021-11-20 22:38:44 +00:00
|
|
|
<label for="node">{{ __('Node') }}</label>
|
2023-01-18 22:54:37 +00:00
|
|
|
<select name="node" required id="node" x-model="selectedNode"
|
|
|
|
:disabled="!fetchedLocations" @change="fetchProducts();" class="custom-select">
|
2021-11-20 22:38:44 +00:00
|
|
|
<option x-text="getNodeInputText()" disabled selected hidden value="null">
|
2021-11-07 15:29:18 +00:00
|
|
|
</option>
|
|
|
|
|
|
|
|
<template x-for="location in locations" :key="location.id">
|
|
|
|
<optgroup :label="location.name">
|
|
|
|
|
|
|
|
<template x-for="node in location.nodes" :key="node.id">
|
2021-11-20 22:38:44 +00:00
|
|
|
<option x-text="node.name" :value="node.id">
|
2021-11-07 15:29:18 +00:00
|
|
|
|
|
|
|
</option>
|
|
|
|
</template>
|
|
|
|
</optgroup>
|
2021-11-06 00:56:57 +00:00
|
|
|
</template>
|
2021-11-07 15:29:18 +00:00
|
|
|
|
2021-11-06 00:56:57 +00:00
|
|
|
</select>
|
2021-06-05 09:26:32 +00:00
|
|
|
</div>
|
2021-11-06 00:56:57 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2021-11-25 12:34:01 +00:00
|
|
|
|
|
|
|
<div class="w-100"></div>
|
|
|
|
<div class="col" x-show="selectedNode != null">
|
2021-12-12 23:29:32 +00:00
|
|
|
<div class="row mt-4 justify-content-center">
|
2021-11-25 12:34:01 +00:00
|
|
|
<template x-for="product in products" :key="product.id">
|
2021-12-12 23:29:32 +00:00
|
|
|
<div class="card col-xl-3 col-lg-3 col-md-4 col-sm-10 mr-2 ml-2 ">
|
2021-11-25 12:34:01 +00:00
|
|
|
<div class="card-body d-flex flex-column">
|
|
|
|
<h4 class="card-title" x-text="product.name"></h4>
|
|
|
|
<div class="mt-2">
|
|
|
|
<div>
|
2021-12-20 21:15:03 +00:00
|
|
|
<p class="card-text text-muted mb-1">{{ __('Resource Data:') }}</p>
|
2021-11-25 12:34:01 +00:00
|
|
|
<ul class="pl-0">
|
|
|
|
<li class="d-flex justify-content-between">
|
2021-11-25 21:21:06 +00:00
|
|
|
<span class="d-inline-block"><i class="fas fa-microchip"></i>
|
|
|
|
{{ __('CPU') }}</span>
|
2021-12-22 19:34:27 +00:00
|
|
|
<span class=" d-inline-block"
|
|
|
|
x-text="product.cpu + ' {{ __('vCores') }}'"></span>
|
2021-11-25 12:34:01 +00:00
|
|
|
</li>
|
2021-11-25 21:21:06 +00:00
|
|
|
<li class="d-flex justify-content-between">
|
|
|
|
<span class="d-inline-block"><i class="fas fa-memory"></i>
|
|
|
|
{{ __('Memory') }}</span>
|
2021-11-25 12:34:01 +00:00
|
|
|
<span class=" d-inline-block"
|
|
|
|
x-text="product.memory + ' {{ __('MB') }}'"></span>
|
2021-11-25 21:21:06 +00:00
|
|
|
</li>
|
|
|
|
<li class="d-flex justify-content-between">
|
|
|
|
<div>
|
|
|
|
<i class="fas fa-hdd"></i>
|
|
|
|
<span class="d-inline-block">
|
|
|
|
{{ __('Disk') }}
|
|
|
|
</span>
|
|
|
|
</div>
|
2021-11-25 12:34:01 +00:00
|
|
|
<span class="d-inline-block"
|
|
|
|
x-text="product.disk + ' {{ __('MB') }}'"></span>
|
2021-11-25 21:21:06 +00:00
|
|
|
</li>
|
|
|
|
<li class="d-flex justify-content-between">
|
|
|
|
<span class="d-inline-block"><i class="fas fa-save"></i>
|
|
|
|
{{ __('Backups') }}</span>
|
2021-11-25 12:34:01 +00:00
|
|
|
<span class=" d-inline-block" x-text="product.backups"></span>
|
2021-11-25 21:21:06 +00:00
|
|
|
</li>
|
|
|
|
<li class="d-flex justify-content-between">
|
|
|
|
<span class="d-inline-block"><i class="fas fa-database"></i>
|
|
|
|
{{ __('MySQL') }}
|
2021-11-25 12:34:01 +00:00
|
|
|
{{ __('Databases') }}</span>
|
|
|
|
<span class="d-inline-block" x-text="product.databases"></span>
|
2021-11-25 21:21:06 +00:00
|
|
|
</li>
|
|
|
|
<li class="d-flex justify-content-between">
|
|
|
|
<span class="d-inline-block"><i class="fas fa-network-wired"></i>
|
|
|
|
{{ __('Allocations') }}
|
2021-11-25 12:34:01 +00:00
|
|
|
({{ __('ports') }})</span>
|
|
|
|
<span class="d-inline-block" x-text="product.allocations"></span>
|
2021-11-25 21:21:06 +00:00
|
|
|
</li>
|
2023-01-16 20:46:07 +00:00
|
|
|
<li class="d-flex justify-content-between">
|
|
|
|
<span class="d-inline-block"><i class="fa fa-coins"></i>
|
2023-01-18 22:54:37 +00:00
|
|
|
{{ __('Required') }} {{ CREDITS_DISPLAY_NAME }}
|
|
|
|
{{ __('to create this server') }}</span>
|
|
|
|
<span class="d-inline-block"
|
2023-01-25 20:34:45 +00:00
|
|
|
x-text="product.minimum_credits == -1 ? {{ config('SETTINGS::USER:MINIMUM_REQUIRED_CREDITS_TO_MAKE_SERVER') }} : product.minimum_credits"></span>
|
2023-01-16 20:46:07 +00:00
|
|
|
</li>
|
2021-11-25 12:34:01 +00:00
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
<div class="mt-2 mb-2">
|
2021-12-20 21:15:03 +00:00
|
|
|
<span class="card-text text-muted">{{ __('Description') }}</span>
|
2023-01-18 22:54:37 +00:00
|
|
|
<p class="card-text" style="white-space:pre-wrap"
|
|
|
|
x-text="product.description"></p>
|
2021-11-25 12:34:01 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
2021-11-25 21:21:06 +00:00
|
|
|
<div class="mt-auto border rounded border-secondary">
|
|
|
|
<div class="d-flex justify-content-between p-2">
|
2021-11-27 12:51:48 +00:00
|
|
|
<span class="d-inline-block mr-4">
|
2021-11-25 21:21:06 +00:00
|
|
|
{{ __('Price') }}:
|
2021-11-25 15:16:03 +00:00
|
|
|
</span>
|
2021-11-27 13:02:38 +00:00
|
|
|
<span class="d-inline-block"
|
|
|
|
x-text="product.price + ' {{ CREDITS_DISPLAY_NAME }}'"></span>
|
2021-11-25 15:16:03 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
2023-01-18 22:50:52 +00:00
|
|
|
<div>
|
|
|
|
<input type="hidden" name="product" x-model="selectedProduct">
|
|
|
|
</div>
|
|
|
|
<div>
|
|
|
|
<button type="submit" x-model="selectedProduct" name="product"
|
|
|
|
:disabled="product.minimum_credits > user.credits || product.doesNotFit == true ||
|
|
|
|
submitClicked"
|
|
|
|
:class="product.minimum_credits > user.credits || product.doesNotFit == true ||
|
|
|
|
submitClicked ? 'disabled' : ''"
|
|
|
|
class="btn btn-primary btn-block mt-2" @click="setProduct(product.id);"
|
|
|
|
x-text=" product.doesNotFit == true ? '{{ __('Server cant fit on this Node') }}' : (product.minimum_credits > user.credits ? '{{ __('Not enough') }} {{ CREDITS_DISPLAY_NAME }}!' : '{{ __('Create server') }}')">
|
|
|
|
</button>
|
2023-01-02 14:15:59 +00:00
|
|
|
</div>
|
2021-11-25 12:34:01 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2021-11-25 21:21:06 +00:00
|
|
|
</template>
|
2021-11-25 12:34:01 +00:00
|
|
|
</div>
|
2021-11-25 21:21:06 +00:00
|
|
|
</div>
|
2021-11-25 12:34:01 +00:00
|
|
|
|
2021-11-25 21:21:06 +00:00
|
|
|
</form>
|
|
|
|
<!-- END FORM -->
|
2021-06-05 09:26:32 +00:00
|
|
|
|
|
|
|
</div>
|
|
|
|
</section>
|
|
|
|
<!-- END CONTENT -->
|
|
|
|
|
2021-11-06 00:56:57 +00:00
|
|
|
|
|
|
|
<script>
|
|
|
|
function serverApp() {
|
|
|
|
return {
|
2021-11-07 00:47:16 +00:00
|
|
|
//loading
|
2021-11-06 00:56:57 +00:00
|
|
|
loading: false,
|
2021-11-07 15:29:18 +00:00
|
|
|
fetchedLocations: false,
|
2021-11-06 00:56:57 +00:00
|
|
|
fetchedProducts: false,
|
|
|
|
|
2021-11-07 00:47:16 +00:00
|
|
|
//input fields
|
2021-11-06 00:56:57 +00:00
|
|
|
name: null,
|
|
|
|
selectedNest: null,
|
|
|
|
selectedEgg: null,
|
|
|
|
selectedNode: null,
|
|
|
|
selectedProduct: null,
|
|
|
|
|
2021-11-07 00:47:16 +00:00
|
|
|
//selected objects based on input
|
|
|
|
selectedNestObject: {},
|
|
|
|
selectedEggObject: {},
|
|
|
|
selectedNodeObject: {},
|
|
|
|
selectedProductObject: {},
|
|
|
|
|
|
|
|
//values
|
2021-11-07 11:07:30 +00:00
|
|
|
user: {!! $user !!},
|
2021-11-06 00:56:57 +00:00
|
|
|
nests: {!! $nests !!},
|
2021-11-20 22:38:44 +00:00
|
|
|
eggsSave: {!! $eggs !!}, //store back-end eggs
|
2021-11-06 00:56:57 +00:00
|
|
|
eggs: [],
|
2021-11-07 15:29:18 +00:00
|
|
|
locations: [],
|
2021-11-06 00:56:57 +00:00
|
|
|
products: [],
|
|
|
|
|
2023-01-18 22:54:37 +00:00
|
|
|
submitClicked: false,
|
|
|
|
|
2021-11-06 00:56:57 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @description set available eggs based on the selected nest
|
|
|
|
* @note called whenever a nest is selected
|
|
|
|
* @see selectedNest
|
|
|
|
*/
|
2021-11-12 16:01:32 +00:00
|
|
|
async setEggs() {
|
2021-11-07 15:29:18 +00:00
|
|
|
this.fetchedLocations = false;
|
2021-11-06 00:56:57 +00:00
|
|
|
this.fetchedProducts = false;
|
2021-11-07 15:29:18 +00:00
|
|
|
this.locations = [];
|
2021-11-06 00:56:57 +00:00
|
|
|
this.products = [];
|
2021-11-07 00:47:16 +00:00
|
|
|
this.selectedEgg = 'null';
|
|
|
|
this.selectedNode = 'null';
|
|
|
|
this.selectedProduct = 'null';
|
2021-11-06 00:56:57 +00:00
|
|
|
|
|
|
|
this.eggs = this.eggsSave.filter(egg => egg.nest_id == this.selectedNest)
|
2021-11-12 16:01:32 +00:00
|
|
|
|
|
|
|
//automatically select the first entry if there is only 1
|
|
|
|
if (this.eggs.length === 1) {
|
|
|
|
this.selectedEgg = this.eggs[0].id;
|
|
|
|
await this.fetchLocations();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-11-07 00:47:16 +00:00
|
|
|
this.updateSelectedObjects()
|
2021-11-06 00:56:57 +00:00
|
|
|
},
|
|
|
|
|
2021-11-27 12:51:48 +00:00
|
|
|
setProduct(productId) {
|
|
|
|
if (!productId) return
|
|
|
|
|
|
|
|
this.selectedProduct = productId;
|
|
|
|
this.updateSelectedObjects();
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2021-11-06 00:56:57 +00:00
|
|
|
/**
|
|
|
|
* @description fetch all available locations based on the selected egg
|
|
|
|
* @note called whenever a server configuration is selected
|
|
|
|
* @see selectedEg
|
|
|
|
*/
|
2021-11-07 15:29:18 +00:00
|
|
|
async fetchLocations() {
|
2021-11-06 00:56:57 +00:00
|
|
|
this.loading = true;
|
2021-11-07 15:29:18 +00:00
|
|
|
this.fetchedLocations = false;
|
2021-11-06 00:56:57 +00:00
|
|
|
this.fetchedProducts = false;
|
2021-11-07 15:29:18 +00:00
|
|
|
this.locations = [];
|
2021-11-06 00:56:57 +00:00
|
|
|
this.products = [];
|
2021-11-07 00:47:16 +00:00
|
|
|
this.selectedNode = 'null';
|
|
|
|
this.selectedProduct = 'null';
|
2021-11-06 00:56:57 +00:00
|
|
|
|
2021-11-20 22:38:44 +00:00
|
|
|
let response = await axios.get(`{{ route('products.locations.egg') }}/${this.selectedEgg}`)
|
2021-11-06 00:56:57 +00:00
|
|
|
.catch(console.error)
|
|
|
|
|
2021-11-07 15:29:18 +00:00
|
|
|
this.fetchedLocations = true;
|
|
|
|
this.locations = response.data
|
2021-11-12 16:01:32 +00:00
|
|
|
|
|
|
|
//automatically select the first entry if there is only 1
|
|
|
|
if (this.locations.length === 1 && this.locations[0]?.nodes?.length === 1) {
|
2021-11-12 19:26:39 +00:00
|
|
|
this.selectedNode = this.locations[0]?.nodes[0]?.id;
|
2021-11-12 16:01:32 +00:00
|
|
|
await this.fetchProducts();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-11-06 00:56:57 +00:00
|
|
|
this.loading = false;
|
2021-11-07 00:47:16 +00:00
|
|
|
this.updateSelectedObjects()
|
2021-11-06 00:56:57 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @description fetch all available products based on the selected node
|
|
|
|
* @note called whenever a node is selected
|
|
|
|
* @see selectedNode
|
|
|
|
*/
|
|
|
|
async fetchProducts() {
|
|
|
|
this.loading = true;
|
|
|
|
this.fetchedProducts = false;
|
|
|
|
this.products = [];
|
2021-11-07 00:47:16 +00:00
|
|
|
this.selectedProduct = 'null';
|
2021-11-06 00:56:57 +00:00
|
|
|
|
2021-11-20 22:38:44 +00:00
|
|
|
let response = await axios.get(
|
|
|
|
`{{ route('products.products.node') }}/${this.selectedEgg}/${this.selectedNode}`)
|
2021-11-06 00:56:57 +00:00
|
|
|
.catch(console.error)
|
|
|
|
|
|
|
|
this.fetchedProducts = true;
|
2021-12-01 20:58:21 +00:00
|
|
|
// TODO: Sortable by user chosen property (cpu, ram, disk...)
|
2023-01-18 22:54:37 +00:00
|
|
|
this.products = response.data.sort((p1, p2) => parseInt(p1.price, 10) > parseInt(p2.price, 10) &&
|
|
|
|
1 || -1)
|
2021-12-22 19:34:27 +00:00
|
|
|
|
|
|
|
//divide cpu by 100 for each product
|
|
|
|
this.products.forEach(product => {
|
|
|
|
product.cpu = product.cpu / 100;
|
|
|
|
})
|
2021-12-01 20:58:21 +00:00
|
|
|
|
2021-11-12 16:01:32 +00:00
|
|
|
|
2021-11-06 00:56:57 +00:00
|
|
|
this.loading = false;
|
2021-11-07 00:47:16 +00:00
|
|
|
this.updateSelectedObjects()
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @description map selected id's to selected objects
|
|
|
|
* @note being used in the server info box
|
|
|
|
*/
|
|
|
|
updateSelectedObjects() {
|
|
|
|
this.selectedNestObject = this.nests.find(nest => nest.id == this.selectedNest) ?? {}
|
|
|
|
this.selectedEggObject = this.eggs.find(egg => egg.id == this.selectedEgg) ?? {}
|
2021-11-07 15:29:18 +00:00
|
|
|
|
2021-11-12 22:16:59 +00:00
|
|
|
this.selectedNodeObject = {};
|
2021-11-07 15:29:18 +00:00
|
|
|
this.locations.forEach(location => {
|
2021-11-12 22:16:59 +00:00
|
|
|
if (!this.selectedNodeObject?.id) {
|
2021-11-20 22:38:44 +00:00
|
|
|
this.selectedNodeObject = location.nodes.find(node => node.id == this.selectedNode) ??
|
|
|
|
{};
|
2021-11-12 22:16:59 +00:00
|
|
|
}
|
2021-11-07 15:29:18 +00:00
|
|
|
})
|
|
|
|
|
2021-11-07 00:47:16 +00:00
|
|
|
this.selectedProductObject = this.products.find(product => product.id == this.selectedProduct) ?? {}
|
2021-11-27 12:51:48 +00:00
|
|
|
console.log(this.selectedProduct, this.selectedProductObject, this.products)
|
2021-11-07 00:47:16 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @description check if all options are selected
|
|
|
|
* @return {boolean}
|
|
|
|
*/
|
|
|
|
isFormValid() {
|
|
|
|
if (Object.keys(this.selectedNestObject).length === 0) return false;
|
|
|
|
if (Object.keys(this.selectedEggObject).length === 0) return false;
|
|
|
|
if (Object.keys(this.selectedNodeObject).length === 0) return false;
|
|
|
|
if (Object.keys(this.selectedProductObject).length === 0) return false;
|
|
|
|
return !!this.name;
|
2021-11-06 00:56:57 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
getNodeInputText() {
|
2021-11-07 15:29:18 +00:00
|
|
|
if (this.fetchedLocations) {
|
|
|
|
if (this.locations.length > 0) {
|
2021-11-20 22:38:44 +00:00
|
|
|
return '{{ __('Please select a node ...') }}';
|
2021-11-06 00:56:57 +00:00
|
|
|
}
|
2021-11-20 22:38:44 +00:00
|
|
|
return '{{ __('No nodes found matching current configuration') }}'
|
2021-11-06 00:56:57 +00:00
|
|
|
}
|
2021-11-20 22:38:44 +00:00
|
|
|
return '{{ __('---') }}';
|
2021-11-06 00:56:57 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
getProductInputText() {
|
|
|
|
if (this.fetchedProducts) {
|
|
|
|
if (this.products.length > 0) {
|
2021-11-20 22:38:44 +00:00
|
|
|
return '{{ __('Please select a resource ...') }}';
|
2021-11-06 00:56:57 +00:00
|
|
|
}
|
2021-11-20 22:38:44 +00:00
|
|
|
return '{{ __('No resources found matching current configuration') }}'
|
2021-11-06 00:56:57 +00:00
|
|
|
}
|
2021-11-20 22:38:44 +00:00
|
|
|
return '{{ __('---') }}';
|
2021-11-06 00:56:57 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
getEggInputText() {
|
|
|
|
if (this.selectedNest) {
|
2021-11-20 22:38:44 +00:00
|
|
|
return '{{ __('Please select a configuration ...') }}';
|
2021-11-06 00:56:57 +00:00
|
|
|
}
|
2021-11-20 22:38:44 +00:00
|
|
|
return '{{ __('---') }}';
|
2021-11-07 11:07:30 +00:00
|
|
|
},
|
|
|
|
|
2021-11-07 15:29:18 +00:00
|
|
|
getProductOptionText(product) {
|
2021-11-07 11:07:30 +00:00
|
|
|
let text = product.name + ' (' + product.description + ')';
|
|
|
|
|
2021-11-07 15:29:18 +00:00
|
|
|
if (product.minimum_credits > this.user.credits) {
|
2021-11-20 22:38:44 +00:00
|
|
|
return '{{ __('Not enough credits!') }} | ' + text;
|
2021-11-07 11:07:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return text;
|
2021-11-06 00:56:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|
2021-06-05 09:26:32 +00:00
|
|
|
@endsection
|