Enabled moving address, minor CSS fixes

This commit is contained in:
Deon George 2021-08-08 17:27:22 +10:00
parent 7cd7849241
commit 8d4ca2963d
6 changed files with 202 additions and 12 deletions

View File

@ -3,6 +3,7 @@
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Arr;
use App\Models\{Address,System,Zone};
use App\Rules\{FidoInteger,TwoByteInteger};
@ -312,6 +313,47 @@ class SystemController extends Controller
return redirect()->to(sprintf('ftn/system/addedit/%d',$o->id));
}
/**
* Move address to another system
*
* @param Request $request
* @param System $so
* @param Address $o
* @throws \Illuminate\Auth\Access\AuthorizationException
*/
public function mov_address(Request $request,System $so,Address $o)
{
// Quick check that this address belongs to this system
if ($so->addresses->search(function($item) use ($o) { return $item->id == $o->id; }) === FALSE)
abort(404);
if ($request->post()) {
$this->authorize('admin',$o);
$validated = $request->validate([
'system_id' => 'required|exists:systems,id',
'remove' => 'nullable|boolean',
'remsess' => 'nullable|boolean|exclude_if:remove,1',
]);
$o->system_id = $validated['system_id'];
$o->save();
if (Arr::get($validated,'remove')) {
$so->sessions()->detach($o->zone);
$so->delete();
} elseif (Arr::get($validated,'remsess')) {
$so->sessions()->detach($o->zone);
}
return redirect()->to('ftn/system/addedit/'.$validated['system_id']);
}
return view('system.moveaddr')
->with('o',$o);
}
public function ours()
{
return view('system.ours');

View File

@ -398,6 +398,9 @@ ul#searchbar li i {
margin-bottom: 16px;
}
.actions {
width: 1%;
}
dl {
margin:1em -1px 0 1px
}
@ -488,7 +491,9 @@ label.list-group-item {
background-color: inherit;
color: inherit;
}
.nowrap {
white-space: nowrap;
}
p {
margin:0 0 1em;
padding:0;
@ -631,7 +636,7 @@ tbody {
.monotable tbody td {
padding-left:1.5ch!important;
padding-right:1.5ch!important;
vertical-align:middle!important
vertical-align:top;
}
.monotable tbody tr:first-child td {
padding-top:9px!important

View File

@ -45,7 +45,7 @@ use App\Models\Setup;
@if(! $o->system_id)
Add a <a href="{{ url('ftn/system/addedit') }}">NEW System</a>
@else
Edit <a href="{{ url('ftn/system/addedit',[$o->system_id]) }}">System</a>
<a href="{{ url('ftn/system/addedit',[$o->system_id]) }}">Edit</a> System
@endif
</span>
</div>

View File

@ -4,6 +4,10 @@
@if($o->exists) Update @else Add @endif System
@endsection
@php
use App\Http\Controllers\DomainController as DC;
@endphp
@section('content')
@if ($o->exists)
<h1>{{ $o->name }}@if($o->setup)<sup class="success" style="text-shadow: 0 0; font-size: 50%; top: -1em;">*</sup>@endif</h1>
@ -158,17 +162,17 @@
<td>{{ $oo->ftn }}</td>
<td>{{ $oo->active ? 'YES' : 'NO' }}</td>
<td>{{ $oo->role_name }}</td>
<td style="width: 70px;">
@if (! $oo->children)
<td class="nowrap actions">
@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/susaddress',[$oo->id]) }}" title="@if($oo->active)Pause @else Activate @endif Address"><i class="bi @if($oo->active)bi-pause-circle-fill @else bi-play-circle-fill @endif"></i></a>
{{--
@if (! $oo->role & (DC::NODE_ZC|DC::NODE_RC|DC::NODE_NC))
<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>
@endif
--}}
<a href="{{ url('ftn/system/movaddress',[$o->id,$oo->id]) }}" title="Move Address to another System"><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
@endif
</td>
</tr>
@endforeach
@ -211,7 +215,6 @@
<tbody>
@foreach($x as $zo)
<!-- @todo Not showing when multiple addresses in the same domain -->
@foreach ($o->match($zo) as $oo)
<tr>
<td>{{ $oo->ftn }}</td>

View File

@ -0,0 +1,137 @@
@extends('layouts.app')
@section('htmlheader_title')
Move Address
@endsection
@section('content')
<div class="row">
<div class="col-12">
<h1>{{ $o->system->name }} - {{ $o->ftn }}@if($o->system->setup)<sup class="success" style="text-shadow: 0 0; font-size: 50%; top: -1em;">*</sup>@endif</h1>
@if($o->system->setup)<sup class="success" style="float:right;top:-2em;">* This Host</sup>@endif
</div>
</div>
<div class="row pt-0">
<div class="col-12">
<!-- @todo The list of presented system should only be those that the user can see -->
<div class="greyframe titledbox shadow0xb0">
<h2 class="cap">Move Address</h2>
<form class="row g-0 needs-validation" method="post" novalidate>
@csrf
<div class="row">
<!-- Choose System -->
<div class="col-4">
<label for="system_id" class="form-label">Move <strong class="highlight">{{ $o->ftn }}</strong> to system:</label>
<div class="input-group has-validation">
<span class="input-group-text"><i class="bi bi-display-fill"></i></span>
<select style="width: 80%;" class="form-select @error('system_id') is-invalid @enderror" id="system_id" name="system_id" required @cannot('admin',$o)disabled @endcannot>
<option value="">&nbsp;</option>
@foreach (\App\Models\System::active()->where('id','<>',$o->system_id)->orderBy('name')->cursor() as $oo)
<option value="{{ $oo->id }}" @if(old('system_id')==$oo->id)selected @endif>{{ $oo->name }}</option>
@endforeach
</select>
<span class="invalid-feedback" role="alert">
@error('system_id')
{{ $message }}
@else
Please select the System that should have the address.
@enderror
</span>
<span class="input-helper">
Add a <a href="{{ url('ftn/system/addedit') }}">NEW System</a>
</span>
</div>
</div>
<div class="col-3">
<label for="remove" class="form-label">Delete System after Move</label>
<div class="input-group">
<div class="btn-group" role="group">
<input type="radio" class="btn-check" name="remove" id="remove_yes" value="1" @if($o->system->setup || $o->system->addresses->count() > 1)disabled @endif @if(old('remove',FALSE))checked @endif>
<label class="btn btn-outline-danger" for="remove_yes">Yes</label>
<input type="radio" class="btn-check" name="remove" id="remove_no" value="0" @if($o->system->addresses->count() > 1)disabled @endif @if(! old('remove',FALSE))checked @endif>
<label class="btn btn-outline-success" for="remove_no">No</label>
</div>
</div>
<span class="invalid-feedback" role="alert">
@error('remove')
{{ $message }}
@enderror
</span>
</div>
@if ($o->session('sespass'))
<div class="col-3" id="session-remove">
<label for="remsess" class="form-label">Remove Session Details for Zone</label>
<div class="input-group has-validation">
<div class="btn-group @error('remsess') is-invalid @enderror" role="group">
<input type="radio" class="btn-check" name="remsess" id="remsess_yes" value="1" @if($o->system->match($o->zone)->count() > 1)disabled @endif @if(old('remsess',FALSE))checked @endif>
<label class="btn btn-outline-danger" for="remsess_yes">Yes</label>
<input type="radio" class="btn-check" name="remsess" id="remsess_no" value="0" @if($o->system->match($o->zone)->count() > 1)disabled @endif @if(! old('remsess',FALSE))checked @endif>
<label class="btn btn-outline-success" for="remsess_no">No</label>
</div>
<span class="invalid-feedback" role="alert">
@error('remsess')
{{ $message }}
@enderror
</span>
</div>
</div>
@endif
</div>
<div class="row">
<div class="col-2">
<a href="{{ url('ftn/domain') }}" class="btn btn-danger">Cancel</a>
</div>
<span class="col-6 mt-auto mx-auto text-center align-bottom">
@if($errors->count())
<span class="btn btn-sm btn-danger" role="alert">
There were errors with the submission.
@dump($errors)
</span>
@endif
</span>
@can('admin',$o)
<div class="col-2">
<button type="submit" name="submit" class="btn btn-success float-end">Move</button>
</div>
@endcan
</div>
</form>
</div>
</div>
</div>
@endsection
@section('page-css')
<link type="text/css" rel="stylesheet" href="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/css/select2.min.css">
@append
@section('page-scripts')
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/js/select2.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('#system_id').select2();
@if ($o->session('sespass'))
$('#remove_yes').on('change',function() {
if (! $('#session-remove').hasClass('d-none'))
$('#session-remove').addClass('d-none');
});
$('#remove_no').on('change',function() {
if ($('#session-remove').hasClass('d-none'))
$('#session-remove').removeClass('d-none');
});
@endif
});
</script>
@append

View File

@ -50,6 +50,9 @@ Route::middleware(['verified','activeuser'])->group(function () {
Route::get('ftn/system/delsession/{o}/{zo}',[SystemController::class,'del_session'])
->where('o','[0-9]+')
->where('zo','[0-9]+');
Route::match(['get','post'],'ftn/system/movaddress/{so}/{o}',[SystemController::class,'mov_address'])
->where('so','[0-9]+')
->where('o','[0-9]+');
Route::get('ftn/system/susaddress/{o}',[SystemController::class,'sus_address'])
->where('o','[0-9]+');