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

View File

@ -3,6 +3,7 @@
namespace App\Classes\LDAP\Attribute; namespace App\Classes\LDAP\Attribute;
use Illuminate\Contracts\View\View; use Illuminate\Contracts\View\View;
use Illuminate\Support\Collection;
use App\Classes\LDAP\Attribute; use App\Classes\LDAP\Attribute;
@ -11,15 +12,33 @@ use App\Classes\LDAP\Attribute;
*/ */
final class ObjectClass extends 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) { parent::__construct($name,$values);
case 'is_structural': return FALSE; // @todo - need to determine which of the values is the structural objectclass value(s)
default: $this->structural = collect();
return parent::__get($key);
// 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 public function render(bool $edit=FALSE): View
{ {
return view('components.attribute.objectclass') return view('components.attribute.objectclass')

View File

@ -257,6 +257,7 @@ final class AttributeType extends Base {
case 'children': return $this->children; case 'children': return $this->children;
case 'forced_as_may': return $this->forced_as_may; case 'forced_as_may': return $this->forced_as_may;
case 'is_collective': return $this->is_collective; 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_no_user_modification': return $this->is_no_user_modification;
case 'is_single_value': return $this->is_single_value; case 'is_single_value': return $this->is_single_value;
case 'equality': return $this->equality; case 'equality': return $this->equality;

View File

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

18
public/css/fixes.css vendored
View File

@ -216,4 +216,20 @@ p {
margin: 5px 0 0; 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> </style>
<script> <script type="text/javascript">
// Example starter JavaScript for disabling form submissions if there are invalid fields // Example starter JavaScript for disabling form submissions if there are invalid fields
(function () { (function () {
'use strict'; 'use strict';

View File

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

View File

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

View File

@ -4,7 +4,7 @@
<div id="{{ $o->name_lc }}"> <div id="{{ $o->name_lc }}">
@foreach (old($o->name_lc,$o->values) as $value) @foreach (old($o->name_lc,$o->values) as $value)
@if ($edit && ! $o->is_rdn) @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 @else
{{ $value }}<br> {{ $value }}<br>
@endif @endif
@ -16,7 +16,7 @@
@if($o->is_rdn) @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> <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) @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> <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> </div>
@endif @endif

View File

@ -6,10 +6,11 @@
@case('image/jpeg') @case('image/jpeg')
@default @default
<td> <td>
<input type="hidden" name="{{ $o->name_lc }}[]" value="{{ md5($value) }}">
<img class="jpegphoto" src="data:{{ $x }};base64, {{ base64_encode($value) }}" /> <img class="jpegphoto" src="data:{{ $x }};base64, {{ base64_encode($value) }}" />
@if($edit) @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 @endif
</td> </td>
@endswitch @endswitch

View File

@ -3,10 +3,15 @@
<div class="col-12"> <div class="col-12">
<div id="{{ $o->name_lc }}"> <div id="{{ $o->name_lc }}">
@foreach (old($o->name_lc,$o->values) as $value) @foreach (old($o->name_lc,$o->values) as $value)
@if ($edit && ! $o->is_structural) @if ($edit && ($value === NULL || (! $o->isStructural($value))))
<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($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 @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 @endif
@endforeach @endforeach
</div> </div>
@ -16,7 +21,7 @@
@if($o->is_rdn) @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> <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) @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> <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> </div>
@endif @endif

View File

@ -4,7 +4,7 @@
<div id="{{ $o->name_lc }}"> <div id="{{ $o->name_lc }}">
@foreach (old($o->name_lc,$o->values) as $value) @foreach (old($o->name_lc,$o->values) as $value)
@if ($edit) @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 @else
{{ $value }}<br> {{ $value }}<br>
@endif @endif

View File

@ -81,7 +81,7 @@
<input type="hidden" name="dn" value="{{ $o->getDNSecure() }}"> <input type="hidden" name="dn" value="{{ $o->getDNSecure() }}">
<div class="row"> <div class="row">
<div class="offset-2 col-8"> <div class="col-12 offset-lg-2 col-lg-8">
<table class="table"> <table class="table">
@foreach ($o->getVisibleAttributes() as $ao) @foreach ($o->getVisibleAttributes() as $ao)
<tr class="bg-light text-dark small"> <tr class="bg-light text-dark small">
@ -106,7 +106,7 @@
</div> </div>
</div> </div>
<div class="row"> <div class="row d-none">
<div class="col-12 offset-sm-2 col-sm-4 col-lg-2"> <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-reset" class="btn btn-outline-danger">@lang('Reset')</span>
<span id="form-submit" class="btn btn-success">@lang('Update')</span> <span id="form-submit" class="btn btn-success">@lang('Update')</span>
@ -118,7 +118,7 @@
<!-- Internal Attributes --> <!-- Internal Attributes -->
<div class="tab-pane" id="internal" role="tabpanel"> <div class="tab-pane" id="internal" role="tabpanel">
<div class="row"> <div class="row">
<div class="offset-2 col-8"> <div class="col-12 offset-lg-2 col-lg-8">
<table class="table"> <table class="table">
@foreach ($o->getInternalAttributes() as $ao) @foreach ($o->getInternalAttributes() as $ao)
<tr class="bg-light text-dark small"> <tr class="bg-light text-dark small">
@ -155,7 +155,20 @@
@endsection @endsection
@section('page-scripts') @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() { $(document).ready(function() {
$('#reset').click(function() { $('#reset').click(function() {
$('#form-entry')[0].reset(); $('#form-entry')[0].reset();
@ -168,9 +181,22 @@
// Create a new entry when Add Value clicked // Create a new entry when Add Value clicked
$('.addable').click(function(item) { $('.addable').click(function(item) {
var cln = $(this).parent().parent().find('input:last').clone(); 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) 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> </script>
@append @append

View File

@ -40,11 +40,15 @@
@if(file_exists('home-note.html')) @if(file_exists('home-note.html'))
<hr> <hr>
<div class="mx-auto card text-white card-body bg-primary w-50"> <div class="row">
<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> <div class="col-12 offset-lg-2 col-lg-8">
<span class="w-100 pb-0"> <div class="mx-auto card text-white card-body bg-primary">
{!! file_get_contents('home-note.html') !!} <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> <span class="w-100 pb-0">
{!! file_get_contents('home-note.html') !!}
</span>
</div>
</div>
</div> </div>
@endif @endif
@endsection @endsection