FEATURE: add custom fields overview
This commit is contained in:
@@ -2,16 +2,24 @@
|
|||||||
|
|
||||||
namespace App\Http\Controllers\Admin;
|
namespace App\Http\Controllers\Admin;
|
||||||
|
|
||||||
use App\Enumerations\UserRoles;
|
use App\Enumerations\CustomFieldResources;
|
||||||
|
use App\Enumerations\CustomFieldTypes;
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
use App\Http\Requests;
|
use App\Http\Requests;
|
||||||
use App\Http\Requests\CreateNewUserRequest;
|
use App\Models\CustomField;
|
||||||
use App\Models\User;
|
|
||||||
use Illuminate\Http\Request;
|
|
||||||
use Illuminate\Support\Facades\Hash;
|
|
||||||
|
|
||||||
class CustomFieldsOverview extends Controller {
|
class CustomFieldsOverview extends Controller
|
||||||
public function getOverview() {
|
{
|
||||||
return view('admin.customFields.overview');
|
public function getOverview()
|
||||||
|
{
|
||||||
|
$model = new CustomField();
|
||||||
|
$fields = $model->getIndexedByResource();
|
||||||
|
|
||||||
|
return view('admin.customFields.overview', [
|
||||||
|
'customFields' => $fields,
|
||||||
|
'usedResources' => array_keys($fields),
|
||||||
|
'resources' => CustomFieldResources::getWithTranslations(),
|
||||||
|
'types' => CustomFieldTypes::getWithTranslations()
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -9,9 +9,7 @@ use Illuminate\Database\Eloquent\Model;
|
|||||||
*/
|
*/
|
||||||
class CustomField extends Model
|
class CustomField extends Model
|
||||||
{
|
{
|
||||||
|
|
||||||
public $timestamps = false;
|
public $timestamps = false;
|
||||||
|
|
||||||
protected $fillable = [
|
protected $fillable = [
|
||||||
'name',
|
'name',
|
||||||
'type_id',
|
'type_id',
|
||||||
@@ -24,8 +22,24 @@ class CustomField extends Model
|
|||||||
'max_length',
|
'max_length',
|
||||||
'required'
|
'required'
|
||||||
];
|
];
|
||||||
|
|
||||||
protected $guarded = [];
|
protected $guarded = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter for all custom fields indexed by resource ID.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function getIndexedByResource()
|
||||||
|
{
|
||||||
|
// find all records in table
|
||||||
|
$fields = CustomField::all();
|
||||||
|
|
||||||
|
// add them to array indexed by resource ID
|
||||||
|
$customFields = [];
|
||||||
|
foreach ($fields as $field) {
|
||||||
|
$customFields[$field->resource_id][] = $field;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $customFields;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -10,6 +10,52 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
|
|
||||||
|
{{--draw tabs--}}
|
||||||
|
@if (!empty($usedResources))
|
||||||
|
<ul class="tabs" data-tabs id="customFieldsOverview">
|
||||||
|
<?php $isFirst = true?>
|
||||||
|
@foreach($usedResources as $i => $resource)
|
||||||
|
<li class="tabs-title @if($isFirst)is-active @endif"><a href="#customFieldResource{{$resource}}">@lang($resources[$resource]){{key($usedResources)}}</a></li>
|
||||||
|
<?php $isFirst = false?>
|
||||||
|
@endforeach
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
{{--display list of custom fields--}}
|
||||||
|
<?php $isFirst = true?>
|
||||||
|
<div class="tabs-content" data-tabs-content="customFieldsOverview">
|
||||||
|
@foreach($customFields as $resourceId => $fields)
|
||||||
|
<div class="tabs-panel @if($isFirst)is-active @endif" id="customFieldResource{{$resourceId}}">
|
||||||
|
<table class="full-width">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>@lang('admin/customFields.name')</th>
|
||||||
|
<th>@lang('admin/customFields.description')</th>
|
||||||
|
<th>@lang('admin/customFields.type')</th>
|
||||||
|
<th></th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
@foreach($fields as $field)
|
||||||
|
<tr>
|
||||||
|
<td>{{$field->name}}</td>
|
||||||
|
<td>{{str_limit($field->description)}}</td>
|
||||||
|
<td>@lang($types[$field->type_id])</td>
|
||||||
|
<td>
|
||||||
|
<a href="#"><i class="fa red confirm fa-remove"></i></a>
|
||||||
|
<a href="#"><i class="fa green fa-edit"></i></a>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
@endforeach
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
<?php $isFirst = false?>
|
||||||
|
@endforeach
|
||||||
|
</div>
|
||||||
|
|
||||||
|
@else
|
||||||
<em>@lang('admin/customFields.noFields')</em>
|
<em>@lang('admin/customFields.noFields')</em>
|
||||||
|
@endif
|
||||||
</div>
|
</div>
|
||||||
@stop
|
@stop
|
||||||
Reference in New Issue
Block a user