mirror of
https://github.com/grocy/grocy.git
synced 2025-04-29 17:45:39 +00:00
Added the possibility to undo a task (closes #252)
This commit is contained in:
parent
914dde4609
commit
b4d2e2a20a
@ -11,5 +11,6 @@
|
||||
- Items can now be marked as "done" (new check mark button per item, when clicked, the item will be displayed greyed out, when clicked again the item will be displayed normally again)
|
||||
- Improved that products can now also be consumed as spoiled from the stock overview page (option in the more/context menu per line)
|
||||
- Added a "consume this recipe"-button to the meal plan (and also a button to consume all recipes for a whole week)
|
||||
- Added the possibility to undo a task (new button per task, only visible when task is already completed) and also a corresponding API endpoint
|
||||
- Added a new `config.php` setting `DISABLE_AUTH` to be able to disable authentication / the login screen, defaults to `false`
|
||||
- Added a new `config.php` setting `CALENDAR_FIRST_DAY_OF_WEEK` to be able to change the first day of a week used for calendar views (meal plan for example) in the frontend, defaults to locale default
|
||||
|
@ -39,4 +39,17 @@ class TasksApiController extends BaseApiController
|
||||
return $this->GenericErrorResponse($response, $ex->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function UndoTask(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args)
|
||||
{
|
||||
try
|
||||
{
|
||||
$this->TasksService->UndoTask($args['taskId']);
|
||||
return $this->EmptyApiResponse($response);
|
||||
}
|
||||
catch (\Exception $ex)
|
||||
{
|
||||
return $this->GenericErrorResponse($response, $ex->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2151,6 +2151,40 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"/tasks/{taskId}/undo": {
|
||||
"post": {
|
||||
"summary": "Marks the given task as not completed",
|
||||
"tags": [
|
||||
"Tasks"
|
||||
],
|
||||
"parameters": [
|
||||
{
|
||||
"in": "path",
|
||||
"name": "taskId",
|
||||
"required": true,
|
||||
"description": "A valid task id",
|
||||
"schema": {
|
||||
"type": "integer"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"204": {
|
||||
"description": "The operation was successful"
|
||||
},
|
||||
"400": {
|
||||
"description": "The operation was not successful (possible errors are: Not existing task)",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/GenericErrorResponse"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/calendar/ical": {
|
||||
"get": {
|
||||
"summary": "Returns the calendar in iCal format",
|
||||
|
@ -1283,3 +1283,6 @@ msgstr ""
|
||||
|
||||
msgid "Not all ingredients of recipe \"%s\" are in stock, nothing removed"
|
||||
msgstr ""
|
||||
|
||||
msgid "Undo task \"%s\""
|
||||
msgstr ""
|
||||
|
@ -102,6 +102,32 @@ $(document).on('click', '.do-task-button', function(e)
|
||||
);
|
||||
});
|
||||
|
||||
$(document).on('click', '.undo-task-button', function(e)
|
||||
{
|
||||
e.preventDefault();
|
||||
|
||||
// Remove the focus from the current button
|
||||
// to prevent that the tooltip stays until clicked anywhere else
|
||||
document.activeElement.blur();
|
||||
|
||||
Grocy.FrontendHelpers.BeginUiBusy();
|
||||
|
||||
var taskId = $(e.currentTarget).attr('data-task-id');
|
||||
var taskName = $(e.currentTarget).attr('data-task-name');
|
||||
|
||||
Grocy.Api.Post('tasks/' + taskId + '/undo', { },
|
||||
function()
|
||||
{
|
||||
window.location.reload();
|
||||
},
|
||||
function(xhr)
|
||||
{
|
||||
Grocy.FrontendHelpers.EndUiBusy();
|
||||
console.error(xhr);
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
$(document).on('click', '.delete-task-button', function (e)
|
||||
{
|
||||
e.preventDefault();
|
||||
|
@ -201,6 +201,7 @@ $app->group('/api', function()
|
||||
{
|
||||
$this->get('/tasks', '\Grocy\Controllers\TasksApiController:Current');
|
||||
$this->post('/tasks/{taskId}/complete', '\Grocy\Controllers\TasksApiController:MarkTaskAsCompleted');
|
||||
$this->post('/tasks/{taskId}/undo', '\Grocy\Controllers\TasksApiController:UndoTask');
|
||||
}
|
||||
|
||||
// Calendar
|
||||
|
@ -26,6 +26,22 @@ class TasksService extends BaseService
|
||||
return true;
|
||||
}
|
||||
|
||||
public function UndoTask($taskId)
|
||||
{
|
||||
if (!$this->TaskExists($taskId))
|
||||
{
|
||||
throw new \Exception('Task does not exist');
|
||||
}
|
||||
|
||||
$taskRow = $this->Database->tasks()->where('id = :1', $taskId)->fetch();
|
||||
$taskRow->update(array(
|
||||
'done' => 0,
|
||||
'done_timestamp' => null
|
||||
));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private function TaskExists($taskId)
|
||||
{
|
||||
$taskRow = $this->Database->tasks()->where('id = :1', $taskId)->fetch();
|
||||
|
@ -73,11 +73,19 @@
|
||||
@foreach($tasks as $task)
|
||||
<tr id="task-{{ $task->id }}-row" class="@if($task->done == 1) text-muted @endif @if(!empty($task->due_date) && $task->due_date < date('Y-m-d')) table-danger @elseif(!empty($task->due_date) && $task->due_date < date('Y-m-d', strtotime("+$nextXDays days"))) table-warning @endif">
|
||||
<td class="fit-content border-right">
|
||||
<a class="btn btn-success btn-sm do-task-button @if($task->done == 1) disabled @endif" href="#" data-toggle="tooltip" data-placement="left" title="{{ $__t('Mark task "%s" as completed', $task->name) }}"
|
||||
@if($task->done == 0)
|
||||
<a class="btn btn-success btn-sm do-task-button" href="#" data-toggle="tooltip" data-placement="left" title="{{ $__t('Mark task "%s" as completed', $task->name) }}"
|
||||
data-task-id="{{ $task->id }}"
|
||||
data-task-name="{{ $task->name }}">
|
||||
<i class="fas fa-check"></i>
|
||||
</a>
|
||||
@else
|
||||
<a class="btn btn-secondary btn-sm undo-task-button" href="#" data-toggle="tooltip" data-placement="left" title="{{ $__t('Undo task "%s"', $task->name) }}"
|
||||
data-task-id="{{ $task->id }}"
|
||||
data-task-name="{{ $task->name }}">
|
||||
<i class="fas fa-undo"></i>
|
||||
</a>
|
||||
@endif
|
||||
<a class="btn btn-sm btn-danger delete-task-button" href="#"
|
||||
data-task-id="{{ $task->id }}"
|
||||
data-task-name="{{ $task->name }}">
|
||||
|
Loading…
x
Reference in New Issue
Block a user