feat: tags and tag deploy webhooks
This commit is contained in:
@@ -29,7 +29,7 @@ class Index extends Component
|
||||
}
|
||||
$this->project = $project;
|
||||
$this->environment = $environment;
|
||||
$this->applications = $environment->applications->sortBy('name');
|
||||
$this->applications = $environment->applications->load(['tags'])->sortBy('name');
|
||||
$this->applications = $this->applications->map(function ($application) {
|
||||
if (data_get($application, 'environment.project.uuid')) {
|
||||
$application->hrefLink = route('project.application.configuration', [
|
||||
|
||||
62
app/Livewire/Project/Shared/Tags.php
Normal file
62
app/Livewire/Project/Shared/Tags.php
Normal file
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
namespace App\Livewire\Project\Shared;
|
||||
|
||||
use App\Models\Tag;
|
||||
use Livewire\Component;
|
||||
|
||||
class Tags extends Component
|
||||
{
|
||||
public $resource = null;
|
||||
public ?string $new_tag = null;
|
||||
protected $listeners = [
|
||||
'refresh' => '$refresh',
|
||||
];
|
||||
public function mount()
|
||||
{
|
||||
}
|
||||
public function deleteTag($id, $name)
|
||||
{
|
||||
try {
|
||||
$found_more_tags = Tag::where(['name' => $name, 'team_id' => currentTeam()->id])->first();
|
||||
$this->resource->tags()->detach($id);
|
||||
if ($found_more_tags->resources()->get()->count() == 0) {
|
||||
$found_more_tags->delete();
|
||||
}
|
||||
$this->refresh();
|
||||
} catch (\Exception $e) {
|
||||
return handleError($e, $this);
|
||||
}
|
||||
}
|
||||
public function refresh()
|
||||
{
|
||||
$this->resource->load(['tags']);
|
||||
$this->new_tag = null;
|
||||
}
|
||||
public function submit()
|
||||
{
|
||||
try {
|
||||
$this->validate([
|
||||
'new_tag' => 'required|string|min:2'
|
||||
]);
|
||||
$tags = str($this->new_tag)->trim()->explode(' ');
|
||||
foreach ($tags as $tag) {
|
||||
$found = Tag::where(['name' => $tag, 'team_id' => currentTeam()->id])->first();
|
||||
if (!$found) {
|
||||
$found = Tag::create([
|
||||
'name' => $tag,
|
||||
'team_id' => currentTeam()->id
|
||||
]);
|
||||
}
|
||||
$this->resource->tags()->syncWithoutDetaching($found->id);
|
||||
}
|
||||
$this->refresh();
|
||||
} catch (\Exception $e) {
|
||||
return handleError($e, $this);
|
||||
}
|
||||
}
|
||||
public function render()
|
||||
{
|
||||
return view('livewire.project.shared.tags');
|
||||
}
|
||||
}
|
||||
18
app/Livewire/Tags/Index.php
Normal file
18
app/Livewire/Tags/Index.php
Normal file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace App\Livewire\Tags;
|
||||
|
||||
use App\Models\Tag;
|
||||
use Livewire\Component;
|
||||
|
||||
class Index extends Component
|
||||
{
|
||||
public $tags = [];
|
||||
public function mount() {
|
||||
$this->tags = Tag::where('team_id', currentTeam()->id)->get()->unique('name')->sortBy('name');
|
||||
}
|
||||
public function render()
|
||||
{
|
||||
return view('livewire.tags.index');
|
||||
}
|
||||
}
|
||||
27
app/Livewire/Tags/Show.php
Normal file
27
app/Livewire/Tags/Show.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Livewire\Tags;
|
||||
|
||||
use App\Models\Tag;
|
||||
use Livewire\Component;
|
||||
|
||||
class Show extends Component
|
||||
{
|
||||
public Tag $tag;
|
||||
public $resources;
|
||||
public $webhook = null;
|
||||
public function mount()
|
||||
{
|
||||
$tag = Tag::ownedByCurrentTeam()->where('name', request()->tag_name)->first();
|
||||
if (!$tag) {
|
||||
return redirect()->route('tags.index');
|
||||
}
|
||||
$this->webhook = generatTagDeployWebhook($tag->name);
|
||||
$this->resources = $tag->resources()->get();
|
||||
$this->tag = $tag;
|
||||
}
|
||||
public function render()
|
||||
{
|
||||
return view('livewire.tags.show');
|
||||
}
|
||||
}
|
||||
@@ -211,6 +211,10 @@ class Application extends BaseModel
|
||||
: explode(',', $this->ports_exposes)
|
||||
);
|
||||
}
|
||||
public function tags()
|
||||
{
|
||||
return $this->morphToMany(Tag::class, 'taggable');
|
||||
}
|
||||
public function team()
|
||||
{
|
||||
return data_get($this, 'environment.project.team');
|
||||
|
||||
32
app/Models/Tag.php
Normal file
32
app/Models/Tag.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||
|
||||
class Tag extends BaseModel
|
||||
{
|
||||
protected $guarded = [];
|
||||
|
||||
|
||||
public function name(): Attribute
|
||||
{
|
||||
return Attribute::make(
|
||||
get: fn ($value) => strtolower($value),
|
||||
set: fn ($value) => strtolower($value)
|
||||
);
|
||||
}
|
||||
static public function ownedByCurrentTeam()
|
||||
{
|
||||
return Tag::whereTeamId(currentTeam()->id)->orderBy('name');
|
||||
}
|
||||
public function applications()
|
||||
{
|
||||
return $this->morphedByMany(Application::class, 'taggable');
|
||||
}
|
||||
|
||||
public function resources() {
|
||||
return $this->applications();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user