Commit 1bd84876 authored by Jacob Priddy's avatar Jacob Priddy 👌
Browse files

Re add in bootstrap assets and move the events web endpoint to an api

endpoint
parent e3337294
......@@ -2,10 +2,13 @@
namespace App\Http\Controllers\Api;
use Carbon\Carbon;
use Illuminate\Http\JsonResponse;
use Source\UseCases\Users\GetUser\GetUserUseCase;
use Source\UseCases\Tokens\GetTokens\GetTokensUseCase;
use Source\UseCases\Users\UpdateUser\UpdateCurrentUser;
use Source\UseCases\Door\ScheduleEvents\ScheduleEvents;
use Source\UseCases\Door\ScheduleEvents\EventsPresenter;
use Source\UseCases\GroupUser\GetUserGroups\GetUserGroupsUseCase;
use Source\UseCases\DoorUser\UserDoorAccess\UserDoorAccessUseCase;
use Source\UseCases\Users\GetUser\APIPresenter as GetUserAPIPresenter;
......@@ -154,4 +157,42 @@ class MeController extends ApiController
return $this->respondWithData($presenter->getViewModel());
}
/**
* My Access Events
*
* This endpoint shows all door events for the current user. These events include user access schedules,
* overrides, and special exclusion rules.
*
* @authenticated
* @urlParam door_id required The door to see events for. Example: 1
* @urlParam start required The start date to view events for. Example: 2020-04-03 12:43:22
* @urlParam end required The end date to see events for. Example: 2020-04-04 12:43:22
* @param \Source\UseCases\Door\ScheduleEvents\ScheduleEvents $scheduleEvents
* @return \Illuminate\Http\JsonResponse
* @throws \Illuminate\Validation\ValidationException
* @throws \Exception
*/
public function doorSchedules(ScheduleEvents $scheduleEvents): JsonResponse
{
$this->validate($this->request, [
'door_id' => 'required|integer',
'start' => 'required|date|before:end',
'end' => 'required|date|after:start'
]);
// Cannot be null since it was validated up above and is known to exist
$startDate = new Carbon($this->request->input('start'));
$endDate = new Carbon($this->request->input('end'));
$eventsPresenter = new EventsPresenter();
$scheduleEvents->getStatusForDoor(
$this->request->input('door_id'),
$this->authorizer->getCurrentUserId(),
$startDate,
$endDate,
$eventsPresenter
);
return new JsonResponse($eventsPresenter->getViewModel(), 200);
}
}
......@@ -2,8 +2,11 @@
namespace App\Http\Controllers\Api;
use Carbon\Carbon;
use Illuminate\Http\JsonResponse;
use Source\Authorization\Permissions;
use Source\UseCases\Door\ScheduleEvents\EventsPresenter;
use Source\UseCases\Door\ScheduleEvents\ScheduleEvents;
use Source\UseCases\Schedules\ScheduleGet\ScheduleGetUseCase;
use Source\UseCases\Schedules\SchedulesGet\SchedulesGetUseCase;
use Source\UseCases\Schedules\APIPresenter as ScheduleApiPresenter;
......@@ -180,4 +183,50 @@ class SchedulesController extends ApiController
return $this->respondWithData($presenter->getViewModel());
}
/**
* Access Event Times
*
* This endpoint shows all door events for a given door and user id. If no user id is given,
* only door open events are shown, other wise user access blocks are also shown. These events include
* overrides and special exclusion rules. In other words, this is what the doors actually do.
*
* @authenticated
* @urlParam door_id required The door to see events for. Example: 1
* @urlParam user_id The user to see access schedules for. Example: 2
* @urlParam start required The start date to view events for. Example: 2020-04-03 12:43:22
* @urlParam end required The end date to see events for. Example: 2020-04-04 12:43:22
*
* @param \Source\UseCases\Door\ScheduleEvents\ScheduleEvents $scheduleEvents
* @return \Illuminate\Http\JsonResponse
* @throws \Illuminate\Validation\ValidationException
* @throws \Source\Exceptions\AuthorizationException
* @throws \Source\Exceptions\EntityNotFoundException
* @throws \Exception
*/
public function events(ScheduleEvents $scheduleEvents): JsonResponse
{
$this->authorizer->protectOne([Permissions::MANAGE_DOORS, Permissions::MANAGE_USERS, Permissions::LOGS_READ]);
$this->validate($this->request, [
'door_id' => 'required|integer',
'user_id' => 'integer|nullable',
'start' => 'required|date|before:end',
'end' => 'required|date|after:start'
]);
// Cannot be null since it was validated up above and is known to exist
$startDate = new Carbon($this->request->input('start'));
$endDate = new Carbon($this->request->input('end'));
$eventsPresenter = new EventsPresenter();
$scheduleEvents->getStatusForDoor(
$this->request->input('door_id'),
$this->request->input('user_id'),
$startDate,
$endDate,
$eventsPresenter
);
return new JsonResponse($eventsPresenter->getViewModel(), 200);
}
}
......@@ -9,7 +9,7 @@ use Illuminate\Http\JsonResponse;
use App\Http\Controllers\Controller;
use Source\UseCases\Doors\GetDoors\MePresenter;
use Source\UseCases\Doors\GetDoors\GetDoorsUseCase;
use Source\UseCases\Door\ScheduleEvents\WebPresenter;
use Source\UseCases\Door\ScheduleEvents\EventsPresenter;
use Source\UseCases\Tokens\GetTokens\GetTokensUseCase;
use Source\UseCases\Door\ScheduleEvents\ScheduleEvents;
use Source\UseCases\Users\UpdateUser\UpdateCurrentUser;
......@@ -88,35 +88,6 @@ class MeController extends Controller
->with('doors', $doorsPresenter->getViewModel());
}
/**
* @param \Source\UseCases\Door\ScheduleEvents\ScheduleEvents $scheduleEvents
* @return \Illuminate\Http\JsonResponse
* @throws \Illuminate\Validation\ValidationException
* @throws \Exception
*/
public function accessJson(ScheduleEvents $scheduleEvents): JsonResponse
{
$this->validate($this->request, [
'door_id' => 'required|integer|required_with:start',
'start' => 'required|date|before:end',
'end' => 'required|date|after:start'
]);
// Cannot be null since it was validated up above and is known to exist
$startDate = new Carbon($this->request->input('start'));
$endDate = new Carbon($this->request->input('end'));
$eventsPresenter = new WebPresenter();
$scheduleEvents->getStatusForDoor(
$this->request->input('door_id'),
$this->authorizer->getCurrentUserId(),
$startDate,
$endDate,
$eventsPresenter
);
return new JsonResponse($eventsPresenter->getViewModel(), 200);
}
/**
* @param \Source\UseCases\Tokens\GetTokens\GetTokensUseCase $userTokens
* @return \Illuminate\View\View
......
......@@ -1954,6 +1954,12 @@
"integrity": "sha1-aN/1++YMUes3cl6p4+0xDcwed24=",
"dev": true
},
"bootstrap": {
"version": "4.5.0",
"resolved": "https://registry.npmjs.org/bootstrap/-/bootstrap-4.5.0.tgz",
"integrity": "sha512-Z93QoXvodoVslA+PWNdk23Hze4RBYIkpb5h8I2HY2Tu2h7A0LpAgLcyrhrSUyo2/Oxm2l1fRZPs1e5hnxnliXA==",
"dev": true
},
"bootstrap-select": {
"version": "1.13.18",
"resolved": "https://registry.npmjs.org/bootstrap-select/-/bootstrap-select-1.13.18.tgz",
......@@ -3067,6 +3073,12 @@
"type": "^1.0.1"
}
},
"de-indent": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/de-indent/-/de-indent-1.0.2.tgz",
"integrity": "sha1-sgOOhG3DO6pXlhKNCAS0VbjB4h0=",
"dev": true
},
"debug": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz",
......@@ -5254,6 +5266,12 @@
}
}
},
"jquery": {
"version": "3.5.1",
"resolved": "https://registry.npmjs.org/jquery/-/jquery-3.5.1.tgz",
"integrity": "sha512-XwIBPqcMn57FxfT+Go5pzySnm4KWkT1Tv7gjrpT1srtf8Weynl6R273VJ5GjkRb51IzMp5nbaPjJXMWeju2MKg==",
"dev": true
},
"js-tokens": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz",
......@@ -6478,6 +6496,12 @@
"find-up": "^3.0.0"
}
},
"popper.js": {
"version": "1.16.1",
"resolved": "https://registry.npmjs.org/popper.js/-/popper.js-1.16.1.tgz",
"integrity": "sha512-Wb4p1J4zyFTbM+u6WuO4XstYx4Ky9Cewe4DWrel7B0w6VVICvPwdOpotjzcf6eD8TsckVnIMNONQyPIUFOUbCQ==",
"dev": true
},
"portfinder": {
"version": "1.0.26",
"resolved": "https://registry.npmjs.org/portfinder/-/portfinder-1.0.26.tgz",
......@@ -9207,6 +9231,16 @@
"loader-utils": "^1.0.2"
}
},
"vue-template-compiler": {
"version": "2.6.11",
"resolved": "https://registry.npmjs.org/vue-template-compiler/-/vue-template-compiler-2.6.11.tgz",
"integrity": "sha512-KIq15bvQDrcCjpGjrAhx4mUlyyHfdmTaoNfeoATHLAiWB+MU3cx4lOzMwrnUh9cCxy0Lt1T11hAFY6TQgroUAA==",
"dev": true,
"requires": {
"de-indent": "^1.0.2",
"he": "^1.1.0"
}
},
"vue-template-es2015-compiler": {
"version": "1.9.1",
"resolved": "https://registry.npmjs.org/vue-template-es2015-compiler/-/vue-template-es2015-compiler-1.9.1.tgz",
......
......@@ -10,15 +10,19 @@
"production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --no-progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js"
},
"devDependencies": {
"@fullcalendar/core": "^5.1.0",
"@fullcalendar/timegrid": "^5.1.0",
"axios": "^0.19",
"bootstrap": "^4.0.0",
"bootstrap-select": "^1.13.18",
"cross-env": "^7.0",
"jquery": "^3.2",
"laravel-mix": "^5.0.1",
"lodash": "^4.17.13",
"popper.js": "^1.12",
"resolve-url-loader": "^3.1.0",
"sass": "^1.15.2",
"sass-loader": "^8.0.0",
"@fullcalendar/core": "^5.1.0",
"@fullcalendar/timegrid": "^5.1.0",
"bootstrap-select": "^1.13.18"
"vue-template-compiler": "^2.6.11"
}
}
......@@ -54576,7 +54576,7 @@ document.addEventListener('DOMContentLoaded', function () {
initialView: 'timeGridWeek',
nowIndicator: true,
events: {
url: '/access.json',
url: '/api/me/schedule-events',
method: 'GET',
extraParams: {
door_id: doorId
......@@ -29,7 +29,7 @@ document.addEventListener('DOMContentLoaded', function() {
initialView: 'timeGridWeek',
nowIndicator: true,
events: {
url: '/access.json',
url: '/api/me/schedule-events',
method: 'GET',
extraParams: {
door_id: doorId
......
......@@ -6,12 +6,12 @@ window._ = require('lodash');
* code may be modified to fit the specific needs of your application.
*/
// try {
// window.Popper = require('popper.js').default;
// window.$ = window.jQuery = require('jquery');
//
// require('bootstrap');
// } catch (e) {}
try {
window.Popper = require('popper.js').default;
window.$ = window.jQuery = require('jquery');
require('bootstrap');
} catch (e) {}
/**
* We'll load the axios HTTP library which allows us to easily issue requests
......
......@@ -2,7 +2,7 @@
@import url('https://fonts.googleapis.com/css?family=Nunito');
// Bootstrap
//@import '~bootstrap/scss/bootstrap';
@import '~bootstrap/scss/bootstrap';
// Bootstrap select
@import '~bootstrap-select/dist/css/bootstrap-select.min';
......
......@@ -79,6 +79,7 @@ Route::group(['middleware' => 'auth:api'], static function () {
Route::get('/', [SchedulesController::class, 'index'])->name('schedules.index');
Route::post('/', [SchedulesController::class, 'create'])->name('schedules.create');
Route::get('{scheduleId}', [SchedulesController::class, 'get'])->name('schedules.get');
Route::get('/events', [SchedulesController::class, 'events'])->name('schedules.events');
Route::patch('{scheduleId}', [SchedulesController::class, 'update'])->name('schedules.update');
});
......@@ -122,5 +123,6 @@ Route::group(['middleware' => 'auth:api'], static function () {
Route::patch('/', [MeController::class, 'update'])->name('me.update');
Route::get('permissions', [MeController::class, 'permissions'])->name('me.perms');
Route::get('/access', [MeController::class, 'doors'])->name('me.access');
Route::get('/schedule-events', [MeController::class, 'doorSchedules'])->name('me.schedules.events');
});
});
......@@ -19,7 +19,6 @@ Route::view('/door-code', 'doorcode')->name('web.doorcode');
Route::post('/door-code', [MeController::class, 'doorcodeUpdate'])->name('web.doorcode.change');
Route::view('/password', 'password')->name('web.password');
Route::post('/password', [MeController::class, 'passwordUpdate'])->name('web.password.change');
Route::get('/access.json', [MeController::class, 'accessJson'])->name('web.access.json');
Route::get('/access', [MeController::class, 'access'])->name('web.access');
Route::get('/tokens', [MeController::class, 'tokens'])->name('web.tokens');
Route::view('/about', 'about');
......@@ -5,7 +5,7 @@ namespace Source\UseCases\Door\ScheduleEvents;
use Source\UseCases\BasePresenter;
use Source\Entities\ScheduleEvent;
class WebPresenter extends BasePresenter implements Presenter
class EventsPresenter extends BasePresenter implements Presenter
{
protected array $viewModel = [];
......
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