Commit 5c85ea18 authored by Jacob Priddy's avatar Jacob Priddy 👌
Browse files

Add schedule dropdown

parent 9f0cfc11
Pipeline #12520 passed with stages
in 2 minutes and 29 seconds
...@@ -3,9 +3,12 @@ ...@@ -3,9 +3,12 @@
namespace App\Http\Controllers\Web\Admin; namespace App\Http\Controllers\Web\Admin;
use Carbon\Carbon;
use Illuminate\View\View; use Illuminate\View\View;
use App\Http\Controllers\Controller; use App\Http\Controllers\Controller;
use Illuminate\Http\RedirectResponse; use Illuminate\Http\RedirectResponse;
use Source\UseCases\Schedules\SchedulesGet\DropdownPresenter;
use Source\UseCases\Schedules\SchedulesGet\SchedulesGetUseCase;
use Source\UseCases\DoorGroup\GetGroupDoors\GetGroupDoorsUseCase; use Source\UseCases\DoorGroup\GetGroupDoors\GetGroupDoorsUseCase;
use Source\UseCases\GroupUser\GetGroupUsers\GetGroupUsersUseCase; use Source\UseCases\GroupUser\GetGroupUsers\GetGroupUsersUseCase;
use Source\UseCases\DoorGroup\AddDoorToGroup\AddDoorToGroupSearch; use Source\UseCases\DoorGroup\AddDoorToGroup\AddDoorToGroupSearch;
...@@ -60,18 +63,25 @@ class GroupRelationController extends Controller ...@@ -60,18 +63,25 @@ class GroupRelationController extends Controller
/** /**
* @param string $groupId * @param string $groupId
* @param \Source\UseCases\GroupSchedule\GetGroupSchedules\GetGroupSchedulesUseCase $groupSchedules * @param \Source\UseCases\GroupSchedule\GetGroupSchedules\GetGroupSchedulesUseCase $groupSchedules
* @param \Source\UseCases\Schedules\SchedulesGet\SchedulesGetUseCase $schedules
* @return \Illuminate\View\View * @return \Illuminate\View\View
* @throws \Source\Exceptions\EntityNotFoundException * @throws \Source\Exceptions\EntityNotFoundException
* @throws \Exception
*/ */
public function schedules(string $groupId, GetGroupSchedulesUseCase $groupSchedules): View public function schedules(string $groupId, GetGroupSchedulesUseCase $groupSchedules, SchedulesGetUseCase $schedules): View
{ {
$schedulesPresenter = new DropdownPresenter();
$schedules->filter(null, Carbon::now(), null, $schedulesPresenter);
$presenter = new GroupSchedulesPresenter(); $presenter = new GroupSchedulesPresenter();
$groupSchedules->getSchedulesForGroup($groupId, $presenter); $groupSchedules->getSchedulesForGroup($groupId, $presenter);
return view('admin.groupEntity', array_merge( return view('admin.groupScheduleEntity', array_merge(
$presenter->getViewModel(), $presenter->getViewModel(),
['groupId' => $groupId], ['groupId' => $groupId],
['schedules' => $schedulesPresenter->getViewModel()],
)); ));
} }
...@@ -122,7 +132,7 @@ class GroupRelationController extends Controller ...@@ -122,7 +132,7 @@ class GroupRelationController extends Controller
public function addSchedule(string $groupId, AddSchedulesToGroupsUseCase $schedulesToGroups): RedirectResponse public function addSchedule(string $groupId, AddSchedulesToGroupsUseCase $schedulesToGroups): RedirectResponse
{ {
$this->validate($this->request, [ $this->validate($this->request, [
'schedule' => 'required|string', 'schedule' => 'required|numeric|integer',
]); ]);
$presenter = new ScheduleGroupPresenter(); $presenter = new ScheduleGroupPresenter();
......
@extends('admin.groupEntity')
@section('form-body')
<label for="entity">
Select Schedule.
</label>
<select class="form-control" name="schedule" id="entity" required>
@foreach($schedules as $schedule)
<option value="{{ $schedule['id'] }}">
{{ $schedule['display'] }}
</option>
@endforeach
</select>
@endsection
...@@ -96,7 +96,7 @@ class DatabaseSchedulesRepository implements SchedulesRepository ...@@ -96,7 +96,7 @@ class DatabaseSchedulesRepository implements SchedulesRepository
*/ */
public function filter(?int $type = null, ?Carbon $begin = null, ?Carbon $end = null): array public function filter(?int $type = null, ?Carbon $begin = null, ?Carbon $end = null): array
{ {
$query = \App\Schedule::query()->orderByDesc('created_at'); $query = \App\Schedule::query()->orderBy('id');
if ($type !== null) { if ($type !== null) {
$query->where('type', $type); $query->where('type', $type);
......
...@@ -48,7 +48,6 @@ class WebPresenter extends BasePresenter implements Presenter ...@@ -48,7 +48,6 @@ class WebPresenter extends BasePresenter implements Presenter
], ],
'controls' => 'groupEntity', 'controls' => 'groupEntity',
], ],
'label' => 'Enter schedule ID.',
'resource' => 'schedules', 'resource' => 'schedules',
]; ];
} }
......
<?php
namespace Source\UseCases\Schedules\SchedulesGet;
use Source\Entities\Schedule;
use Source\Sanitize\Paginates;
use Source\UseCases\BasePresenter;
class DropdownPresenter extends BasePresenter implements Presenter
{
use Paginates;
protected array $schedules = [];
/** @inheritDoc */
public function present(ResponseModel $responseModel): void
{
$this->schedules = $responseModel->getSchedules();
usort($this->schedules, fn (Schedule $a, Schedule $b) => strcmp($a->getDescription(), $b->getDescription()));
$this->schedules = array_map(static function (Schedule $schedule): array {
if ($schedule->getType() === Schedule::TYPE_OPEN_MODE) {
$type = '(Open) ';
} else {
$type = '(Access) ';
}
return [
'id' => $schedule->getId(),
'display' => $type . ' ' . $schedule->getDescription(),
];
}, $this->schedules);
}
/** @inheritDoc */
public function getViewModel(array $appends = []): array
{
return $this->schedules;
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment