diff --git a/app/Modules/Jobs/Domain/ValueObjects/BoardPreferences.php b/app/Modules/Jobs/Domain/ValueObjects/BoardPreferences.php index 3271565..dc25f1c 100644 --- a/app/Modules/Jobs/Domain/ValueObjects/BoardPreferences.php +++ b/app/Modules/Jobs/Domain/ValueObjects/BoardPreferences.php @@ -12,20 +12,26 @@ use App\Modules\Shared\Domain\ValueObjects\HexColor; /** * One user's Kanban board settings: card density, the urgent threshold, - * and their own colour and order for each column. A column without a - * colour of its own uses the design's default colour. + * their own colour and order for each column, and which cards they keep + * open (task list shown). A column without a colour of its own uses the + * design's default colour. */ final readonly class BoardPreferences { + /** At most this many open cards are remembered, the latest kept. */ + public const int MAX_EXPANDED_CARDS = 500; + /** * @param array $columnColors by BoardColumn value * @param array $columnSorts by BoardColumn value + * @param list $expandedCards card keys ("job-12", "task-34"), oldest first */ public function __construct( public BoardDensity $density = BoardDensity::Normal, public UrgentThreshold $urgentThreshold = UrgentThreshold::Urgent, public array $columnColors = [], public array $columnSorts = [], + public array $expandedCards = [], ) {} public static function defaults(): self @@ -33,14 +39,20 @@ final readonly class BoardPreferences return new self; } + public static function isCardKey(string $key): bool + { + return preg_match('/^(job|task)-\d+$/', $key) === 1; + } + /** * Rebuilds stored settings, dropping unknown columns and invalid values * so a bad stored value never breaks the board. * * @param array $colors * @param array $sorts + * @param array $expanded */ - public static function fromStored(?string $density, ?string $threshold, array $colors, array $sorts): self + public static function fromStored(?string $density, ?string $threshold, array $colors, array $sorts, array $expanded = []): self { $columnColors = []; @@ -60,11 +72,14 @@ final readonly class BoardPreferences } } + $expandedCards = array_values(array_unique(array_filter($expanded, fn ($key): bool => is_string($key) && self::isCardKey($key)))); + return new self( BoardDensity::tryFrom((string) $density) ?? BoardDensity::Normal, UrgentThreshold::tryFrom((string) $threshold) ?? UrgentThreshold::Urgent, $columnColors, $columnSorts, + array_slice($expandedCards, -self::MAX_EXPANDED_CARDS), ); } @@ -83,14 +98,19 @@ final readonly class BoardPreferences return $this->columnSorts[$column->value] ?? ColumnSort::Manual; } + public function isCardExpanded(string $key): bool + { + return in_array($key, $this->expandedCards, true); + } + public function withDensity(BoardDensity $density): self { - return new self($density, $this->urgentThreshold, $this->columnColors, $this->columnSorts); + return new self($density, $this->urgentThreshold, $this->columnColors, $this->columnSorts, $this->expandedCards); } public function withUrgentThreshold(UrgentThreshold $threshold): self { - return new self($this->density, $threshold, $this->columnColors, $this->columnSorts); + return new self($this->density, $threshold, $this->columnColors, $this->columnSorts, $this->expandedCards); } /** @@ -106,7 +126,7 @@ final readonly class BoardPreferences $colors[$column->value] = $color; } - return new self($this->density, $this->urgentThreshold, $colors, $this->columnSorts); + return new self($this->density, $this->urgentThreshold, $colors, $this->columnSorts, $this->expandedCards); } public function withColumnSort(BoardColumn $column, ColumnSort $sort): self @@ -114,7 +134,26 @@ final readonly class BoardPreferences $sorts = $this->columnSorts; $sorts[$column->value] = $sort; - return new self($this->density, $this->urgentThreshold, $this->columnColors, $sorts); + return new self($this->density, $this->urgentThreshold, $this->columnColors, $sorts, $this->expandedCards); + } + + /** + * Opens or closes a card's task list for this user. A card key that is + * not one ("job-12" / "task-34") changes nothing. + */ + public function withCardExpanded(string $key, bool $expanded): self + { + if (! self::isCardKey($key)) { + return $this; + } + + $cards = array_values(array_diff($this->expandedCards, [$key])); + + if ($expanded) { + $cards[] = $key; + } + + return new self($this->density, $this->urgentThreshold, $this->columnColors, $this->columnSorts, array_slice($cards, -self::MAX_EXPANDED_CARDS)); } /** diff --git a/app/Modules/Jobs/Infrastructure/Persistence/Eloquent/JobBoardPreferenceModel.php b/app/Modules/Jobs/Infrastructure/Persistence/Eloquent/JobBoardPreferenceModel.php index 614aa67..751e983 100644 --- a/app/Modules/Jobs/Infrastructure/Persistence/Eloquent/JobBoardPreferenceModel.php +++ b/app/Modules/Jobs/Infrastructure/Persistence/Eloquent/JobBoardPreferenceModel.php @@ -15,9 +15,10 @@ use Illuminate\Database\Eloquent\Model; * @property string $urgent_threshold * @property array|null $column_colors * @property array|null $column_sorts + * @property list|null $expanded_cards */ #[Table('job_board_preferences')] -#[Fillable(['user_id', 'density', 'urgent_threshold', 'column_colors', 'column_sorts'])] +#[Fillable(['user_id', 'density', 'urgent_threshold', 'column_colors', 'column_sorts', 'expanded_cards'])] class JobBoardPreferenceModel extends Model { /** @@ -29,6 +30,7 @@ class JobBoardPreferenceModel extends Model 'user_id' => 'integer', 'column_colors' => 'array', 'column_sorts' => 'array', + 'expanded_cards' => 'array', ]; } } diff --git a/app/Modules/Jobs/Infrastructure/Persistence/Repositories/EloquentBoardRepository.php b/app/Modules/Jobs/Infrastructure/Persistence/Repositories/EloquentBoardRepository.php index a15e4a3..22afba9 100644 --- a/app/Modules/Jobs/Infrastructure/Persistence/Repositories/EloquentBoardRepository.php +++ b/app/Modules/Jobs/Infrastructure/Persistence/Repositories/EloquentBoardRepository.php @@ -38,7 +38,7 @@ class EloquentBoardRepository implements BoardRepository return $model === null ? BoardPreferences::defaults() - : BoardPreferences::fromStored($model->density, $model->urgent_threshold, $model->column_colors ?? [], $model->column_sorts ?? []); + : BoardPreferences::fromStored($model->density, $model->urgent_threshold, $model->column_colors ?? [], $model->column_sorts ?? [], $model->expanded_cards ?? []); } public function savePreferences(int $userId, BoardPreferences $preferences): void @@ -48,6 +48,7 @@ class EloquentBoardRepository implements BoardRepository 'urgent_threshold' => $preferences->urgentThreshold->value, 'column_colors' => $preferences->colorValues(), 'column_sorts' => $preferences->sortValues(), + 'expanded_cards' => $preferences->expandedCards, ]); } } diff --git a/app/Modules/Jobs/Presentation/Livewire/⚡board.blade.php b/app/Modules/Jobs/Presentation/Livewire/⚡board.blade.php index 4bfab05..3219416 100644 --- a/app/Modules/Jobs/Presentation/Livewire/⚡board.blade.php +++ b/app/Modules/Jobs/Presentation/Livewire/⚡board.blade.php @@ -36,6 +36,7 @@ use App\Modules\Users\Domain\Enums\Role; use Illuminate\Support\Facades\Gate; use Livewire\Attributes\Computed; use Livewire\Attributes\On; +use Livewire\Attributes\Renderless; use Livewire\Attributes\Url; use Livewire\Component; @@ -391,6 +392,20 @@ new class extends Component $this->statusMessage = __('jobs.board.customer_color_saved', ['customer' => $card->customerName ?? '']); } + /** + * A card's task list opened or closed: remembered for this user only. + * Renderless, so opening a card does not redraw the board. + */ + #[Renderless] + public function setCardExpanded(string $key, bool $expanded): void + { + if ($this->findCard($key) === null) { + return; + } + + $this->savePreferences($this->preferences->withCardExpanded($key, $expanded)); + } + public function setColumnColor(string $columnValue, ?string $color): void { $column = BoardColumn::tryFrom($columnValue); @@ -772,6 +787,7 @@ new class extends Component @elseif ($card->isOngoing()) json('expanded_cards')->nullable()->after('column_sorts'); + }); + } + + public function down(): void + { + Schema::table('job_board_preferences', function (Blueprint $table) { + $table->dropColumn('expanded_cards'); + }); + } +}; diff --git a/resources/views/components/jobs/board/job-card.blade.php b/resources/views/components/jobs/board/job-card.blade.php index 18bad64..c800377 100644 --- a/resources/views/components/jobs/board/job-card.blade.php +++ b/resources/views/components/jobs/board/job-card.blade.php @@ -4,7 +4,7 @@ due date, hours and the job's tasks, which open inside the card and can be marked done. Compact cards have three rows. --}} -@props(['card', 'compact' => false, 'canMove' => false, 'canColor' => false, 'canCheck' => false]) +@props(['card', 'expanded' => false, 'compact' => false, 'canMove' => false, 'canColor' => false, 'canCheck' => false]) @use('App\Modules\Jobs\Presentation\Support\BoardFormat') @@ -15,7 +15,7 @@
@@ -40,7 +40,8 @@ @if ($total > 0)