wip previews

This commit is contained in:
Andras Bacsai 2023-05-16 14:11:55 +02:00
parent 9bbf25b9f4
commit ec233162e9
8 changed files with 49 additions and 11 deletions

View File

@ -0,0 +1,15 @@
<?php
namespace App\Data;
use Spatie\LaravelData\Data;
class ApplicationPreview extends Data
{
public function __construct(
public int $pullRequestId,
public string $branch,
public ?string $commit,
) {
}
}

View File

@ -8,8 +8,4 @@
class Previews extends Component
{
public Application $application;
public function render()
{
return view('livewire.project.application.previews');
}
}

View File

@ -2,9 +2,11 @@
namespace App\Models;
use Illuminate\Contracts\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Spatie\Activitylog\Models\Activity;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Spatie\SchemalessAttributes\Casts\SchemalessAttributes;
class Application extends BaseModel
{
@ -20,8 +22,6 @@ protected static function booted()
$application->persistentStorages()->delete();
});
}
protected $fillable = [
'name',
'project_id',
@ -40,6 +40,16 @@ protected static function booted()
'publish_directory',
'private_key_id'
];
public $casts = [
'previews' => SchemalessAttributes::class,
];
public function scopeWithExtraAttributes(): Builder
{
return $this->previews->modelScope();
}
public function publishDirectory(): Attribute
{
return Attribute::make(

View File

@ -28,7 +28,6 @@ protected static function booted()
'extra_attributes' => SchemalessAttributes::class,
];
public function standaloneDockers()
{
return $this->hasMany(StandaloneDocker::class);

View File

@ -41,6 +41,8 @@ public function up(): void
$table->string('base_directory')->default('/');
$table->string('publish_directory')->nullable();
$table->schemalessAttributes('previews');
$table->string('health_check_path')->default('/');
$table->string('health_check_port')->nullable();
$table->string('health_check_host')->default('localhost');

View File

@ -2,6 +2,7 @@
namespace Database\Seeders;
use App\Data\ApplicationPreview;
use App\Models\Application;
use App\Models\ApplicationSetting;
use App\Models\Environment;
@ -36,6 +37,16 @@ public function run(): void
'destination_type' => StandaloneDocker::class,
'source_id' => $github_public_source->id,
'source_type' => GithubApp::class,
'previews' => [
ApplicationPreview::from([
'pullRequestId' => 1,
'branch' => 'nodejs-fastify'
]),
ApplicationPreview::from([
'pullRequestId' => 2,
'branch' => 'nodejs-fastify'
])
]
]);
}
}

View File

@ -1,3 +1,8 @@
<div>
<h2>Previews</h2>
<div class="flex gap-2">
@foreach ($application->previews as $preview)
<div class="box">{{ $preview['pullRequestId'] }} | {{ $preview['branch'] }}</div>
@endforeach
</div>
</div>

View File

@ -18,9 +18,9 @@
<a :class="activeTab === 'storages' && 'text-purple-500'"
@click.prevent="activeTab = 'storages'; window.location.hash = 'storages'" href="#">Storages
</a>
<a :class="activeTab === 'previews' && 'text-purple-500'"
{{-- <a :class="activeTab === 'previews' && 'text-purple-500'"
@click.prevent="activeTab = 'previews'; window.location.hash = 'previews'" href="#">Previews
</a>
</a> --}}
</div>
<div class="w-full pl-8">
<div x-cloak x-show="activeTab === 'general'">
@ -38,9 +38,9 @@
<div x-cloak x-show="activeTab === 'storages'">
<livewire:project.application.storages.all :application="$application" />
</div>
<div x-cloak x-show="activeTab === 'previews'">
{{-- <div x-cloak x-show="activeTab === 'previews'">
<livewire:project.application.previews :application="$application" />
</div>
</div> --}}
</div>
</div>
</x-layout>