From f7d590383f12834c456c5a0952cfd5d53af5c9ab Mon Sep 17 00:00:00 2001 From: maxpozdeev Date: Mon, 1 Aug 2022 22:16:01 +0300 Subject: [PATCH] * can save setting of alltasks list to show or not completed tasks --- src/includes/api/ListsController.php | 18 +++++++++++++++++- src/includes/api/TasksController.php | 3 +-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/includes/api/ListsController.php b/src/includes/api/ListsController.php index 6a17ab7..61fc6c3 100644 --- a/src/includes/api/ListsController.php +++ b/src/includes/api/ListsController.php @@ -157,17 +157,19 @@ class ListsController extends ApiController { //default values $hidden = 1; $sort = 3; + $showCompleted = 1; $opts = Config::requestDomain('alltasks.json'); if ( isset($opts['hidden']) ) $hidden = (int)$opts['hidden'] ? 1 : 0; if ( isset($opts['sort']) ) $sort = (int)$opts['sort']; + if ( isset($opts['showCompleted']) ) $showCompleted = (int)$opts['showCompleted']; return array( 'id' => -1, 'name' => htmlarray(__('alltasks')), 'sort' => $sort, 'published' => 0, - 'showCompl' => 1, + 'showCompl' => $showCompleted, 'showNotes' => 0, 'hidden' => $hidden, ); @@ -226,6 +228,20 @@ class ListsController extends ApiController { } } + static function setListShowCompletedById(int $listId, bool $showCompleted) + { + $db = DBConnection::instance(); + if ($listId == -1) { + $opts = Config::requestDomain('alltasks.json'); + $opts['showCompleted'] = (int)$showCompleted; + Config::saveDomain('alltasks.json', $opts); + } + else { + $bitwise = $showCompleted ? 'taskview & ~1' : 'taskview | 1'; + $db->dq("UPDATE {$db->prefix}lists SET taskview=$bitwise WHERE id=?", [$listId]); + } + } + private function publishList(int $listId) { $db = DBConnection::instance(); diff --git a/src/includes/api/TasksController.php b/src/includes/api/TasksController.php index 1cb9cad..431f240 100644 --- a/src/includes/api/TasksController.php +++ b/src/includes/api/TasksController.php @@ -99,8 +99,7 @@ class TasksController extends ApiController { $t['list'][] = $this->prepareTaskRow($r); } if (_get('setCompl') && haveWriteAccess($listId)) { - $bitwise = (_get('compl') == 0) ? 'taskview & ~1' : 'taskview | 1'; - $db->dq("UPDATE {$db->prefix}lists SET taskview=$bitwise WHERE id=$listId"); + ListsController::setListShowCompletedById($listId, !(_get('compl') == 0) ); } if (_get('saveSort') == 1 && haveWriteAccess($listId)) { ListsController::setListSortingById($listId, $sort);