1
0

ajout en cours d'une fonctiondeleteDevice

This commit is contained in:
Daniel Tartavel 2022-06-21 08:57:58 +02:00
parent b3f7171421
commit 566fc0e40c
3 changed files with 33 additions and 1 deletions

View File

@ -139,6 +139,10 @@ function apiServer($read)
logger(DEBUG, $command . _(" reached"), __FILE__ . ":" . __LINE__); logger(DEBUG, $command . _(" reached"), __FILE__ . ":" . __LINE__);
htmlSend($spawn, PropertiesDashboard($argList)); htmlSend($spawn, PropertiesDashboard($argList));
break; break;
case "deleteDevice":
logger(DEBUG, $command . _(" reached"), __FILE__ . ":" . __LINE__);
htmlSend($spawn, deleteDevice($argList));
break;
default: default:
if (is_numeric(array_key_first($argList))) if (is_numeric(array_key_first($argList)))
{ {
@ -152,7 +156,6 @@ function apiServer($read)
htmlSend($spawn, file_get_contents("php://temp/". $command), 'Content-Type: image/png'); htmlSend($spawn, file_get_contents("php://temp/". $command), 'Content-Type: image/png');
} }
} }
} }
if (array_key_exists("page", $argList)) if (array_key_exists("page", $argList))
{ {

View File

@ -29,6 +29,7 @@ function apiDashboard($socket, $n="Général")
{ {
logger(DEBUG, _("Write Access OK ") . ($propertyObject["access"] & 2), __FILE__ . ":" . __LINE__); logger(DEBUG, _("Write Access OK ") . ($propertyObject["access"] & 2), __FILE__ . ":" . __LINE__);
$response .= "     " . displayChoice($device, $property, $value); $response .= "     " . displayChoice($device, $property, $value);
$response .= "   " . displayMethod($device, $property);
} }
if(($propertyObject["access"] & 4)) if(($propertyObject["access"] & 4))
{ {
@ -124,9 +125,16 @@ function displayChoice($device, $propertyName, $value)
default: default:
logger(DEBUG, "type of property not recognized:" . $propertyObject["type"] , __FILE__ . ":" . __LINE__); logger(DEBUG, "type of property not recognized:" . $propertyObject["type"] , __FILE__ . ":" . __LINE__);
} }
return $formHTML; return $formHTML;
} }
function displayMethod($device, $property)
{
$html = '<input type="button" id="' . $device->topic ."/" . $device->friendlyName . "/" . $propertyName . "/" . strtolower($value) . '" method="' . IDLE . "\" onmouseup=\"setPropertyMethod('" . $device->topic . "', '" . $device->friendlyName . "', '" . IDLE . "', '" . $propertyName . "')\">";
$html = '<input type="button" id="' . $device->topic ."/" . $device->friendlyName . "/" . $propertyName . "/" . strtolower($value) . '" method="' . AUTO . "\" onmouseup=\"setPropertyMethod('" . $device->topic . "', '" . $device->friendlyName . "', '" . AUTO . "', '" . $propertyName . "')\">";
$html = '<input type="button" id="' . $device->topic ."/" . $device->friendlyName . "/" . $propertyName . "/" . strtolower($value) . '" method="' . MANUAL . "\" onmouseup=\"setPropertyMethod('" . $device->topic . "', '" . $device->friendlyName . "', '" . MANUAL . "', '" . $propertyName . "')\">";
}
function mkHTML($device, $propertyName, $choice) function mkHTML($device, $propertyName, $choice)
{ {
$html = ""; $html = "";
@ -184,6 +192,7 @@ function apiBrowse($socket, $argList, $page="/browse")
{ {
require_once "apiserver/javascript.php"; require_once "apiserver/javascript.php";
$response .= insertJavascript(); $response .= insertJavascript();
foreach($device->properties as $key => $value) foreach($device->properties as $key => $value)
{ {
$response = displayProperty($device, $key, $value, $response); $response = displayProperty($device, $key, $value, $response);
@ -527,7 +536,13 @@ function apiHookActive($argList, $status)
{ {
return _("Hook does not exists"); return _("Hook does not exists");
} }
}
function deleteDevice($argList)
{
global $indexFriendlyNames;
logger(DEBUG, _("removing ") . $indexFriendlyNames[$argList["fn"]]->friendlyname , __FILE__ . ":" . __LINE__);
//unset($indexFriendlyNames[$argList["fn"]]);
} }
/* /*
function apiDisplayByType($argList) function apiDisplayByType($argList)

View File

@ -20,6 +20,13 @@ return '<script language="javascript">
xhr.onload = function () {}; xhr.onload = function () {};
xhr.send(); xhr.send();
} }
function setPropertyMethod(topic, fn, method, property)
{
let xhr = new XMLHttpRequest();
xhr.open("GET", "http://192.168.1.253:' . $listenPort . '/set&fn="+fn+"&property="+property+"&topic="+topic+"&method="+method);
xhr.onload = function () {};
xhr.send();
}
function getPropertyValue(topic, fn, property) function getPropertyValue(topic, fn, property)
{ {
let xhr = new XMLHttpRequest(); let xhr = new XMLHttpRequest();
@ -31,6 +38,13 @@ return '<script language="javascript">
location.reload(); location.reload();
}, 1000); }, 1000);
} }
function deleteDevice($topic, fn)
{
let xhr = new XMLHttpRequest();
xhr.open("GET", "http://192.168.1.253:' . $listenPort . '/deleteDevice&fn="+fn+"&topic="+topic);
xhr.onload = function () {};
xhr.send();
}
// --> // -->
</script>'; </script>';
} }