Commit 2ebaaf27 authored by Jacob Priddy's avatar Jacob Priddy 👌
Browse files

start adding in webpack and custom sass and js assets

parent c328da59
......@@ -4,12 +4,33 @@ namespace App\Http\Controllers\Web;
use Illuminate\View\View;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Source\UseCases\Users\GetUser\GetUserUseCase;
use Source\UseCases\Tokens\GetTokens\WebPresenter as UserTokensWebPresenter;
use Source\UseCases\Tokens\GetTokens\GetTokensUseCase;
use Source\UseCases\Users\GetUser\WebPresenter as GetUserWebPresenter;
class MeController extends Controller
{
public function index(Request $request): View
{
return view('home');
/**
* @param \Source\UseCases\Users\GetUser\GetUserUseCase $getUser
* @param \Source\UseCases\Tokens\GetTokens\GetTokensUseCase $userTokens
* @return \Illuminate\View\View
* @throws \Source\Exceptions\EntityNotFoundException
*/
public function index(
GetUserUseCase $getUser,
GetTokensUseCase $userTokens
): View {
$userPresenter = new GetUserWebPresenter();
$tokensPresenter = new UserTokensWebPresenter();
$userId = $this->authorizer->getCurrentUserId();
$getUser->get($userId, $userPresenter);
$userTokens->filter($userId, null, $tokensPresenter);
return view('home', $userPresenter->getViewModel());
}
}
......@@ -37,6 +37,7 @@
}
},
"autoload": {
"files": ["helpers.php"],
"psr-4": {
"App\\": "app/",
"Source\\": "src/"
......
<?php
use Source\Gateways\Users\DatabaseUsersRepository;
if (! function_exists('user')) {
/**
* Get the available auth instance.
*
* @return \Source\Entities\User|null
*/
function user()
{
/** @var App\User $user */
$user = auth()->user();
if (!$user) {
return null;
}
return DatabaseUsersRepository::makeUserFromDbUser($user);
}
}
{
"private": true,
"scripts": {
"dev": "npm run development",
"development": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
"watch": "npm run development -- --watch",
"watch-poll": "npm run watch -- --watch-poll",
"hot": "cross-env NODE_ENV=development node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --hot --disable-host-check --config=node_modules/laravel-mix/setup/webpack.config.js",
"prod": "npm run production",
"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": {
"axios": "^0.19",
"cross-env": "^7.0",
"laravel-mix": "^5.0.1",
"lodash": "^4.17.13",
"resolve-url-loader": "^3.1.0",
"sass": "^1.15.2",
"sass-loader": "^8.0.0"
}
}
require('./bootstrap');
window._ = require('lodash');
/**
* We'll load the axios HTTP library which allows us to easily issue requests
* to our Laravel back-end. This library automatically handles sending the
* CSRF token as a header based on the value of the "XSRF" token cookie.
*/
window.axios = require('axios');
window.axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest';
/**
* Echo exposes an expressive API for subscribing to channels and listening
* for events that are broadcast by Laravel. Echo and event broadcasting
* allows your team to easily build robust real-time web applications.
*/
// import Echo from 'laravel-echo';
// window.Pusher = require('pusher-js');
// window.Echo = new Echo({
// broadcaster: 'pusher',
// key: process.env.MIX_PUSHER_APP_KEY,
// cluster: process.env.MIX_PUSHER_APP_CLUSTER,
// forceTLS: true
// });
// Body
$body-bg: #f8fafc;
// Typography
$font-family-sans-serif: 'Nunito', sans-serif;
$font-size-base: 0.9rem;
$line-height-base: 1.6;
// Colors
$blue: #3490dc;
$indigo: #6574cd;
$purple: #9561e2;
$pink: #f66d9b;
$red: #e3342f;
$orange: #f6993f;
$yellow: #ffed4a;
$green: #38c172;
$teal: #4dc0b5;
$cyan: #6cb2eb;
......@@ -3,7 +3,5 @@
@section('title', 'Home')
@section('content')
<p>
hello
</p>
@include('partials.user')
@endsection
......@@ -17,29 +17,27 @@
</button>
<div class="collapse navbar-collapse" id="navbarCollapse">
<ul class="navbar-nav mr-auto">
@can(\Source\Authorization\Permissions::ADMIN)
<li class="nav-item mr-2">
<a class="nav-link" href="#">Admin Panel</a>
</li>
@endauth
<li class="nav-item mr-2">
<a class="nav-link" href="#">About</a>
</li>
<li class="nav-item mr-2">
<li class="nav-item">
<a class="nav-link" href="/api/docs/">Api Docs</a>
</li>
@can(\Source\Authorization\Permissions::ADMIN)
<li class="nav-item">
<a class="nav-link" href="#">Admin Panel</a>
</li>
@endauth
</ul>
<div class="mr-5 d-flex flex-row">
<span class="text-white-50 my-2 mr-5">
Hello, {{ auth()->user()->first_name }}
</span>
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link" href="{{ route('saml.logout') }}">Logout</a>
</li>
</ul>
<div class="dropdown">
<button class="btn btn-secondary dropdown-toggle" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Hello, {{ user()->getFirstName() }}
</button>
<div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
<a class="dropdown-item" href="{{ route('web.index') }}">View Access</a>
<a class="dropdown-item" href="{{ route('web.doorcode') }}">Change Doorcode</a>
<a class="dropdown-item" href="{{ route('saml.logout') }}">Logout</a>
</div>
</div>
</div>
</nav>
......
<div class="card">
<div class="card-body">
<h5 class="card-title">{{ $user['Full Name'] }}</h5>
<div class="card-body">
<dl>
@foreach($user as $key => $value)
<dt>{{ ucwords(str_replace("_", " ", $key)) }}</dt>
<dd>{{ $value }}</dd>
@endforeach
</dl>
</div>
</div>
</div>
......@@ -15,3 +15,4 @@ use App\Http\Controllers\Web\MeController;
*/
Route::get('/', [MeController::class, 'index'])->name('web.index');
Route::get('/door-code', [MeController::class, 'doorcode'])->name('web.doorcode');
......@@ -199,7 +199,7 @@ class DatabaseTokensRepository implements TokensRepository
*/
public function filter(?string $userId = null, ?Carbon $validAt = null): array
{
$query = \App\Token::query()->whereNotNull('name');
$query = \App\Token::query()->whereNotNull('name')->orderByDesc('created_at');
if ($userId) {
$query->where('user_id', $this->castToInt($userId));
......
......@@ -15,6 +15,8 @@ use Source\Entities\Schedule;
abstract class BasePresenter
{
public const HUMAN_DATE_FORMAT = 'M j, Y H:i:s';
/**
* @param Carbon|null $datetime
* @param string $format
......
<?php
namespace Source\UseCases\Tokens\GetTokens;
use Source\Entities\Token;
use Source\Sanitize\Paginates;
use Source\UseCases\BasePresenter;
class WebPresenter extends BasePresenter implements Presenter
{
use Paginates;
protected array $tokens = [];
/** @inheritDoc */
public function present(ResponseModel $responseModel): void
{
$this->tokens = array_map(function (Token $token) {
return [
'Name' => $token->getName(),
'Expires At' => $this->formatDateTime($token->getExpiresAt(), self::HUMAN_DATE_FORMAT) ?? 'Never Expires',
];
}, $responseModel->getTokens());
}
/** @inheritDoc */
public function getViewModel(array $appends = []): array
{
return $this->paginate($this->tokens, $appends);
}
}
<?php
namespace Source\UseCases\Users\GetUser;
use Source\UseCases\BasePresenter;
class WebPresenter extends BasePresenter implements Presenter
{
protected array $viewModel = [];
/** @inheritDoc */
public function present(ResponseModel $responseModel): void
{
$user = $responseModel->getUser();
$this->viewModel['user'] = [
'Id' => $user->getId(),
'First Name' => $user->getFirstName(),
'Last Name' => $user->getLastName(),
'Full Name' => $user->getDisplayName(),
'Employee Id' => $user->getEmplid() ?? 'No Employee Id Set',
'Email' => $user->getEmail(),
'Expires At' => $this->formatDateTime($user->getExpiresAt(), self::HUMAN_DATE_FORMAT) ?? 'Never Expires',
'Created At' => $this->formatDateTime($user->getCreatedAt(), self::HUMAN_DATE_FORMAT) ?? 'Never',
'Updated At' => $this->formatDateTime($user->getUpdatedAt(), self::HUMAN_DATE_FORMAT) ?? 'Never',
];
}
/** @inheritDoc */
public function getViewModel(): array
{
return $this->viewModel;
}
}
const mix = require('laravel-mix');
/*
|--------------------------------------------------------------------------
| Mix Asset Management
|--------------------------------------------------------------------------
|
| Mix provides a clean, fluent API for defining some Webpack build steps
| for your Laravel application. By default, we are compiling the Sass
| file for the application as well as bundling up all the JS files.
|
*/
mix.js('resources/js/app.js', 'public/js')
.sass('resources/sass/app.scss', 'public/css');
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