Browse Source

ADD: new get status in Status ESL page

Giancarlo Voci 7 years ago
parent
commit
77c0a0dd19

+ 14 - 0
src/OpenMind/Admin/Pages.php

@@ -8,6 +8,7 @@
 namespace OpenMind\Admin;
 
 use OpenMind\FindBox\FindBoxCoreSystem;
+use OpenMind\FindBox\SmartESL;
 use OpenMind\Web\Controller;
 use Template;
 
@@ -78,6 +79,7 @@ class Pages extends Controller
 
 		$configOBJ = json_decode($config);
 		switch ($configOBJ->method) {
+
 			case 'saveconfig':
 				$newConfig = $frameworkUtils->Encrypt($configOBJ->value);
 				@rename('cfg/config.bin', 'cfg/config.bin.old');
@@ -86,6 +88,7 @@ class Pages extends Controller
 					"err" => "Configuration saved"
 				]);
 				break;
+
 			case 'loadconfig':
 				$config = $frameworkUtils->Decrypt(file_get_contents('cfg/config.bin'));
 				echo json_encode([
@@ -93,6 +96,17 @@ class Pages extends Controller
 					"value" => $config
 				]);
 				break;
+
+			case 'geteslstatus':
+				$labelID = $configOBJ->label_id;
+				$esl = new SmartESL($this->findBoxCore, [$labelID]);
+				$status = $esl->GetStatus(true);
+				echo json_encode([
+					"err" => "Configuration reloaded successfully",
+					"value" => $status[$configOBJ->label_id]
+				]);
+
+				break;
 		}
 
 		return;

+ 36 - 0
src/OpenMind/Admin/ui/assets/js/admin.js

@@ -23,6 +23,11 @@ $(function () {
 			})
 		}
 	});
+
+	$('.statusmodal').on('shown.bs.modal', function () {
+		labelID = $('.statusmodal #labelID').html();
+		refreshESLStatus(labelID);
+	});
 });
 
 /**
@@ -71,3 +76,34 @@ function LoadConfig() {
 		})
 		.catch(err => toastr.error(err.url, `${err.status} (${err.statusText})`));
 }
+
+function OpenESLDetails(labelID) {
+	$('.statusmodal #labelID').html(labelID);
+	$('.statusmodal').modal('show');
+}
+
+function fillStatusApList(ESLstatus) {
+	$('#esl_rssi_list').html('');
+	for (let [ap, rssi] of Object.entries(ESLstatus)) {
+		let ap_rssi = `<div class="ml-4"><span class="badge badge-primary">${ap}</span><span class="ml-2 badge text-inverse badge-warning">${rssi}</span></div>`;
+		$('#esl_rssi_list').append(ap_rssi);
+	}
+}
+
+function refreshESLStatus(labelID) {
+	AjaxReq(`${BASEURL}/admin/config`, {
+		method: 'POST',
+		body: JSON.stringify({"method": "geteslstatus", "label_id": labelID})
+	})
+		.then(json => {
+			$('#esl_rssi').html(json.value.status.rssi);
+			fillStatusApList(json.value.rssi);
+			toastr.success(json.err);
+		})
+		.catch(err => {
+			if (err.url !== undefined)
+				toastr.error(err.url, `${err.status} (${err.statusText})`);
+			else
+				toastr.error(err);
+		});
+}

+ 20 - 1
src/OpenMind/Admin/ui/labelstatus.tpl

@@ -29,6 +29,7 @@
 					<th>DT type</th>
 					<th>Leds Count</th>
 					<th>rssi</th>
+					<th class="text-center">OPS</th>
 				</tr>
 				</thead>
 				<tbody>
@@ -42,6 +43,9 @@
 						<td>{{@STATUS['data']['devtype_id']}}</td>
 						<td>{{@STATUS['data']['led']}}</td>
 						<td><span class="text-danger">{{@STATUS['status']['rssi']}}</span></td>
+						<td class="text-center">
+							<button onclick="OpenESLDetails('{{@LABEL_ID}}')" class="btn btn-primary">Details</button>
+						</td>
 					</tr>
 
 				</repeat>
@@ -50,4 +54,19 @@
 		</div>
 	</div>
 </div>
-<!-- end col -->
+
+{* Modal *}
+<div class="modal fade statusmodal" tabindex="-1" role="dialog" aria-labelledby="statusmodal" aria-hidden="true" style="display: none;">
+	<div class="modal-dialog modal-sm">
+		<div class="modal-content">
+			<div class="modal-header">
+				<h4 class="modal-title mt-0" id="statusmodal">Status label <span id="labelID"></span></h4>
+				<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
+			</div>
+			<div class="modal-body">
+				RSSI: <span class="badge badge-warning text-inverse" id="esl_rssi"></span><br/>
+				RSS_AP: <span id="esl_rssi_list"></span>
+			</div>
+		</div>
+	</div>
+</div>

+ 0 - 1
src/OpenMind/FindBox/FindBoxCoreSystem.php

@@ -82,7 +82,6 @@ class FindBoxCoreSystem
 			//$requestText = "{$method} {$URI}{$Parameters} HTTP/1.0\r\nHost: {$this->Host}\r\n{$auth}Accept: */*\r\nConnection: close\r\n\r\n";
 			$requestBodyLength = strlen($Parameters);
 			$requestText = "POST {$URI} HTTP/1.0\r\nHost: {$this->Host}\r\n{$auth}Accept: */*\r\nContent-Type: application/json\r\nContent-Length: {$requestBodyLength}\r\n\r\n{$Parameters}\r\n";
-			//file_put_contents("request.txt", $requestText);
 			fwrite($streamfbOS, $requestText);
 			if (!$skipResponse) {
 				$r = stream_get_contents($streamfbOS);

+ 8 - 14
src/OpenMind/FindBox/SmartESL.php

@@ -23,13 +23,17 @@ class SmartESL
 
 	/**
 	 * Request to label(s) its properties
+	 *
+	 * @param bool $force request directly to ESL
 	 * @return null|object Details
 	 */
-	public function GetStatus()
+	public function GetStatus(bool $force = false)
 	{
-		$labels = json_encode(array($this->labels));
-		$URI = "/1.0.0/index.php/smartesl.getstatus/3.1.0/";
-		$ret = $this->core->CallAPI($URI, $labels);
+		$labels = json_encode($this->labels);
+		//$URI = "/1.0.0/index.php/smartesl.getstatus/3.1.0/";
+		$forceStr = var_export($force, true);
+		$URI = "/1.0.0/index.php/smartesl.getstatus/4.0.0/[{$labels},{$forceStr}]";
+		$ret = $this->core->CallAPI($URI, '');
 		if ($ret['err'] == 0 && $ret['value']['code'] == 0) {
 			// Update current properties
 			$this->labelProperties = $ret['value']['value'];
@@ -38,16 +42,6 @@ class SmartESL
 		return null;
 	}
 
-	/**
-	 * Retrieve cached label properties
-	 *
-	 * @return null|object
-	 */
-	public function getDetails()
-	{
-		return $this->labelProperties;
-	}
-
 	/**
 	 * Get label version splitted into the three components major, minor, patch
 	 *