diff --git a/src/content/mytinytodo.js b/src/content/mytinytodo.js index 9f3fad5..9246150 100644 --- a/src/content/mytinytodo.js +++ b/src/content/mytinytodo.js @@ -1866,6 +1866,7 @@ function showEditForm(isAdd) form.task.value = json.title form.tags.value = (form.tags.value != '') ? form.tags.value +', '+ json.tags : json.tags; form.prio.value = json.prio; + form.duedate.value = json.duedate; $('#task').val(''); }); diff --git a/src/includes/api/TasksController.php b/src/includes/api/TasksController.php index 6c8289c..4588b96 100644 --- a/src/includes/api/TasksController.php +++ b/src/includes/api/TasksController.php @@ -237,13 +237,18 @@ class TasksController extends ApiController { $t = array( 'title' => trim( $this->req->jsonBody['title'] ?? '' ), 'prio' => 0, - 'tags' => '' + 'tags' => '', + 'duedate' => '', ); if (Config::get('smartsyntax') != 0 && (false !== $a = $this->parseSmartSyntax($t['title']))) { - $t['title'] = (string) $a['title']; - $t['prio'] = (int) $a['prio']; - $t['tags'] = (string) $a['tags']; + $t['title'] = (string) ($a['title'] ?? ''); + $t['prio'] = (int) ($a['prio'] ?? 0); + $t['tags'] = (string) ($a['tags'] ?? ''); + if (isset($a['duedate']) && $a['duedate'] != '') { + $dueA = $this->prepareDuedate($a['duedate']); + $t['duedate'] = $dueA['formatted']; + } } $this->response->data = $t; } @@ -317,15 +322,19 @@ class TasksController extends ApiController { $title = trim($this->req->jsonBody['title'] ?? ''); $prio = 0; $tags = ''; + $duedate = null; if (Config::get('smartsyntax') != 0) { $a = $this->parseSmartSyntax($title); if ($a === false) { return $t; } - $title = $a['title']; - $prio = $a['prio']; - $tags = $a['tags']; + $title = (string)$a['title']; + $prio = (int)$a['prio']; + $tags = (string)$a['tags']; + if (isset($a['duedate']) && preg_match("|^\d+-\d+-\d+$|", $a['duedate'])) { + $duedate = $a['duedate']; + } } if ($title == '') { return $t; @@ -336,8 +345,8 @@ class TasksController extends ApiController { $ow = 1 + (int)$db->sq("SELECT MAX(ow) FROM {$db->prefix}todolist WHERE list_id=$listId AND compl=0"); $date = time(); $db->ex("BEGIN"); - $db->dq("INSERT INTO {$db->prefix}todolist (uuid,list_id,title,d_created,d_edited,ow,prio) VALUES (?,?,?,?,?,?,?)", - array(generateUUID(), $listId, $title, $date, $date, $ow, $prio) ); + $db->dq("INSERT INTO {$db->prefix}todolist (uuid,list_id,title,d_created,d_edited,ow,prio,duedate) VALUES (?,?,?,?,?,?,?,?)", + array(generateUUID(), $listId, $title, $date, $date, $ow, $prio, $duedate) ); $id = (int) $db->lastInsertId(); if ($tags != '') { @@ -783,14 +792,27 @@ class TasksController extends ApiController { $a = [ 'prio' => 0, 'title' => $title, - 'tags' => '' + 'tags' => '', + 'duedate' => null, ]; + // priority if ( preg_match("|^([-+]{1}\d+)(.+)|", $a['title'], $m) ) { $a['prio'] = (int) $m[1]; if ( $a['prio'] < -1 ) $a['prio'] = -1; elseif ( $a['prio'] > 2 ) $a['prio'] = 2; $a['title'] = trim($m[2]); } + // duedate + if ( preg_match("|(.+)@(\S+)$|", $a['title'], $m) ) { + $rest = $m[1]; + $duepre = $m[2]; + $duedate = $this->findDuedate($duepre); + if ($duedate) { + $a['duedate'] = $duedate; + $a['title'] = $rest; + } + } + // tags $tags = []; $a['title'] = trim( preg_replace_callback( "/(?:^|\s+)#([^#\s]+)/", @@ -809,4 +831,35 @@ class TasksController extends ApiController { return $a; } + private function findDuedate(string $s): ?string + { + $duedate = null; + if (preg_match("|(\d+)([dwmy]{1})|",$s, $m)) { // 5d,2w... + $count = (int)$m[1]; + $period = $m[2]; + if ($period == 'd' || $period == 'w') { // days, weeks + if ($period == 'w') $count *= 7; + $duedate = date("Y-m-d", time() + 86400*$count); + } + else if ($period == 'm' || $period == 'y') { //months,years + if ($period == 'y') $count *= 12; + $a = explode(',', date('Y,m,d')); + $y = (int)$a[0]; + $m = (int)$a[1] + $count; + $d = (int)$a[2]; + if ($m > 12) { + $yy = (int)floor($m/12); + $y += $yy; + $m = $m - $yy*12; + } + $d = min($d, $this->daysInMonth($m, $y)); + $duedate = "$y-$m-$d"; + } + } + else { + $duedate = $this->parseDuedate($s); + } + return $duedate; + } + } diff --git a/src/includes/lang/en.json b/src/includes/lang/en.json index b1b6253..f02caeb 100644 --- a/src/includes/lang/en.json +++ b/src/includes/lang/en.json @@ -165,7 +165,7 @@ "set_newpass": "New password", "set_newpass_descr": "Leave blank if won't change current password.", "set_smartsyntax": "Smart syntax", - "set_smartsyntax2_descr": "Example: +1 Task title #tag1 #tag2", + "set_smartsyntax3_descr": "Example: +1 Task title #tag1 #tag2 @duedate", "set_timezone": "Time zone", "set_autotag": "Autotagging", "set_autotag_descr": "Automatically adds tag of current tag filter to newly created task.", diff --git a/src/includes/lang/ru.json b/src/includes/lang/ru.json index a6462a8..94c6a02 100644 --- a/src/includes/lang/ru.json +++ b/src/includes/lang/ru.json @@ -165,7 +165,7 @@ "set_newpass": "Новый пароль", "set_newpass_descr": "Не заполняйте поле если не хотите менять текущий пароль.", "set_smartsyntax": "Smart syntax", - "set_smartsyntax2_descr": "Пример синтаксиса: +1 Задача #Тэг1 #Тэг2", + "set_smartsyntax3_descr": "Пример синтаксиса: +1 Задача #Тэг1 #Тэг2 @Срок", "set_timezone": "Часовой пояс", "set_autotag": "Автотеги", "set_autotag_descr": "Автодобавление текущего тега из фильтра в новую задачу.", diff --git a/src/settings.php b/src/settings.php index 8f75a0d..79a0451 100644 --- a/src/settings.php +++ b/src/settings.php @@ -269,7 +269,7 @@ header('Content-type:text/html; charset=utf-8');
-
:
+
: