Enabled adding new attributes to a DN

This commit is contained in:
2023-09-02 20:50:54 +10:00
parent 6d900d0964
commit 652cdee034
22 changed files with 403 additions and 105 deletions

View File

@@ -0,0 +1,20 @@
<!-- $o=AttributeType::class -->
<div class="row pb-3">
<div class="col-12 col-sm-1 col-md-2"></div>
<div class="col-12 col-sm-10 col-md-8">
<div class="row">
<div class="col-12 bg-light text-dark p-2">
<strong><abbr title="{{ $o->description }}">{{ $o->name }}</abbr></strong>
<!-- Attribute Hints -->
<span class="float-end small">
@foreach($o->hints as $name => $description)
@if ($loop->index),@endif
<abbr title="{{ $description }}">{{ $name }}</abbr>
@endforeach
</span>
</div>
</div>
<x-attribute :edit="true" :new="$new" :o="$o"/>
</div>
</div>

View File

@@ -1,31 +1,26 @@
<!-- $o=Attribute::class -->
<div class="row">
<div class="col-12">
<div class="row pt-2">
<div class="col-1"></div>
<div class="col-10 p-2">
<div id="{{ $o->name_lc }}">
@foreach (old($o->name_lc,$o->values) as $value)
@foreach (old($o->name_lc,$new ? [NULL] : $o->values) as $value)
@if ($edit && ! $o->is_rdn)
<div class="input-group has-validation">
<input type="text" class="form-control @if($e=$errors->get($o->name_lc.'.'.$loop->index))is-invalid @endif mb-1 @if($o->values->search($value) === FALSE) border-focus @endif" name="{{ $o->name_lc }}[]" value="{{ $value }}" placeholder="{{ ! is_null($x=Arr::get($o->values,$loop->index)) ? $x : '['.__('NEW').']' }}" readonly="true">
<input type="text" class="form-control @if($e=$errors->get($o->name_lc.'.'.$loop->index))is-invalid @endif mb-1 @if($o->values->search($value) === FALSE) border-focus @endif" name="{{ $o->name_lc }}[]" value="{{ $value }}" placeholder="{{ ! is_null($x=Arr::get($o->values,$loop->index)) ? $x : '['.__('NEW').']' }}" @if (! $new)readonly="true" @endif">
<div class="invalid-feedback pb-2">
@if($e)
{{ join('|',$e) }}
@endif
</div>
</div>
@else
{{ $value }}<br>
{{ $value }}
@endif
@endforeach
</div>
</div>
<div class="col-12 col-sm-6 col-lg-4">
@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 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
@include('components.attribute.widget.options')
</div>
</div>
</div>

View File

@@ -3,31 +3,31 @@
<div class="input-group has-validation @if($e=$errors->get($o->name_lc))is-invalid @endif">
@endif
<table class="table table-borderless p-0 m-0">
<tr>
@foreach ($o->values as $value)
@switch ($x=$f->buffer($value,FILEINFO_MIME_TYPE))
@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) }}" />
<table class="table table-borderless p-0 m-0">
<tr>
@foreach ($o->values as $value)
@switch ($x=$f->buffer($value,FILEINFO_MIME_TYPE))
@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 deletable d-none"><i class="fas fa-trash-alt"></i> @lang('Delete')</span>
@endif
</td>
@endswitch
@endforeach
</tr>
</table>
@if($edit)
<div class="invalid-feedback pb-2">
@if($e)
{{ join('|',$e) }}
@endif
</div>
@if($edit)
<br><span class="btn btn-sm btn-danger deletable d-none"><i class="fas fa-trash-alt"></i> @lang('Delete')</span>
@endif
</td>
@endswitch
@endforeach
</tr>
</table>
@if($edit)
<div class="invalid-feedback pb-2">
@if($e)
{{ join('|',$e) }}
@endif
</div>
@endif
</div>
@endif

View File

@@ -1,6 +1,7 @@
<!-- $o=Attribute::class -->
<div class="row">
<div class="col-12">
<div class="col-1"></div>
<div class="col-10 p-2">
<div id="{{ $o->name_lc }}">
@foreach (old($o->name_lc,$o->values) as $value)
@if ($edit && ($value === NULL || (! $o->isStructural($value))))
@@ -22,15 +23,7 @@
@endif
@endforeach
</div>
</div>
<div class="col-12 col-sm-6 col-lg-4">
@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 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
@include('components.attribute.widget.options')
</div>
</div>

View File

@@ -0,0 +1,34 @@
@if($o->is_rdn)
<span class="btn btn-sm btn-outline-focus mt-3"><i class="fas fa-fw fa-exchange"></i> @lang('Rename')</span>
@elseif($edit && $o->can_addvalues)
<div class="p-0 m-0">
<span class="btn btn-sm btn-outline-primary mt-3 addable @if(! $new)d-none @endif" id="{{ $o->name_lc }}"><i class="fas fa-fw fa-plus"></i> @lang('Add Value')</span>
@if($new)
<script type="text/javascript">
$(document).ready(function() {
// Create a new entry when Add Value clicked
$('#{{ $o->name_lc }}.addable').click(function (item) {
var cln = $(this).parent().parent().find('input:last').clone();
cln.val('').attr('placeholder', '[@lang('NEW')]');
cln.appendTo('#' + item.currentTarget.id)
});
});
</script>
@endif
</div>
@endif
@section('page-scripts')
@if(($edit && $o->can_addvalues))
<script type="text/javascript">
$(document).ready(function() {
// Create a new entry when Add Value clicked
$('#{{ $o->name_lc }}.addable').click(function (item) {
var cln = $(this).parent().parent().find('input:last').clone();
cln.val('').attr('placeholder', '[@lang('NEW')]');
cln.appendTo('#' + item.currentTarget.id)
});
});
</script>
@endif
@append

View File

@@ -49,6 +49,7 @@
</div>
@endif
<!-- @todo If we are redirected here, check old() and add back any attributes that were in the original submission -->
@if($errors->any())
<div class="alert alert-danger">
<h4 class="alert-heading"><i class="fas fa-fw fa-thumbs-down"></i> Error?</h4>
@@ -75,38 +76,48 @@
<div class="tab-content">
<!-- All Attributes -->
<div class="tab-pane active" id="attributes" role="tabpanel">
<form id="form-entry" method="POST" class="needs-validation" action="{{ url('entry/update') }}" novalidate>
<form id="dn-edit" method="POST" class="needs-validation" action="{{ url('entry/update/pending') }}" novalidate>
@csrf
<input type="hidden" name="dn" value="{{ $o->getDNSecure() }}">
@foreach ($o->getVisibleAttributes() as $ao)
<x-attribute-type :edit="true" :o="$ao"/>
@endforeach
<div id="newattrs"></div>
<!-- Add new attributes -->
<div class="row">
<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">
<th class="w-25">
<abbr title="{{ $ao->description }}">{{ $ao->name }}</abbr>
<!-- Attribute Hints -->
<span class="float-end">
@foreach($ao->hints as $name => $description)
@if ($loop->index),@endif
<abbr title="{{ $description }}">{{ $name }}</abbr>
@endforeach
</span>
</th>
</tr>
<tr>
<td class="ps-5">
<x-attribute :edit="true" :o="$ao"/>
</td>
</tr>
@endforeach
</table>
<div class="col-12 col-sm-1 col-md-2"></div>
<div class="col-12 col-sm-10 col-md-8">
<div class="d-none" id="newattr-select">
@if($o->getMissingAttributes()->count())
<div class="row">
<div class="col-12 bg-dark text-light p-2">
<i class="fas fa-plus-circle"></i> Add New Attribute
</div>
</div>
<div class="row">
<div class="col-12 pt-2">
<label for="newattr" class="form-label">Select from...</label>
<select class="form-select" id="newattr">
<option value="">&nbsp;</option>
@foreach ($o->getMissingAttributes() as $ao)
<option value="{{ $ao->name_lc }}">{{ $ao->name }}</option>
@endforeach
</select>
</div>
</div>
@endif
</div>
</div>
<div class="col-2"></div>
</div>
<div class="row d-none">
<div class="row d-none pt-3">
<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>
@@ -140,12 +151,15 @@
<!-- Debug -->
<div class="tab-pane" id="debug" role="tabpanel">
<div class="row">
<div class="col-6">
<div class="col-4">
@dump($o)
</div>
<div class="col-6">
<div class="col-4">
@dump($o->getAttributes())
</div>
<div class="col-4">
@dump(['available'=>$o->getAvailableAttributes()->pluck('name'),'missing'=>$o->getMissingAttributes()->pluck('name')])
</div>
</div>
</div>
</div>
@@ -167,22 +181,43 @@
$('.row.d-none').removeClass('d-none');
$('.addable.d-none').removeClass('d-none');
$('.deletable.d-none').removeClass('d-none');
@if($o->getMissingAttributes()->count())
$('#newattr-select.d-none').removeClass('d-none');
@endif
}
$(document).ready(function() {
$('#reset').click(function() {
$('#form-entry')[0].reset();
$('#form-reset').click(function() {
$('#dn-edit')[0].reset();
})
$('#form-submit').click(function() {
$('#form-entry')[0].submit();
$('#dn-edit')[0].submit();
})
// 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','[@lang('NEW')]');
cln.appendTo('#'+item.currentTarget.id)
$('#newattr').on('change',function(item) {
$.ajax({
type: 'GET',
beforeSend: function() {
},
success: function(data) {
$('#newattrs').append(data);
},
error: function(e) {
if (e.status != 412)
alert('That didnt work? Please try again....');
},
url: '{{ url('entry/newattr') }}/'+item.target.value,
cache: false
})
// Remove the option from the list
$(this).find('[value="'+item.target.value+'"]').remove()
// If there are no more options
if ($(this).find("option").length === 1)
$('#newattr-select').remove();
});
$('button[id=entry-edit]').on('click',function(item) {

View File

@@ -0,0 +1,111 @@
@extends('dn')
@section('page_title')
<table class="table table-borderless">
<tr>
<td class="{{ ($x=Arr::get($o->getAttributes(),'jpegphoto')) ? 'border' : '' }}" rowspan="2">{!! $x ? $x->render() : sprintf('<div class="page-title-icon f32"><i class="%s"></i></div>',$o->icon() ?? "fas fa-info") !!}</td>
<td class="text-end align-text-top p-0 {{ $x ? 'ps-5' : 'pt-2' }}"><strong>{{ $dn }}</strong></td>
</tr>
<tr>
<td class="line-height-1" style="font-size: 55%;vertical-align: bottom;" colspan="2">
<table>
<tr>
<td class="p-1 m-1">Created</td>
<th class="p-1 m-1">{{ ($x=Arr::get($o->getAttributes(),'createtimestamp')) ? $x->render() : __('Unknown') }} [{{ ($x=Arr::get($o->getAttributes(),'creatorsname')) ? $x->render() : __('Unknown') }}]</th>
</tr>
<tr>
<td class="p-1 m-1">Modified</td>
<th class="p-1 m-1">{{ ($x=Arr::get($o->getAttributes(),'modifytimestamp')) ? $x->render() : __('Unknown') }} [{{ ($x=Arr::get($o->getAttributes(),'modifiersname')) ? $x->render() : __('Unknown') }}]</th>
</tr>
<tr>
<td class="p-1 m-1">UUID</td>
<th class="p-1 m-1">{{ $o->entryuuid[0] ?? '' }}</th>
</tr>
</table>
</td>
</tr>
</table>
@endsection
@section('main-content')
@if(session()->has('note'))
<div class="alert alert-info">
<h4 class="alert-heading"><i class="fas fa-fw fa-note-sticky"></i> Note:</h4>
<hr>
<p>{{ session()->pull('note') }}</p>
</div>
@endif
@if(session()->has('success'))
<div class="alert alert-success">
<h4 class="alert-heading"><i class="fas fa-fw fa-thumbs-up"></i> Success!</h4>
<hr>
<p>{{ session()->pull('success') }}</p>
<ul style="list-style-type: square;">
@foreach (session()->pull('updated') as $key => $values)
<li>{{ $key }}: {{ join(',',$values) }}</li>
@endforeach
</ul>
</div>
@endif
@if($errors->any())
<div class="alert alert-danger">
<h4 class="alert-heading"><i class="fas fa-fw fa-thumbs-down"></i> Error?</h4>
<hr>
<ul style="list-style-type: square;">
@foreach ($errors->all() as $error)
<li>{{ $error }}</li>
@endforeach
</ul>
</div>
@endif
<div class="main-card mb-3 card">
<div class="card-body">
<div class="row">
<div class="col-12 col-lg-6 col-xl-4 mx-auto pt-3">
<form id="dn-edit" method="POST" class="needs-validation" action="{{ url('entry/update/commit') }}" novalidate>
@csrf
<input type="hidden" name="dn" value="{{ $o->getDNSecure() }}">
<div class="card-title"><h3>@lang('Do you want to make the following changes?')</h3></div>
<table class="table table-bordered table-striped">
<thead>
<tr>
<th>Attribute</th>
<th>OLD</th>
<th>NEW</th>
</tr>
</thead>
<tbody>
@foreach ($o->getDirty() as $key => $value)
<tr>
<th rowspan="{{ $x=max(count($value),count(Arr::get($o->getOriginal(),$key,[])))}}">{{ $key }}</th>
@for($xx=0;$xx<$x;$xx++)
@if($xx)
</tr><tr>
@endif
<td>{{ Arr::get(Arr::get($o->getOriginal(),$key,['['.strtoupper(__('New Value')).']']),$xx) }}</td>
<td>{{ $y=Arr::get($value,$xx) }}<input type="hidden" name="{{ $key }}[]" value="{{ $y }}"></td>
@endfor
</tr>
@endforeach
</tbody>
</table>
</form>
</div>
<div class="row pt-3">
<div class="col-12 offset-sm-2 col-sm-4 col-lg-2 mx-auto">
<span id="form-reset" class="btn btn-outline-danger">@lang('Reset')</span>
<span id="form-submit" class="btn btn-success">@lang('Update')</span>
</div>
</div>
</div>
</div>
</div>
@endsection