- Added add, edit and delete API calls for components.

- Added documentation for the new calls.
This commit is contained in:
Aaron Daniels
2016-03-30 16:39:39 +10:00
parent 658d8d205c
commit 9706a85454
3 changed files with 184 additions and 3 deletions

View File

@ -535,8 +535,8 @@ function get_components() {
unset ($_GET['label']);
}
// Add the rest of the options with an equals query
foreach ($_GET as $k) {
$options['filter'][$k] = array('=',$_GET[$k]);
foreach ($_GET as $k => $v) {
$options['filter'][$k] = array('=',$v);
}
// use hostname as device_id if it's all digits
@ -556,6 +556,100 @@ function get_components() {
}
function add_components() {
global $config;
$code = 200;
$status = 'ok';
$message = '';
$app = \Slim\Slim::getInstance();
$router = $app->router()->getCurrentRoute()->getParams();
$hostname = $router['hostname'];
$ctype = $router['type'];
// use hostname as device_id if it's all digits
$device_id = ctype_digit($hostname) ? $hostname : getidbyname($hostname);
$COMPONENT = new component();
$component = $COMPONENT->createComponent($device_id,$ctype);
$output = array(
'status' => "$status",
'err-msg' => $message,
'count' => count($component),
'components' => $component,
);
$app->response->setStatus($code);
$app->response->headers->set('Content-Type', 'application/json');
echo _json_encode($output);
}
function edit_components() {
global $config;
$app = \Slim\Slim::getInstance();
$router = $app->router()->getCurrentRoute()->getParams();
$hostname = $router['hostname'];
$data = json_decode(file_get_contents('php://input'), true);
// use hostname as device_id if it's all digits
$device_id = ctype_digit($hostname) ? $hostname : getidbyname($hostname);
$COMPONENT = new component();
if ($COMPONENT->setComponentPrefs($device_id,$data)) {
// Edit Success.
$code = 200;
$status = 'ok';
$message = '';
}
else {
// Edit Failure.
$code = 500;
$status = 'error';
$message = 'Components could not be edited.';
}
$output = array(
'status' => "$status",
'err-msg' => $message,
'count' => count($data),
);
$app->response->setStatus($code);
$app->response->headers->set('Content-Type', 'application/json');
echo _json_encode($output);
}
function delete_components() {
global $config;
$app = \Slim\Slim::getInstance();
$router = $app->router()->getCurrentRoute()->getParams();
$cid = $router['component'];
$COMPONENT = new component();
if ($COMPONENT->deleteComponent($cid)) {
// Edit Success.
$code = 200;
$status = 'ok';
$message = '';
}
else {
// Edit Failure.
$code = 500;
$status = 'error';
$message = 'Components could not be deleted.';
}
$output = array(
'status' => "$status",
'err-msg' => $message,
);
$app->response->setStatus($code);
$app->response->headers->set('Content-Type', 'application/json');
echo _json_encode($output);
}
function get_graphs() {
global $config;
$code = 200;