Added non active servers tab, table and cache

Added non active servers tab, table and cache
This commit is contained in:
cp6 2022-03-04 16:11:25 +11:00
parent f76aaf2e2a
commit 9ce7bbd410
2 changed files with 243 additions and 132 deletions

View File

@ -23,17 +23,27 @@ class ServerController extends Controller
public function index() public function index()
{ {
$servers = Cache::remember('all_servers', 1440, function () { $servers = Cache::remember('all_active_servers', 1440, function () {
return DB::table('servers as s') return DB::table('servers as s')
->join('pricings as pr', 's.id', '=', 'pr.service_id') ->join('pricings as pr', 's.id', '=', 'pr.service_id')
->join('providers as p', 's.provider_id', '=', 'p.id') ->join('providers as p', 's.provider_id', '=', 'p.id')
->join('locations as l', 's.location_id', '=', 'l.id') ->join('locations as l', 's.location_id', '=', 'l.id')
->join('os as o', 's.os_id', '=', 'o.id') ->join('os as o', 's.os_id', '=', 'o.id')
->where('s.active', '=', 1)
->get(['s.*', 'pr.currency', 'pr.price', 'pr.term', 'pr.as_usd', 'pr.next_due_date', 'p.name as provider_name', 'l.name as location', 'o.name as os_name']); ->get(['s.*', 'pr.currency', 'pr.price', 'pr.term', 'pr.as_usd', 'pr.next_due_date', 'p.name as provider_name', 'l.name as location', 'o.name as os_name']);
}); });
return view('servers.index', compact(['servers'])); $non_active_servers = Cache::remember('non_active_servers', 1440, function () {
return DB::table('servers as s')
->join('pricings as pr', 's.id', '=', 'pr.service_id')
->join('providers as p', 's.provider_id', '=', 'p.id')
->join('locations as l', 's.location_id', '=', 'l.id')
->join('os as o', 's.os_id', '=', 'o.id')
->where('s.active', '=', 0)
->get(['s.*', 'pr.currency', 'pr.price', 'pr.term', 'pr.as_usd', 'p.name as provider_name', 'l.name as location', 'o.name as os_name']);
});
return view('servers.index', compact(['servers', 'non_active_servers']));
} }
public function showServersPublic() public function showServersPublic()
@ -172,7 +182,8 @@ class ServerController extends Controller
Cache::forget('services_count');//Main page services_count cache Cache::forget('services_count');//Main page services_count cache
Cache::forget('due_soon');//Main page due_soon cache Cache::forget('due_soon');//Main page due_soon cache
Cache::forget('recently_added');//Main page recently_added cache Cache::forget('recently_added');//Main page recently_added cache
Cache::forget('all_servers');//all servers cache Cache::forget('all_active_servers');//all servers cache
Cache::forget('non_active_servers');//all servers cache
return redirect()->route('servers.index') return redirect()->route('servers.index')
->with('success', 'Server Created Successfully.'); ->with('success', 'Server Created Successfully.');
@ -313,7 +324,8 @@ class ServerController extends Controller
Cache::forget('services_count');//Main page services_count cache Cache::forget('services_count');//Main page services_count cache
Cache::forget('due_soon');//Main page due_soon cache Cache::forget('due_soon');//Main page due_soon cache
Cache::forget('recently_added');//Main page recently_added cache Cache::forget('recently_added');//Main page recently_added cache
Cache::forget('all_servers');//all servers cache Cache::forget('all_active_servers');//all servers cache
Cache::forget('non_active_servers');//all servers cache
return redirect()->route('servers.index') return redirect()->route('servers.index')
->with('success', 'Server Updated Successfully.'); ->with('success', 'Server Updated Successfully.');
@ -335,7 +347,8 @@ class ServerController extends Controller
Cache::forget('services_count');//Main page services_count cache Cache::forget('services_count');//Main page services_count cache
Cache::forget('due_soon');//Main page due_soon cache Cache::forget('due_soon');//Main page due_soon cache
Cache::forget('recently_added');//Main page recently_added cache Cache::forget('recently_added');//Main page recently_added cache
Cache::forget('all_servers');//all servers cache Cache::forget('all_active_servers');//all servers cache
Cache::forget('non_active_servers');//all servers cache
return redirect()->route('servers.index') return redirect()->route('servers.index')
->with('success', 'Server was deleted Successfully.'); ->with('success', 'Server was deleted Successfully.');

View File

@ -12,138 +12,236 @@
</x-slot> </x-slot>
<div class="container" id="app"> <div class="container" id="app">
<x-delete-confirm-modal></x-delete-confirm-modal> <x-delete-confirm-modal></x-delete-confirm-modal>
<x-card class="shadow mt-3"> <ul class="nav nav-tabs" id="myTab" role="tablist">
<a href="{{ route('servers.create') }}" class="btn btn-primary mb-3">Add server</a> <li class="nav-item" role="presentation">
<a href="{{ route('servers-compare-choose') }}" class="btn btn-primary mb-3 ms-2">Compare servers</a> <button class="nav-link active" id="home-tab" data-bs-toggle="tab" data-bs-target="#home" type="button"
<x-success-alert></x-success-alert> role="tab" aria-controls="home" aria-selected="true">Active
<div class="table-responsive"> </button>
<table class="table table-bordered"> </li>
<thead class="table-light"> <li class="nav-item" role="presentation">
<tr class="bg-gray-100"> <button class="nav-link @if(!isset($non_active_servers[0]))disabled @endif" id="profile-tab"
<th>Name</th> data-bs-toggle="tab" data-bs-target="#non-active" type="button" role="tab"
<th class="text-center"><i class="fas fa-box" title="Virt"></i></th> aria-controls="profile" aria-selected="false">Non active
<th class="text-center">OS</th> </button>
<th class="text-center"><i class="fas fa-microchip" title="CPU"></i></th> </li>
<th class="text-center"><i class="fas fa-memory" title="ram"></i></th> </ul>
<th class="text-center"><i class="fas fa-compact-disc" title="disk"></i></th> <div class="tab-content" id="myTabContent">
<th>Location</th> <div class="tab-pane fade show active" id="home" role="tabpanel" aria-labelledby="home-tab">
<th>Provider</th> <x-card class="shadow mt-3">
<th>Price</th> <a href="{{ route('servers.create') }}" class="btn btn-primary mb-3">Add server</a>
<th>Due in</th> <a href="{{ route('servers-compare-choose') }}" class="btn btn-primary mb-3 ms-2">Compare
<th class="text-center">Had since</th> servers</a>
<th>Actions</th> <x-success-alert></x-success-alert>
</tr> <div class="table-responsive">
</thead> <table class="table table-bordered">
<tbody> <thead class="table-light">
@if(!empty($servers)) <tr class="bg-gray-100">
@foreach($servers as $server) <th>Name</th>
<tr> <th class="text-center"><i class="fas fa-box" title="Virt"></i></th>
<td>{{ $server->hostname }}</td> <th class="text-center">OS</th>
<td class="text-center"> <th class="text-center"><i class="fas fa-microchip" title="CPU"></i></th>
{{ App\Models\Server::serviceServerType($server->server_type) }} <th class="text-center"><i class="fas fa-memory" title="ram"></i></th>
</td> <th class="text-center"><i class="fas fa-compact-disc" title="disk"></i></th>
<td class="text-center">{!!App\Models\Server::osIntToIcon($server->os_id, $server->os_name)!!}</td> <th>Location</th>
<td class="text-center">{{$server->cpu}}</td> <th>Provider</th>
<td class="text-center"> <th>Price</th>
@if($server->ram_as_mb > 1024) <th>Due in</th>
{{ number_format(($server->ram_as_mb / 1000),0) }}<small>GB</small> <th class="text-center">Had since</th>
@else <th>Actions</th>
{{$server->ram_as_mb}}<small>MB</small>
@endif
</td>
<td class="text-center">
@if($server->disk > 1000)
{{ number_format(($server->disk / 1000),1) }}<small>TB</small>
@else
{{$server->disk}}<small>GB</small>
@endif
</td>
<td class="text-nowrap">{{ $server->location }}</td>
<td class="text-nowrap">{{ $server->provider_name }}</td>
<td class="text-nowrap">{{ $server->price }} {{$server->currency}} {{\App\Process::paymentTermIntToString($server->term)}}</td>
<td class="text-nowrap">
{{now()->diffInDays(Carbon\Carbon::parse($server->next_due_date))}}
<small>days</small></td>
<td class="text-center"> {{ $server->owned_since }}</td>
<td class="text-nowrap">
<form action="{{ route('servers.destroy', $server->id) }}" method="POST">
<a href="{{ route('servers.show', $server->id) }}"
class="text-body mx-1">
<i class="fas fa-eye" title="view"></i>
</a>
<a href="{{ route('servers.edit', $server->id) }}"
class="text-body mx-1">
<i class="fas fa-pen" title="edit"></i>
</a>
<i class="fas fa-plug mx-1" id="btn-{{$server->hostname}}"
title="check if up"
@click="onClk">
</i>
<i class="fas fa-trash text-danger ms-3" @click="modalForm"
id="btn-{{$server->hostname}}" title="{{$server->id}}"></i>
</form>
</td>
</tr> </tr>
@endforeach </thead>
@else <tbody>
<tr> @if(!empty($servers))
<td class="px-4 py-2 border text-red-500" colspan="3">No servers found.</td> @foreach($servers as $server)
</tr> <tr>
@endif <td>{{ $server->hostname }}</td>
</tbody> <td class="text-center">
</table> {{ App\Models\Server::serviceServerType($server->server_type) }}
</td>
<td class="text-center">{!!App\Models\Server::osIntToIcon($server->os_id, $server->os_name)!!}</td>
<td class="text-center">{{$server->cpu}}</td>
<td class="text-center">
@if($server->ram_as_mb > 1024)
{{ number_format(($server->ram_as_mb / 1000),0) }}<small>GB</small>
@else
{{$server->ram_as_mb}}<small>MB</small>
@endif
</td>
<td class="text-center">
@if($server->disk > 1000)
{{ number_format(($server->disk / 1000),1) }}<small>TB</small>
@else
{{$server->disk}}<small>GB</small>
@endif
</td>
<td class="text-nowrap">{{ $server->location }}</td>
<td class="text-nowrap">{{ $server->provider_name }}</td>
<td class="text-nowrap">{{ $server->price }} {{$server->currency}} {{\App\Process::paymentTermIntToString($server->term)}}</td>
<td class="text-nowrap">
{{now()->diffInDays(Carbon\Carbon::parse($server->next_due_date))}}
<small>days</small></td>
<td class="text-center"> {{ $server->owned_since }}</td>
<td class="text-nowrap">
<form action="{{ route('servers.destroy', $server->id) }}" method="POST">
<a href="{{ route('servers.show', $server->id) }}"
class="text-body mx-1">
<i class="fas fa-eye" title="view"></i>
</a>
<a href="{{ route('servers.edit', $server->id) }}"
class="text-body mx-1">
<i class="fas fa-pen" title="edit"></i>
</a>
<i class="fas fa-plug mx-1" id="btn-{{$server->hostname}}"
title="check if up"
@click="onClk">
</i>
<i class="fas fa-trash text-danger ms-3" @click="modalForm"
id="btn-{{$server->hostname}}" title="{{$server->id}}"></i>
</form>
</td>
</tr>
@endforeach
@else
<tr>
<td class="px-4 py-2 border text-red-500" colspan="3">No servers found.</td>
</tr>
@endif
</tbody>
</table>
</div>
</x-card>
</div> </div>
</x-card> <div class="tab-pane fade" id="non-active" role="tabpanel" aria-labelledby="non-active-tab">
<x-card class="shadow mt-3">
<a href="{{ route('servers.create') }}" class="btn btn-primary mb-3">Add server</a>
<a href="{{ route('servers-compare-choose') }}" class="btn btn-primary mb-3 ms-2">Compare
servers</a>
<x-success-alert></x-success-alert>
<div class="table-responsive">
<table class="table table-bordered">
<thead class="table-light">
<tr class="bg-gray-100">
<th>Name</th>
<th class="text-center"><i class="fas fa-box" title="Virt"></i></th>
<th class="text-center">OS</th>
<th class="text-center"><i class="fas fa-microchip" title="CPU"></i></th>
<th class="text-center"><i class="fas fa-memory" title="ram"></i></th>
<th class="text-center"><i class="fas fa-compact-disc" title="disk"></i></th>
<th>Location</th>
<th>Provider</th>
<th>Price</th>
<th class="text-center">Had since</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
@if(!empty($non_active_servers))
@foreach($non_active_servers as $server)
<tr>
<td>{{ $server->hostname }}</td>
<td class="text-center">
{{ App\Models\Server::serviceServerType($server->server_type) }}
</td>
<td class="text-center">{!!App\Models\Server::osIntToIcon($server->os_id, $server->os_name)!!}</td>
<td class="text-center">{{$server->cpu}}</td>
<td class="text-center">
@if($server->ram_as_mb > 1024)
{{ number_format(($server->ram_as_mb / 1000),0) }}<small>GB</small>
@else
{{$server->ram_as_mb}}<small>MB</small>
@endif
</td>
<td class="text-center">
@if($server->disk > 1000)
{{ number_format(($server->disk / 1000),1) }}<small>TB</small>
@else
{{$server->disk}}<small>GB</small>
@endif
</td>
<td class="text-nowrap">{{ $server->location }}</td>
<td class="text-nowrap">{{ $server->provider_name }}</td>
<td class="text-nowrap">{{ $server->price }} {{$server->currency}} {{\App\Process::paymentTermIntToString($server->term)}}</td>
<td class="text-center"> {{ $server->owned_since }}</td>
<td class="text-nowrap">
<form action="{{ route('servers.destroy', $server->id) }}" method="POST">
<a href="{{ route('servers.show', $server->id) }}"
class="text-body mx-1">
<i class="fas fa-eye" title="view"></i>
</a>
<a href="{{ route('servers.edit', $server->id) }}"
class="text-body mx-1">
<i class="fas fa-pen" title="edit"></i>
</a>
@if(Session::has('timer_version_footer') && Session::get('timer_version_footer') === 1) <i class="fas fa-plug mx-1" id="btn-{{$server->hostname}}"
<p class="text-muted mt-4 text-end"><small>Built on Laravel title="check if up"
v{{ Illuminate\Foundation\Application::VERSION }} (PHP v{{ PHP_VERSION }})</small></p> @click="onClk">
@endif </i>
</div> <i class="fas fa-trash text-danger ms-3" @click="modalForm"
id="btn-{{$server->hostname}}" title="{{$server->id}}"></i>
</form>
</td>
</tr>
@endforeach
@else
<tr>
<td class="px-4 py-2 border text-red-500" colspan="3">No non-active servers found.</td>
</tr>
@endif
</tbody>
</table>
</div>
</x-card>
</div>
@if(Session::has('timer_version_footer') && Session::get('timer_version_footer') === 1)
<p class="text-muted mt-4 text-end"><small>Built on Laravel
v{{ Illuminate\Foundation\Application::VERSION }} (PHP v{{ PHP_VERSION }})</small></p>
@endif
</div>
<script> <script>
axios.defaults.headers.common = { axios.defaults.headers.common = {
'Content-Type': 'application/json', 'Content-Type': 'application/json',
'X-Requested-With': 'XMLHttpRequest', 'X-Requested-With': 'XMLHttpRequest',
'X-CSRF-TOKEN': document.querySelector('meta[name="csrf-token"]').getAttribute('content'), 'X-CSRF-TOKEN': document.querySelector('meta[name="csrf-token"]').getAttribute('content'),
'Accept': 'application/json', 'Accept': 'application/json',
}; };
let app = new Vue({ let app = new Vue({
el: "#app", el: "#app",
data: { data: {
"status": false, "status": false,
"modal_hostname": '', "modal_hostname": '',
"modal_id": '', "modal_id": '',
"delete_form_action": '', "delete_form_action": '',
showModal: false showModal: false
},
methods: {
onClk(event) {
var hostname = event.target.id.replace('btn-', '');
if (hostname) {
axios
.get('/api/online/' + event.target.id.replace('btn-', ''), {headers: {'Authorization': 'Bearer ' + document.querySelector('meta[name="api_token"]').getAttribute('content')}})
.then(response => (this.status = response.data.is_online))
.finally(() => {
if (this.status) {
event.target.className = "fas fa-plug text-success mx-1";
} else if (!this.status) {
event.target.className = "fas fa-plug text-danger mx-1";
}
});
}
}, },
modalForm(event) { methods: {
this.showModal = true; onClk(event) {
this.modal_hostname = event.target.id.replace('btn-', ''); var hostname = event.target.id.replace('btn-', '');
this.modal_id = event.target.title;
this.delete_form_action = 'servers/' + this.modal_id; if (hostname) {
axios
.get('/api/online/' + event.target.id.replace('btn-', ''), {headers: {'Authorization': 'Bearer ' + document.querySelector('meta[name="api_token"]').getAttribute('content')}})
.then(response => (this.status = response.data.is_online))
.finally(() => {
if (this.status) {
event.target.className = "fas fa-plug text-success mx-1";
} else if (!this.status) {
event.target.className = "fas fa-plug text-danger mx-1";
}
});
}
},
modalForm(event) {
this.showModal = true;
this.modal_hostname = event.target.id.replace('btn-', '');
this.modal_id = event.target.title;
this.delete_form_action = 'servers/' + this.modal_id;
}
} }
} });
}); </script>
</script>
</x-app-layout> </x-app-layout>