Compare commits

..

No commits in common. "d9952a59fb8eba73c761314acfd35491b30e2005" and "bad58f82e28a71ee024fee8ea9d5dd15271c29ba" have entirely different histories.

9 changed files with 26 additions and 58 deletions

View File

@ -19,7 +19,7 @@ $router->any('/logout', 'Logout');
$router->any('/automation', 'Automation'); $router->any('/automation', 'Automation');
$router->any('/setting', 'Setting'); $router->any('/setting', 'Setting');
$router->any('/device', 'Device'); $router->any('/device', 'Device');
$router->any('/device/{sortBy}/{sortType}', 'Device'); $router->get('/device/{sortBy}/{sortType}', 'Device');
$router->any('/plugins', 'Plugins'); $router->any('/plugins', 'Plugins');
$router->any('/ajax', 'Ajax'); $router->any('/ajax', 'Ajax');
$router->any('/oauth', 'Oauth'); $router->any('/oauth', 'Oauth');

View File

@ -7,9 +7,11 @@ class DevicesApi extends ApiController{
$response = []; $response = [];
// TODO: process the request // TODO: process the request
$this->response($response); $this->response($response);
} }
public function getDevicesByRoom($roomId){ public function getDevicesByRoom($roomId){
} }
} }

View File

@ -1,7 +1,6 @@
<?php <?php
if (!empty ($_POST)){ if (!empty ($_POST)){
$deviceManager = new DeviceManager (); $deviceManager = new DeviceManager ();
$subDeviceManager = new SubDeviceManager ();
if (!empty ($_FILES['deviceFirmware']) && !empty ($_FILES['deviceFirmware']['tmp_name']) && !empty ($_POST['deviceId'])) { if (!empty ($_FILES['deviceFirmware']) && !empty ($_FILES['deviceFirmware']['tmp_name']) && !empty ($_POST['deviceId'])) {
$file = $_FILES['deviceFirmware']; $file = $_FILES['deviceFirmware'];
$deviceMac = $deviceManager->getDeviceById ($_POST['deviceId'])['mac']; $deviceMac = $deviceManager->getDeviceById ($_POST['deviceId'])['mac'];
@ -28,9 +27,6 @@ if (!empty ($_POST)){
if (!empty ($_POST['deviceName']) && !empty ($_POST['deviceId'])) { if (!empty ($_POST['deviceName']) && !empty ($_POST['deviceId'])) {
$deviceManager->edit ($_POST['deviceId'], array ('name' => $_POST['deviceName'])); $deviceManager->edit ($_POST['deviceId'], array ('name' => $_POST['deviceName']));
} }
if (isset ($_POST['deviceHistory']) && !empty ($_POST['deviceId'])) { header('Location: ./device');
$subDeviceManager->editSubDevicesByDevice($_POST['deviceId'], array ('history' => $_POST['deviceHistory']));
}
header('Location: ' . BASEURL . str_replace(BASEDIR, "", $_SERVER['REQUEST_URI']));
die(); die();
} }

View File

@ -187,31 +187,20 @@ class Utilities
* @param string $operator ('asc'/'desc') * @param string $operator ('asc'/'desc')
* @return void * @return void
*/ */
static function sortArrayByKey($data = [], $key, $operator = "asc") static function sortArrayByKey($data = [], $key, $operator = "asc"){
if ($operator == "asc")
{ {
if ($operator == "asc") {
uasort($data, function($a, $b) use ($key){ uasort($data, function($a, $b) use ($key){
$SortA = $a[$key]; if ($a[$key] == $b[$key]) return 0;
$SortB = $b[$key]; return ($a[$key] < $b[$key]) ? -1 : 1;
if ($key == "room_id") {
$SortA = RoomManager::getRoomName($SortA);
$SortB = RoomManager::getRoomName($SortB);
}
if ($SortA == $SortB) return 0;
return ($SortA < $SortB) ? -1 : 1;
}); });
} else{ } else{
uasort($data, function($a, $b) use ($key){ uasort($data, function($a, $b) use ($key){
$SortA = $a[$key]; if ($a[$key] == $b[$key]) return 0;
$SortB = $b[$key]; return ($a[$key] > $b[$key]) ? -1 : 1;
if ($key == "room_id") {
$SortA = RoomManager::getRoomName($SortA);
$SortB = RoomManager::getRoomName($SortB);
}
if ($SortA == $SortB) return 0;
return ($SortA > $SortB) ? -1 : 1;
}); });
} }
return $data; return $data;
} }
} }

View File

@ -19,12 +19,6 @@ class RoomManager{
return $allRoom; return $allRoom;
} }
public static function getRoomName ($room_id) {
//TODO: ignore Widgets withoud data
$allRoom = Db::loadAlone ("SELECT name FROM rooms WHERE room_id=?", array ($room_id));
return $allRoom;
}
public static function create ($name) { public static function create ($name) {
$room = array ( $room = array (
'name' => $name, 'name' => $name,

View File

@ -66,10 +66,6 @@ class SubDeviceManager
} }
} }
public static function editSubDevicesByDevice ($deviceId, $subDeviceParameters) {
DB::edit('subdevices', $subDeviceParameters, 'WHERE device_id=?', array ($deviceId));
}
public static function remove($subDeviceId) public static function remove($subDeviceId)
{ {
RecordManager::cleanSubdeviceRecords($subDeviceId); RecordManager::cleanSubdeviceRecords($subDeviceId);

View File

@ -28,8 +28,7 @@ class Device extends Template
"token" => "token", "token" => "token",
"signal" => "signal", "signal" => "signal",
"firmware" => "firmware_hash", "firmware" => "firmware_hash",
"icon" => "icon", "icon" => "icon"
"history" => "history",
]; ];
$sortIcons = [ $sortIcons = [
@ -48,17 +47,12 @@ class Device extends Template
$sortBy = "id"; $sortBy = "id";
$sortType = "DESC"; $sortType = "DESC";
} }
$template->prepare('sortIcon', [$sortBy => $sortIcons[$sortType]]); $template->prepare('sortIcon', [$sortBy => $sortIcons[$sortType]]);
foreach ($devices as $key => $device) { foreach ($devices as $key => $device) {
//Signal Stenght //Signal Stenght
$subdevice = $subDeviceManager->getSubDeviceByMasterAndType($device['device_id'], "wifi"); $subdevice = $subDeviceManager->getSubDeviceByMasterAndType($device['device_id'], "wifi");
$subdeviceLocal = $subDeviceManager->getSubDeviceByMaster($device['device_id']);
if (!empty ($subdeviceLocal)) {
$devices[$key]['history'] = (!empty ($subdeviceLocal['history']) ? $subdeviceLocal['history'] : 0);
} else {
unset($devices[$key]['history']);
}
$devices[$key]['signal'] = ""; $devices[$key]['signal'] = "";
if (!empty($subdevice['subdevice_id'])) { if (!empty($subdevice['subdevice_id'])) {
$record = $recordManager->getLastRecord($subdevice['subdevice_id']); $record = $recordManager->getLastRecord($subdevice['subdevice_id']);

View File

@ -36,7 +36,6 @@
<a href="device/mac/<?php echo $SORTTYPE; ?>">(Mac)</a><i class="fa"><?php echo (!empty($SORTICON['mac']) ? $SORTICON['mac'] : ""); ?></i><br> <a href="device/mac/<?php echo $SORTTYPE; ?>">(Mac)</a><i class="fa"><?php echo (!empty($SORTICON['mac']) ? $SORTICON['mac'] : ""); ?></i><br>
<a href="device/token/<?php echo $SORTTYPE; ?>">Token</a><i class="fa"><?php echo (!empty($SORTICON['token']) ? $SORTICON['token'] : ""); ?></i> <a href="device/token/<?php echo $SORTTYPE; ?>">Token</a><i class="fa"><?php echo (!empty($SORTICON['token']) ? $SORTICON['token'] : ""); ?></i>
</th> </th>
<th><a href="device/history/<?php echo $SORTTYPE; ?>">Historie</a><i class="fa"><?php echo (!empty($SORTICON['history']) ? $SORTICON['history'] : ""); ?></i></th>
<th>Action <th>Action
<form method="post" action=""> <form method="post" action="">
<button class="fa custom-file-input" type="submit" name="deviceCommand" value="reset" title="Reset All"><b>&#xf01e;</b></button> <button class="fa custom-file-input" type="submit" name="deviceCommand" value="reset" title="Reset All"><b>&#xf01e;</b></button>
@ -101,14 +100,6 @@
<td><?php echo (!empty($device['mac']) ? $device['mac'] : ""); ?><br> <td><?php echo (!empty($device['mac']) ? $device['mac'] : ""); ?><br>
<?php echo (!empty($device['ip_address']) ? $device['ip_address'] : ""); ?><br> <?php echo (!empty($device['ip_address']) ? $device['ip_address'] : ""); ?><br>
<?php echo (!empty($device['token']) ? $device['token'] : ""); ?></td> <?php echo (!empty($device['token']) ? $device['token'] : ""); ?></td>
<td>
<?php if (isset($device['history'])): ?>
<form method="post" action="">
<input type="hidden" name="deviceId" value="<?php echo (!empty($device['device_id']) ? $device['device_id'] : ""); ?>">
<input class="input" type="number" onchange="this.form.submit();" name="deviceHistory" value="<?php echo (!empty($device['history']) ? $device['history'] : 0); ?>">
</form>
<?php endif; ?>
</td>
<td> <td>
<?php if (!empty($device['mac'])) : ?> <?php if (!empty($device['mac'])) : ?>
<form method="post" action=""> <form method="post" action="">
@ -131,6 +122,12 @@
$partial->render(); $partial->render();
//TODO js do main.js //TODO js do main.js
?> ?>
<script>
$(function() {
$("#sortable").sortable();
$("#sortable").disableSelection();
});
</script>
</body> </body>
</html> </html>

View File

@ -3,7 +3,7 @@
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<title><?php echo $this->title; ?></title> <title><?php echo $this->title ?></title>
</head> </head>
<body> <body>
<?php echo $this->content(); ?> <?php echo $this->content(); ?>