Skip to content

Commit

Permalink
addded column system for labels and delete some redundant code in tas…
Browse files Browse the repository at this point in the history
…k.index
  • Loading branch information
vladimir-xz committed Sep 5, 2024
1 parent 2e8547f commit 502441c
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 7 deletions.
2 changes: 1 addition & 1 deletion app/Http/Controllers/TaskController.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function create(Task $task)
{
$usersByIds = Utils::groupByIdWithName(User::all());
$statusesByIds = Utils::groupByIdWithName(TaskStatus::all());
$labelsById = Utils::groupByIdWithName(Label::all());
$labelsById = Utils::groupByIdWithName(Label::where('system', false)->get());

return view('tasks.create', compact('task', 'usersByIds', 'statusesByIds', 'labelsById'));
}
Expand Down
2 changes: 1 addition & 1 deletion app/Models/Task.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function assignedTo(): BelongsTo

public function labels(): BelongsToMany
{
return $this->belongsToMany(Label::class);
return $this->belongsToMany(Label::class)->where('system', false);
}

public function comments(): HasMany
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('labels', function (Blueprint $table) {
$table->boolean('system')->default(false);
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('labels', function (Blueprint $table) {
$table->dropColumn('system');
});
}
};
6 changes: 4 additions & 2 deletions database/seeders/LabelSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,13 @@ public function run(): void
]);
Label::firstOrCreate([
'name' => 'error',
'description' => 'Произошла ошибка'
'description' => 'Произошла ошибка',
'system' => true
]);
Label::firstOrCreate([
'name' => 'new response',
'description' => 'Новое сообщение'
'description' => 'Новое сообщение',
'system' => true
]);
}
}
4 changes: 1 addition & 3 deletions resources/views/tasks/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,7 @@
@endif

@if ($task->notifications()->exists())
@php $newMessage = $task->notifications->first(fn ($notif) => $notif->label->name === 'new response' && $notif->recipient == Auth::user())
@endphp
@if ($newMessage)
@if ($newMessage = $task->notifications()->where('user_id', Auth::user()?->id)->first())
<x-label :withIcon='false'>
{{ $newMessage->label->name }}
</x-label>
Expand Down

0 comments on commit 502441c

Please sign in to comment.