Skip to content

Commit

Permalink
updated dashboard page
Browse files Browse the repository at this point in the history
  • Loading branch information
AVMG20 committed Aug 16, 2022
1 parent 0c1e590 commit 48e9e16
Show file tree
Hide file tree
Showing 13 changed files with 97 additions and 56 deletions.
3 changes: 1 addition & 2 deletions app/Http/Controllers/Admin/ServerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,9 @@ public function update(ServerUpdateRequest $request, Server $server, Pterodactyl
* Remove the specified resource from storage.
*
* @param Server $server
* @param PterodactylClient $client
* @return RedirectResponse
*/
public function destroy(Server $server, PterodactylClient $client)
public function destroy(Server $server)
{
$this->checkPermission(self::WRITE_PERMISSIONS);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<?php

namespace App\Http\Controllers;
namespace App\Http\Controllers\User;

use App\Classes\Pterodactyl\PterodactylClient;
use App\Exceptions\PterodactylRequestException;
use App\Helper\PterodactylServerHelper;
use App\Http\Controllers\Controller;
use App\Http\Requests\Server\ServerStoreRequest;
use App\Models\Server;
use App\Settings\GeneralSettings;
Expand Down Expand Up @@ -56,7 +57,7 @@ public function createServer(ServerStoreRequest $request, PterodactylServerHelpe
return redirect()->back()->with('error', __('Unexpected error during server creation'));
}

return redirect()->route('dashboard')->with('success', __('Server created successfully!'));
return redirect()->route('dashboard.index')->with('success', __('Server created successfully!'));
}


Expand Down
52 changes: 35 additions & 17 deletions app/Http/Controllers/User/HomeController.php
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use App\Settings\GeneralSettings;
use Exception;
use Illuminate\Contracts\Support\Renderable;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Blade;
use Yajra\DataTables\Html\Builder;
Expand All @@ -24,67 +25,84 @@ public function index(Request $request, GeneralSettings $settings)
{
/** @var User $user */
$user = $request->user();
$servers = $user->servers;

//datatables
if ($request->ajax()) {
return $this->dataTableQuery();
return $this->dataTableQuery($request);
}

$html = $this->dataTable();
return view('home', compact('html', 'settings', 'user'));
}

/**
* Remove the specified resource from storage.
*
* @param int $id
* @return RedirectResponse
*/
public function destroy(int $id): RedirectResponse
{
$server = Server::query()->findOrFail($id);
$server->delete();

return redirect()
->route('dashboard.index')
->with('success', __('Server removed'));
}

/**
* @description create table
*
* @return Builder
*/
public function dataTable(): Builder
{
/** @var GeneralSettings $settings */
$settings = app(GeneralSettings::class);

return $this->htmlBuilder
->addColumn(['data' => 'name', 'name' => 'name', 'title' => __('Name')])
->addColumn(['data' => 'price', 'name' => 'price', 'title' => $settings->credits_display_name])
->addColumn(['data' => 'cpu', 'name' => 'cpu', 'title' => __('CPU')])
->addColumn(['data' => 'memory', 'name' => 'memory', 'title' => __('Memory')])
->addColumn(['data' => 'disk', 'name' => 'disk', 'title' => __('Disk')])
->addColumn(['data' => 'egg.name', 'name' => 'egg.name', 'title' => __('Egg')])
->addColumn(['data' => 'price', 'name' => 'price', 'title' => __('Cost')])
->addColumn(['data' => 'egg.name', 'name' => 'egg.name', 'title' => __('Config')])
->addColumn(['data' => 'details', 'name' => 'details', 'title' => __('Details'),'searchable' => false, 'orderable' => false])
->addColumn(['data' => 'suspended', 'name' => 'suspended', 'title' => __('Suspended')])
->addAction(['data' => 'actions', 'name' => 'actions', 'title' => __('Actions'), 'searchable' => false, 'orderable' => false])
->parameters($this->dataTableDefaultParameters());
}

/**
* @param Request $request
* @return mixed
* @throws Exception
*/
public function dataTableQuery(): mixed
public function dataTableQuery(Request $request): mixed
{
$query = Server::query()->with('egg');
$query = Server::query()
->with(['egg'])
->whereBelongsTo($request->user());

return datatables($query)
->addColumn('actions', function (Server $server) {
return Blade::render('
<a title="{{__(\'Edit\')}}" href="" class="btn btn-sm btn-info">
<i class="fa fas fa-edit"></i>
</a>
<form class="d-inline" method="post" action="">
<form class="d-inline" method="post" action="{{route("dashboard.destroy", $server)}}">
@csrf
@method("DELETE")
<button title="{{__(\'Delete\')}}" type="submit" class="btn btn-sm btn-danger confirm"><i
class="fa fas fa-trash"></i></button>
</form>'
, compact('server'));
})
->addColumn('details', function (Server $server) {
return "CPU: {$server->cpu}%, RAM: {$server->memory}MB, DISK:{$server->disk}MB";
})
->editColumn('price', function (Server $server) {
return "<span><i class='fa fa-coins me-2'></i>{$server->price}</span>";
})
->editColumn('suspended', function (Server $server) {
return $server->suspended
? "<span class='badge bg-danger'>" . __('Suspended') . "</span>"
: "<span class='badge bg-success'>" . __('Active') . "</span>";
})
->rawColumns(['actions', 'suspended'])
->rawColumns(['actions', 'suspended', 'price'])
->make(true);
}
}
2 changes: 1 addition & 1 deletion app/Http/Livewire/Checkout.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public function createServer(PterodactylServerHelper $pterodactylServerHelper, P
return redirect()->back()->with('error', __('Unexpected error during server creation'));
}

return redirect()->route('dashboard')->with('success', __('Server created successfully!'));
return redirect()->route('dashboard.index')->with('success', __('Server created successfully!'));
}

/**
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Requests/Configuration/ConfigurationRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function rules()
'backups' => 'required|integer|max:1000000|min:0',
'allocations' => 'required|integer|max:1000000|min:0',
'locations' => 'required',
'locations.*' => 'required|exists:nodes,id',
'locations.*' => 'required|exists:nodes,location_id',
'eggs' => 'required',
'eggs.*' => 'required|exists:eggs,id',
'disabled' => 'required|boolean',
Expand Down
46 changes: 31 additions & 15 deletions app/Models/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasOne;
use Illuminate\Http\Client\Response;

class Server extends Model
Expand All @@ -35,10 +36,10 @@ class Server extends Model
'allocations',
'threads',
'oom_disabled',
'node',
'allocation',
'nest',
'egg',
'node_id',
'allocation_id',
'nest_id',
'egg_id',
'price',
];

Expand All @@ -58,9 +59,10 @@ class Server extends Model
'io' => 'int',
'databases' => 'int',
'backups' => 'int',
'allocations' => 'int',
'nest' => 'int',
'egg' => 'int',
'allocations_id' => 'int',
'nest_id' => 'int',
'egg_id' => 'int',
'node_id' => 'int',
];

protected $appends = [
Expand All @@ -80,6 +82,7 @@ protected static function boot()
$client = app(PterodactylClient::class);

try {
//delete server on pterodactyl
$client->deleteServer($server->pterodactyl_id);
} catch (PterodactylRequestException $exception) {
//throw exception if it's not a 404 error
Expand Down Expand Up @@ -119,10 +122,10 @@ public static function createFromPterodactylResponse(Response $response, User $u
'databases' => $data['attributes']['feature_limits']['databases'],
'backups' => $data['attributes']['feature_limits']['backups'],
'allocations' => $data['attributes']['feature_limits']['allocations'],
'node' => $data['attributes']['node'],
'allocation' => $data['attributes']['allocation'],
'nest' => $data['attributes']['nest'],
'egg' => $data['attributes']['egg'],
'node_id' => $data['attributes']['node'],
'allocation_id' => $data['attributes']['allocation'],
'nest_id' => $data['attributes']['nest'],
'egg_id' => $data['attributes']['egg'],
'price' => $price
]);
}
Expand Down Expand Up @@ -157,14 +160,27 @@ public function pterodactylAdminUrl(): Attribute
});
}

/**
* Get the price per hour
*
* @return Attribute
*/
public function price(): Attribute
{
return Attribute::make(
get: fn($value) => number_format($value, '2', '.', ''),
set: fn($value) => floatval($value),
);
}

/**
* Get the price per hour
*
* @return Attribute
*/
public function pricePerHour(): Attribute
{
return Attribute::get(fn() => floatval(number_format($this->price / 30 / 24, 6)));
return Attribute::get(fn() => number_format($this->price / 30 / 24, '2', '.', ''));
}

/**
Expand All @@ -174,7 +190,7 @@ public function pricePerHour(): Attribute
*/
public function pricePerDay(): Attribute
{
return Attribute::get(fn() => floatval(number_format($this->price / 30, 6)));
return Attribute::get(fn() => number_format($this->price / 30, '2', '.', ''));
}

/**
Expand All @@ -194,7 +210,7 @@ public function user(): BelongsTo
*/
public function egg(): BelongsTo
{
return $this->belongsTo(Egg::class, 'egg');
return $this->belongsTo(Egg::class);
}

/**
Expand All @@ -204,6 +220,6 @@ public function egg(): BelongsTo
*/
public function node(): BelongsTo
{
return $this->belongsTo(Node::class, 'node');
return $this->belongsTo(Node::class, );
}
}
1 change: 0 additions & 1 deletion database/factories/ServerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Database\Factories;

use App\Models\Server;
use Illuminate\Database\Eloquent\Factories\Factory;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ public function up()
$table->unsignedInteger('allocations');
$table->unsignedInteger('threads')->nullable();
$table->boolean('oom_disabled')->default(true);
$table->unsignedInteger('node');
$table->unsignedInteger('allocation');
$table->unsignedInteger('nest');
$table->unsignedInteger('egg');
$table->unsignedInteger('node_id');
$table->unsignedInteger('allocation_id');
$table->unsignedInteger('nest_id');
$table->unsignedInteger('egg_id');
$table->float('price', 18, 6)->default(0);
$table->timestamps();
});
Expand Down
2 changes: 1 addition & 1 deletion resources/views/checkout.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<div class="w-100" id="navbar-default-primary">
<ul class="navbar-nav navbar-nav-hover align-items-lg-center">
<li class="nav-item">
<a href="{{ route('dashboard') }}" class="nav-link">
<a href="{{ route('dashboard.index') }}" class="nav-link">
<span>
<i style="font-size: 16px;" class="fas pe-1 fa-home"></i>
{{__('Home')}}
Expand Down
21 changes: 15 additions & 6 deletions resources/views/home.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,18 @@
<div class="row">

<!-- Information -->
<div class="col-lg-12 col-xl-6">
<div class="card p-3">
<h2>Welcome to controlpanel</h2>

<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Asperiores eaque enim ex facilis fuga harum, impedit ipsam magnam magni nihil nostrum reprehenderit vitae voluptatum! Asperiores aut ducimus error laboriosam laborum.</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Asperiores eaque enim ex facilis fuga harum, impedit ipsam magnam magni nihil nostrum reprehenderit vitae voluptatum! Asperiores aut ducimus error laboriosam laborum.</p>
<div class="card card-body border-0 shadow table-wrapper table-responsive">
<div class="d-flex justify-content-between mb-3">
<div>
<h2 class="mb-4 h5">{{ __('Servers') }}</h2>
</div>
<div>
<button class="btn btn-primary"><i class="fas fa-plus me-2"></i> {{__('Create server')}}</button>
</div>
</div>

{!! $html->table() !!}

</div>
<!-- /Information -->

Expand All @@ -88,3 +93,7 @@
</div>
@endsection

@section('scripts')
{!! $html->scripts() !!}
@endsection

2 changes: 1 addition & 1 deletion resources/views/layouts/parts/nav.blade.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<nav class="navbar navbar-dark navbar-theme-primary px-4 col-12 d-md-none">
<a class="navbar-brand me-lg-5" href="{{ route('dashboard') }}">
<a class="navbar-brand me-lg-5" href="{{ route('dashboard.index') }}">
<img class="navbar-brand-dark" src="{{ asset('images/brand/light.svg') }}" alt="Volt logo" />
<img class="navbar-brand-light" src="{{ asset('images/brand/dark.svg') }}" alt="Volt logo" />
</a>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<li class="nav-item {{ request()->routeIs('home') ? 'active' : '' }}">
<a href="{{ route('dashboard') }}" class="nav-link">
<a href="{{ route('dashboard.index') }}" class="nav-link">
<span class="sidebar-icon me-3">
<i class="fas fa-home fa-fw"></i>
</span>
Expand Down
7 changes: 3 additions & 4 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
use App\Http\Controllers\Admin\RoleController;
use App\Http\Controllers\Admin\ServerController as AdminServerController;
use App\Http\Controllers\Admin\UserController;
use App\Http\Controllers\CheckoutController;
use App\Http\Controllers\Settings\GeneralSettingsController;
use App\Http\Controllers\Settings\PterodactylSettingsController;
use App\Http\Controllers\Settings\SmtpSettingsController;
use App\Http\Controllers\User\CheckoutController;
use App\Http\Controllers\User\HomeController;
use App\Http\Controllers\User\ProfileController;
use App\Settings\GeneralSettings;
Expand All @@ -33,7 +33,7 @@
//redirect to mainsite
Route::get('/main', function (GeneralSettings $settings) {
if ($settings->main_site) return redirect($settings->main_site);
return redirect()->route('dashboard');
return redirect()->route('dashboard.index');
})->name('main-site');

//auth routes
Expand All @@ -42,8 +42,7 @@

//client area
Route::middleware('auth')->group(function () {

Route::get('/dashboard', [HomeController::class, 'index'])->name('dashboard');
Route::resource('dashboard', HomeController::class);

Route::get('profile', [ProfileController::class, 'show'])->name('profile.show');
Route::put('profile', [ProfileController::class, 'update'])->name('profile.update');
Expand Down

0 comments on commit 48e9e16

Please sign in to comment.