mirror of
https://github.com/maxpozdeev/mytinytodo.git
synced 2026-03-11 08:55:27 +00:00
changes in internal api
This commit is contained in:
parent
696c795a4a
commit
d4cabb61b6
4 changed files with 51 additions and 18 deletions
|
|
@ -2876,6 +2876,10 @@ function extensionSettingsAction(actionString, ext, formData)
|
|||
window.location.assign(json.redirect);
|
||||
return;
|
||||
}
|
||||
if (json.html) {
|
||||
$('#page_ajax .mtt-settings-table').html(json.html); //FIXME: maybe whole page?
|
||||
return;
|
||||
}
|
||||
const callback = function() {
|
||||
if (json.msg) flashInfo(json.msg, json.details);
|
||||
if (json.reload) {
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
/*
|
||||
This file is a part of myTinyTodo.
|
||||
(C) Copyright 2022 Max Pozdeev <maxpozdeev@gmail.com>
|
||||
(C) Copyright 2022-2023 Max Pozdeev <maxpozdeev@gmail.com>
|
||||
Licensed under the GNU GPL version 2 or any later. See file COPYRIGHT for details.
|
||||
*/
|
||||
|
||||
|
|
@ -47,19 +47,9 @@ class ListsController extends ApiController {
|
|||
function post()
|
||||
{
|
||||
checkWriteAccess();
|
||||
$id = DBCore::default()->createListWithName($this->req->jsonBody['name'] ?? '');
|
||||
$db = DBConnection::instance();
|
||||
$t = array();
|
||||
$t['total'] = 0;
|
||||
$name = str_replace(
|
||||
array('"',"'",'<','>','&'),
|
||||
'',
|
||||
trim( $this->req->jsonBody['name'] ?? '' )
|
||||
);
|
||||
$ow = 1 + (int)$db->sq("SELECT MAX(ow) FROM {$db->prefix}lists");
|
||||
$time = time();
|
||||
$db->dq("INSERT INTO {$db->prefix}lists (uuid,name,ow,d_created,d_edited,taskview) VALUES (?,?,?,?,?,?)",
|
||||
array(generateUUID(), $name, $ow, $time, $time, 1) );
|
||||
$id = $db->lastInsertId();
|
||||
$t['total'] = 1;
|
||||
$r = $db->sqa("SELECT * FROM {$db->prefix}lists WHERE id=$id");
|
||||
$oo = $this->prepareList($r, true);
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
/*
|
||||
This file is a part of myTinyTodo.
|
||||
(C) Copyright 2022 Max Pozdeev <maxpozdeev@gmail.com>
|
||||
(C) Copyright 2022-2023 Max Pozdeev <maxpozdeev@gmail.com>
|
||||
Licensed under the GNU GPL version 2 or any later. See file COPYRIGHT for details.
|
||||
*/
|
||||
|
||||
|
|
@ -169,5 +169,34 @@ class DBCore
|
|||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
function createListWithName(string $name): int
|
||||
{
|
||||
$db = DBConnection::instance();
|
||||
$name = str_replace( ['"',"'",'<','>','&'], '', trim($name) );
|
||||
$ow = 1 + (int)$db->sq("SELECT MAX(ow) FROM {$db->prefix}lists");
|
||||
$time = time();
|
||||
$db->dq("INSERT INTO {$db->prefix}lists (uuid,name,ow,d_created,d_edited,taskview) VALUES (?,?,?,?,?,?)",
|
||||
array(generateUUID(), $name, $ow, $time, $time, 1) );
|
||||
$id = $db->lastInsertId();
|
||||
return (int)$id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds all variations of tag by its "normalized" name. Return array of id.
|
||||
* @param string $name
|
||||
* @return int[]
|
||||
* @throws Exception
|
||||
*/
|
||||
function getTagIdsByName(string $name): array
|
||||
{
|
||||
$db = DBConnection::instance();
|
||||
$q = $db->dq("SELECT id FROM {$db->prefix}tags WHERE ". $db->like('name', '%s', $name));
|
||||
$a = [];
|
||||
while ($r = $q->fetchAssoc()) {
|
||||
$a[] = (int) $r['id'];
|
||||
}
|
||||
return $a;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
/*
|
||||
This file is a part of myTinyTodo.
|
||||
(C) Copyright 2022 Max Pozdeev <maxpozdeev@gmail.com>
|
||||
(C) Copyright 2022-2023 Max Pozdeev <maxpozdeev@gmail.com>
|
||||
Licensed under the GNU GPL version 2 or any later. See file COPYRIGHT for details.
|
||||
*/
|
||||
|
||||
|
|
@ -89,9 +89,10 @@ abstract class ApiController
|
|||
|
||||
abstract class MTTExtension
|
||||
{
|
||||
const bundleId = '';
|
||||
const bundleId = ''; //abstract
|
||||
|
||||
abstract function init();
|
||||
function init() {
|
||||
}
|
||||
|
||||
public static function extMetaInfo(string $ext): ?array
|
||||
{
|
||||
|
|
@ -114,9 +115,18 @@ abstract class MTTExtension
|
|||
return null;
|
||||
}
|
||||
|
||||
public function httpApiUrlPrefix()
|
||||
public static function extApiActionUrl(string $action, ?string $params = null)
|
||||
{
|
||||
return get_unsafe_mttinfo('api_url'). 'ext/'. $this::bundleId;
|
||||
$url = get_unsafe_mttinfo('api_url'). 'ext/'. static::bundleId. "/$action";
|
||||
if (!is_null($params)) {
|
||||
if (false !== strpos($url, '?')) {
|
||||
$url .= '&'. $params;
|
||||
}
|
||||
else {
|
||||
$url .= '?'. $params;
|
||||
}
|
||||
}
|
||||
return $url;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue