Replace the demo home page with a dashboard
Everyone sees their open tasks on an agenda, their open jobs, this week's hours and quick links. Admin and management also get a lazily loaded management panel: things to do, the month so far against the previous month, jobs and late work, and everyone's workload. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
This commit is contained in:
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
|
||||
namespace App\Modules\Dashboard\Infrastructure\Adapters;
|
||||
|
||||
use App\Modules\Dashboard\Application\Contracts\DashboardWork;
|
||||
use App\Modules\Dashboard\Application\DTOs\WorkJob;
|
||||
use App\Modules\Dashboard\Application\DTOs\WorkTask;
|
||||
use App\Modules\Jobs\Application\Contracts\JobOverviewQueries;
|
||||
use App\Modules\Jobs\Application\Contracts\TaskCalendarQueries;
|
||||
use App\Modules\Jobs\Application\DTOs\CustomerJobSummary;
|
||||
use App\Modules\Jobs\Application\DTOs\OpenTask;
|
||||
use App\Modules\Jobs\Application\Services\TaskPlanner;
|
||||
|
||||
/**
|
||||
* Jobs, tasks and bookings for the home page through the Jobs module.
|
||||
*/
|
||||
class WorkForDashboard implements DashboardWork
|
||||
{
|
||||
public function __construct(
|
||||
private JobOverviewQueries $overview,
|
||||
private TaskCalendarQueries $calendar,
|
||||
private TaskPlanner $planner,
|
||||
) {}
|
||||
|
||||
public function openTasksOf(int $userId): array
|
||||
{
|
||||
return array_map(self::task(...), $this->overview->openTasksOf($userId));
|
||||
}
|
||||
|
||||
public function openJobsOf(int $userId): array
|
||||
{
|
||||
return array_map(fn (CustomerJobSummary $job): WorkJob => new WorkJob(
|
||||
$job->id,
|
||||
$job->number,
|
||||
$job->name,
|
||||
$job->customerName,
|
||||
$job->status->value,
|
||||
$job->priority->value,
|
||||
$job->dueOn,
|
||||
), $this->overview->openJobsOf($userId));
|
||||
}
|
||||
|
||||
public function jobCountsByStatus(): array
|
||||
{
|
||||
return $this->overview->jobCountsByStatus();
|
||||
}
|
||||
|
||||
public function overdueJobCount(string $today): int
|
||||
{
|
||||
return $this->overview->overdueJobCount($today);
|
||||
}
|
||||
|
||||
public function overdueTaskCount(string $today): int
|
||||
{
|
||||
return $this->overview->overdueTaskCount($today);
|
||||
}
|
||||
|
||||
public function oldestOverdueTasks(string $today, int $limit): array
|
||||
{
|
||||
return array_map(self::task(...), $this->overview->oldestOverdueTasks($today, $limit));
|
||||
}
|
||||
|
||||
public function dailyCapacityMinutes(): int
|
||||
{
|
||||
return $this->planner->capacityMinutes();
|
||||
}
|
||||
|
||||
public function bookedMinutes(array $userIds, string $from, string $to): array
|
||||
{
|
||||
return array_map(fn (array $days): int => array_sum($days), $this->calendar->openMinutesByUser($userIds, $from, $to));
|
||||
}
|
||||
|
||||
private static function task(OpenTask $task): WorkTask
|
||||
{
|
||||
return new WorkTask(
|
||||
$task->taskId,
|
||||
$task->jobId,
|
||||
$task->jobNumber,
|
||||
$task->jobName,
|
||||
$task->title,
|
||||
$task->status->value,
|
||||
$task->dueOn,
|
||||
$task->plannedFrom,
|
||||
$task->plannedTo,
|
||||
$task->assigneeName,
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user