mirror of
https://github.com/grocy/grocy.git
synced 2026-03-28 07:39:25 +01:00
Merge pull request #1 from oliversum-ch/codex/add-location-dropdown-to-equipment
Add location support to equipment
This commit is contained in:
commit
1d677e6a7c
|
|
@ -11,29 +11,32 @@ class EquipmentController extends BaseController
|
|||
|
||||
public function EditForm(Request $request, Response $response, array $args)
|
||||
{
|
||||
if ($args['equipmentId'] == 'new')
|
||||
{
|
||||
return $this->renderPage($response, 'equipmentform', [
|
||||
'mode' => 'create',
|
||||
'userfields' => $this->getUserfieldsService()->GetFields('equipment')
|
||||
]);
|
||||
}
|
||||
else
|
||||
{
|
||||
return $this->renderPage($response, 'equipmentform', [
|
||||
'equipment' => $this->getDatabase()->equipment($args['equipmentId']),
|
||||
'mode' => 'edit',
|
||||
'userfields' => $this->getUserfieldsService()->GetFields('equipment')
|
||||
]);
|
||||
}
|
||||
}
|
||||
if ($args['equipmentId'] == 'new')
|
||||
{
|
||||
return $this->renderPage($response, 'equipmentform', [
|
||||
'mode' => 'create',
|
||||
'userfields' => $this->getUserfieldsService()->GetFields('equipment'),
|
||||
'locations' => $this->getDatabase()->locations()->orderBy('name', 'COLLATE NOCASE')
|
||||
]);
|
||||
}
|
||||
else
|
||||
{
|
||||
return $this->renderPage($response, 'equipmentform', [
|
||||
'equipment' => $this->getDatabase()->equipment($args['equipmentId']),
|
||||
'mode' => 'edit',
|
||||
'userfields' => $this->getUserfieldsService()->GetFields('equipment'),
|
||||
'locations' => $this->getDatabase()->locations()->orderBy('name', 'COLLATE NOCASE')
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
public function Overview(Request $request, Response $response, array $args)
|
||||
{
|
||||
return $this->renderPage($response, 'equipment', [
|
||||
'equipment' => $this->getDatabase()->equipment()->orderBy('name', 'COLLATE NOCASE'),
|
||||
'userfields' => $this->getUserfieldsService()->GetFields('equipment'),
|
||||
'userfieldValues' => $this->getUserfieldsService()->GetAllValues('equipment')
|
||||
]);
|
||||
}
|
||||
public function Overview(Request $request, Response $response, array $args)
|
||||
{
|
||||
return $this->renderPage($response, 'equipment', [
|
||||
'equipment' => $this->getDatabase()->equipment()->orderBy('name', 'COLLATE NOCASE'),
|
||||
'userfields' => $this->getUserfieldsService()->GetFields('equipment'),
|
||||
'userfieldValues' => $this->getUserfieldsService()->GetAllValues('equipment'),
|
||||
'locations' => $this->getDatabase()->locations()->orderBy('name', 'COLLATE NOCASE')
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
1
migrations/0255.sql
Normal file
1
migrations/0255.sql
Normal file
|
|
@ -0,0 +1 @@
|
|||
ALTER TABLE equipment ADD location_id INTEGER;
|
||||
|
|
@ -29,16 +29,28 @@ equipmentTable.on('select', function(e, dt, type, indexes)
|
|||
function DisplayEquipment(id)
|
||||
{
|
||||
Grocy.Api.Get('objects/equipment/' + id,
|
||||
function(equipmentItem)
|
||||
{
|
||||
$(".selected-equipment-name").text(equipmentItem.name);
|
||||
$("#description-tab-content").html(equipmentItem.description);
|
||||
$(".equipment-edit-button").attr("href", U("/equipment/" + equipmentItem.id.toString()));
|
||||
function(equipmentItem)
|
||||
{
|
||||
$(".selected-equipment-name").text(equipmentItem.name);
|
||||
$("#description-tab-content").html(equipmentItem.description);
|
||||
$(".equipment-edit-button").attr("href", U("/equipment/" + equipmentItem.id.toString()));
|
||||
|
||||
if (equipmentItem.instruction_manual_file_name)
|
||||
{
|
||||
var pdfUrl = U('/api/files/equipmentmanuals/' + btoa(equipmentItem.instruction_manual_file_name));
|
||||
$("#selected-equipment-instruction-manual").attr("src", pdfUrl);
|
||||
var equipmentLocation = FindObjectInArrayByPropertyValue(Grocy.Locations, 'id', equipmentItem.location_id);
|
||||
if (equipmentLocation)
|
||||
{
|
||||
$("#selected-equipment-location-name").text(equipmentLocation.name);
|
||||
$("#selected-equipment-location").removeClass("d-none");
|
||||
}
|
||||
else
|
||||
{
|
||||
$("#selected-equipment-location-name").text("");
|
||||
$("#selected-equipment-location").addClass("d-none");
|
||||
}
|
||||
|
||||
if (equipmentItem.instruction_manual_file_name)
|
||||
{
|
||||
var pdfUrl = U('/api/files/equipmentmanuals/' + btoa(equipmentItem.instruction_manual_file_name));
|
||||
$("#selected-equipment-instruction-manual").attr("src", pdfUrl);
|
||||
$("#selectedEquipmentInstructionManualDownloadButton").attr("href", pdfUrl);
|
||||
$("#selected-equipment-instruction-manual").removeClass("d-none");
|
||||
$("#selectedEquipmentInstructionManualDownloadButton").removeClass("d-none");
|
||||
|
|
|
|||
|
|
@ -12,7 +12,11 @@
|
|||
return;
|
||||
}
|
||||
|
||||
var jsonData = $('#equipment-form').serializeJSON();
|
||||
var jsonData = $('#equipment-form').serializeJSON();
|
||||
if (jsonData.location_id == "")
|
||||
{
|
||||
jsonData.location_id = null;
|
||||
}
|
||||
Grocy.FrontendHelpers.BeginUiBusy("equipment-form");
|
||||
|
||||
if ($("#instruction-manual")[0].files.length > 0)
|
||||
|
|
|
|||
|
|
@ -5,10 +5,14 @@
|
|||
@section('title', $__t('Equipment'))
|
||||
|
||||
@section('content')
|
||||
<script>
|
||||
Grocy.Locations = @json($locations);
|
||||
</script>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-12 col-md-4 pb-3">
|
||||
<div class="title-related-links border-bottom mb-2 py-1">
|
||||
<h2 class="title">@yield('title')</h2>
|
||||
<div class="col-12 col-md-4 pb-3">
|
||||
<div class="title-related-links border-bottom mb-2 py-1">
|
||||
<h2 class="title">@yield('title')</h2>
|
||||
<div class="float-right @if($embedded) pr-5 @endif">
|
||||
<button class="btn btn-outline-dark d-md-none mt-2 order-1 order-md-3"
|
||||
type="button"
|
||||
|
|
@ -65,14 +69,15 @@
|
|||
data-toggle="tooltip"
|
||||
title="{{ $__t('Table options') }}"
|
||||
data-table-selector="#equipment-table"
|
||||
href="#"><i class="fa-solid fa-eye"></i></a>
|
||||
</th>
|
||||
<th>{{ $__t('Name') }}</th>
|
||||
href="#"><i class="fa-solid fa-eye"></i></a>
|
||||
</th>
|
||||
<th>{{ $__t('Name') }}</th>
|
||||
<th>{{ $__t('Location') }}</th>
|
||||
|
||||
@include('components.userfields_thead', array(
|
||||
'userfields' => $userfields,
|
||||
'excludeFieldTypes' => [\Grocy\Services\UserfieldsService::USERFIELD_TYPE_FILE]
|
||||
))
|
||||
@include('components.userfields_thead', array(
|
||||
'userfields' => $userfields,
|
||||
'excludeFieldTypes' => [\Grocy\Services\UserfieldsService::USERFIELD_TYPE_FILE]
|
||||
))
|
||||
|
||||
</tr>
|
||||
</thead>
|
||||
|
|
@ -102,15 +107,21 @@
|
|||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
<td>
|
||||
{{ $equipmentItem->name }}
|
||||
</td>
|
||||
</td>
|
||||
<td>
|
||||
{{ $equipmentItem->name }}
|
||||
</td>
|
||||
<td>
|
||||
@php $location = FindObjectInArrayByPropertyValue($locations, 'id', $equipmentItem->location_id); @endphp
|
||||
@if(!empty($location))
|
||||
{{ $location->name }}
|
||||
@endif
|
||||
</td>
|
||||
|
||||
@include('components.userfields_tbody', array(
|
||||
'userfields' => $userfields,
|
||||
'userfieldValues' => FindAllObjectsInArrayByPropertyValue($userfieldValues, 'object_id', $equipmentItem->id),
|
||||
'excludeFieldTypes' => [\Grocy\Services\UserfieldsService::USERFIELD_TYPE_FILE]
|
||||
@include('components.userfields_tbody', array(
|
||||
'userfields' => $userfields,
|
||||
'userfieldValues' => FindAllObjectsInArrayByPropertyValue($userfieldValues, 'object_id', $equipmentItem->id),
|
||||
'excludeFieldTypes' => [\Grocy\Services\UserfieldsService::USERFIELD_TYPE_FILE]
|
||||
))
|
||||
|
||||
</tr>
|
||||
|
|
@ -119,10 +130,15 @@
|
|||
</table>
|
||||
</div>
|
||||
|
||||
<div class="col-12 col-md-8">
|
||||
<ul class="nav nav-tabs grocy-tabs mb-1">
|
||||
<li class="nav-item">
|
||||
<a class="nav-link active"
|
||||
<div class="col-12 col-md-8">
|
||||
<p id="selected-equipment-location"
|
||||
class="text-muted d-none">
|
||||
<i class="fa-solid fa-location-dot"></i>
|
||||
<span id="selected-equipment-location-name"></span>
|
||||
</p>
|
||||
<ul class="nav nav-tabs grocy-tabs mb-1">
|
||||
<li class="nav-item">
|
||||
<a class="nav-link active"
|
||||
data-toggle="tab"
|
||||
href="#instruction-manual-tab">{{ $__t('Instruction manual') }}</a>
|
||||
</li>
|
||||
|
|
|
|||
|
|
@ -38,21 +38,27 @@
|
|||
<form id="equipment-form"
|
||||
novalidate>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="name">{{ $__t('Name') }}</label>
|
||||
<input type="text"
|
||||
class="form-control"
|
||||
required
|
||||
id="name"
|
||||
name="name"
|
||||
value="@if($mode == 'edit'){{ $equipment->name }}@endif">
|
||||
<div class="invalid-feedback">{{ $__t('A name is required') }}</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="name">{{ $__t('Name') }}</label>
|
||||
<input type="text"
|
||||
class="form-control"
|
||||
required
|
||||
id="name"
|
||||
name="name"
|
||||
value="@if($mode == 'edit'){{ $equipment->name }}@endif">
|
||||
<div class="invalid-feedback">{{ $__t('A name is required') }}</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="description">{{ $__t('Notes') }}</label>
|
||||
<textarea class="form-control wysiwyg-editor"
|
||||
id="description"
|
||||
@include('components.locationpicker', array(
|
||||
'locations' => $locations,
|
||||
'isRequired' => false,
|
||||
'prefillById' => $mode == 'edit' ? $equipment->location_id : ''
|
||||
))
|
||||
|
||||
<div class="form-group">
|
||||
<label for="description">{{ $__t('Notes') }}</label>
|
||||
<textarea class="form-control wysiwyg-editor"
|
||||
id="description"
|
||||
name="description">@if($mode == 'edit'){{ $equipment->description }}@endif</textarea>
|
||||
</div>
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user