mirror of
https://github.com/grocy/grocy.git
synced 2025-08-20 20:26:42 +00:00
Added a quick mockup for equipment / instruction manuals (references #25)
This commit is contained in:
31
controllers/EquipmentController.php
Normal file
31
controllers/EquipmentController.php
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Grocy\Controllers;
|
||||||
|
|
||||||
|
|
||||||
|
class EquipmentController extends BaseController
|
||||||
|
{
|
||||||
|
public function Overview(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args)
|
||||||
|
{
|
||||||
|
return $this->AppContainer->view->render($response, 'equipment', [
|
||||||
|
'equipment' => $this->Database->equipment()->orderBy('name')
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function EditForm(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args)
|
||||||
|
{
|
||||||
|
if ($args['equipmentId'] == 'new')
|
||||||
|
{
|
||||||
|
return $this->AppContainer->view->render($response, 'equipmentform', [
|
||||||
|
'mode' => 'create'
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return $this->AppContainer->view->render($response, 'equipmentform', [
|
||||||
|
'equipment' => $this->Database->equipment($args['equipmentId']),
|
||||||
|
'mode' => 'edit'
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -1677,7 +1677,8 @@
|
|||||||
"recipes_pos",
|
"recipes_pos",
|
||||||
"tasks",
|
"tasks",
|
||||||
"task_categories",
|
"task_categories",
|
||||||
"product_groups"
|
"product_groups",
|
||||||
|
"equipment"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"StockTransactionType": {
|
"StockTransactionType": {
|
||||||
|
7
migrations/0041.sql
Normal file
7
migrations/0041.sql
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
CREATE TABLE equipment (
|
||||||
|
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,
|
||||||
|
name TEXT NOT NULL UNIQUE,
|
||||||
|
description TEXT,
|
||||||
|
instruction_manual_file_name TEXT,
|
||||||
|
row_created_timestamp DATETIME DEFAULT (datetime('now', 'localtime'))
|
||||||
|
)
|
81
public/viewjs/equipment.js
Normal file
81
public/viewjs/equipment.js
Normal file
@@ -0,0 +1,81 @@
|
|||||||
|
var equipmentTable = $('#equipment-table').DataTable({
|
||||||
|
'paginate': false,
|
||||||
|
'order': [[1, 'asc']],
|
||||||
|
'columnDefs': [
|
||||||
|
{ 'orderable': false, 'targets': 0 }
|
||||||
|
],
|
||||||
|
'language': JSON.parse(L('datatables_localization')),
|
||||||
|
'scrollY': false,
|
||||||
|
'colReorder': true,
|
||||||
|
'stateSave': true,
|
||||||
|
'stateSaveParams': function(settings, data)
|
||||||
|
{
|
||||||
|
data.search.search = "";
|
||||||
|
|
||||||
|
data.columns.forEach(column =>
|
||||||
|
{
|
||||||
|
column.search.search = "";
|
||||||
|
});
|
||||||
|
},
|
||||||
|
'select': 'single',
|
||||||
|
'initComplete': function()
|
||||||
|
{
|
||||||
|
this.api().row({ order: 'current' }, 0).select();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
equipmentTable.on('select', function(e, dt, type, indexes)
|
||||||
|
{
|
||||||
|
if (type === 'row')
|
||||||
|
{
|
||||||
|
var selectedEquipmentId = $(equipmentTable.row(indexes[0]).node()).data("equipment-id");
|
||||||
|
console.log(selectedEquipmentId);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
$("#search").on("keyup", function()
|
||||||
|
{
|
||||||
|
var value = $(this).val();
|
||||||
|
if (value === "all")
|
||||||
|
{
|
||||||
|
value = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
equipmentTable.search(value).draw();
|
||||||
|
});
|
||||||
|
|
||||||
|
$(document).on('click', '.equipment-delete-button', function (e)
|
||||||
|
{
|
||||||
|
var objectName = $(e.currentTarget).attr('data-equipment-name');
|
||||||
|
var objectId = $(e.currentTarget).attr('data-equipment-id');
|
||||||
|
|
||||||
|
bootbox.confirm({
|
||||||
|
message: L('Are you sure to delete equipment "#1"?', objectName),
|
||||||
|
buttons: {
|
||||||
|
confirm: {
|
||||||
|
label: L('Yes'),
|
||||||
|
className: 'btn-success'
|
||||||
|
},
|
||||||
|
cancel: {
|
||||||
|
label: L('No'),
|
||||||
|
className: 'btn-danger'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
callback: function(result)
|
||||||
|
{
|
||||||
|
if (result === true)
|
||||||
|
{
|
||||||
|
Grocy.Api.Get('delete-object/equipment/' + objectId,
|
||||||
|
function(result)
|
||||||
|
{
|
||||||
|
window.location.href = U('/equipment');
|
||||||
|
},
|
||||||
|
function(xhr)
|
||||||
|
{
|
||||||
|
console.error(xhr);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
123
public/viewjs/equipmentform.js
Normal file
123
public/viewjs/equipmentform.js
Normal file
@@ -0,0 +1,123 @@
|
|||||||
|
$('#save-equipment-button').on('click', function(e)
|
||||||
|
{
|
||||||
|
e.preventDefault();
|
||||||
|
|
||||||
|
var jsonData = $('#equipment-form').serializeJSON();
|
||||||
|
if ($("#instruction-manual")[0].files.length > 0)
|
||||||
|
{
|
||||||
|
var someRandomStuff = Math.random().toString(36).substring(2, 100) + Math.random().toString(36).substring(2, 100);
|
||||||
|
jsonData.instruction_manual_file_name = someRandomStuff + $("#instruction-manual")[0].files[0].name;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Grocy.DeleteInstructionManualOnSave)
|
||||||
|
{
|
||||||
|
jsonData.instruction_manual_file_name = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Grocy.EditMode === 'create')
|
||||||
|
{
|
||||||
|
Grocy.Api.Post('add-object/equipment', jsonData,
|
||||||
|
function(result)
|
||||||
|
{
|
||||||
|
if (jsonData.hasOwnProperty("instruction_manual_file_name") && !Grocy.DeleteInstructionManualOnSave)
|
||||||
|
{
|
||||||
|
Grocy.Api.UploadFile($("#instruction-manual")[0].files[0], 'equipmentmanuals', jsonData.instruction_manual_file_name,
|
||||||
|
function(result)
|
||||||
|
{
|
||||||
|
window.location.href = U('/equipment');
|
||||||
|
},
|
||||||
|
function(xhr)
|
||||||
|
{
|
||||||
|
Grocy.FrontendHelpers.ShowGenericError('Error while saving, probably this item already exists', xhr.response)
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
window.location.href = U('/equipment');
|
||||||
|
}
|
||||||
|
},
|
||||||
|
function(xhr)
|
||||||
|
{
|
||||||
|
Grocy.FrontendHelpers.ShowGenericError('Error while saving, probably this item already exists', xhr.response)
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (Grocy.DeleteInstructionManualOnSave)
|
||||||
|
{
|
||||||
|
Grocy.Api.DeleteFile(Grocy.InstructionManualFileNameName, 'equipmentmanuals',
|
||||||
|
function(result)
|
||||||
|
{
|
||||||
|
// Nothing to do
|
||||||
|
},
|
||||||
|
function(xhr)
|
||||||
|
{
|
||||||
|
Grocy.FrontendHelpers.ShowGenericError('Error while saving, probably this item already exists', xhr.response)
|
||||||
|
}
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
Grocy.Api.Post('edit-object/equipment/' + Grocy.EditObjectId, jsonData,
|
||||||
|
function(result)
|
||||||
|
{
|
||||||
|
if (jsonData.hasOwnProperty("instruction_manual_file_name") && !Grocy.DeleteInstructionManualOnSave)
|
||||||
|
{
|
||||||
|
Grocy.Api.UploadFile($("#instruction-manual")[0].files[0], 'equipmentmanuals', jsonData.instruction_manual_file_name,
|
||||||
|
function(result)
|
||||||
|
{
|
||||||
|
window.location.href = U('/equipment');;
|
||||||
|
},
|
||||||
|
function(xhr)
|
||||||
|
{
|
||||||
|
Grocy.FrontendHelpers.ShowGenericError('Error while saving, probably this item already exists', xhr.response)
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
window.location.href = U('/equipment');;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
function(xhr)
|
||||||
|
{
|
||||||
|
Grocy.FrontendHelpers.ShowGenericError('Error while saving, probably this item already exists', xhr.response)
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
$('#equipment-form input').keyup(function(event)
|
||||||
|
{
|
||||||
|
Grocy.FrontendHelpers.ValidateForm('equipment-form');
|
||||||
|
});
|
||||||
|
|
||||||
|
$('#equipment-form input').keydown(function(event)
|
||||||
|
{
|
||||||
|
if (event.keyCode === 13) //Enter
|
||||||
|
{
|
||||||
|
event.preventDefault();
|
||||||
|
|
||||||
|
if (document.getElementById('equipment-form').checkValidity() === false) //There is at least one validation error
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$('#save-equipment-button').click();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Grocy.DeleteInstructionManualOnSave = false;
|
||||||
|
$('#delete-current-instruction-manual-button').on('click', function (e)
|
||||||
|
{
|
||||||
|
Grocy.DeleteInstructionManualOnSave = true;
|
||||||
|
//$("#current-instruction-manual").addClass("d-none");
|
||||||
|
$("#delete-current-instruction-manual-on-save-hint").removeClass("d-none");
|
||||||
|
$("#delete-current-instruction-manual-button").addClass("disabled");
|
||||||
|
});
|
||||||
|
|
||||||
|
$('#name').focus();
|
||||||
|
Grocy.FrontendHelpers.ValidateForm('equipment-form');
|
@@ -61,6 +61,10 @@ $app->group('', function()
|
|||||||
$this->get('/taskcategories', '\Grocy\Controllers\TasksController:TaskCategoriesList');
|
$this->get('/taskcategories', '\Grocy\Controllers\TasksController:TaskCategoriesList');
|
||||||
$this->get('/taskcategory/{categoryId}', '\Grocy\Controllers\TasksController:TaskCategoryEditForm');
|
$this->get('/taskcategory/{categoryId}', '\Grocy\Controllers\TasksController:TaskCategoryEditForm');
|
||||||
|
|
||||||
|
// Equipment routes
|
||||||
|
$this->get('/equipment', '\Grocy\Controllers\EquipmentController:Overview');
|
||||||
|
$this->get('/equipment/{equipmentId}', '\Grocy\Controllers\EquipmentController:EditForm');
|
||||||
|
|
||||||
// OpenAPI routes
|
// OpenAPI routes
|
||||||
$this->get('/api', '\Grocy\Controllers\OpenApiController:DocumentationUi');
|
$this->get('/api', '\Grocy\Controllers\OpenApiController:DocumentationUi');
|
||||||
$this->get('/manageapikeys', '\Grocy\Controllers\OpenApiController:ApiKeysList');
|
$this->get('/manageapikeys', '\Grocy\Controllers\OpenApiController:ApiKeysList');
|
||||||
|
@@ -105,6 +105,9 @@ class DemoDataGeneratorService extends BaseService
|
|||||||
INSERT INTO tasks (name, due_date, assigned_to_user_id) VALUES ('{$localizationService->Localize('Find a solution for what to do when I forget the door keys')}', date(datetime('now', 'localtime'), '+3 day'), 1);
|
INSERT INTO tasks (name, due_date, assigned_to_user_id) VALUES ('{$localizationService->Localize('Find a solution for what to do when I forget the door keys')}', date(datetime('now', 'localtime'), '+3 day'), 1);
|
||||||
INSERT INTO tasks (name, due_date, assigned_to_user_id) VALUES ('{$localizationService->Localize('Task')}3', date(datetime('now', 'localtime'), '+4 day'), 1);
|
INSERT INTO tasks (name, due_date, assigned_to_user_id) VALUES ('{$localizationService->Localize('Task')}3', date(datetime('now', 'localtime'), '+4 day'), 1);
|
||||||
|
|
||||||
|
INSERT INTO equipment (name, description) VALUES ('{$localizationService->Localize('Coffee machine')}', '{$loremIpsum}'); --1
|
||||||
|
INSERT INTO equipment (name, description) VALUES ('{$localizationService->Localize('Dishwasher')}', '{$loremIpsum}'); --2
|
||||||
|
|
||||||
INSERT INTO migrations (migration) VALUES (-1);
|
INSERT INTO migrations (migration) VALUES (-1);
|
||||||
";
|
";
|
||||||
|
|
||||||
|
62
views/equipment.blade.php
Normal file
62
views/equipment.blade.php
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
@extends('layout.default')
|
||||||
|
|
||||||
|
@section('title', $L('Equipment'))
|
||||||
|
@section('activeNav', 'equipment')
|
||||||
|
@section('viewJsName', 'equipment')
|
||||||
|
|
||||||
|
@section('content')
|
||||||
|
<div class="row">
|
||||||
|
<div class="col">
|
||||||
|
<h1>
|
||||||
|
@yield('title')
|
||||||
|
<a class="btn btn-outline-dark" href="{{ $U('/equipment/new') }}">
|
||||||
|
<i class="fas fa-plus"></i> {{ $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>
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
|
||||||
|
<div class="col-xs-12 col-md-3 pb-3">
|
||||||
|
<table id="equipment-table" class="table table-sm table-striped dt-responsive">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>#</th>
|
||||||
|
<th>{{ $L('Name') }}</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
@foreach($equipment as $equipmentItem)
|
||||||
|
<tr data-equipment-id="{{ $equipmentItem->id }}">
|
||||||
|
<td class="fit-content">
|
||||||
|
<a class="btn btn-info btn-sm" href="{{ $U('/equipment/') }}{{ $equipmentItem->id }}">
|
||||||
|
<i class="fas fa-edit"></i>
|
||||||
|
</a>
|
||||||
|
<a class="btn btn-danger btn-sm equipment-delete-button" href="#" data-equipment-id="{{ $equipmentItem->id }}" data-equipment-name="{{ $equipmentItem->name }}">
|
||||||
|
<i class="fas fa-trash"></i>
|
||||||
|
</a>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
{{ $equipmentItem->name }}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
@endforeach
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="col-xs-12 col-md-9">
|
||||||
|
<h3>{{ $L('Instruction manual') }}</h3>
|
||||||
|
<p id="selected-equipment-has-no-instruction-manual-hint">{{ $L('The selected equipment has no instruction manual') }}</p>
|
||||||
|
<p>TODO: Here the current instruction manual needs to be shown (PDF.js), if any...</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
@stop
|
65
views/equipmentform.blade.php
Normal file
65
views/equipmentform.blade.php
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
@extends('layout.default')
|
||||||
|
|
||||||
|
@if($mode == 'edit')
|
||||||
|
@section('title', $L('Edit equipment'))
|
||||||
|
@else
|
||||||
|
@section('title', $L('Create equipment'))
|
||||||
|
@endif
|
||||||
|
|
||||||
|
@section('viewJsName', 'equipmentform')
|
||||||
|
|
||||||
|
@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 = {{ $equipment->id }};</script>
|
||||||
|
|
||||||
|
@if(!empty($equipment->instruction_manual_file_name))
|
||||||
|
<script>Grocy.InstructionManualFileNameName = '{{ $equipment->instruction_manual_file_name }}';</script>
|
||||||
|
@endif
|
||||||
|
@endif
|
||||||
|
|
||||||
|
<form id="equipment-form" novalidate>
|
||||||
|
|
||||||
|
<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'){{ $equipment->name }}@endif">
|
||||||
|
<div class="invalid-feedback">{{ $L('A name is required') }}</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="instruction-manual">{{ $L('Instruction manual') }} (PDF)</label>
|
||||||
|
<div class="custom-file">
|
||||||
|
<input type="file" class="custom-file-input" id="instruction-manual" accept="application/pdf">
|
||||||
|
<label class="custom-file-label" for="instruction-manual">{{ $L('No file selected') }}</label>
|
||||||
|
</div>
|
||||||
|
<p class="form-text text-muted small">{{ $L('If you don\'t select a file, the current instruction manual will not be altered') }}</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="description">{{ $L('Description') }}</label>
|
||||||
|
<textarea class="form-control" rows="25" id="description" name="description">@if($mode == 'edit'){{ $equipment->description }}@endif</textarea>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<button id="save-equipment-button" class="btn btn-success">{{ $L('Save') }}</button>
|
||||||
|
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="col-lg-6 col-xs-12">
|
||||||
|
<label class="mt-2">{{ $L('Current instruction manual') }}</label>
|
||||||
|
<button id="delete-current-instruction-manual-button" class="btn btn-sm btn-danger @if(empty($equipment->instruction_manual_file_name)) disabled @endif"><i class="fas fa-trash"></i> {{ $L('Delete') }}</button>
|
||||||
|
@if(!empty($equipment->instruction_manual_file_name))
|
||||||
|
<p>TODO: Here the current instruction manual needs to be shown (PDF.js), if any...</p>
|
||||||
|
<p id="delete-current-instruction-manual-on-save-hint" class="form-text text-muted font-italic d-none">{{ $L('The current instruction manual will be deleted when you save the equipment') }}</p>
|
||||||
|
@else
|
||||||
|
<p id="no-current-instruction-manual-hint" class="form-text text-muted font-italic">{{ $L('No instruction manual') }}</p>
|
||||||
|
@endif
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
@stop
|
@@ -93,6 +93,12 @@
|
|||||||
<span class="nav-link-text">{{ $L('Batteries overview') }}</span>
|
<span class="nav-link-text">{{ $L('Batteries overview') }}</span>
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
|
<li class="nav-item" data-toggle="tooltip" data-placement="right" title="{{ $L('Equipment') }}" data-nav-for-page="equipment">
|
||||||
|
<a class="nav-link discrete-link" href="{{ $U('/equipment') }}">
|
||||||
|
<i class="fas fa-warehouse"></i>
|
||||||
|
<span class="nav-link-text">{{ $L('Equipment') }}</span>
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
|
||||||
<li class="nav-item mt-4" data-toggle="tooltip" data-placement="right" title="{{ $L('Purchase') }}" data-nav-for-page="purchase">
|
<li class="nav-item mt-4" data-toggle="tooltip" data-placement="right" title="{{ $L('Purchase') }}" data-nav-for-page="purchase">
|
||||||
<a class="nav-link discrete-link" href="{{ $U('/purchase') }}">
|
<a class="nav-link discrete-link" href="{{ $U('/purchase') }}">
|
||||||
|
@@ -114,7 +114,7 @@
|
|||||||
))
|
))
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="product-pictur">{{ $L('Product picture') }}</label>
|
<label for="product-picture">{{ $L('Product picture') }}</label>
|
||||||
<div class="custom-file">
|
<div class="custom-file">
|
||||||
<input type="file" class="custom-file-input" id="product-picture" accept="image/*">
|
<input type="file" class="custom-file-input" id="product-picture" accept="image/*">
|
||||||
<label class="custom-file-label" for="product-picture">{{ $L('No file selected') }}</label>
|
<label class="custom-file-label" for="product-picture">{{ $L('No file selected') }}</label>
|
||||||
|
Reference in New Issue
Block a user