From 752ed3aa1c68c82b865a0c5548110483f6c1831e Mon Sep 17 00:00:00 2001 From: dongpd Date: Tue, 26 May 2020 09:59:28 +0700 Subject: [PATCH] update --- controllers/ConfigController.php | 88 +++++++++++++++++-- nbproject/private/private.xml | 4 +- .../yiisoft/yii2-app/layouts/header.php | 5 ++ views/config/cau-hinh-nhan-dien.tpl | 5 ++ views/config/index.tpl | 13 ++- web/js/common.js | 16 ++++ web/js/config.js | 22 +++-- 7 files changed, 135 insertions(+), 18 deletions(-) diff --git a/controllers/ConfigController.php b/controllers/ConfigController.php index 0a5cc47b..339db217 100644 --- a/controllers/ConfigController.php +++ b/controllers/ConfigController.php @@ -126,7 +126,8 @@ class ConfigController extends Controller { "show_video" => 1, "full_screen" => 1, "width" => 1920, - "height" => 1080 + "height" => 1080, + "banner" => "Have a nice day!" ], "id_city" => 1581130, "open_door" => [ @@ -156,11 +157,12 @@ class ConfigController extends Controller { $tempConfig = json_decode(file_get_contents("http://localhost:4004/ReadAPIConfig", false, stream_context_create($options)), true); if ($tempConfig['status']) { $t = json_decode($tempConfig['data'], true); - $temp = explode(":", $t['servermqtt']); - $ip = $temp[0]; + $temp = explode("/", $t['url']); + $servermqtt = $t['servermqtt']; } return $this->render('index', [ - "ip" => $ip + "servermqtt" => $servermqtt, + "url" => $temp[2] ]); } @@ -172,13 +174,13 @@ class ConfigController extends Controller { 'header' => "Content-Type: application/json", 'method' => "POST", 'content' => json_encode([ - "servermqtt" => $post['server'] . ":1883", - "url" => "http://" . $post['server'] . ":5001/api/box/getConfig" + "servermqtt" => $post['servermqtt'], + "url" => "http://" . $post['url'] . "/api/box/getConfig" ]), ] ]; json_decode(file_get_contents("http://localhost:4004/SaveAPIConfig", false, stream_context_create($options)), true); - return Url::to(['cau-hinh-nhan-dien']); + return Url::to(['check-engine']); } } @@ -224,6 +226,9 @@ class ConfigController extends Controller { return $this->redirect(['/config']); $engineConfig = json_decode($tempConfig['data'], true); + if (count($engineConfig['data']['engines']) == 0) + return $this->redirect(['/config']); + $checkConfig = json_decode(file_get_contents("http://localhost:4004/ReadConfig", false, stream_context_create([ 'http' => [ 'header' => "Content-Type: application/json", @@ -233,10 +238,10 @@ class ConfigController extends Controller { ]) ] ])), true); - + if (!$checkConfig['status']) return $this->redirect(['/config']); - + $config_json = $this->config_json; if ($checkConfig['status']) $config_json = json_decode($checkConfig['data'], true); @@ -247,4 +252,69 @@ class ConfigController extends Controller { } } + public function actionReset() { + if (Yii::$app->request->isAjax) { + $tempConfig = json_decode(file_get_contents("http://localhost:4004/ReadEngineConfig", false, stream_context_create([ + 'http' => [ + 'header' => "Content-Type: application/json", + 'method' => "POST" + ] + ])), true); + if (!$tempConfig['status']) + return $this->redirect(['/config']); + + $engineConfig = json_decode($tempConfig['data'], true); + if (count($engineConfig['data']['engines']) == 0) { + $path = ""; + } else { + $path = $engineConfig['data']['engines'][0]['path']; + } + + file_get_contents("http://localhost:4004/Reset", false, stream_context_create([ + 'http' => [ + 'header' => "Content-Type: application/json", + 'method' => "POST", + 'content' => json_encode([ + 'path' => $path + ]) + ] + ])); + return Url::to(['/config']); + } + } + + public function actionCheckEngine() { + if (Yii::$app->request->isAjax) { + Yii::$app->response->format = "json"; + $tempConfig = json_decode(file_get_contents("http://localhost:4004/ReadEngineConfig", false, stream_context_create([ + 'http' => [ + 'header' => "Content-Type: application/json", + 'method' => "POST" + ] + ])), true); + if (!$tempConfig['status']) + return ['status' => false]; + + $engineConfig = json_decode($tempConfig['data'], true); + if (count($engineConfig['data']['engines']) == 0) + return ['status' => false]; + + $checkConfig = json_decode(file_get_contents("http://localhost:4004/ReadConfig", false, stream_context_create([ + 'http' => [ + 'header' => "Content-Type: application/json", + 'method' => "POST", + 'content' => json_encode([ + 'path' => $engineConfig['data']['engines'][0]['path'] + ]) + ] + ])), true); + + if (!$checkConfig['status']) { + return ['status' => false]; + } else { + return ['status' => true, 'url' => Url::to(['cau-hinh-nhan-dien'])]; + } + } + } + } diff --git a/nbproject/private/private.xml b/nbproject/private/private.xml index 6807a2ba..de7067d1 100644 --- a/nbproject/private/private.xml +++ b/nbproject/private/private.xml @@ -2,6 +2,8 @@ - + + file:/E:/BiFace_Server_Lite/controllers/ConfigController.php + diff --git a/vendor/dmstr/yii2-adminlte-asset/example-views/yiisoft/yii2-app/layouts/header.php b/vendor/dmstr/yii2-adminlte-asset/example-views/yiisoft/yii2-app/layouts/header.php index 342bdef5..55a1f8d6 100644 --- a/vendor/dmstr/yii2-adminlte-asset/example-views/yiisoft/yii2-app/layouts/header.php +++ b/vendor/dmstr/yii2-adminlte-asset/example-views/yiisoft/yii2-app/layouts/header.php @@ -46,6 +46,11 @@ use yii\widgets\ActiveForm; Cấu hình +
  • + + Reset thiết bị + +
  • + {/block} \ No newline at end of file diff --git a/web/js/common.js b/web/js/common.js index 85eb8381..5d00d021 100644 --- a/web/js/common.js +++ b/web/js/common.js @@ -279,6 +279,22 @@ common.success = function (id) { $("#" + id).addClass("has-success").removeClass("has-error"); $("#" + id).find(".help-block").addClass("hidden"); }; +common.reset = function (e) { + if (confirm("Bạn có chắc chắn muốn reset thiết bị về cấu hình mặc định không?")) { + common.modalBlock(true); + $.ajax({ + url: $(e).attr("href"), + type: 'POST', + success: function (data) { + window.location = data; + }, + error: function (jqXHR, textStatus, errorThrown) { + common.modalBlock(false); + common.ajaxError(); + } + }); + } +}; /** * ========================= */ diff --git a/web/js/config.js b/web/js/config.js index d3ccb1ca..4b5a98be 100644 --- a/web/js/config.js +++ b/web/js/config.js @@ -7,12 +7,23 @@ function saveStep1(e) { url: $(e).attr("data-href"), type: 'POST', data: { - server: $("input[name='servermqtt']").val() + servermqtt: $("input[name='servermqtt']").val(), + url: $("input[name='url']").val() }, success: function (data) { - setTimeout(function () { - window.location = data; - }, 2000); + setInterval(function () { + $.ajax({ + url: data, + type: 'POST', + success: function (data) { + if (data.status) + window.location = data.url; + }, + error: function (jqXHR, textStatus, errorThrown) { + common.ajaxError(); + } + }); + }, 1000); }, error: function (jqXHR, textStatus, errorThrown) { common.modalBlock(false); @@ -114,7 +125,8 @@ function saveStep2(e) { "show_video": parseInt($("#text-c61").html()), "full_screen": parseInt($("#text-c62").html()), "width": parseInt($("#text-c63").html()), - "height": parseInt($("#text-c64").html()) + "height": parseInt($("#text-c64").html()), + "banner": parseInt($("#text-c65").html()) }, "id_city": parseInt($("#text-c7").html()), "open_door": {