diff --git a/app/Models/Folder.php b/app/Models/Folder.php index acb4bb7..9f10953 100644 --- a/app/Models/Folder.php +++ b/app/Models/Folder.php @@ -16,17 +16,23 @@ use Illuminate\Support\Collection; * @property int $id * @property int $user_id * @property string $name + * @property string|null $color * @property int|null $parent_id * @property Folder|null $parent * @property Carbon|null $created_at * @property Carbon|null $updated_at */ -#[Fillable(['user_id', 'name', 'parent_id'])] +#[Fillable(['user_id', 'name', 'parent_id', 'color'])] class Folder extends Model { /** @use HasFactory */ use HasFactory; + public const COLORS = [ + 'zinc', 'red', 'orange', 'amber', 'green', 'emerald', + 'sky', 'blue', 'indigo', 'violet', 'fuchsia', 'pink', + ]; + /** @return BelongsTo */ public function user(): BelongsTo { diff --git a/app/Models/Todo.php b/app/Models/Todo.php index 5d3a23b..47c6a23 100644 --- a/app/Models/Todo.php +++ b/app/Models/Todo.php @@ -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 */ @@ -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); + } } diff --git a/app/TodoStatus.php b/app/TodoStatus.php index 37e0f44..08b826e 100644 --- a/app/TodoStatus.php +++ b/app/TodoStatus.php @@ -10,6 +10,7 @@ enum TodoStatus: string case Blocked = 'blocked'; case Cancelled = 'cancelled'; case Deferred = 'deferred'; + case Completed = 'completed'; /** * Get the human-friendly label for the status. @@ -23,6 +24,7 @@ enum TodoStatus: string self::Blocked => 'Blocked', self::Cancelled => 'Cancelled', self::Deferred => 'Deferred', + self::Completed => 'Completed', }; } @@ -38,6 +40,7 @@ enum TodoStatus: string self::Blocked => 'red', self::Cancelled => 'zinc', self::Deferred => 'purple', + self::Completed => 'emerald', }; } @@ -46,6 +49,6 @@ enum TodoStatus: string */ public function isTerminal(): bool { - return in_array($this, [self::Cancelled, self::Deferred], true); + return in_array($this, [self::Cancelled, self::Deferred, self::Completed], true); } } diff --git a/database/factories/FolderFactory.php b/database/factories/FolderFactory.php index f5fb997..9205704 100644 --- a/database/factories/FolderFactory.php +++ b/database/factories/FolderFactory.php @@ -21,6 +21,7 @@ class FolderFactory extends Factory return [ 'user_id' => User::factory(), 'name' => fake()->unique()->words(2, true), + 'color' => fake()->optional()->randomElement(Folder::COLORS), 'parent_id' => null, ]; } diff --git a/database/migrations/2026_09_19_073127_add_position_to_todos_table.php b/database/migrations/2026_09_19_073127_add_position_to_todos_table.php new file mode 100644 index 0000000..5a04c33 --- /dev/null +++ b/database/migrations/2026_09_19_073127_add_position_to_todos_table.php @@ -0,0 +1,30 @@ +integer('position')->nullable()->after('status'); + $table->index(['user_id', 'position']); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('todos', function (Blueprint $table) { + $table->dropIndex(['user_id', 'position']); + $table->dropColumn('position'); + }); + } +}; diff --git a/database/migrations/2026_09_20_223105_add_color_to_folders_table.php b/database/migrations/2026_09_20_223105_add_color_to_folders_table.php new file mode 100644 index 0000000..39ec765 --- /dev/null +++ b/database/migrations/2026_09_20_223105_add_color_to_folders_table.php @@ -0,0 +1,28 @@ +string('color', 20)->nullable()->after('name'); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('folders', function (Blueprint $table) { + $table->dropColumn('color'); + }); + } +}; diff --git a/database/seeders/DatabaseSeeder.php b/database/seeders/DatabaseSeeder.php index ed72a44..8dc388b 100644 --- a/database/seeders/DatabaseSeeder.php +++ b/database/seeders/DatabaseSeeder.php @@ -5,6 +5,7 @@ namespace Database\Seeders; use App\Models\Folder; use App\Models\Todo; use App\Models\User; +use App\TodoStatus; use Illuminate\Database\Console\Seeds\WithoutModelEvents; use Illuminate\Database\Seeder; @@ -19,11 +20,14 @@ class DatabaseSeeder extends Seeder { $this->call(BaseDatabaseSeeder::class); - $user = User::factory()->create([ - 'name' => 'Test User', - 'email' => 'test@example.com', - 'is_admin' => true, - ]); + $user = User::updateOrCreate( + ['email' => 'test@example.com'], + [ + 'name' => 'Test User', + 'password' => 'password', + 'is_admin' => true, + ], + ); $work = $this->createTopLevelFolder($user, 'Work'); $business = $this->createTopLevelFolder($user, 'Business'); @@ -63,29 +67,45 @@ class DatabaseSeeder extends Seeder $foldersByName = $folders->keyBy(fn (Folder $folder) => $folder->name); foreach ($samples as [$description, $folderName, $daysFromToday, $status]) { - $todo = Todo::factory()->recycle($user)->create([ - 'folder_id' => $foldersByName[$folderName]->id, - 'description' => $description, - 'due_date' => $daysFromToday === null ? null : today()->addDays($daysFromToday), - ]); + $todo = Todo::firstOrCreate( + ['user_id' => $user->id, 'folder_id' => $foldersByName[$folderName]->id, 'description' => $description], + ['status' => TodoStatus::Open], + ); + + if ($daysFromToday === null) { + $todo->update(['due_date' => null]); + } else { + $todo->update(['due_date' => today()->addDays($daysFromToday)]); + } if ($status === 'overdue') { $todo->update(['due_date' => today()->subDays(3)]); } if ($status === 'completed') { - $todo->update(['completed_at' => now()->subDay()]); + $todo->update([ + 'status' => TodoStatus::Completed, + 'completed_at' => now()->subDay(), + ]); + } else { + $todo->update(['completed_at' => null]); } } } private function createTopLevelFolder(User $user, string $name): Folder { - return Folder::factory()->recycle($user)->create(['name' => $name]); + return Folder::firstOrCreate( + ['user_id' => $user->id, 'name' => $name, 'parent_id' => null], + ['color' => fake()->optional()->randomElement(Folder::COLORS)], + ); } private function createChildFolder(Folder $parent, string $name): Folder { - return Folder::factory()->childOf($parent)->create(['name' => $name]); + return Folder::firstOrCreate( + ['user_id' => $parent->user_id, 'name' => $name, 'parent_id' => $parent->id], + ['color' => fake()->optional()->randomElement(Folder::COLORS)], + ); } } diff --git a/deploy.sh b/deploy.sh new file mode 100755 index 0000000..73d62bd --- /dev/null +++ b/deploy.sh @@ -0,0 +1,47 @@ +#!/usr/bin/env bash +set -euo pipefail + +# Update deployment script for mytodos. +# Run from the repository root on the server: +# ./deploy.sh +# +# Pulls the latest code, installs dependencies, runs the new migrations +# (status + position on todos, color on folders), and refreshes the +# admin user via BaseDatabaseSeeder. DatabaseSeeder (demo data) is +# intentionally NOT run in production. + +APP_DIR="${APP_DIR:-$(pwd)}" + +echo "==> Deploying mytodos update in ${APP_DIR}" + +cd "${APP_DIR}" + +echo "==> Pulling latest code" +git pull --ff-only origin main + +echo "==> Installing PHP dependencies" +composer install --no-dev --prefer-dist --optimize-autoloader + +echo "==> Installing and building frontend assets" +if [ -f package-lock.json ]; then + npm ci --no-audit --no-fund +else + npm install --no-audit --no-fund +fi +npm run build + +echo "==> Running new migrations" +php artisan migrate --force + +echo "==> Seeding base data (admin user)" +php artisan db:seed --class=BaseDatabaseSeeder --force + +echo "==> Caching configuration" +php artisan config:cache +php artisan route:cache +php artisan view:cache + +echo "==> Restarting queue workers" +php artisan queue:restart + +echo "==> Update deployed successfully" \ No newline at end of file diff --git a/public/favicon.svg b/public/favicon.svg index e4e710e..7337f3e 100644 --- a/public/favicon.svg +++ b/public/favicon.svg @@ -1,3 +1,10 @@ - - - + + + + + + + + + \ No newline at end of file diff --git a/public/mytodos_main_logo.svg b/public/mytodos_main_logo.svg new file mode 100644 index 0000000..fdcb62f --- /dev/null +++ b/public/mytodos_main_logo.svg @@ -0,0 +1,16 @@ + + + + + + + + + + My + + + \ No newline at end of file diff --git a/resources/views/components/app-logo-icon.blade.php b/resources/views/components/app-logo-icon.blade.php index 0adc3a2..95cae30 100644 --- a/resources/views/components/app-logo-icon.blade.php +++ b/resources/views/components/app-logo-icon.blade.php @@ -1,8 +1 @@ - - - +{{ config('app.name', 'Laravel') }}merge(['class' => 'max-w-full']) }} /> \ No newline at end of file diff --git a/resources/views/components/color-picker.blade.php b/resources/views/components/color-picker.blade.php new file mode 100644 index 0000000..b697695 --- /dev/null +++ b/resources/views/components/color-picker.blade.php @@ -0,0 +1,44 @@ +@props(['model' => null]) + +@php +$swatches = [ + 'zinc' => 'bg-zinc-400', + 'red' => 'bg-red-500', + 'orange' => 'bg-orange-500', + 'amber' => 'bg-amber-500', + 'green' => 'bg-green-500', + 'emerald' => 'bg-emerald-500', + 'sky' => 'bg-sky-500', + 'blue' => 'bg-blue-500', + 'indigo' => 'bg-indigo-500', + 'violet' => 'bg-violet-500', + 'fuchsia' => 'bg-fuchsia-500', + 'pink' => 'bg-pink-500', +]; + +$selected = 'ring-2 ring-zinc-900/80 ring-offset-2 ring-offset-white dark:ring-zinc-100/80 dark:ring-offset-zinc-900'; +@endphp + +
+ + + @foreach ($swatches as $name => $class) + + @endforeach +
\ No newline at end of file diff --git a/resources/views/components/folder-dot.blade.php b/resources/views/components/folder-dot.blade.php new file mode 100644 index 0000000..4fc4552 --- /dev/null +++ b/resources/views/components/folder-dot.blade.php @@ -0,0 +1,23 @@ +@props(['color' => null]) + +@php +$classes = match ($color) { + 'zinc' => 'bg-zinc-400', + 'red' => 'bg-red-500', + 'orange' => 'bg-orange-500', + 'amber' => 'bg-amber-500', + 'green' => 'bg-green-500', + 'emerald' => 'bg-emerald-500', + 'sky' => 'bg-sky-500', + 'blue' => 'bg-blue-500', + 'indigo' => 'bg-indigo-500', + 'violet' => 'bg-violet-500', + 'fuchsia' => 'bg-fuchsia-500', + 'pink' => 'bg-pink-500', + default => null, +}; +@endphp + +@if ($classes) + merge(['class' => "inline-block size-2.5 shrink-0 rounded-full {$classes}"]) }} aria-hidden="true"> +@endif \ No newline at end of file diff --git a/resources/views/layouts/app/header.blade.php b/resources/views/layouts/app/header.blade.php index b8c2a67..c36bd0b 100644 --- a/resources/views/layouts/app/header.blade.php +++ b/resources/views/layouts/app/header.blade.php @@ -13,6 +13,9 @@ {{ __('Dashboard') }} + + {{ __('Todos') }} + {{ __('Folders') }} @@ -59,6 +62,9 @@ {{ __('Dashboard') }} + + {{ __('Todos') }} + {{ __('Folders') }} diff --git a/resources/views/layouts/app/sidebar.blade.php b/resources/views/layouts/app/sidebar.blade.php index 5ab49e0..3f26c46 100644 --- a/resources/views/layouts/app/sidebar.blade.php +++ b/resources/views/layouts/app/sidebar.blade.php @@ -15,6 +15,9 @@ {{ __('Dashboard') }} + + {{ __('Todos') }} + {{ __('Folders') }} @@ -31,16 +34,6 @@ - - - {{ __('Repository') }} - - - - {{ __('Documentation') }} - - -