Commit the Projects/Tasks/Ideas/TaskComments feature
This was already implemented, migrated, and running live, but had never been committed. Bringing it into git: Project/Task/Idea/ TaskComment models, their JSON API (CRUD + status transitions, task comments, idea<->project linking), Livewire UI pages, and the nav/route wiring for them. All 42 of its own tests pass. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,103 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class Idea extends Model
|
||||
{
|
||||
use HasFactory, SoftDeletes;
|
||||
|
||||
public const STATUSES = ['new', 'considered', 'planned', 'rejected', 'implemented'];
|
||||
|
||||
public const CATEGORIES = ['feature', 'improvement', 'bugfix', 'research', 'other'];
|
||||
|
||||
protected $fillable = [
|
||||
'title',
|
||||
'description',
|
||||
'status',
|
||||
'project_id',
|
||||
'priority',
|
||||
'category',
|
||||
'tags',
|
||||
'user_id',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'priority' => 'integer',
|
||||
];
|
||||
|
||||
public function project(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Project::class);
|
||||
}
|
||||
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
public function scopeNew($query)
|
||||
{
|
||||
return $query->where('status', 'new');
|
||||
}
|
||||
|
||||
public function scopeConsidered($query)
|
||||
{
|
||||
return $query->where('status', 'considered');
|
||||
}
|
||||
|
||||
public function scopePlanned($query)
|
||||
{
|
||||
return $query->where('status', 'planned');
|
||||
}
|
||||
|
||||
public function scopeRejected($query)
|
||||
{
|
||||
return $query->where('status', 'rejected');
|
||||
}
|
||||
|
||||
public function scopeImplemented($query)
|
||||
{
|
||||
return $query->where('status', 'implemented');
|
||||
}
|
||||
|
||||
public function scopeByCategory($query, string $category)
|
||||
{
|
||||
return $query->where('category', $category);
|
||||
}
|
||||
|
||||
public function scopeLinkedToProject($query)
|
||||
{
|
||||
return $query->whereNotNull('project_id');
|
||||
}
|
||||
|
||||
public function scopeUnlinked($query)
|
||||
{
|
||||
return $query->whereNull('project_id');
|
||||
}
|
||||
|
||||
public function scopeSearch($query, string $search)
|
||||
{
|
||||
return $query->where('title', 'like', '%' . $search . '%')
|
||||
->orWhere('description', 'like', '%' . $search . '%')
|
||||
->orWhere('tags', 'like', '%' . $search . '%');
|
||||
}
|
||||
|
||||
public function getTagsArrayAttribute(): array
|
||||
{
|
||||
return $this->tags ? explode(',', $this->tags) : [];
|
||||
}
|
||||
|
||||
public function setTagsAttribute(array|string|null $value): void
|
||||
{
|
||||
if (is_array($value)) {
|
||||
$this->attributes['tags'] = implode(',', $value);
|
||||
} else {
|
||||
$this->attributes['tags'] = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class Project extends Model
|
||||
{
|
||||
use HasFactory, SoftDeletes;
|
||||
|
||||
public const STATUSES = ['active', 'completed', 'archived', 'on_hold', 'planned'];
|
||||
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'description',
|
||||
'status',
|
||||
'due_at',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'due_at' => 'datetime',
|
||||
];
|
||||
|
||||
public function tasks(): HasMany
|
||||
{
|
||||
return $this->hasMany(Task::class)->orderBy('priority', 'desc')->orderBy('created_at');
|
||||
}
|
||||
|
||||
public function ideas(): HasMany
|
||||
{
|
||||
return $this->hasMany(Idea::class)->orderBy('priority', 'desc')->orderBy('created_at', 'desc');
|
||||
}
|
||||
|
||||
public function activeTasks()
|
||||
{
|
||||
return $this->tasks()->whereIn('status', ['todo', 'in_progress', 'waiting_review']);
|
||||
}
|
||||
|
||||
public function completedTasks()
|
||||
{
|
||||
return $this->tasks()->where('status', 'done');
|
||||
}
|
||||
|
||||
public function scopeActive($query)
|
||||
{
|
||||
return $query->where('status', 'active');
|
||||
}
|
||||
|
||||
public function scopeCompleted($query)
|
||||
{
|
||||
return $query->where('status', 'completed');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class Task extends Model
|
||||
{
|
||||
use HasFactory, SoftDeletes;
|
||||
|
||||
public const STATUSES = ['todo', 'in_progress', 'done', 'blocked', 'waiting_review'];
|
||||
|
||||
protected $fillable = [
|
||||
'title',
|
||||
'description',
|
||||
'status',
|
||||
'project_id',
|
||||
'priority',
|
||||
'due_at',
|
||||
'started_at',
|
||||
'completed_at',
|
||||
'estimated_hours',
|
||||
'actual_hours',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'due_at' => 'datetime',
|
||||
'started_at' => 'datetime',
|
||||
'completed_at' => 'datetime',
|
||||
];
|
||||
|
||||
public function project(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Project::class);
|
||||
}
|
||||
|
||||
public function comments(): HasMany
|
||||
{
|
||||
return $this->hasMany(TaskComment::class)->orderBy('created_at');
|
||||
}
|
||||
|
||||
public function scopeByStatus($query, string $status)
|
||||
{
|
||||
return $query->where('status', $status);
|
||||
}
|
||||
|
||||
public function scopeTodo($query)
|
||||
{
|
||||
return $query->where('status', 'todo');
|
||||
}
|
||||
|
||||
public function scopeInProgress($query)
|
||||
{
|
||||
return $query->where('status', 'in_progress');
|
||||
}
|
||||
|
||||
public function scopeDone($query)
|
||||
{
|
||||
return $query->where('status', 'done');
|
||||
}
|
||||
|
||||
public function scopeBlocked($query)
|
||||
{
|
||||
return $query->where('status', 'blocked');
|
||||
}
|
||||
|
||||
public function scopeWaitingReview($query)
|
||||
{
|
||||
return $query->where('status', 'waiting_review');
|
||||
}
|
||||
|
||||
public function scopeDueSoon($query, int $days = 3)
|
||||
{
|
||||
return $query->where('due_at', '>=', now())
|
||||
->where('due_at', '<=', now()->addDays($days))
|
||||
->where('status', '!=', 'done');
|
||||
}
|
||||
|
||||
public function scopeOverdue($query)
|
||||
{
|
||||
return $query->where('due_at', '<', now())
|
||||
->where('status', '!=', 'done');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class TaskComment extends Model
|
||||
{
|
||||
use HasFactory, SoftDeletes;
|
||||
|
||||
public const AUTHOR_TYPES = ['user', 'ai', 'system'];
|
||||
|
||||
protected $fillable = [
|
||||
'task_id',
|
||||
'body',
|
||||
'author_type',
|
||||
'author_name',
|
||||
];
|
||||
|
||||
public function task(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Task::class);
|
||||
}
|
||||
|
||||
public function isFromAI(): bool
|
||||
{
|
||||
return $this->author_type === 'ai';
|
||||
}
|
||||
|
||||
public function isFromUser(): bool
|
||||
{
|
||||
return $this->author_type === 'user';
|
||||
}
|
||||
|
||||
public function isSystem(): bool
|
||||
{
|
||||
return $this->author_type === 'system';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user