Minor css fixes, delete/pause addresses, validation fixes for nodes with 0 in address

This commit is contained in:
Deon George 2021-07-02 00:25:41 +10:00
parent 88d189110d
commit 54bcdf4b13
7 changed files with 132 additions and 9 deletions

View File

@ -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');

33
app/Rules/FidoInteger.php Normal file
View File

@ -0,0 +1,33 @@
<?php
namespace App\Rules;
use Illuminate\Contracts\Validation\Rule;
use App\Http\Controllers\DomainController;
class FidoInteger implements Rule
{
/**
* Determine if the validation rule passes.
* This will check that a number used for zone, net, host is between 1 and DomainController::NUMBER_MAX.
*
* @param string $attribute
* @param mixed $value
* @return bool
*/
public function passes($attribute,$value)
{
return (is_numeric($value) && ($value >= 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);
}
}

View File

@ -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));
}
/**

View File

@ -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;
@ -709,3 +709,10 @@ a.goback:focus:before {
.gohome:hover:after {
color:#a50!important
}
.modal-header.bg-danger .modal-title {
color: #fff !important;
}
.modal-body {
color: #0c0c0c;
}

View File

@ -290,7 +290,7 @@
<tr>
<th>Address</th>
<th>Active</th>
<th>Role</th>
<th colspan="2">Role</th>
</tr>
</thead>
@ -300,6 +300,16 @@
<td>{{ $oo->ftn }}</td>
<td>{{ $oo->active ? 'YES' : 'NO' }}</td>
<td>{{ $oo->role }}</td>
<td style="width: 70px;">
@can('admin',$oo)
<a href="{{ url('ftn/system/susaddress',[$oo->id]) }}" title="@if($oo->active)Pause @else Activate @endif Address" class="suspend"><i class="bi @if($oo->active)bi-pause-circle-fill @else bi-play-circle-fill @endif"></i></a>
{{--
<a href="{{ url('ftn/system/modaddress',[$oo->id]) }}" title="Modify Address" class="modify"><i class="bi bi-pen-fill"></i></a>
<a href="{{ url('ftn/system/movaddress',[$oo->id]) }}" title="Move Address to another System" class="move"><i class="bi bi-arrow-right-square-fill"></i></a>
--}}
<a href="{{ url('ftn/system/deladdress',[$oo->id]) }}" title="Delete Address" class="delete"><i class="bi bi-trash-fill"></i></a>
@endcan
</td>
</tr>
@endforeach
</tbody>
@ -494,6 +504,8 @@
</div>
@endif
</div>
@include('widgets.modal_delete')
@endsection
@section('page-scripts')

View File

@ -0,0 +1,31 @@
<div class="modal fade" id="confirm-delete" tabindex="-1">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header bg-danger">
<h5 class="modal-title">WARNING: Deleting record</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<p>This action is irreversible. Are you sure, your sure, that you want to delete it?</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
<a type="button" class="btn btn-danger btn-ok">Delete</a>
</div>
</div>
</div>
</div>
@section('page-scripts')
<script>
var confirmdelete = new bootstrap.Modal(document.getElementById('confirm-delete'), {});
$(document).ready(function() {
$('.delete').click(function(e) {
confirmdelete.show();
$('#confirm-delete').find('.btn-ok').attr('href',e.currentTarget.href);
return false;
});
});
</script>
@append

View File

@ -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'])