From 54bcdf4b13791c44839c9a508c2bd61b7fab9e60 Mon Sep 17 00:00:00 2001 From: Deon George Date: Fri, 2 Jul 2021 00:25:41 +1000 Subject: [PATCH] Minor css fixes, delete/pause addresses, validation fixes for nodes with 0 in address --- app/Http/Controllers/SystemController.php | 44 +++++++++++++++++-- app/Rules/FidoInteger.php | 33 ++++++++++++++ app/Rules/TwoByteInteger.php | 4 +- public/oldschool/css/main.css | 11 ++++- resources/views/system/addedit.blade.php | 14 +++++- .../views/widgets/modal_delete.blade.php | 31 +++++++++++++ routes/web.php | 4 ++ 7 files changed, 132 insertions(+), 9 deletions(-) create mode 100644 app/Rules/FidoInteger.php create mode 100644 resources/views/widgets/modal_delete.blade.php diff --git a/app/Http/Controllers/SystemController.php b/app/Http/Controllers/SystemController.php index 20eb0da..f88494d 100644 --- a/app/Http/Controllers/SystemController.php +++ b/app/Http/Controllers/SystemController.php @@ -5,7 +5,7 @@ namespace App\Http\Controllers; use Illuminate\Http\Request; use App\Models\{Address,System}; -use App\Rules\TwoByteInteger; +use App\Rules\{FidoInteger,TwoByteInteger}; class SystemController extends Controller { @@ -74,7 +74,7 @@ class SystemController extends Controller case 'host': $request->validate([ - 'region_id' => ['required',new TwoByteInteger], + 'region_id' => ['required',new FidoInteger], 'host_id_new' => [ 'required', new TwoByteInteger, @@ -133,8 +133,8 @@ class SystemController extends Controller case 'node': $request->validate([ - 'region_id' => ['required',new TwoByteInteger], - 'host_id' => ['required',new TwoByteInteger], + 'region_id' => ['required',new FidoInteger], + 'host_id' => ['required',new FidoInteger], 'node_id' => [ 'required', new TwoByteInteger, @@ -215,6 +215,42 @@ class SystemController extends Controller ->with('o',$o); } + /** + * Delete address assigned to a host + * + * @param Address $o + * @return \Illuminate\Http\RedirectResponse + * @throws \Illuminate\Auth\Access\AuthorizationException + */ + public function del_address(Address $o) + { + $this->authorize('admin',$o); + session()->flash('add_address',TRUE); + + $sid = $o->system_id; + $o->delete(); + + return redirect()->to(sprintf('ftn/system/addedit/%d',$sid)); + } + + /** + * Suspend address assigned to a host + * + * @param Address $o + * @return \Illuminate\Http\RedirectResponse + * @throws \Illuminate\Auth\Access\AuthorizationException + */ + public function sus_address(Address $o) + { + $this->authorize('admin',$o); + session()->flash('add_address',TRUE); + + $o->active = (! $o->active); + $o->save(); + + return redirect()->to(sprintf('ftn/system/addedit/%d',$o->system_id)); + } + public function home() { return view('system.home'); diff --git a/app/Rules/FidoInteger.php b/app/Rules/FidoInteger.php new file mode 100644 index 0000000..f5123f3 --- /dev/null +++ b/app/Rules/FidoInteger.php @@ -0,0 +1,33 @@ += 0) && ($value < DomainController::NUMBER_MAX)); + } + + /** + * Get the validation error message. + * + * @return string + */ + public function message() + { + return sprintf('The number must be between 0 and %d.',DomainController::NUMBER_MAX); + } +} diff --git a/app/Rules/TwoByteInteger.php b/app/Rules/TwoByteInteger.php index edcc93f..e388edc 100644 --- a/app/Rules/TwoByteInteger.php +++ b/app/Rules/TwoByteInteger.php @@ -16,9 +16,9 @@ class TwoByteInteger implements Rule * @param mixed $value * @return bool */ - public function passes($attribute, $value) + public function passes($attribute,$value) { - return (is_numeric($value) && ($value > 0) && ($value < DomainController::NUMBER_MAX)) || ($value === 'no'); + return (is_numeric($value) && ($value > 0) && ($value < DomainController::NUMBER_MAX)); } /** diff --git a/public/oldschool/css/main.css b/public/oldschool/css/main.css index 6d70a1a..248bceb 100644 --- a/public/oldschool/css/main.css +++ b/public/oldschool/css/main.css @@ -257,8 +257,8 @@ ul#searchbar li i { #sidebar { position:absolute; left:0; - top:calc(3em + 8px); - height:calc(100vh - 3em + 8px); + top:calc(3em + 5px); + height:calc(100vh - 3em + 5px); width:22ch; overflow:hidden; padding-top:1.5em; @@ -708,4 +708,11 @@ a.goback:focus:before { .gohome:hover:before, .gohome:hover:after { color:#a50!important +} + +.modal-header.bg-danger .modal-title { + color: #fff !important; +} +.modal-body { + color: #0c0c0c; } \ No newline at end of file diff --git a/resources/views/system/addedit.blade.php b/resources/views/system/addedit.blade.php index 52851f7..3936560 100644 --- a/resources/views/system/addedit.blade.php +++ b/resources/views/system/addedit.blade.php @@ -290,7 +290,7 @@ Address Active - Role + Role @@ -300,6 +300,16 @@ {{ $oo->ftn }} {{ $oo->active ? 'YES' : 'NO' }} {{ $oo->role }} + + @can('admin',$oo) + + {{-- + + + --}} + + @endcan + @endforeach @@ -494,6 +504,8 @@ @endif + + @include('widgets.modal_delete') @endsection @section('page-scripts') diff --git a/resources/views/widgets/modal_delete.blade.php b/resources/views/widgets/modal_delete.blade.php new file mode 100644 index 0000000..3c537be --- /dev/null +++ b/resources/views/widgets/modal_delete.blade.php @@ -0,0 +1,31 @@ + + +@section('page-scripts') + +@append \ No newline at end of file diff --git a/routes/web.php b/routes/web.php index bada59e..2dd44fc 100644 --- a/routes/web.php +++ b/routes/web.php @@ -44,6 +44,10 @@ Route::middleware(['verified','activeuser'])->group(function () { ->where('o','[0-9]+'); Route::post('ftn/system/addaddress/{o?}',[SystemController::class,'add_address']) ->where('o','[0-9]+'); + Route::get('ftn/system/deladdress/{o?}',[SystemController::class,'del_address']) + ->where('o','[0-9]+'); + Route::get('ftn/system/susaddress/{o?}',[SystemController::class,'sus_address']) + ->where('o','[0-9]+'); Route::get('ftn/zone',[ZoneController::class,'home']); Route::match(['get','post'],'ftn/zone/addedit/{o?}',[ZoneController::class,'add_edit'])