Commit bf0acfd5 authored by Jacob Priddy's avatar Jacob Priddy 👌
Browse files

Add group rlations from table

parent 6560c860
...@@ -192,7 +192,7 @@ class DoorsController extends Controller ...@@ -192,7 +192,7 @@ class DoorsController extends Controller
$doorGroup->addDoorToGroup([$doorId], [$this->request->input('group_id')], $presenter); $doorGroup->addDoorToGroup([$doorId], [$this->request->input('group_id')], $presenter);
return redirect(route('web.admin.doors.groups', ['doorId' => $doorId]))->with($presenter->getViewModel()); return redirect()->back()->with($presenter->getViewModel());
} }
/** /**
...@@ -211,6 +211,6 @@ class DoorsController extends Controller ...@@ -211,6 +211,6 @@ class DoorsController extends Controller
$doorGroup->removeDoorFromGroup([$doorId], [$this->request->input('group_id')], $presenter); $doorGroup->removeDoorFromGroup([$doorId], [$this->request->input('group_id')], $presenter);
return redirect(route('web.admin.doors.groups', ['doorId' => $doorId]))->with($presenter->getViewModel()); return redirect()->back()->with($presenter->getViewModel());
} }
} }
...@@ -4,9 +4,78 @@ ...@@ -4,9 +4,78 @@
namespace App\Http\Controllers\Web\Admin; namespace App\Http\Controllers\Web\Admin;
use Illuminate\View\View;
use App\Http\Controllers\Controller; use App\Http\Controllers\Controller;
use Illuminate\Http\RedirectResponse;
use Source\UseCases\GroupSchedule\GetGroupSchedules\WebPresenter as GroupSchedulesPresenter;
use Source\UseCases\GroupSchedule\GetGroupSchedules\GetGroupSchedulesUseCase;
use Source\UseCases\GroupUser\GetGroupUsers\WebPresenter as GroupUsersPresenter;
use Source\UseCases\DoorGroup\GetGroupDoors\WebPresenter as GroupDoorsPresenter;
use Source\UseCases\DoorGroup\GetGroupDoors\GetGroupDoorsUseCase;
use Source\UseCases\GroupUser\GetGroupUsers\GetGroupUsersUseCase;
class GroupRelationController extends Controller class GroupRelationController extends Controller
{ {
/**
* @param string $groupId
* @param \Source\UseCases\DoorGroup\GetGroupDoors\GetGroupDoorsUseCase $groupDoors
* @return \Illuminate\View\View
* @throws \Source\Exceptions\EntityNotFoundException
*/
public function doors(string $groupId, GetGroupDoorsUseCase $groupDoors): View
{
$presenter = new GroupDoorsPresenter();
$groupDoors->getDoorsForGroup($groupId, $presenter);
return view('admin.groupEntity', array_merge(
$presenter->getViewModel(),
['groupId' => $groupId],
));
}
/**
* @param string $groupId
* @param \Source\UseCases\GroupUser\GetGroupUsers\GetGroupUsersUseCase $groupUsers
* @return \Illuminate\View\View
* @throws \Source\Exceptions\EntityNotFoundException
*/
public function users(string $groupId, GetGroupUsersUseCase $groupUsers): View
{
$presenter = new GroupUsersPresenter();
$groupUsers->getUsersForGroup($groupId, $presenter);
return view('admin.groupEntity', array_merge(
$presenter->getViewModel(),
['groupId' => $groupId],
));
}
public function schedules(string $groupId, GetGroupSchedulesUseCase $groupSchedules): View
{
$presenter = new GroupSchedulesPresenter();
$groupSchedules->getSchedulesForGroup($groupId, $presenter);
return view('admin.groupEntity', array_merge(
$presenter->getViewModel(),
['groupId' => $groupId],
));
}
public function addDoor(): RedirectResponse
{
}
public function addUser(): RedirectResponse
{
}
public function addSchedule(): RedirectResponse
{
}
} }
...@@ -196,7 +196,7 @@ class SchedulesController extends Controller ...@@ -196,7 +196,7 @@ class SchedulesController extends Controller
$scheduleGroup->addGroup($this->request->input('group_id')); $scheduleGroup->addGroup($this->request->input('group_id'));
$scheduleGroup->attach($presenter); $scheduleGroup->attach($presenter);
return redirect(route('web.admin.schedules.groups', ['scheduleId' => $scheduleId]))->with($presenter->getViewModel()); return redirect()->back()->with($presenter->getViewModel());
} }
/** /**
...@@ -219,6 +219,6 @@ class SchedulesController extends Controller ...@@ -219,6 +219,6 @@ class SchedulesController extends Controller
$scheduleGroup->detach($presenter); $scheduleGroup->detach($presenter);
return redirect(route('web.admin.schedules.groups', ['scheduleId' => $scheduleId]))->with($presenter->getViewModel()); return redirect()->back()->with($presenter->getViewModel());
} }
} }
...@@ -213,7 +213,7 @@ class UsersController extends Controller ...@@ -213,7 +213,7 @@ class UsersController extends Controller
$userGroup->addUserToGroup([$userId], [$this->request->input('group_id')], $presenter); $userGroup->addUserToGroup([$userId], [$this->request->input('group_id')], $presenter);
return redirect(route('web.admin.users.groups', ['userId' => $userId]))->with($presenter->getViewModel()); return redirect()->back()->with($presenter->getViewModel());
} }
/** /**
...@@ -232,6 +232,6 @@ class UsersController extends Controller ...@@ -232,6 +232,6 @@ class UsersController extends Controller
$removeUser->removeUserFromGroup([$userId], [$this->request->input('group_id')], $presenter); $removeUser->removeUserFromGroup([$userId], [$this->request->input('group_id')], $presenter);
return redirect(route('web.admin.users.groups', ['userId' => $userId]))->with($presenter->getViewModel()); return redirect()->back()->with($presenter->getViewModel());
} }
} }
@extends('layouts.admin.tableData', [
'title' => 'Group ' . ucfirst($resource),
'route' => route('web.admin.groups.' . $resource, ['groupId' => $groupId]),
])
@section('controls')
<button class="btn btn-primary float-right" data-toggle="modal" data-target="#attachGroup">
Add {{ ucfirst(\Illuminate\Support\Str::singular($resource)) }}
</button>
<div class="modal fade" id="attachGroup" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Add {{ ucfirst(\Illuminate\Support\Str::singular($resource)) }} to Group</h5>
<button class="close" type="button" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<form method="POST" action="{{ route('web.admin.groups.' . $resource, ['groupId' => $groupId]) }}">
@csrf
<div class="modal-body">
@hasSection('form-body')
@yield('form-body')
@else
<label for="entity">
{{ $label }}
</label>
<input class="form-control" type="text" name="{{ \Illuminate\Support\Str::singular($resource) }}" id="entity" required>
@endif
</div>
<div class="modal-footer">
<button class="btn btn-secondary" type="button" data-dismiss="modal">Cancel</button>
<button class="btn btn-primary" type="submit">
Add {{ ucfirst(\Illuminate\Support\Str::singular($resource)) }}
</button>
</div>
</form>
</div>
</div>
</div>
@endsection
...@@ -211,54 +211,54 @@ ...@@ -211,54 +211,54 @@
</div> </div>
</li> </li>
<!-- Nav Item - Alerts --> {{-- <!-- Nav Item - Alerts -->--}}
<li class="nav-item dropdown no-arrow mx-1"> {{-- <li class="nav-item dropdown no-arrow mx-1">--}}
<a class="nav-link dropdown-toggle" href="#" id="alertsDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> {{-- <a class="nav-link dropdown-toggle" href="#" id="alertsDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">--}}
<i class="fas fa-bell fa-fw"></i> {{-- <i class="fas fa-bell fa-fw"></i>--}}
<!-- Counter - Alerts --> {{-- <!-- Counter - Alerts -->--}}
<span class="badge badge-danger badge-counter">3+</span> {{-- <span class="badge badge-danger badge-counter">3+</span>--}}
</a> {{-- </a>--}}
<!-- Dropdown - Alerts --> {{-- <!-- Dropdown - Alerts -->--}}
<div class="dropdown-list dropdown-menu dropdown-menu-right shadow animated--grow-in" aria-labelledby="alertsDropdown"> {{-- <div class="dropdown-list dropdown-menu dropdown-menu-right shadow animated--grow-in" aria-labelledby="alertsDropdown">--}}
<h6 class="dropdown-header"> {{-- <h6 class="dropdown-header">--}}
Alerts Center {{-- Alerts Center--}}
</h6> {{-- </h6>--}}
<a class="dropdown-item d-flex align-items-center" href="#"> {{-- <a class="dropdown-item d-flex align-items-center" href="#">--}}
<div class="mr-3"> {{-- <div class="mr-3">--}}
<div class="icon-circle bg-primary"> {{-- <div class="icon-circle bg-primary">--}}
<i class="fas fa-file-alt text-white"></i> {{-- <i class="fas fa-file-alt text-white"></i>--}}
</div> {{-- </div>--}}
</div> {{-- </div>--}}
<div> {{-- <div>--}}
<div class="small text-gray-500">December 12, 2019</div> {{-- <div class="small text-gray-500">December 12, 2019</div>--}}
<span class="font-weight-bold">A new monthly report is ready to download!</span> {{-- <span class="font-weight-bold">A new monthly report is ready to download!</span>--}}
</div> {{-- </div>--}}
</a> {{-- </a>--}}
<a class="dropdown-item d-flex align-items-center" href="#"> {{-- <a class="dropdown-item d-flex align-items-center" href="#">--}}
<div class="mr-3"> {{-- <div class="mr-3">--}}
<div class="icon-circle bg-success"> {{-- <div class="icon-circle bg-success">--}}
<i class="fas fa-donate text-white"></i> {{-- <i class="fas fa-donate text-white"></i>--}}
</div> {{-- </div>--}}
</div> {{-- </div>--}}
<div> {{-- <div>--}}
<div class="small text-gray-500">December 7, 2019</div> {{-- <div class="small text-gray-500">December 7, 2019</div>--}}
$290.29 has been deposited into your account! {{-- $290.29 has been deposited into your account!--}}
</div> {{-- </div>--}}
</a> {{-- </a>--}}
<a class="dropdown-item d-flex align-items-center" href="#"> {{-- <a class="dropdown-item d-flex align-items-center" href="#">--}}
<div class="mr-3"> {{-- <div class="mr-3">--}}
<div class="icon-circle bg-warning"> {{-- <div class="icon-circle bg-warning">--}}
<i class="fas fa-exclamation-triangle text-white"></i> {{-- <i class="fas fa-exclamation-triangle text-white"></i>--}}
</div> {{-- </div>--}}
</div> {{-- </div>--}}
<div> {{-- <div>--}}
<div class="small text-gray-500">December 2, 2019</div> {{-- <div class="small text-gray-500">December 2, 2019</div>--}}
Spending Alert: We've noticed unusually high spending for your account. {{-- Spending Alert: We've noticed unusually high spending for your account.--}}
</div> {{-- </div>--}}
</a> {{-- </a>--}}
<a class="dropdown-item text-center small text-gray-500" href="#">Show All Alerts</a> {{-- <a class="dropdown-item text-center small text-gray-500" href="#">Show All Alerts</a>--}}
</div> {{-- </div>--}}
</li> {{-- </li>--}}
<!-- Nav Item - Messages --> <!-- Nav Item - Messages -->
<li class="nav-item dropdown no-arrow mx-1"> <li class="nav-item dropdown no-arrow mx-1">
...@@ -377,6 +377,7 @@ ...@@ -377,6 +377,7 @@
<!-- Scripts --> <!-- Scripts -->
<script src="{{ asset('vendor/jquery/jquery.min.js') }}"></script> <script src="{{ asset('vendor/jquery/jquery.min.js') }}"></script>
<script src="{{ asset('vendor/popper.js/popper.min.js') }}"></script>
<script src="{{ asset('vendor/bootstrap/js/bootstrap.min.js') }}"></script> <script src="{{ asset('vendor/bootstrap/js/bootstrap.min.js') }}"></script>
<script src="{{ asset('vendor/jquery-easing/jquery.easing.min.js') }}"></script> <script src="{{ asset('vendor/jquery-easing/jquery.easing.min.js') }}"></script>
<script src="{{ asset('js/sb-admin-2.min.js') }}"></script> <script src="{{ asset('js/sb-admin-2.min.js') }}"></script>
......
<div class="dropdown">
<button class="btn btn-secondary dropdown-toggle" type="button" id="dropdownMenuButton{{ $id }}" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<i class="fas fa-object-group"></i>
</button>
<div class="dropdown-menu shadow" aria-labelledby="dropdownMenuButton{{ $id }}">
<a class="dropdown-item" href="{{ route('web.admin.groups.doors', ['groupId' => $id]) }}">
<i class="fas fa-door-closed fa-sm fa-fw mr-2 text-gray-400"></i>
Doors
</a>
<a class="dropdown-item" href="{{ route('web.admin.groups.users', ['groupId' => $id]) }}">
<i class="fas fa-user fa-sm fa-fw mr-2 text-gray-400"></i>
Users
</a>
<a class="dropdown-item" href="{{ route('web.admin.groups.schedules', ['groupId' => $id]) }}">
<i class="fas fa-calendar-alt fa-sm fa-fw mr-2 text-gray-400"></i>
Schedules
</a>
</div>
</div>
<a class="btn btn-dark" href="{{ route('web.admin.groups.events', ['groupId' => $id]) }}" data-toggle="tooltip" title="View Open Mode Schedule"> <a class="btn btn-dark" href="{{ route('web.admin.groups.events', ['groupId' => $id]) }}" data-toggle="tooltip" title="View Open Mode Schedule">
<i class="fas fa-calendar-alt"></i> <i class="fas fa-calendar-alt"></i>
</a> </a>
......
<form method="POST" action="{{ route('web.admin.' . $resource. '.groups', [ \Illuminate\Support\Str::singular($resource) . 'Id' => $id]) }}">
@method('DELETE')
@csrf
<input type="hidden" name="group_id" value="{{ $groupId }}">
<button class="btn btn-danger" type="submit" data-toggle="tooltip" title="Delete">
<i class="fas fa-trash"></i>
</button>
</form>
...@@ -116,18 +116,14 @@ Route::name('web.')->middleware(['auth:api'])->group(static function () { ...@@ -116,18 +116,14 @@ Route::name('web.')->middleware(['auth:api'])->group(static function () {
Route::delete('/{groupId}', [GroupsController::class, 'destroy'])->name('destroy'); Route::delete('/{groupId}', [GroupsController::class, 'destroy'])->name('destroy');
Route::get('/{groupId}/events', [GroupsController::class, 'events'])->name('events'); Route::get('/{groupId}/events', [GroupsController::class, 'events'])->name('events');
Route::get('/{groupId}/doors', [GroupRelationController::class, 'doors'])->name('doors'); Route::get('/{groupId}/doors', [GroupRelationController::class, 'doors'])->name('doors');
Route::post('/{groupId}/doors', [GroupRelationController::class, 'addDoor'])->name('addDoor'); Route::post('/{groupId}/doors', [GroupRelationController::class, 'addDoor'])->name('addDoor');
Route::delete('{groupId}/doors', [GroupRelationController::class, 'removeDoor'])->name('removeDoor');
Route::get('/{groupId}/users', [GroupRelationController::class, 'users'])->name('users'); Route::get('/{groupId}/users', [GroupRelationController::class, 'users'])->name('users');
Route::post('/{groupId}/users', [GroupRelationController::class, 'addUser'])->name('addUser'); Route::post('/{groupId}/users', [GroupRelationController::class, 'addUser'])->name('addUser');
Route::delete('{groupId}/users', [GroupRelationController::class, 'removeUser'])->name('removeUser');
Route::get('/{groupId}/schedules', [GroupRelationController::class, 'schedules'])->name('schedules'); Route::get('/{groupId}/schedules', [GroupRelationController::class, 'schedules'])->name('schedules');
Route::post('/{groupId}/schedules', [GroupRelationController::class, 'addSchedule'])->name('addSchedule'); Route::post('/{groupId}/schedules', [GroupRelationController::class, 'addSchedule'])->name('addSchedule');
Route::delete('{groupId}/schedules', [GroupRelationController::class, 'removeSchedule'])->name('removeSchedule');
}); });
Route::name('schedules.') Route::name('schedules.')
......
<?php
namespace Source\UseCases\DoorGroup\GetGroupDoors;
use Source\Entities\Door;
use Source\Sanitize\Paginates;
use Source\UseCases\BasePresenter;
class WebPresenter extends BasePresenter implements Presenter
{
use Paginates;
protected array $doors = [];
/** @inheritDoc */
public function present(ResponseModel $responseModel): void
{
$this->doors = array_map(static function (Door $door): array {
return [
'id' => $door->getId(),
'door_id' => $door->getId(),
'name' => $door->getName(),
'location' => $door->getLocation(),
];
}, $responseModel->getDoors());
}
/** @inheritDoc */
public function getViewModel(): array
{
return [
'tableParams' => [
'paginatedData' => $this->webPaginate($this->doors),
'headers' => [
'Door' => 'door_id',
'Name' => 'name',
'Location' => 'location',
],
'controls' => 'groupEntity',
],
'label' => 'Enter door Name/Location/ID.',
'resource' => 'doors',
];
}
}
...@@ -36,7 +36,7 @@ class WebPresenter extends BasePresenter implements Presenter ...@@ -36,7 +36,7 @@ class WebPresenter extends BasePresenter implements Presenter
public function getViewModel(array $appends = []): array public function getViewModel(array $appends = []): array
{ {
return [ return [
'doors' => $this->webPaginate($this->doors, $appends, 25), 'doors' => $this->webPaginate($this->doors, $appends),
'headers' => [ 'headers' => [
'ID' => 'id', 'ID' => 'id',
'Name' => 'name', 'Name' => 'name',
......
<?php
namespace Source\UseCases\GroupSchedule\GetGroupSchedules;
use Source\Entities\Schedule;
use Source\Sanitize\Paginates;
use Source\UseCases\BasePresenter;
class WebPresenter extends BasePresenter implements Presenter
{
use Paginates;
protected array $schedules = [];
/** @inheritDoc */
public function present(ResponseModel $responseModel): void
{
$this->schedules = array_map(static function (Schedule $schedule): array {
if ($schedule->getType() === Schedule::TYPE_OPEN_MODE) {
$type = 'Open Mode';
} else {
$type = 'User Access';
}
return [
'id' => $schedule->getId(),
'schedule_id' => $schedule->getId(),
'type' => $type,
'description' => $schedule->getDescription(),
'start_date' => self::formatDateTime($schedule->getStart(), self::HUMAN_DATE_FORMAT),
'end_date' => self::formatDateTime($schedule->getEnd(), self::HUMAN_DATE_FORMAT) ?? 'Infinite',
];
}, $responseModel->getSchedules());
}
/** @inheritDoc */
public function getViewModel(): array
{
return [
'tableParams' => [
'paginatedData' => $this->webPaginate($this->schedules),
'headers' => [
'Schedule' => 'schedule_id',
'Type' => 'type',
'Description' => 'description',
'Start' => 'start_date',
'End' => 'end_date',
],
'controls' => 'groupEntity',
],
'label' => 'Enter schedule ID.',
'resource' => 'schedules',
];
}
}
<?php
namespace Source\UseCases\GroupUser\GetGroupUsers;
use Source\Entities\User;
use Source\Sanitize\Paginates;
use Source\UseCases\BasePresenter;
class WebPresenter extends BasePresenter implements Presenter
{
use Paginates;
protected array $users = [];
/** @inheritDoc */
public function present(ResponseModel $responseModel): void
{
$this->users = array_map(static function (User $user): array {
return [
'id' => $user->getId(),
'user_id' => $user->getId(),
'display_name' => $user->getDisplayName(),
'emplid' => $user->getEmplid(),
'email' => $user->getEmail(),
];
}, $responseModel->getUsers());
}
/** @inheritDoc */
public function getViewModel(): array
{
return [
'tableParams' => [
'paginatedData' => $this->webPaginate($this->users),
'headers' => [
'User' => 'user_id',
'Name' => 'display_name',
'Employee ID' => 'emplid',
'Email' => 'email',
],
'controls' => 'groupEntity',
],
'label' => 'Enter user Email, Employee ID, or ID.',
'resource' => 'users',
];
}
}
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