diff --git a/app/Routes.php b/app/Routes.php
index dd87d63..d5e646b 100644
--- a/app/Routes.php
+++ b/app/Routes.php
@@ -19,7 +19,7 @@ $router->any('/logout', 'Logout');
$router->any('/automation', 'Automation');
$router->any('/setting', 'Setting');
$router->any('/device', 'Device');
-$router->get('/device/{sortBy}/{sortType}', 'Device');
+$router->any('/device/{sortBy}/{sortType}', 'Device');
$router->any('/plugins', 'Plugins');
$router->any('/ajax', 'Ajax');
$router->any('/oauth', 'Oauth');
diff --git a/app/api/DevicesApi.php b/app/api/DevicesApi.php
index daa8ece..46ec318 100644
--- a/app/api/DevicesApi.php
+++ b/app/api/DevicesApi.php
@@ -7,11 +7,9 @@ class DevicesApi extends ApiController{
$response = [];
// TODO: process the request
-
$this->response($response);
}
public function getDevicesByRoom($roomId){
-
}
}
diff --git a/app/controllers/deviceController.php b/app/controllers/deviceController.php
index 0958618..1a928e2 100644
--- a/app/controllers/deviceController.php
+++ b/app/controllers/deviceController.php
@@ -1,6 +1,7 @@
getDeviceById ($_POST['deviceId'])['mac'];
@@ -27,6 +28,9 @@ if (!empty ($_POST)){
if (!empty ($_POST['deviceName']) && !empty ($_POST['deviceId'])) {
$deviceManager->edit ($_POST['deviceId'], array ('name' => $_POST['deviceName']));
}
- header('Location: ./device');
+ if (isset ($_POST['deviceHistory']) && !empty ($_POST['deviceId'])) {
+ $subDeviceManager->editSubDevicesByDevice($_POST['deviceId'], array ('history' => $_POST['deviceHistory']));
+ }
+ header('Location: ' . BASEURL . str_replace(BASEDIR, "", $_SERVER['REQUEST_URI']));
die();
}
diff --git a/app/models/Utilities.php b/app/models/Utilities.php
index a5a81af..b37865b 100644
--- a/app/models/Utilities.php
+++ b/app/models/Utilities.php
@@ -187,20 +187,31 @@ class Utilities
* @param string $operator ('asc'/'desc')
* @return void
*/
- static function sortArrayByKey($data = [], $key, $operator = "asc"){
- if ($operator == "asc")
- {
- uasort($data, function($a, $b) use ($key){
- if ($a[$key] == $b[$key]) return 0;
- return ($a[$key] < $b[$key]) ? -1 : 1;
+ static function sortArrayByKey($data = [], $key, $operator = "asc")
+ {
+ if ($operator == "asc") {
+ uasort($data, function ($a, $b) use ($key) {
+ $SortA = $a[$key];
+ $SortB = $b[$key];
+ if ($key == "room_id") {
+ $SortA = RoomManager::getRoomName($SortA);
+ $SortB = RoomManager::getRoomName($SortB);
+ }
+ if ($SortA == $SortB) return 0;
+ return ($SortA < $SortB) ? -1 : 1;
});
- } else{
- uasort($data, function($a, $b) use ($key){
- if ($a[$key] == $b[$key]) return 0;
- return ($a[$key] > $b[$key]) ? -1 : 1;
+ } else {
+ uasort($data, function ($a, $b) use ($key) {
+ $SortA = $a[$key];
+ $SortB = $b[$key];
+ if ($key == "room_id") {
+ $SortA = RoomManager::getRoomName($SortA);
+ $SortB = RoomManager::getRoomName($SortB);
+ }
+ if ($SortA == $SortB) return 0;
+ return ($SortA > $SortB) ? -1 : 1;
});
}
return $data;
-
}
}
diff --git a/app/models/managers/RoomManager.php b/app/models/managers/RoomManager.php
index b279cde..722b923 100644
--- a/app/models/managers/RoomManager.php
+++ b/app/models/managers/RoomManager.php
@@ -19,6 +19,12 @@ class RoomManager{
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) {
$room = array (
'name' => $name,
diff --git a/app/models/managers/SubDeviceManager.php b/app/models/managers/SubDeviceManager.php
index 9739c2d..d714e9f 100644
--- a/app/models/managers/SubDeviceManager.php
+++ b/app/models/managers/SubDeviceManager.php
@@ -66,6 +66,10 @@ class SubDeviceManager
}
}
+ public static function editSubDevicesByDevice ($deviceId, $subDeviceParameters) {
+ DB::edit('subdevices', $subDeviceParameters, 'WHERE device_id=?', array ($deviceId));
+ }
+
public static function remove($subDeviceId)
{
RecordManager::cleanSubdeviceRecords($subDeviceId);
@@ -103,7 +107,7 @@ class SubDeviceManager
public static function getSubdeviceDetailById($subDeviceId){
if (empty($subDeviceId)) return NULL;
- $rows = Db::loadOne("SELECT d.room_id, d.sleep_time, sd.subdevice_id, sd.type, sd.device_id FROM subdevices sd
+ $rows = Db::loadOne("SELECT d.room_id, d.sleep_time, sd.subdevice_id, sd.type, sd.device_id FROM subdevices sd
JOIN devices d ON sd.device_id = d.device_id
WHERE sd.subdevice_id = ? ", [$subDeviceId]);
diff --git a/app/views/Device.php b/app/views/Device.php
index bd48bcf..c201367 100644
--- a/app/views/Device.php
+++ b/app/views/Device.php
@@ -28,7 +28,8 @@ class Device extends Template
"token" => "token",
"signal" => "signal",
"firmware" => "firmware_hash",
- "icon" => "icon"
+ "icon" => "icon",
+ "history" => "history",
];
$sortIcons = [
@@ -47,18 +48,23 @@ class Device extends Template
$sortBy = "id";
$sortType = "DESC";
}
-
$template->prepare('sortIcon', [$sortBy => $sortIcons[$sortType]]);
foreach ($devices as $key => $device) {
//Signal Stenght
$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'] = "";
if (!empty($subdevice['subdevice_id'])) {
$record = $recordManager->getLastRecord($subdevice['subdevice_id']);
if (!empty($record)) {
$devices[$key]['signal'] = $record['value'] . " " . $subdevice['unit'];
- }
+ }
}
//Firmware Status
diff --git a/app/views/templates/device.phtml b/app/views/templates/device.phtml
index 6b4832c..7f40c2c 100644
--- a/app/views/templates/device.phtml
+++ b/app/views/templates/device.phtml
@@ -36,6 +36,7 @@
(Mac)
Token
+