Skip to content

Commit

Permalink
Closes #30
Browse files Browse the repository at this point in the history
  • Loading branch information
asavann committed May 31, 2024
1 parent 795a3a3 commit b8fde4e
Show file tree
Hide file tree
Showing 3 changed files with 116 additions and 1 deletion.
7 changes: 6 additions & 1 deletion app/Http/Controllers/HomeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,12 @@ public function index(Request $request)
if ($tab === "applications") {
$applications = $servers->flatMap(fn(YnhServer $server) => $server->applications);
}
return view('home.index', compact('tab', 'servers', 'orders', 'users', 'invitations', 'memory_usage', 'disk_usage', 'security_events', 'interdependencies', 'traces', 'pendingActions', 'domains', 'applications'));

$backups = collect();
if ($tab === 'backups') {
$backups = $servers->flatMap(fn(YnhServer $server) => $server->backups);
}
return view('home.index', compact('tab', 'servers', 'orders', 'users', 'invitations', 'memory_usage', 'disk_usage', 'security_events', 'interdependencies', 'traces', 'pendingActions', 'domains', 'applications', 'backups'));
}

private function memoryUsage(Collection $servers): Collection
Expand Down
97 changes: 97 additions & 0 deletions resources/views/home/cards/_towerify_backups.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
@if(Auth::user()->canListServers())
<?php
function formatBytes($bytes, $precision = 2)
{
$units = array('B', 'KiB', 'MiB', 'GiB', 'TiB');
$bytes = max($bytes, 0);
$pow = floor(($bytes ? log($bytes) : 0) / log(1024));
$pow = min($pow, count($units) - 1);
$bytes /= pow(1024, $pow);
return round($bytes, $precision) . $units[$pow];
}
?>
<div class="card card-accent-secondary tw-card">
<div class="card-header d-flex flex-row">
<div class="align-items-start">
<h3 class="m-0">
{{ __('Backups') }}
</h3>
</div>
</div>
<div id="result-8" class="alert alert-dismissible fade show m-2" style="display:none;">
<button type="button" class="btn-close" aria-label="Close" onclick="closeResult8()"></button>
<span id="result-message-8"></span>
</div>
@if($backups->isEmpty())
<div class="card-body">
<div class="row">
<div class="col">
None.
</div>
</div>
</div>
@else
<div class="card-body p-0">
<table class="table table-hover">
<thead>
<tr>
<th>{{ __('Date') }}</th>
<th>{{ __('Server') }}</th>
<th>{{ __('Name') }}</th>
<th>{{ __('Size') }}</th>
<th></th>
</tr>
</thead>
<tbody>
@foreach($backups->sortByDesc('updated_at') as $backup)
<tr>
<td>
{{ $backup->updated_at->format('Y-m-d H:i:s') }}
</td>
<td>
{{ $backup->server->name }}
</td>
<td>
{{ $backup->name }}
</td>
<td>
{{ formatBytes($backup->size) }}
</td>
<td>
@if($server->isReady() && Auth::user()->canManageServers())
<a href="/ynh/servers/{{ $server->id }}/backup/{{ $backup->id }}"
class="cursor-pointer"
title="download">
<img src="{{ asset('images/download.png') }}" height="20" class="float-end">
</a>
@endif
</td>
</tr>
<tr>
<td colspan="4">
@foreach($backup->result['apps'] as $app => $status)
@if($status === 'Success')
<span class="tw-pill rounded-pill bg-success">{{ $app }}</span>
@else
<span class="tw-pill rounded-pill bg-danger">{{ $app }}</span>
@endif
@endforeach
</td>
</tr>
@endforeach
</tbody>
</table>
</div>
@endif
</div>
<script>
function closeResult8() {
const resultDiv = document.getElementById('result-8');
resultDiv.style.display = 'none';
}
</script>
@endif
13 changes: 13 additions & 0 deletions resources/views/home/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
<span class="breadcrumb-item active">{{ __('My Apps') }}</span>
@elseif($tab === 'servers')
<span class="breadcrumb-item active">{{ __('Servers') }}</span>
@elseif($tab === 'backups')
<span class="breadcrumb-item active">{{ __('Backups') }}</span>
@elseif($tab === 'domains')
<span class="breadcrumb-item active">{{ __('Domains') }}</span>
@elseif($tab === 'applications')
Expand Down Expand Up @@ -52,6 +54,14 @@
</li>
@endif
@if(Auth::user()->canListServers())
<li class="nav-item">
<a class="nav-link {{ $tab === 'backups' ? 'active' : '' }}"
href="/home?tab=backups">
{{ __('Backups') }}
</a>
</li>
@endif
@if(Auth::user()->canListServers())
<li class="nav-item">
<a class="nav-link {{ $tab === 'domains' ? 'active' : '' }}"
href="/home?tab=domains">
Expand Down Expand Up @@ -130,6 +140,9 @@
@if($tab === 'servers')
@include('home.cards._servers')
@endif
@if($tab === 'backups')
@include('home.cards._towerify_backups')
@endif
@if($tab === 'domains')
@include('home.cards._towerify_domains')
@endif
Expand Down

0 comments on commit b8fde4e

Please sign in to comment.