Skip to content

Commit d101fd5

Browse files
committed
feat: #22 add services list to the services page
1 parent 2842e3e commit d101fd5

File tree

6 files changed

+72
-3
lines changed

6 files changed

+72
-3
lines changed

app/Http/Controllers/ServiceController.php

+7-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,13 @@ class ServiceController extends Controller
1818
*/
1919
public function index()
2020
{
21-
return Inertia::render('Services/Index');
21+
$services = Service::with(['latestDeployment' => function ($query) {
22+
$query->with(['taskGroup' => function ($query) {
23+
$query->with('latestTask');
24+
}]);
25+
}])->get();
26+
27+
return Inertia::render('Services/Index', ['services' => $services]);
2228
}
2329

2430
/**

app/Models/Deployment.php

+6
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use App\Models\NodeTasks\ApplyCaddyConfig\ApplyCaddyConfigMeta;
1313
use App\Traits\HasOwningTeam;
1414
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
15+
use Illuminate\Database\Eloquent\Relations\HasOne;
1516
use Illuminate\Database\Query\Builder as QueryBuilder;
1617
use Illuminate\Database\Eloquent\Casts\Json;
1718
use Illuminate\Database\Eloquent\Factories\HasFactory;
@@ -40,6 +41,11 @@ public function service(): BelongsTo
4041
return $this->belongsTo(Service::class);
4142
}
4243

44+
public function taskGroup(): BelongsTo
45+
{
46+
return $this->belongsTo(NodeTaskGroup::class);
47+
}
48+
4349
public function makeResourceName($name): string
4450
{
4551
return $this->service->makeResourceName("dpl_". $this->id . "_" . $name);

app/Models/NodeTask.php

+2
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ public function complete(AbstractTaskResult $result): void
151151
$this->save();
152152

153153
if ($this->taskGroup->allTasksEnded()) {
154+
$this->taskGroup->ended_at = now();
154155
$this->taskGroup->status = TaskStatus::Completed;
155156
$this->taskGroup->save();
156157
}
@@ -166,6 +167,7 @@ public function fail(AbstractTaskResult $result): void
166167
$this->result = $result;
167168
$this->save();
168169

170+
$this->taskGroup->ended_at = now();
169171
$this->taskGroup->status = TaskStatus::Failed;
170172
$this->taskGroup->save();
171173

app/Models/NodeTaskGroup.php

+6
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Illuminate\Database\Eloquent\Model;
1111
use Illuminate\Database\Eloquent\Relations\BelongsTo;
1212
use Illuminate\Database\Eloquent\Relations\HasMany;
13+
use Illuminate\Database\Eloquent\Relations\HasOne;
1314
use Symfony\Component\VarDumper\VarDumper;
1415
use function Psy\debug;
1516

@@ -36,6 +37,11 @@ public function tasks(): HasMany
3637
return $this->hasMany(NodeTask::class, 'task_group_id');
3738
}
3839

40+
public function latestTask(): HasOne
41+
{
42+
return $this->hasOne(NodeTask::class, 'task_group_id')->latest();
43+
}
44+
3945
public function allTasksEnded() :bool
4046
{
4147
return ! $this->tasks()->whereNull('ended_at')->exists();

app/Models/Service.php

+6
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Illuminate\Database\Eloquent\Factories\HasFactory;
77
use Illuminate\Database\Eloquent\Model;
88
use Illuminate\Database\Eloquent\Relations\HasMany;
9+
use Illuminate\Database\Eloquent\Relations\HasOne;
910
use Illuminate\Support\Str;
1011

1112
class Service extends Model
@@ -30,6 +31,11 @@ public function deployments(): HasMany
3031
return $this->hasMany(Deployment::class);
3132
}
3233

34+
public function latestDeployment(): HasOne
35+
{
36+
return $this->hasOne(Deployment::class)->latest();
37+
}
38+
3339
public function makeResourceName($name): string
3440
{
3541
$name = dockerize_name("svc_" . $this->id . '_'. $name);

resources/js/Pages/Services/Index.vue

+45-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
<script setup>
22
import AppLayout from "@/Layouts/AppLayout.vue";
3-
import NodeStatus from "@/Components/NodeStatus.vue";
43
import {router} from "@inertiajs/vue3";
54
import PrimaryButton from "@/Components/PrimaryButton.vue";
5+
import TaskResult from "@/Components/NodeTasks/TaskResult.vue";
6+
import { Link } from '@inertiajs/vue3';
7+
8+
9+
const props = defineProps({
10+
'services': Array
11+
})
612
</script>
713

814
<template>
@@ -19,8 +25,45 @@ import PrimaryButton from "@/Components/PrimaryButton.vue";
1925

2026
<div class="py-12">
2127
<div class="max-w-7xl mx-auto sm:px-6 lg:px-8">
22-
this is your "Services" page.
28+
<div class=" grid grid-cols-3 gap-4">
29+
<div v-for="service in props.services" :key="service.id">
30+
<div
31+
class="bg-white dark:bg-gray-800 shadow sm:rounded-lg"
32+
>
33+
<Link :href="route('services.show', {'service': service.id})" class="p-4 flex justify-between">
34+
<div class="flex flex-col">
35+
<span class="font-semibold text-lg">{{ service.name }}</span>
36+
<span class="text-sm text-gray-500">{{ service.latest_deployment.data.dockerImage }}</span>
37+
</div>
38+
39+
<div class="flex flex-col w-44 overflow-hidden ">
40+
<span class="text-sm text-gray-500">{{ service.latest_deployment.data.internalDomain }}</span>
41+
<span v-if="service.latest_deployment.data.caddy[0]"
42+
class="text-sm text-gray-400"
43+
>
44+
<span v-if="service.latest_deployment.data.caddy[0].publishedPort === 80">http://</span>
45+
<span v-else-if="service.latest_deployment.data.caddy[0].publishedPort === 443">https://</span>
46+
<span class="text-black">{{ service.latest_deployment.data.caddy[0].domain }}</span>
47+
<span>{{ service.latest_deployment.data.caddy[0].path }}</span>
48+
</span>
49+
<span v-if="service.latest_deployment.data.caddy.length > 1"
50+
class="text-xs text-gray-400"
51+
>(+{{ service.latest_deployment.data.caddy.length - 1 }} more)</span>
52+
</div>
53+
54+
<!-- <pre>{{service}}</pre>-->
55+
</Link>
56+
<ul v-if="service.latest_deployment.task_group.latest_task.status !== 'completed'"
2357

58+
class="border-t-2 relative">
59+
<TaskResult
60+
:task="service.latest_deployment.task_group.latest_task"
61+
class="">
62+
</TaskResult>
63+
</ul>
64+
</div>
65+
</div>
66+
</div>
2467
</div>
2568
</div>
2669
</AppLayout>

0 commit comments

Comments
 (0)