Work on DN edit rendering

This commit is contained in:
Deon George 2023-04-12 08:17:57 +10:00
parent 20a2fede08
commit f01f88b3bd
14 changed files with 147 additions and 61 deletions

View File

@ -25,9 +25,6 @@ class Attribute
// Current and Old Values
protected Collection $values;
// Can this attribute be deleted
protected bool $is_deletable = FALSE;
// Is this attribute an internal attribute
protected bool $is_internal = FALSE;
@ -129,6 +126,8 @@ class Attribute
'description' => $this->schema ? $this->schema->{$key} : NULL,
// Attribute hints
'hints' => $this->hints(),
// Can this attribute be edited
'is_editable' => $this->schema ? $this->schema->{$key} : NULL,
// Is this an internal attribute
'is_internal' => isset($this->{$key}) && $this->{$key},
// Is this attribute the RDN

View File

@ -3,6 +3,7 @@
namespace App\Classes\LDAP\Attribute;
use Illuminate\Contracts\View\View;
use Illuminate\Support\Collection;
use App\Classes\LDAP\Attribute;
@ -11,15 +12,33 @@ use App\Classes\LDAP\Attribute;
*/
final class ObjectClass extends Attribute
{
public function __get(string $key): mixed
// Which of the values is the structural object class
protected Collection $structural;
public function __construct(string $name,array $values)
{
switch ($key) {
case 'is_structural': return FALSE; // @todo - need to determine which of the values is the structural objectclass value(s)
default:
return parent::__get($key);
parent::__construct($name,$values);
$this->structural = collect();
// Determine which of the values is the structural objectclass
foreach ($values as $oc) {
if (config('server')->schema('objectclasses',$oc)->isStructural())
$this->structural->push($oc);
}
}
/**
* Is a specific value the structural objectclass
*
* @param string $value
* @return bool
*/
public function isStructural(string $value): bool
{
return $this->structural->search($value) !== FALSE;
}
public function render(bool $edit=FALSE): View
{
return view('components.attribute.objectclass')

View File

@ -257,6 +257,7 @@ final class AttributeType extends Base {
case 'children': return $this->children;
case 'forced_as_may': return $this->forced_as_may;
case 'is_collective': return $this->is_collective;
case 'is_editable': return ! $this->is_no_user_modification;
case 'is_no_user_modification': return $this->is_no_user_modification;
case 'is_single_value': return $this->is_single_value;
case 'equality': return $this->equality;

View File

@ -39,9 +39,12 @@ class HomeController extends Controller
{
$dn = Crypt::decryptString($request->post('key'));
$page_actions = collect(['edit'=>TRUE,'copy'=>TRUE]);
return view('frames.dn')
->with('o',config('server')->fetch($dn))
->with('dn',$dn);
->with('dn',$dn)
->with('page_actions',$page_actions);
}
public function entry_update(EntryRequest $request)
@ -56,7 +59,8 @@ class HomeController extends Controller
Session::put('dn',$request->dn);
if (! $dirty=$o->getDirty())
return back()->with(['note'=>__('No attributes changed')]);
return back()
->with('note',__('No attributes changed'));
try {
$o->update($request->except(['_token','dn']));
@ -66,7 +70,8 @@ class HomeController extends Controller
switch ($x=$e->getDetailedError()->getErrorCode()) {
case 50:
return back()->withErrors(sprintf('%s: %s (%s)',__('LDAP Server Error Code'),$x,__($e->getDetailedError()->getErrorMessage())));
return back()
->withErrors(sprintf('%s: %s (%s)',__('LDAP Server Error Code'),$x,__($e->getDetailedError()->getErrorMessage())));
default:
abort(599,$e->getDetailedError()->getErrorMessage());
@ -77,7 +82,8 @@ class HomeController extends Controller
switch ($x=$e->getDetailedError()->getErrorCode()) {
case 8:
return back()->withErrors(sprintf('%s: %s (%s)',__('LDAP Server Error Code'),$x,__($e->getDetailedError()->getErrorMessage())));
return back()
->withErrors(sprintf('%s: %s (%s)',__('LDAP Server Error Code'),$x,__($e->getDetailedError()->getErrorMessage())));
default:
abort(599,$e->getDetailedError()->getErrorMessage());
@ -85,8 +91,8 @@ class HomeController extends Controller
}
return back()
->with(['success'=>__('Entry updated')])
->with(['updated'=>$dirty]);
->with('success',__('Entry updated'))
->with('updated',$dirty);
}
/**

18
public/css/fixes.css vendored
View File

@ -216,4 +216,20 @@ p {
margin: 5px 0 0;
}
}
*/
*/
/** Ensure our DN menu is at the top **/
.app-page-title .page-title-wrapper {
align-items: start;
}
/** Change the background on our read-only form items **/
.form-control:disabled, .form-control[readonly] {
background-color: #f9f9f9;
}
/** Make our placeholder text on forms lighter **/
.form-control::placeholder {
color: #a0aec0;
}

View File

@ -91,7 +91,7 @@
}
</style>
<script>
<script type="text/javascript">
// Example starter JavaScript for disabling form submissions if there are invalid fields
(function () {
'use strict';

View File

@ -14,33 +14,42 @@
</div>
</div>
@isset($page_actions)
@if (isset($page_actions) || old())
<div class="page-title-actions">
{{--
<button type="button" data-bs-toggle="tooltip" title="Example Tooltip" data-bs-placement="bottom" class="btn-shadow me-3 btn btn-dark">
<i class="fas fa-star"></i>
</button>
--}}
<div class="d-inline-block dropdown">
<button type="button" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false" class="btn-shadow dropdown-toggle btn btn-info">
<span class="btn-icon-wrapper pe-2 opacity-7">
<i class="fas fa-business-time fa-w-20"></i>
</span>
Item Menu
</button>
<div class="page-title-actions">
<div class="d-inline-block dropdown">
<button type="button" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false" class="dropdown-toggle btn btn-primary">
<span class="btn-icon-wrapper pe-2 opacity-7">
<i class="fa fa-business-time fa-w-20"></i>
</span>
@lang('Entry Options')
</button>
<div tabindex="-1" role="menu" aria-hidden="true" class="dropdown-menu dropdown-menu-right">
<ul class="nav flex-column">
{{--
<li class="nav-item">
<a href="javascript:void(0);" class="nav-link">
<i class="nav-link-icon lnr-inbox"></i>
<span>Inbox</span>
<div class="ms-auto badge rounded-pill bg-secondary">86</div>
</a>
</li>
--}}
</ul>
<div tabindex="-1" role="menu" aria-hidden="true" class="dropdown-menu dropdown-menu-right">
<ul class="nav flex-column">
@if ((isset($page_actions) && $page_actions->search('edit') !== FALSE) || old())
<li class="nav-item">
<span class="nav-link pt-0 pb-1">
<button id="entry-edit" class="p-2 m-0 border-0 btn-transition btn btn-outline-dark w-100 text-start">
<i class="fas fa-fw fa-edit me-2"></i>
@lang('Edit')
</button>
</span>
</li>
@endif
@if (isset($page_actions) && $page_actions->search('copy') !== FALSE)
<li class="nav-item">
<a class="nav-link pt-0 pb-1">
<button class="p-2 m-0 border-0 btn-transition btn btn-outline-dark w-100 text-start">
<i class="fas fa-fw fa-truck-moving me-2"></i>
@lang('Copy or Move')
</button>
</a>
</li>
@endif
</ul>
</div>
</div>
</div>
</div>

View File

@ -57,7 +57,7 @@
</div>
@section('page-scripts')
<script>
<script type="text/javascript">
$(document).ready(function() {
$('.server-icon').click(function(e) {
var content;

View File

@ -4,7 +4,7 @@
<div id="{{ $o->name_lc }}">
@foreach (old($o->name_lc,$o->values) as $value)
@if ($edit && ! $o->is_rdn)
<input class="form-control mb-1 @if($x=($o->values->search($value) === FALSE)) border-danger @endif" type="text" name="{{ $o->name_lc }}[]" value="{{ $value }}" @if($x)placeholder="{{ Arr::get($o->values,$loop->index) }}"@endif>
<input class="form-control mb-1 @if($x=($o->values->search($value) === FALSE)) border-focus @endif" type="text" name="{{ $o->name_lc }}[]" value="{{ $value }}" placeholder="{{ Arr::get($o->values,$loop->index) ?: '['.__('NEW').']' }}" readonly="true">
@else
{{ $value }}<br>
@endif
@ -16,7 +16,7 @@
@if($o->is_rdn)
<span class="btn btn-sm btn-outline-focus mt-3 mb-3"><i class="fas fa-fw fa-exchange"></i> @lang('Rename')</span>
@elseif($edit && $o->can_addvalues)
<div class="p-0 m-0 addable" id="{{ $o->name_lc }}">
<div class="p-0 m-0 addable d-none" id="{{ $o->name_lc }}">
<span class="btn btn-sm btn-outline-primary mt-3 mb-3"><i class="fas fa-fw fa-plus"></i> @lang('Add Value')</span>
</div>
@endif

View File

@ -6,10 +6,11 @@
@case('image/jpeg')
@default
<td>
<input type="hidden" name="{{ $o->name_lc }}[]" value="{{ md5($value) }}">
<img class="jpegphoto" src="data:{{ $x }};base64, {{ base64_encode($value) }}" />
@if($edit)
<br><span class="btn btn-sm btn-danger"><i class="fas fa-trash-alt"></i> @lang('Delete')</span>
<br><span class="btn btn-sm btn-danger deletable d-none"><i class="fas fa-trash-alt"></i> @lang('Delete')</span>
@endif
</td>
@endswitch

View File

@ -3,10 +3,15 @@
<div class="col-12">
<div id="{{ $o->name_lc }}">
@foreach (old($o->name_lc,$o->values) as $value)
@if ($edit && ! $o->is_structural)
<input class="form-control mb-1 @if($x=($o->values->search($value) === FALSE)) border-danger @endif" type="text" name="{{ $o->name_lc }}[]" value="{{ $value }}" @if($x)placeholder="{{ Arr::get($o->values,$loop->index) }}"@endif>
@if ($edit && ($value === NULL || (! $o->isStructural($value))))
<input class="form-control mb-1 @if($o->values->search($value) === FALSE) border-focus @endif" type="text" name="{{ $o->name_lc }}[]" value="{{ $value }}" placeholder="{{ Arr::get($o->values,$loop->index) ?: '['.__('NEW').']' }}" readonly="true">
@else
{{ $value }}@if ($o->is_structural)@lang('structural')@endif<br>
{{ $value }}
@if ($o->isStructural($value))
<input type="hidden" name="{{ $o->name_lc }}[]" value="{{ $value }}">
<span class="float-end mb-2">@lang('structural')</span>
@endif
<br>
@endif
@endforeach
</div>
@ -16,7 +21,7 @@
@if($o->is_rdn)
<span class="btn btn-sm btn-outline-focus mt-3 mb-3"><i class="fas fa-fw fa-exchange"></i> @lang('Rename')</span>
@elseif($edit && $o->can_addvalues)
<div class="p-0 m-0 addable" id="{{ $o->name_lc }}">
<div class="p-0 m-0 addable d-none" id="{{ $o->name_lc }}">
<span class="btn btn-sm btn-outline-primary mt-3 mb-3"><i class="fas fa-fw fa-plus"></i> @lang('Add Value')</span>
</div>
@endif

View File

@ -4,7 +4,7 @@
<div id="{{ $o->name_lc }}">
@foreach (old($o->name_lc,$o->values) as $value)
@if ($edit)
<input type="password" class="form-control mb-1 @if($x=($o->values->search($value) === FALSE)) border-danger @endif" type="text" name="{{ $o->name_lc }}[]" value="{{ str_repeat('*',10) }}">
<input type="password" class="form-control mb-1 @if($x=($o->values->search($value) === FALSE)) border-focus @endif" type="text" name="{{ $o->name_lc }}[]" value="{{ str_repeat('*',10) }}" readonly="true">
@else
{{ $value }}<br>
@endif

View File

@ -81,7 +81,7 @@
<input type="hidden" name="dn" value="{{ $o->getDNSecure() }}">
<div class="row">
<div class="offset-2 col-8">
<div class="col-12 offset-lg-2 col-lg-8">
<table class="table">
@foreach ($o->getVisibleAttributes() as $ao)
<tr class="bg-light text-dark small">
@ -106,7 +106,7 @@
</div>
</div>
<div class="row">
<div class="row d-none">
<div class="col-12 offset-sm-2 col-sm-4 col-lg-2">
<span id="form-reset" class="btn btn-outline-danger">@lang('Reset')</span>
<span id="form-submit" class="btn btn-success">@lang('Update')</span>
@ -118,7 +118,7 @@
<!-- Internal Attributes -->
<div class="tab-pane" id="internal" role="tabpanel">
<div class="row">
<div class="offset-2 col-8">
<div class="col-12 offset-lg-2 col-lg-8">
<table class="table">
@foreach ($o->getInternalAttributes() as $ao)
<tr class="bg-light text-dark small">
@ -155,7 +155,20 @@
@endsection
@section('page-scripts')
<script>
<script type="text/javascript">
function editmode() {
$('button[id=entry-edit]').addClass('active').removeClass('btn-outline-dark').addClass('btn-outline-light');
// Find all input items and turn off readonly
$('input.form-control').each(function() {
$(this).attr('readonly',false);
});
$('.row.d-none').removeClass('d-none');
$('.addable.d-none').removeClass('d-none');
$('.deletable.d-none').removeClass('d-none');
}
$(document).ready(function() {
$('#reset').click(function() {
$('#form-entry')[0].reset();
@ -168,9 +181,22 @@
// Create a new entry when Add Value clicked
$('.addable').click(function(item) {
var cln = $(this).parent().parent().find('input:last').clone();
cln.val('').attr('placeholder',undefined);
cln.val('').attr('placeholder','[@lang('NEW')]');
cln.appendTo('#'+item.currentTarget.id)
})
});
$('button[id=entry-edit]').on('click',function(item) {
item.preventDefault();
if ($(this).hasClass('active'))
return;
editmode();
});
@if(old())
editmode();
@endif
});
</script>
@append

View File

@ -40,11 +40,15 @@
@if(file_exists('home-note.html'))
<hr>
<div class="mx-auto card text-white card-body bg-primary w-50">
<h5 class="text-white card-title"><i class="icon fa-2x fas fa-info pe-3"></i><span class="font-size-xlg">NOTE</span></h5>
<span class="w-100 pb-0">
{!! file_get_contents('home-note.html') !!}
</span>
<div class="row">
<div class="col-12 offset-lg-2 col-lg-8">
<div class="mx-auto card text-white card-body bg-primary">
<h5 class="text-white card-title"><i class="icon fa-2x fas fa-info pe-3"></i><span class="font-size-xlg">NOTE</span></h5>
<span class="w-100 pb-0">
{!! file_get_contents('home-note.html') !!}
</span>
</div>
</div>
</div>
@endif
@endsection