mirror of
https://github.com/maxpozdeev/mytinytodo.git
synced 2026-03-11 08:55:27 +00:00
+ can do some actions in extension settings page
This commit is contained in:
parent
456d34d30d
commit
8590f29e14
4 changed files with 55 additions and 1 deletions
20
src/api.php
20
src/api.php
|
|
@ -60,6 +60,20 @@ $endpoints = array(
|
|||
]
|
||||
);
|
||||
|
||||
// look for extensions
|
||||
foreach (MTTExtensionLoader::registeredExtensions() as $instance) {
|
||||
if ($instance instanceof MTTHttpApiExtender) {
|
||||
$newRoutes = $instance->extendHttpApi();
|
||||
foreach ($newRoutes as $endpoint => $methods) {
|
||||
$endpoint = '/ext/'. $instance::codename. $endpoint;
|
||||
foreach ($methods as $k => &$v) {
|
||||
$v[2] = true; // Mark extension method
|
||||
}
|
||||
$endpoints[$endpoint] = $methods;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$req = new ApiRequest();
|
||||
$response = new ApiResponse();
|
||||
$executed = false;
|
||||
|
|
@ -73,12 +87,16 @@ foreach ($endpoints as $search => $methods) {
|
|||
if ( is_null($classDescr) ) {
|
||||
$response->htmlContent("Unknown method for resource", 500)->exit();
|
||||
}
|
||||
if ( !is_array($classDescr) || count($classDescr) != 2) {
|
||||
if ( !is_array($classDescr) || count($classDescr) < 2) {
|
||||
$response->htmlContent("Incorrect method definition", 500)->exit();
|
||||
}
|
||||
// check if class method exists
|
||||
$class = $classDescr[0];
|
||||
$classMethod = $classDescr[1];
|
||||
$isExt = $classDescr[2] ?? false;
|
||||
if ($isExt) {
|
||||
checkWriteAccess();
|
||||
}
|
||||
$param = null;
|
||||
if (count($m) >= 2) {
|
||||
$param = $m[1];
|
||||
|
|
|
|||
|
|
@ -626,6 +626,11 @@ var mytinytodo = window.mytinytodo = _mtt = {
|
|||
}
|
||||
});
|
||||
|
||||
$("#page_ajax").on('click', 'a[data-ext-settings-action]', function() {
|
||||
extensionSettingsAction(this.dataset.extSettingsAction, this.dataset.ext);
|
||||
return false;
|
||||
});
|
||||
|
||||
|
||||
// tab menu
|
||||
this.addAction('listSelected', tabmenuOnListSelected);
|
||||
|
|
@ -2684,7 +2689,30 @@ function saveExtensionSettings(frm)
|
|||
flashInfo(json.msg);
|
||||
});
|
||||
else showExtensionSettings(ext);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function extensionSettingsAction(actionString, ext)
|
||||
{
|
||||
if (actionString === undefined || ext === undefined) return false;
|
||||
var a = actionString.split(':', 2);
|
||||
if (a.length !== 2) return false;
|
||||
var method = a[0],
|
||||
action = a[1];
|
||||
$.ajax({
|
||||
url: _mtt.apiUrl + 'ext/' + ext + '/' + action,
|
||||
method: method.toUpperCase(),
|
||||
contentType : 'application/json',
|
||||
data: '{}',
|
||||
dataType: 'json',
|
||||
success: function(json) {
|
||||
if (json.total && json.total > 0) {
|
||||
showExtensionSettings(ext, json.msg ? function(){flashInfo(json.msg)} : null);
|
||||
}
|
||||
else if (json.msg) {
|
||||
flashInfo(json.msg);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -9,6 +9,8 @@ class ExtSettingsController extends ApiController {
|
|||
*/
|
||||
function get($ext)
|
||||
{
|
||||
checkWriteAccess();
|
||||
|
||||
/** @var MTTExtension|MTTExtensionSettingsInterface $instance */
|
||||
$instance = $this->extInstance($ext);
|
||||
if (!$instance) {
|
||||
|
|
@ -45,6 +47,8 @@ EOD;
|
|||
*/
|
||||
function put($ext)
|
||||
{
|
||||
checkWriteAccess();
|
||||
|
||||
/** @var MTTExtension|MTTExtensionSettingsInterface $instance */
|
||||
$instance = $this->extInstance($ext);
|
||||
if (!$instance) {
|
||||
|
|
|
|||
|
|
@ -78,6 +78,10 @@ abstract class MTTExtension
|
|||
abstract function init();
|
||||
}
|
||||
|
||||
interface MTTHttpApiExtender
|
||||
{
|
||||
function extendHttpApi(): array;
|
||||
}
|
||||
|
||||
interface MTTExtensionSettingsInterface
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue