Compare commits

...

6 Commits

Author SHA1 Message Date
Deon George
0bd32aab4a Layout updates, switch user updates 2018-08-01 16:29:14 +10:00
Deon George
444c159ab9 Added CompositeKeys Traits for Models with multiple primary keys 2018-07-31 12:56:29 +10:00
Deon George
55cbe4087c More improvements to User Switch 2018-07-17 13:27:25 +10:00
Deon George
ac867a2526 Enhancements to user switch 2018-07-13 14:39:10 +10:00
Deon George
b0fcdaa375 Added artisan command schedule:list 2018-06-15 14:14:04 +10:00
Deon George
55d369df47 Added helpers.php 2018-06-12 16:09:27 +10:00
14 changed files with 208 additions and 29 deletions

View File

@@ -18,7 +18,10 @@
"autoload": { "autoload": {
"psr-4": { "psr-4": {
"Leenooks\\": "src" "Leenooks\\": "src"
} },
"files": [
"src/helpers.php"
]
}, },
"extra": { "extra": {
"laravel": { "laravel": {

View File

@@ -136,4 +136,5 @@ return [
'loggedin' => 'Logged in!', 'loggedin' => 'Logged in!',
'entering' => 'Entering...', 'entering' => 'Entering...',
'registered' => 'User Registered!', 'registered' => 'User Registered!',
'switchoff' => 'Switch Back',
]; ];

View File

@@ -10,7 +10,7 @@
<div id="app" v-cloak> <div id="app" v-cloak>
<div class="register-box"> <div class="register-box">
<div class="register-logo"> <div class="register-logo">
<a href="{{ url('/home') }}"><b>Pipeline</b>Management</a> <a href="{{ url('/home') }}">{!! config('app.name_html_long') !!}</a>
</div> </div>
@if (count($errors) > 0) @if (count($errors) > 0)

View File

@@ -5,7 +5,7 @@
@include('adminlte::layouts.partials.htmlheader') @include('adminlte::layouts.partials.htmlheader')
@show @show
<body class="fixed skin-blue sidebar-mini"> <body class="fixed hold-transition skin-blue sidebar-mini">
<div id="app" v-cloak> <div id="app" v-cloak>
<div class="wrapper"> <div class="wrapper">
@include('adminlte::layouts.partials.mainheader') @include('adminlte::layouts.partials.mainheader')

View File

@@ -1,5 +1,5 @@
<!-- Main Footer --> <!-- Main Footer -->
<footer class="main-footer"> <footer class="main-footer no-print">
<!-- To the right --> <!-- To the right -->
<div class="pull-right hidden-xs"> <div class="pull-right hidden-xs">
<a href="#"></a><b>{{ config('app.name') }}</b></a> <a href="#"></a><b>{{ config('app.name') }}</b></a>

View File

@@ -1,5 +1,6 @@
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>{{ config('app.name') }} - @yield('htmlheader_title', 'Your title here')</title> <title>{{ config('app.name') }} - @yield('htmlheader_title', 'Your title here')</title>
<meta content='width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no' name='viewport'> <meta content='width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no' name='viewport'>
<!-- CSRF Token --> <!-- CSRF Token -->
@@ -14,6 +15,10 @@
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script> <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]--> <![endif]-->
<style>
body { color: #333; }
</style>
<script> <script>
//See https://laracasts.com/discuss/channels/vue/use-trans-in-vuejs //See https://laracasts.com/discuss/channels/vue/use-trans-in-vuejs
window.trans = window.trans =
@@ -32,4 +37,4 @@
<!-- STYLESHEETS --> <!-- STYLESHEETS -->
{!! Asset::styles() !!} {!! Asset::styles() !!}
</head> </head>

View File

@@ -45,7 +45,7 @@
<!-- Top Menu Items --> <!-- Top Menu Items -->
@include('adminlte::layouts.partials.topmenu') @include('adminlte::layouts.partials.topmenu')
<li class="dropdown user user-menu" id="user_menu"> <li class="dropdown user user-menu @if($user->switched) bg-red @endif" id="user_menu">
<!-- Menu Toggle Button --> <!-- Menu Toggle Button -->
<a href="#" class="dropdown-toggle" data-toggle="dropdown"> <a href="#" class="dropdown-toggle" data-toggle="dropdown">
<!-- The user image in the navbar--> <!-- The user image in the navbar-->
@@ -69,16 +69,22 @@
</div> </div>
<div class="pull-right"> <div class="pull-right">
<a href="{{ url('/logout') }}" class="btn btn-default btn-flat" id="logout" @if ($user->switched)
onclick="event.preventDefault(); <a href="{{ url('/admin/switch/stop') }}" class="btn btn-default btn-flat" id="switch">
document.getElementById('logout-form').submit();"> {{ trans('adminlte_lang::message.switchoff') }}
{{ trans('adminlte_lang::message.signout') }} </a>
</a> @else
<a href="{{ url('/logout') }}" class="btn btn-default btn-flat" id="logout"
onclick="event.preventDefault();
document.getElementById('logout-form').submit();">
{{ trans('adminlte_lang::message.signout') }}
</a>
<form id="logout-form" action="{{ url('/logout') }}" method="POST" style="display: none;"> <form id="logout-form" action="{{ url('/logout') }}" method="POST" style="display: none;">
{{ csrf_field() }} {{ csrf_field() }}
<input type="submit" value="logout" style="display: none;"> <input type="submit" value="logout" style="display: none;">
</form> </form>
@endif
</div> </div>
</li> </li>
</ul> </ul>
@@ -95,4 +101,4 @@
</ul> </ul>
</div> </div>
</nav> </nav>
</header> </header>

View File

@@ -18,5 +18,5 @@
Both of these plugins are recommended to enhance the Both of these plugins are recommended to enhance the
user experience. Slimscroll is required when using the user experience. Slimscroll is required when using the
fixed layout. --> fixed layout. -->
@js('/site/js/jquery.slimscroll.min.js','jq.slimscroll'); @js('/site/js/jquery.slimscroll.min.js','jq.slimscroll')
@js('/site/js/fastclick.min.js','jq.fastclick'); @js('/site/js/fastclick.min.js','jq.fastclick')

View File

@@ -1,5 +1,5 @@
<ul class="sidebar-menu" data-widget="tree"> <ul class="sidebar-menu" data-widget="tree">
<li class="header">Menu</li> <li class="header"><b>MENU</b></li>
<!-- Optionally, you can add icons to the links --> <!-- Optionally, you can add icons to the links -->
<li @if(Route::current()->getName() == 'home')class="active"@endif><a href="{{ url('home',['date'=>(isset($ido) ? $ido->id : NULL)]) }}"><i class='fa fa-link'></i> <span>{{ trans('adminlte_lang::message.home') }}</span></a></li> <li @if(Route::current()->getName() == 'home')class="active"@endif><a href="{{ url('home',['date'=>(isset($ido) ? $ido->id : NULL)]) }}"><i class='fa fa-link'></i> <span>{{ trans('adminlte_lang::message.home') }}</span></a></li>
</ul> </ul>

View File

@@ -0,0 +1,66 @@
<?php
namespace Leenooks\Commands;
use Illuminate\Console\Command;
use Illuminate\Console\Scheduling\Schedule;
class ScheduleList extends Command
{
protected $signature = 'schedule:list';
protected $description = 'List when scheduled commands are executed.';
/**
* @var Schedule
*/
protected $schedule;
/**
* ScheduleList constructor.
*
* @param Schedule $schedule
*/
public function __construct(Schedule $schedule)
{
parent::__construct();
$this->schedule = $schedule;
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$events = array_map(function ($event) {
return [
'cron' => $event->expression,
'command' => static::fixupCommand($event->command),
];
}, $this->schedule->events());
$this->table(
['Cron', 'Command'],
$events
);
}
/**
* If it's an artisan command, strip off the PHP
*
* @param $command
* @return string
*/
protected static function fixupCommand($command)
{
$parts = explode(' ', $command);
if (count($parts) > 2 && $parts[1] === "'artisan'") {
array_shift($parts);
}
return implode(' ', $parts);
}
}

View File

@@ -2,12 +2,13 @@
namespace Leenooks\Controllers; namespace Leenooks\Controllers;
use Illuminate\Support\Facades\Auth;
use App\Http\Controllers\Controller; use App\Http\Controllers\Controller;
use App\User;
use Auth;
use Redirect; use Redirect;
use Session; use Session;
use App\User;
class AdminController extends Controller class AdminController extends Controller
{ {
public function __construct() public function __construct()
@@ -15,12 +16,22 @@ class AdminController extends Controller
$this->middleware('auth'); $this->middleware('auth');
} }
public function switch_authorised($id)
{
return (method_exists(Auth::user(),'isAdmin') && Auth::user()->isAdmin($id)) ? TRUE : FALSE;
}
public function switch_session()
{
return ! Session::get('orig_user');
}
/** /**
* @todo Change the background color (or something) so we know we are switched * @todo Change the background color (or something) so we know we are switched
*/ */
public function user_switch_start($id) public function user_switch_start($id)
{ {
if ($this->switch_authorised()) if ($this->switch_session() AND $this->switch_authorised($id))
{ {
$uo = User::find($id); $uo = User::find($id);
@@ -43,10 +54,4 @@ class AdminController extends Controller
return Redirect::to('/home'); return Redirect::to('/home');
} }
}
public function switch_authorised()
{
// @todo
return TRUE;
}
}

View File

@@ -0,0 +1,57 @@
<?php
namespace Leenooks\Traits;
use Illuminate\Database\Eloquent\Builder;
/**
* Trait CompositeKeys
* Enable Models to have multiple primary keys
*
* Need to add to the Model...
* public $incrementing = false;
* protected $primaryKey = [<ARRAY_OF_KEYS>];
*
* @package Leenooks\Traits
*/
trait CompositeKeys {
/**
* Set the keys for a save update query.
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @return \Illuminate\Database\Eloquent\Builder
*/
protected function setKeysForSaveQuery(Builder $query)
{
$keys = $this->getKeyName();
if (! is_array($keys)) {
return parent::setKeysForSaveQuery($query);
}
foreach($keys as $keyName) {
$query->where($keyName, '=', $this->getKeyForSaveQuery($keyName));
}
return $query;
}
/**
* Get the primary key value for a save query.
*
* @param mixed $keyName
* @return mixed
*/
protected function getKeyForSaveQuery($keyName = null)
{
if (is_null($keyName)) {
$keyName = $this->getKeyName();
}
if (isset($this->original[$keyName])) {
return $this->original[$keyName];
}
return $this->getAttribute($keyName);
}
}

21
src/Traits/UserSwitch.php Normal file
View File

@@ -0,0 +1,21 @@
<?php
/**
* Check if users have been switched
*/
namespace Leenooks\Traits;
use Session;
trait UserSwitch
{
public function getSwitchedAttribute()
{
return Session::get('orig_user');
}
public function isAdmin($id)
{
return isset($this->admin) ? $this->admin : FALSE;
}
}

15
src/helpers.php Normal file
View File

@@ -0,0 +1,15 @@
<?php
// is_json helper
if (! function_exists('is_json')) {
function is_json($string) {
try {
json_decode($string);
} catch (\Exception $e) {
return FALSE;
}
return (json_last_error() == JSON_ERROR_NONE);
}
}