fix: tags

This commit is contained in:
Andras Bacsai
2024-02-03 12:39:07 +01:00
parent bc31df6fb2
commit 0b5baf60a5
9 changed files with 70 additions and 40 deletions

View File

@@ -73,12 +73,17 @@ class Deploy extends Controller
$message->push("Tag {$tag} not found.");
continue;
}
$resources = $found_tag->resources()->get();
if ($resources->count() === 0) {
$applications = $found_tag->applications();
$services = $found_tag->services();
if ($applications->count() === 0 && $services->count() === 0) {
$message->push("No resources found for tag {$tag}.");
continue;
}
foreach ($resources as $resource) {
foreach ($applications as $resource) {
$return_message = $this->deploy_resource($resource, $force);
$message = $message->merge($return_message);
}
foreach ($services as $resource) {
$return_message = $this->deploy_resource($resource, $force);
$message = $message->merge($return_message);
}

View File

@@ -37,12 +37,13 @@ class Tags extends Component
return handleError($e, $this);
}
}
public function deleteTag($id, $name)
public function deleteTag(string $id)
{
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 = Tag::where(['id' => $id, 'team_id' => currentTeam()->id])->first();
if ($found_more_tags->applications()->count() == 0 && $found_more_tags->services()->count() == 0){
$found_more_tags->delete();
}
$this->refresh();

View File

@@ -10,14 +10,27 @@ use Livewire\Component;
class Show extends Component
{
public Tag $tag;
public $resources;
public $applications;
public $services;
public $webhook = null;
public $deployments_per_tag_per_server = [];
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->applications = $tag->applications()->get();
$this->services = $tag->services()->get();
$this->tag = $tag;
$this->get_deployments();
}
public function get_deployments()
{
try {
$resource_ids = $this->resources->pluck('id');
$resource_ids = $this->applications->pluck('id');
$this->deployments_per_tag_per_server = ApplicationDeploymentQueue::whereIn("status", ["in_progress", "queued"])->whereIn('application_id', $resource_ids)->get([
"id",
"application_id",
@@ -35,7 +48,11 @@ class Show extends Component
public function redeploy_all()
{
try {
$this->resources->each(function ($resource) {
$this->applications->each(function ($resource) {
$deploy = new Deploy();
$deploy->deploy_resource($resource);
});
$this->services->each(function ($resource) {
$deploy = new Deploy();
$deploy->deploy_resource($resource);
});
@@ -44,17 +61,7 @@ class Show extends Component
return handleError($e, $this);
}
}
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;
$this->get_deployments();
}
public function render()
{
return view('livewire.tags.show');

View File

@@ -216,6 +216,9 @@ class Application extends BaseModel
{
return $this->morphToMany(Tag::class, 'taggable');
}
public function project() {
return data_get($this, 'environment.project');
}
public function team()
{
return data_get($this, 'environment.project.team');

View File

@@ -16,6 +16,10 @@ class Service extends BaseModel
{
return 'service';
}
public function project()
{
return data_get($this, 'environment.project');
}
public function team()
{
return data_get($this, 'environment.project.team');

View File

@@ -24,9 +24,8 @@ class Tag extends BaseModel
{
return $this->morphedByMany(Application::class, 'taggable');
}
public function resources() {
return $this->applications();
public function services()
{
return $this->morphedByMany(Service::class, 'taggable');
}
}