Started working on user-defined-fields for all entities (references #176)

This commit is contained in:
Bernd Bestel
2019-04-22 22:16:35 +02:00
parent 77f3b80540
commit fc11da3c3f
45 changed files with 1161 additions and 78 deletions

View File

@@ -12,6 +12,9 @@
<a class="btn btn-outline-dark" href="{{ $U('/battery/new') }}">
<i class="fas fa-plus"></i>&nbsp;{{ $L('Add') }}
</a>
<a class="btn btn-outline-secondary" href="{{ $U('/userfields?entity=batteries') }}">
<i class="fas fa-sliders-h"></i>&nbsp;{{ $L('Configure userfields') }}
</a>
</h1>
</div>
</div>
@@ -33,6 +36,11 @@
<th>{{ $L('Description') }}</th>
<th>{{ $L('Used in') }}</th>
<th>{{ $L('Charge cycle interval (days)') }}</th>
@include('components.userfields_thead', array(
'userfields' => $userfields
))
</tr>
</thead>
<tbody class="d-none">
@@ -58,6 +66,12 @@
<td>
{{ $battery->charge_interval_days }}
</td>
@include('components.userfields_tbody', array(
'userfields' => $userfields,
'userfieldValues' => FindAllObjectsInArrayByPropertyValue($userfieldValues, 'object_id', $battery->id)
))
</tr>
@endforeach
</tbody>

View File

@@ -46,6 +46,11 @@
<th>{{ $L('Last charged') }}</th>
<th>{{ $L('Next planned charge cycle') }}</th>
<th class="d-none">Hidden status</th>
@include('components.userfields_thead', array(
'userfields' => $userfields
))
</tr>
</thead>
<tbody class="d-none">
@@ -92,6 +97,12 @@
<td class="d-none">
"@if(FindObjectInArrayByPropertyValue($batteries, 'id', $curentBatteryEntry->battery_id)->charge_interval_days > 0 && $curentBatteryEntry->next_estimated_charge_time < date('Y-m-d H:i:s')) overdue @elseif(FindObjectInArrayByPropertyValue($batteries, 'id', $curentBatteryEntry->battery_id)->charge_interval_days > 0 && $curentBatteryEntry->next_estimated_charge_time < date('Y-m-d H:i:s', strtotime("+$nextXDays days"))) duesoon @endif
</td>
@include('components.userfields_tbody', array(
'userfields' => $userfields,
'userfieldValues' => FindAllObjectsInArrayByPropertyValue($userfieldValues, 'object_id', $curentBatteryEntry->battery_id)
))
</tr>
@endforeach
</tbody>

View File

@@ -47,6 +47,11 @@
'invalidFeedback' => $L('This cannot be negative')
))
@include('components.userfieldsform', array(
'userfields' => $userfields,
'entity' => 'batteries'
))
<button id="save-battery-button" class="btn btn-success">{{ $L('Save') }}</button>
</form>

View File

@@ -87,6 +87,11 @@
<input type="hidden" id="period_config" name="period_config" value="@if($mode == 'edit'){{ $chore->period_config }}@endif">
@include('components.userfieldsform', array(
'userfields' => $userfields,
'entity' => 'chores'
))
<button id="save-chore-button" class="btn btn-success">{{ $L('Save') }}</button>
</form>

View File

@@ -12,6 +12,9 @@
<a class="btn btn-outline-dark" href="{{ $U('/chore/new') }}">
<i class="fas fa-plus"></i>&nbsp;{{ $L('Add') }}
</a>
<a class="btn btn-outline-secondary" href="{{ $U('/userfields?entity=chores') }}">
<i class="fas fa-sliders-h"></i>&nbsp;{{ $L('Configure userfields') }}
</a>
</h1>
</div>
</div>
@@ -32,6 +35,11 @@
<th>{{ $L('Name') }}</th>
<th>{{ $L('Period type') }}</th>
<th>{{ $L('Description') }}</th>
@include('components.userfields_thead', array(
'userfields' => $userfields
))
</tr>
</thead>
<tbody class="d-none">
@@ -54,6 +62,12 @@
<td>
{{ $chore->description }}
</td>
@include('components.userfields_tbody', array(
'userfields' => $userfields,
'userfieldValues' => FindAllObjectsInArrayByPropertyValue($userfieldValues, 'object_id', $chore->id)
))
</tr>
@endforeach
</tbody>

View File

@@ -46,6 +46,11 @@
<th>{{ $L('Next estimated tracking') }}</th>
<th>{{ $L('Last tracked') }}</th>
<th class="d-none">Hidden status</th>
@include('components.userfields_thead', array(
'userfields' => $userfields
))
</tr>
</thead>
<tbody class="d-none">
@@ -92,6 +97,12 @@
<td class="d-none">
@if(FindObjectInArrayByPropertyValue($chores, 'id', $curentChoreEntry->chore_id)->period_type !== \Grocy\Services\ChoresService::CHORE_TYPE_MANUALLY && $curentChoreEntry->next_estimated_execution_time < date('Y-m-d H:i:s')) overdue @elseif(FindObjectInArrayByPropertyValue($chores, 'id', $curentChoreEntry->chore_id)->period_type !== \Grocy\Services\ChoresService::CHORE_TYPE_MANUALLY && $curentChoreEntry->next_estimated_execution_time < date('Y-m-d H:i:s', strtotime("+$nextXDays days"))) duesoon @endif
</td>
@include('components.userfields_tbody', array(
'userfields' => $userfields,
'userfieldValues' => FindAllObjectsInArrayByPropertyValue($userfieldValues, 'object_id', $curentChoreEntry->chore_id)
))
</tr>
@endforeach
</tbody>

View File

@@ -0,0 +1,16 @@
@push('componentScripts')
<script src="{{ $U('/viewjs/components/userfieldsform.js', true) }}?v={{ $version }}"></script>
@endpush
@if(count($userfields) > 0)
@foreach($userfields as $userfield)
@if($userfield->show_as_column_in_tables == 1)
@php $userfieldObject = FindObjectInArrayByPropertyValue($userfieldValues, 'name', $userfield->name) @endphp
<td>@if($userfieldObject !== null){{ $userfieldObject->value }}@endif</td>
@endif
@endforeach
@endif

View File

@@ -0,0 +1,15 @@
@push('componentScripts')
<script src="{{ $U('/viewjs/components/userfieldsform.js', true) }}?v={{ $version }}"></script>
@endpush
@if(count($userfields) > 0)
@foreach($userfields as $userfield)
@if($userfield->show_as_column_in_tables == 1)
<th>{{ $userfield->name }}</th>
@endif
@endforeach
@endif

View File

@@ -0,0 +1,32 @@
@push('componentScripts')
<script src="{{ $U('/viewjs/components/userfieldsform.js', true) }}?v={{ $version }}"></script>
@endpush
@if(count($userfields) > 0)
<div id="userfields-form" data-entity="{{ $entity }}" class="border border-info p-2 mb-2" novalidate>
<h2 class="small">{{ $L('Userfields') }}</h2>
@foreach($userfields as $userfield)
@if($userfield->type == \Grocy\Services\UserfieldsService::USERFIELD_TYPE_SINGLE_LINE_TEXT)
<div class="form-group">
<label for="name">{{ $userfield->caption }}</label>
<input type="text" class="form-control userfield-input" id="{{ $userfield->name }}" value="">
</div>
@endif
@if($userfield->type == \Grocy\Services\UserfieldsService::USERFIELD_TYPE_CHECKBOX)
<div class="form-group">
<div class="form-check">
<input class="form-check-input userfield-input" type="checkbox" id="{{ $userfield->name }}" value="1">
<label class="form-check-label" for="{{ $userfield->name }}">{{ $userfield->caption }}</label>
</div>
</div>
@endif
@endforeach
</div>
@endif

View File

@@ -32,6 +32,11 @@
<textarea class="form-control" rows="2" id="description" name="description">@if($mode == 'edit'){{ $location->description }}@endif</textarea>
</div>
@include('components.userfieldsform', array(
'userfields' => $userfields,
'entity' => 'locations'
))
<button id="save-location-button" class="btn btn-success">{{ $L('Save') }}</button>
</form>

View File

@@ -12,6 +12,9 @@
<a class="btn btn-outline-dark" href="{{ $U('/location/new') }}">
<i class="fas fa-plus"></i>&nbsp;{{ $L('Add') }}
</a>
<a class="btn btn-outline-secondary" href="{{ $U('/userfields?entity=locations') }}">
<i class="fas fa-sliders-h"></i>&nbsp;{{ $L('Configure userfields') }}
</a>
</h1>
</div>
</div>
@@ -31,6 +34,11 @@
<th class="border-right"></th>
<th>{{ $L('Name') }}</th>
<th>{{ $L('Description') }}</th>
@include('components.userfields_thead', array(
'userfields' => $userfields
))
</tr>
</thead>
<tbody class="d-none">
@@ -50,6 +58,12 @@
<td>
{{ $location->description }}
</td>
@include('components.userfields_tbody', array(
'userfields' => $userfields,
'userfieldValues' => FindAllObjectsInArrayByPropertyValue($userfieldValues, 'object_id', $location->id)
))
</tr>
@endforeach
</tbody>

View File

@@ -187,8 +187,14 @@
</div>
</div>
@include('components.userfieldsform', array(
'userfields' => $userfields,
'entity' => 'products'
))
<button id="save-product-button" class="btn btn-success">{{ $L('Save') }}</button>
</form>
</div>
<div class="col-lg-6 col-xs-12">

View File

@@ -32,6 +32,11 @@
<textarea class="form-control" rows="2" id="description" name="description">@if($mode == 'edit'){{ $group->description }}@endif</textarea>
</div>
@include('components.userfieldsform', array(
'userfields' => $userfields,
'entity' => 'product_groups'
))
<button id="save-product-group-button" class="btn btn-success">{{ $L('Save') }}</button>
</form>

View File

@@ -12,6 +12,9 @@
<a class="btn btn-outline-dark" href="{{ $U('/productgroup/new') }}">
<i class="fas fa-plus"></i>&nbsp;{{ $L('Add') }}
</a>
<a class="btn btn-outline-secondary" href="{{ $U('/userfields?entity=product_groups') }}">
<i class="fas fa-sliders-h"></i>&nbsp;{{ $L('Configure userfields') }}
</a>
</h1>
</div>
</div>
@@ -32,6 +35,10 @@
<th>{{ $L('Name') }}</th>
<th>{{ $L('Description') }}</th>
<th>{{ $L('Product count') }}</th>
@include('components.userfields_thead', array(
'userfields' => $userfields
))
</tr>
</thead>
<tbody class="d-none">
@@ -57,6 +64,12 @@
<i class="fas fa-external-link-alt"></i>
</a>
</td>
@include('components.userfields_tbody', array(
'userfields' => $userfields,
'userfieldValues' => FindAllObjectsInArrayByPropertyValue($userfieldValues, 'object_id', $productGroup->id)
))
</tr>
@endforeach
</tbody>

View File

@@ -12,6 +12,9 @@
<a class="btn btn-outline-dark" href="{{ $U('/product/new') }}">
<i class="fas fa-plus"></i>&nbsp;{{ $L('Add') }}
</a>
<a class="btn btn-outline-secondary" href="{{ $U('/userfields?entity=products') }}">
<i class="fas fa-sliders-h"></i>&nbsp;{{ $L('Configure userfields') }}
</a>
<a class="btn btn-outline-secondary" href="{{ $U('/stocksettings#productpresets') }}">
<i class="fas fa-sliders-h"></i>&nbsp;{{ $L('Presets for new products') }}
</a>
@@ -48,6 +51,11 @@
<th>{{ $L('QU stock') }}</th>
<th>{{ $L('QU factor') }}</th>
<th>{{ $L('Product group') }}</th>
@include('components.userfields_thead', array(
'userfields' => $userfields
))
</tr>
</thead>
<tbody class="d-none">
@@ -82,6 +90,12 @@
<td>
@if(!empty($product->product_group_id)) {{ FindObjectInArrayByPropertyValue($productGroups, 'id', $product->product_group_id)->name }} @endif
</td>
@include('components.userfields_tbody', array(
'userfields' => $userfields,
'userfieldValues' => FindAllObjectsInArrayByPropertyValue($userfieldValues, 'object_id', $product->id)
))
</tr>
@endforeach
</tbody>

View File

@@ -37,6 +37,11 @@
<textarea class="form-control" rows="2" id="description" name="description">@if($mode == 'edit'){{ $quantityunit->description }}@endif</textarea>
</div>
@include('components.userfieldsform', array(
'userfields' => $userfields,
'entity' => 'quantity_units'
))
<button id="save-quantityunit-button" class="btn btn-success">{{ $L('Save') }}</button>
</form>

View File

@@ -12,6 +12,9 @@
<a class="btn btn-outline-dark" href="{{ $U('/quantityunit/new') }}">
<i class="fas fa-plus"></i>&nbsp;{{ $L('Add') }}
</a>
<a class="btn btn-outline-secondary" href="{{ $U('/userfields?entity=quantity_units') }}">
<i class="fas fa-sliders-h"></i>&nbsp;{{ $L('Configure userfields') }}
</a>
</h1>
</div>
</div>
@@ -31,6 +34,10 @@
<th class="border-right"></th>
<th>{{ $L('Name') }}</th>
<th>{{ $L('Description') }}</th>
@include('components.userfields_thead', array(
'userfields' => $userfields
))
</tr>
</thead>
<tbody class="d-none">
@@ -50,6 +57,12 @@
<td>
{{ $quantityunit->description }}
</td>
@include('components.userfields_tbody', array(
'userfields' => $userfields,
'userfieldValues' => FindAllObjectsInArrayByPropertyValue($userfieldValues, 'object_id', $quantityunit->id)
))
</tr>
@endforeach
</tbody>

View File

@@ -77,6 +77,11 @@
<th class="d-none">Hidden location</th>
<th class="d-none">Hidden status</th>
<th class="d-none">Hidden product group</th>
@include('components.userfields_thead', array(
'userfields' => $userfields
))
</tr>
</thead>
<tbody class="d-none">
@@ -143,6 +148,12 @@
<td class="d-none">
@if($productGroup !== null){{ $productGroup->name }}@endif
</td>
@include('components.userfields_tbody', array(
'userfields' => $userfields,
'userfieldValues' => FindAllObjectsInArrayByPropertyValue($userfieldValues, 'object_id', $currentStockEntry->product_id)
))
</tr>
@endforeach
</tbody>

View File

@@ -12,6 +12,9 @@
<a class="btn btn-outline-dark" href="{{ $U('/taskcategory/new') }}">
<i class="fas fa-plus"></i>&nbsp;{{ $L('Add') }}
</a>
<a class="btn btn-outline-secondary" href="{{ $U('/userfields?entity=task_categories') }}">
<i class="fas fa-sliders-h"></i>&nbsp;{{ $L('Configure userfields') }}
</a>
</h1>
</div>
</div>
@@ -31,6 +34,11 @@
<th class="border-right"></th>
<th>{{ $L('Name') }}</th>
<th>{{ $L('Description') }}</th>
@include('components.userfields_thead', array(
'userfields' => $userfields
))
</tr>
</thead>
<tbody class="d-none">
@@ -50,6 +58,12 @@
<td>
{{ $taskCategory->description }}
</td>
@include('components.userfields_tbody', array(
'userfields' => $userfields,
'userfieldValues' => FindAllObjectsInArrayByPropertyValue($userfieldValues, 'object_id', $taskCategory->id)
))
</tr>
@endforeach
</tbody>

View File

@@ -32,6 +32,11 @@
<textarea class="form-control" rows="2" id="description" name="description">@if($mode == 'edit'){{ $category->description }}@endif</textarea>
</div>
@include('components.userfieldsform', array(
'userfields' => $userfields,
'entity' => 'task_categories'
))
<button id="save-task-category-button" class="btn btn-success">{{ $L('Save') }}</button>
</form>

View File

@@ -0,0 +1,71 @@
@extends('layout.default')
@if($mode == 'edit')
@section('title', $L('Edit userfield'))
@else
@section('title', $L('Create userfield'))
@endif
@section('viewJsName', 'userfieldform')
@section('content')
<div class="row">
<div class="col-lg-6 col-xs-12">
<h1>@yield('title')</h1>
<script>Grocy.EditMode = '{{ $mode }}';</script>
@if($mode == 'edit')
<script>Grocy.EditObjectId = {{ $userfield->id }};</script>
@endif
<form id="userfield-form" novalidate>
<div class="form-group">
<label for="entity">{{ $L('Entity') }}</label>
<select required class="form-control" id="entity" name="entity">
<option></option>
@foreach($entities as $entity)
<option @if($mode == 'edit' && $userfield->entity == $entity) selected="selected" @endif value="{{ $entity }}">{{ $entity }}</option>
@endforeach
</select>
<div class="invalid-feedback">{{ $L('A entity is required') }}</div>
</div>
<div class="form-group">
<label for="name">{{ $L('Name') }}</label>
<input type="text" class="form-control" required id="name" name="name" value="@if($mode == 'edit'){{ $userfield->name }}@endif">
<div class="invalid-feedback">{{ $L('A name is required') }}</div>
</div>
<div class="form-group">
<label for="name">{{ $L('Caption') }}</label>
<input type="text" class="form-control" required id="caption" name="caption" value="@if($mode == 'edit'){{ $userfield->caption }}@endif">
<div class="invalid-feedback">{{ $L('A caption is required') }}</div>
</div>
<div class="form-group">
<label for="entity">{{ $L('Type') }}</label>
<select required class="form-control" id="type" name="type">
<option></option>
@foreach($userfieldTypes as $userfieldType)
<option @if($mode == 'edit' && $userfield->type == $userfieldType) selected="selected" @endif value="{{ $userfieldType }}">{{ $L($userfieldType) }}</option>
@endforeach
</select>
<div class="invalid-feedback">{{ $L('A type is required') }}</div>
</div>
<div class="form-group">
<div class="form-check">
<input type="hidden" name="show_as_column_in_tables" value="0">
<input @if($mode == 'edit' && $userfield->show_as_column_in_tables == 1) checked @endif class="form-check-input" type="checkbox" id="show_as_column_in_tables" name="show_as_column_in_tables" value="1">
<label class="form-check-label" for="show_as_column_in_tables">{{ $L('Show as column in tables') }}</label>
</div>
</div>
<button id="save-userfield-button" class="btn btn-success">{{ $L('Save') }}</button>
</form>
</div>
</div>
@stop

View File

@@ -0,0 +1,76 @@
@extends('layout.default')
@section('title', $L('Userfields'))
@section('activeNav', 'userfields')
@section('viewJsName', 'userfields')
@section('content')
<div class="row">
<div class="col">
<h1>
@yield('title')
<a class="btn btn-outline-dark" href="{{ $U('/userfield/new') }}">
<i class="fas fa-plus"></i>&nbsp;{{ $L('Add') }}
</a>
</h1>
</div>
</div>
<div class="row mt-3">
<div class="col-xs-12 col-md-6 col-xl-3">
<label for="search">{{ $L('Search') }}</label> <i class="fas fa-search"></i>
<input type="text" class="form-control" id="search">
</div>
<div class="col-xs-12 col-md-6 col-xl-3">
<label for="entity-filter">{{ $L('Filter by entity') }}</label> <i class="fas fa-filter"></i>
<select class="form-control" id="entity-filter">
<option value="all">{{ $L('All') }}</option>
@foreach($entities as $entity)
<option value="{{ $entity }}">{{ $entity }}</option>
@endforeach
</select>
</div>
</div>
<div class="row">
<div class="col">
<table id="userfields-table" class="table table-sm table-striped dt-responsive">
<thead>
<tr>
<th class="border-right"></th>
<th>{{ $L('Entity') }}</th>
<th>{{ $L('Name') }}</th>
<th>{{ $L('Caption') }}</th>
<th>{{ $L('Type') }}</th>
</tr>
</thead>
<tbody class="d-none">
@foreach($userfields as $userfield)
<tr>
<td class="fit-content border-right">
<a class="btn btn-info btn-sm" href="{{ $U('/userfield/') }}{{ $userfield->id }}">
<i class="fas fa-edit"></i>
</a>
<a class="btn btn-danger btn-sm userfield-delete-button" href="#" data-userfield-id="{{ $userfield->id }}" data-userfield-name="{{ $userfield->name }}">
<i class="fas fa-trash"></i>
</a>
</td>
<td>
{{ $userfield->entity }}
</td>
<td>
{{ $userfield->name }}
</td>
<td>
{{ $userfield->caption }}
</td>
<td>
{{ $L($userfield->type) }}
</td>
</tr>
@endforeach
</tbody>
</table>
</div>
</div>
@stop