updated folder colors, reordering, new todo page, updated sidebar
tests / ci (push) Canceled after 0s
tests / ci (push) Canceled after 0s
This commit is contained in:
+32
-1
@@ -18,13 +18,14 @@ use Illuminate\Support\Carbon;
|
||||
* @property string $description
|
||||
* @property string|null $notes
|
||||
* @property TodoStatus $status
|
||||
* @property int|null $position
|
||||
* @property Carbon|null $due_date
|
||||
* @property Carbon|null $completed_at
|
||||
* @property Folder $folder
|
||||
* @property Carbon|null $created_at
|
||||
* @property Carbon|null $updated_at
|
||||
*/
|
||||
#[Fillable(['user_id', 'folder_id', 'description', 'notes', 'status', 'due_date', 'completed_at'])]
|
||||
#[Fillable(['user_id', 'folder_id', 'description', 'notes', 'status', 'position', 'due_date', 'completed_at'])]
|
||||
class Todo extends Model
|
||||
{
|
||||
/** @use HasFactory<TodoFactory> */
|
||||
@@ -101,6 +102,7 @@ class Todo extends Model
|
||||
return $query->incomplete()->whereNotIn('status', [
|
||||
TodoStatus::Cancelled->value,
|
||||
TodoStatus::Deferred->value,
|
||||
TodoStatus::Completed->value,
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -125,4 +127,33 @@ class Todo extends Model
|
||||
{
|
||||
return $query->active()->whereDate('due_date', today());
|
||||
}
|
||||
|
||||
public function scopePriority(Builder $query): Builder
|
||||
{
|
||||
return $query
|
||||
->orderByRaw('completed_at IS NOT NULL')
|
||||
->orderByRaw('position IS NULL')
|
||||
->orderBy('position')
|
||||
->orderByDesc('id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the position to assign to a new todo so it appears at the top of the
|
||||
* priority order for the given user.
|
||||
*/
|
||||
public static function nextPositionFor(User|int $user): int
|
||||
{
|
||||
$min = static::query()->forUser($user)->min('position');
|
||||
|
||||
return $min === null ? 1 : $min - 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of days between creation and completion, or null when the
|
||||
* todo has not been completed.
|
||||
*/
|
||||
public function daysToComplete(): ?int
|
||||
{
|
||||
return $this->completed_at === null ? null : $this->created_at->diffInDays($this->completed_at);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user