Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
andrasbacsai committed Aug 29, 2023
1 parent 2f9b7b1 commit 291b9a8
Show file tree
Hide file tree
Showing 23 changed files with 409 additions and 240 deletions.
34 changes: 17 additions & 17 deletions app/Http/Controllers/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,23 +48,23 @@ public function license()
public function force_passoword_reset() {
return view('auth.force-password-reset');
}
public function dashboard()
{
$projects = Project::ownedByCurrentTeam()->get();
$servers = Server::ownedByCurrentTeam()->get();
$s3s = S3Storage::ownedByCurrentTeam()->get();
$resources = 0;
foreach ($projects as $project) {
$resources += $project->applications->count();
$resources += $project->postgresqls->count();
}
return view('dashboard', [
'servers' => $servers->count(),
'projects' => $projects->count(),
'resources' => $resources,
's3s' => $s3s,
]);
}
// public function dashboard()
// {
// $projects = Project::ownedByCurrentTeam()->get();
// $servers = Server::ownedByCurrentTeam()->get();
// $s3s = S3Storage::ownedByCurrentTeam()->get();
// $resources = 0;
// foreach ($projects as $project) {
// $resources += $project->applications->count();
// $resources += $project->postgresqls->count();
// }
// return view('dashboard', [
// 'servers' => $servers->count(),
// 'projects' => $projects->count(),
// 'resources' => $resources,
// 's3s' => $s3s,
// ]);
// }
public function boarding() {
if (currentTeam()->boarding || isDev()) {
return view('boarding');
Expand Down
32 changes: 32 additions & 0 deletions app/Http/Livewire/Dashboard.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace App\Http\Livewire;

use App\Models\Project;
use App\Models\S3Storage;
use App\Models\Server;
use Livewire\Component;

class Dashboard extends Component
{
public int $projects = 0;
public int $servers = 0;
public int $s3s = 0;
public int $resources = 0;

public function mount()
{
$this->servers = Server::ownedByCurrentTeam()->get()->count();
$this->s3s = S3Storage::ownedByCurrentTeam()->get()->count();
$projects = Project::ownedByCurrentTeam()->get();
foreach ($projects as $project) {
$this->resources += $project->applications->count();
$this->resources += $project->postgresqls->count();
}
$this->projects = $projects->count();
}
public function render()
{
return view('livewire.dashboard');
}
}
41 changes: 0 additions & 41 deletions app/Http/Livewire/Dev/S3Test.php

This file was deleted.

20 changes: 20 additions & 0 deletions app/Http/Livewire/Server/All.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace App\Http\Livewire\Server;

use App\Models\Server;
use Illuminate\Database\Eloquent\Collection;
use Livewire\Component;

class All extends Component
{
public ?Collection $servers = null;

public function mount () {
$this->servers = Server::ownedByCurrentTeam()->get();
}
public function render()
{
return view('livewire.server.all');
}
}
19 changes: 19 additions & 0 deletions app/Http/Livewire/Server/Show.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace App\Http\Livewire\Server;

use App\Models\Server;
use Livewire\Component;

class Show extends Component
{
public ?Server $server = null;
public function mount()
{
$this->server = Server::ownedByCurrentTeam(['name', 'description', 'ip', 'port', 'user', 'proxy'])->whereUuid(request()->server_uuid)->firstOrFail();
}
public function render()
{
return view('livewire.server.show');
}
}
2 changes: 1 addition & 1 deletion app/Http/Middleware/IsBoardingFlow.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class IsBoardingFlow
*/
public function handle(Request $request, Closure $next): Response
{
// ray('IsBoardingFlow Middleware');
ray()->showQueries()->color('orange');
if (showBoarding() && !in_array($request->path(), allowedPathsForBoardingAccounts())) {
return redirect('boarding');
}
Expand Down
17 changes: 4 additions & 13 deletions app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,29 +91,20 @@ public function isInstanceAdmin()
return $found_root_team->count() > 0;
}

public function personalTeam()
{
return $this->teams()->where('personal_team', true)->first();
}

public function currentTeam()
{
return $this->teams()->where('team_id', session('currentTeam')->id)->first();
return session('currentTeam');
}

public function otherTeams()
{
$team_id = currentTeam()->id;
return auth()->user()->teams->filter(function ($team) use ($team_id) {
return $team->id != $team_id;
return auth()->user()->teams->filter(function ($team) {
return $team->id != currentTeam()->id;
});
}

public function role()
{
if ($this->teams()->where('team_id', 0)->first()) {
return 'admin';
}
return $this->teams()->where('team_id', currentTeam()->id)->first()->pivot->role;
return session('currentTeam')->pivot->role;
}
}
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"laravel/pint": "^v1.8.0",
"mockery/mockery": "^1.5.1",
"nunomaduro/collision": "^v7.4.0",
"pestphp/pest": "^v2.4.0",
"pestphp/pest": "^2.16",
"phpstan/phpstan": "^1.10",
"phpunit/phpunit": "^10.0.19",
"serversideup/spin": "^v1.1.0",
Expand Down
Loading

0 comments on commit 291b9a8

Please sign in to comment.