-
app/Enums/DashboardSortBy.php
Open in GitHubenum DashboardSortBy: string { case USER_NAME = 'user'; case WORKED = 'worked'; }
-
app/Http/Requests/Reports/DashboardRequest.php
Open in GitHubuse App\Enums\DashboardSortBy; use App\Enums\SortDirection; use App\Http\Requests\CattrFormRequest; use Filter; use Illuminate\Validation\Rules\Enum; class DashboardRequest extends CattrFormRequest { public function _authorize(): bool { return true; } public function _rules(): array { return [ 'users' => 'nullable|exists:users,id|array', 'projects' => 'nullable|exists:projects,id|array', 'start_at' => 'required|date', 'end_at' => 'required|date', 'user_timezone' => 'required|timezone', 'sort_column' => ['nullable', new Enum(DashboardSortBy::class)], 'sort_direction' => ['nullable', new Enum(SortDirection::class)], ]; } }
-
app/Http/Controllers/Api/Reports/DashboardController.php
Open in GitHubuse App\Enums\DashboardSortBy; use App\Enums\SortDirection; use App\Helpers\ReportHelper; use App\Http\Requests\Reports\DashboardRequest; use App\Reports\DashboardExport; use Carbon\Carbon; use Illuminate\Contracts\Bus\Dispatcher; use Illuminate\Http\JsonResponse; use Settings; class DashboardController { // ... public function download(DashboardRequest $request): JsonResponse { $companyTimezone = Settings::scope('core')->get('timezone', 'UTC'); $job = new GenerateAndSendReport( DashboardExport::init( $request->input('users') ?? User::all()->pluck('id')->toArray(), $request->input('projects') ?? Project::all()->pluck('id')->toArray(), Carbon::parse($request->input('start_at'))->setTimezone($companyTimezone), Carbon::parse($request->input('end_at'))->setTimezone($companyTimezone), $companyTimezone, $request->input('user_timezone'), DashboardSortBy::tryFrom($request->input('sort_column')), SortDirection::tryFrom($request->input('sort_direction')), ), $request->user(), ReportHelper::getReportFormat($request), ); app(Dispatcher::class)->dispatchSync($job); return responder()->success(['url' => $job->getPublicPath()])->respond(); } // ... }