Skip to content

Commit

Permalink
Closes #34
Browse files Browse the repository at this point in the history
  • Loading branch information
asavann committed May 30, 2024
1 parent e552794 commit 2c4887d
Show file tree
Hide file tree
Showing 3 changed files with 137 additions and 1 deletion.
10 changes: 9 additions & 1 deletion app/Http/Controllers/HomeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Str;

class HomeController extends Controller
{
Expand Down Expand Up @@ -98,7 +100,13 @@ public function index(Request $request)
if ($tab === 'domains') {
$domains = $servers->flatMap(fn(YnhServer $server) => $server->domains);
}
return view('home.index', compact('tab', 'servers', 'orders', 'users', 'invitations', 'memory_usage', 'disk_usage', 'security_events', 'interdependencies', 'traces', 'pendingActions', 'domains'));

$applications = collect();

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'));
}

private function memoryUsage(Collection $servers): Collection
Expand Down
115 changes: 115 additions & 0 deletions resources/views/home/cards/_towerify_applications.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
@if(Auth::user()->canListApps())
<div class="card card-accent-secondary tw-card">
<div class="card-header">
<h3 class="m-0"><b>{{ __('Applications') }}</b></h3>
</div>
<div id="result-1" class="alert alert-dismissible fade show m-2" style="display:none;">
<button type="button" class="btn-close" aria-label="Close" onclick="closeResult1()"></button>
<span id="result-message-1"></span>
</div>
@if($applications->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>{{ __('Server') }}</th>
<th>{{ __('Name') }}</th>
<th>{{ __('Description') }}</th>
<th>{{ __('Sku') }}</th>
<th>{{ __('Version') }}</th>
<th></th>
</tr>
</thead>
<tbody>
@foreach($applications->sortBy('name', SORT_NATURAL|SORT_FLAG_CASE) as $app)
<tr>
<td>
<span class="font-lg mb-3 fw-bold">
<a href="{{ route('ynh.servers.edit', $app->server->id) }}">
{{ $app->server->name }}
</a>
</span>
</td>
<td>
<span class="font-lg mb-3 fw-bold">
<a href="https://{{ $app->path }}" target="_blank">
{{ $app->name }}
</a>
</span>
</td>
<td>
{{ $app->description }}
</td>
<td>
{{ $app->sku }}
</td>
<td>
{{ $app->version }}
</td>
<td>
@if(Auth::user()->canManageApps())
<button type="button"
onclick="uninstallApp('{{ $app->server->id }}', '{{ $app->id }}', '{{ $app->name }}')"
class="btn btn-xs btn-outline-danger float-end">
{{ __('uninstall') }}
</button>
@endif
</td>
</tr>
@endforeach
</tbody>
</table>
</div>
@endif
</div>
<script>
function closeResult1() {
const resultDiv = document.getElementById('result-1');
resultDiv.style.display = 'none';
}
function uninstallApp(serverId, appId, appName) {
const response = confirm(`Are you sure you want to remove ${appName} from the server?`);
if (response) {
const resultDiv = document.getElementById('result-1');
const messageSpan = document.getElementById('result-message-1');
axios.delete(`/ynh/servers/${serverId}/apps/${appId}`)
.then(function (data) {
resultDiv.className = 'alert alert-dismissible fade show m-2';
resultDiv.style.display = 'block';
if (data.data.success) {
resultDiv.classList.add('alert-success');
resultDiv.classList.remove('alert-danger');
messageSpan.textContent = data.data.success;
} else if (data.data.error) {
resultDiv.classList.add('alert-danger');
resultDiv.classList.remove('alert-success');
messageSpan.textContent = data.data.error;
} else {
console.log(data.data);
}
}).catch(error => {
console.error('Error:', error);
resultDiv.className = 'alert alert-dismissible fade show m-2';
resultDiv.style.display = 'block';
resultDiv.classList.add('alert-danger');
messageSpan.textContent = 'An error occurred.';
});
}
}
</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 @@ -8,6 +8,8 @@
<span class="breadcrumb-item active">{{ __('Servers') }}</span>
@elseif($tab === 'domains')
<span class="breadcrumb-item active">{{ __('Domains') }}</span>
@elseif($tab === 'applications')
<span class="breadcrumb-item active">{{ __('Applications') }}</span>
@elseif($tab === 'traces')
<span class="breadcrumb-item active">{{ __('Traces') }}</span>
@elseif($tab === 'interdependencies')
Expand Down Expand Up @@ -58,6 +60,14 @@
</li>
@endif
@if(Auth::user()->canListServers())
<li class="nav-item">
<a class="nav-link {{ $tab === 'applications' ? 'active' : '' }}"
href="/home?tab=applications">
{{ __('Applications') }}
</a>
</li>
@endif
@if(Auth::user()->canListServers())
<li class="nav-item">
<a class="nav-link {{ $tab === 'traces' ? 'active' : '' }}"
href="/home?tab=traces">
Expand Down Expand Up @@ -123,6 +133,9 @@
@if($tab === 'domains')
@include('home.cards._towerify_domains')
@endif
@if($tab === 'applications')
@include('home.cards._towerify_applications')
@endif
@if($tab === 'orders')
@include('home.cards._orders')
@endif
Expand Down

0 comments on commit 2c4887d

Please sign in to comment.