This commit is contained in:
dongpd 2020-05-26 09:59:28 +07:00
parent b851f4c76f
commit 752ed3aa1c
7 changed files with 135 additions and 18 deletions

View File

@ -126,7 +126,8 @@ class ConfigController extends Controller {
"show_video" => 1, "show_video" => 1,
"full_screen" => 1, "full_screen" => 1,
"width" => 1920, "width" => 1920,
"height" => 1080 "height" => 1080,
"banner" => "Have a nice day!"
], ],
"id_city" => 1581130, "id_city" => 1581130,
"open_door" => [ "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); $tempConfig = json_decode(file_get_contents("http://localhost:4004/ReadAPIConfig", false, stream_context_create($options)), true);
if ($tempConfig['status']) { if ($tempConfig['status']) {
$t = json_decode($tempConfig['data'], true); $t = json_decode($tempConfig['data'], true);
$temp = explode(":", $t['servermqtt']); $temp = explode("/", $t['url']);
$ip = $temp[0]; $servermqtt = $t['servermqtt'];
} }
return $this->render('index', [ return $this->render('index', [
"ip" => $ip "servermqtt" => $servermqtt,
"url" => $temp[2]
]); ]);
} }
@ -172,13 +174,13 @@ class ConfigController extends Controller {
'header' => "Content-Type: application/json", 'header' => "Content-Type: application/json",
'method' => "POST", 'method' => "POST",
'content' => json_encode([ 'content' => json_encode([
"servermqtt" => $post['server'] . ":1883", "servermqtt" => $post['servermqtt'],
"url" => "http://" . $post['server'] . ":5001/api/box/getConfig" "url" => "http://" . $post['url'] . "/api/box/getConfig"
]), ]),
] ]
]; ];
json_decode(file_get_contents("http://localhost:4004/SaveAPIConfig", false, stream_context_create($options)), true); 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']); return $this->redirect(['/config']);
$engineConfig = json_decode($tempConfig['data'], true); $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([ $checkConfig = json_decode(file_get_contents("http://localhost:4004/ReadConfig", false, stream_context_create([
'http' => [ 'http' => [
'header' => "Content-Type: application/json", 'header' => "Content-Type: application/json",
@ -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'])];
}
}
}
} }

View File

@ -2,6 +2,8 @@
<project-private xmlns="http://www.netbeans.org/ns/project-private/1"> <project-private xmlns="http://www.netbeans.org/ns/project-private/1">
<editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/2" lastBookmarkId="0"/> <editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/2" lastBookmarkId="0"/>
<open-files xmlns="http://www.netbeans.org/ns/projectui-open-files/2"> <open-files xmlns="http://www.netbeans.org/ns/projectui-open-files/2">
<group/> <group>
<file>file:/E:/BiFace_Server_Lite/controllers/ConfigController.php</file>
</group>
</open-files> </open-files>
</project-private> </project-private>

View File

@ -46,6 +46,11 @@ use yii\widgets\ActiveForm;
<i class="fa fa-cogs"></i> Cấu hình <i class="fa fa-cogs"></i> Cấu hình
</a> </a>
</li> </li>
<li>
<a href="<?php echo yii\helpers\Url::to(['/config/reset']); ?>" onclick="common.reset(this);return false;">
<i class="fa fa-refresh"></i> Reset thiết bị
</a>
</li>
</ul> </ul>
</div> </div>
<div class="navbar-custom-menu"> <div class="navbar-custom-menu">

View File

@ -572,6 +572,11 @@
<label class="tree_label" for="c64">height</label>: <label class="tree_label" for="c64">height</label>:
<div contenteditable="" id="text-c64" class="editform">{$config_json.screen.height}</div> <div contenteditable="" id="text-c64" class="editform">{$config_json.screen.height}</div>
</li> </li>
<li>
<input type="checkbox" checked="checked" id="c65" />
<label class="tree_label" for="c65">banner</label>:
<div contenteditable="" id="text-c65" class="editform">{$config_json.screen.banner}</div>
</li>
</ul> </ul>
</li> </li>
<li {if $username!='admin'}class='hidden'{/if}> <li {if $username!='admin'}class='hidden'{/if}>

View File

@ -42,8 +42,14 @@
<div class="col-md-4"> <div class="col-md-4">
<div class="form-group"> <div class="form-group">
<div class="input-group"> <div class="input-group">
<div class="input-group-addon">server IP</div> <div class="input-group-addon">server_mqtt</div>
<input type="input" class="form-control" name="servermqtt" value="{$ip}"> <input type="input" class="form-control" name="servermqtt" value="{$servermqtt}">
</div>
</div>
<div class="form-group">
<div class="input-group">
<div class="input-group-addon">url</div>
<input type="input" class="form-control" name="url" value="{$url}">
</div> </div>
</div> </div>
<div class="text-center"> <div class="text-center">
@ -54,4 +60,5 @@
</div> </div>
</div> </div>
</div> </div>
</div>
{/block} {/block}

View File

@ -279,6 +279,22 @@ common.success = function (id) {
$("#" + id).addClass("has-success").removeClass("has-error"); $("#" + id).addClass("has-success").removeClass("has-error");
$("#" + id).find(".help-block").addClass("hidden"); $("#" + 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();
}
});
}
};
/** /**
* ========================= * =========================
*/ */

View File

@ -7,12 +7,23 @@ function saveStep1(e) {
url: $(e).attr("data-href"), url: $(e).attr("data-href"),
type: 'POST', type: 'POST',
data: { data: {
server: $("input[name='servermqtt']").val() servermqtt: $("input[name='servermqtt']").val(),
url: $("input[name='url']").val()
}, },
success: function (data) { success: function (data) {
setTimeout(function () { setInterval(function () {
window.location = data; $.ajax({
}, 2000); 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) { error: function (jqXHR, textStatus, errorThrown) {
common.modalBlock(false); common.modalBlock(false);
@ -114,7 +125,8 @@ function saveStep2(e) {
"show_video": parseInt($("#text-c61").html()), "show_video": parseInt($("#text-c61").html()),
"full_screen": parseInt($("#text-c62").html()), "full_screen": parseInt($("#text-c62").html()),
"width": parseInt($("#text-c63").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()), "id_city": parseInt($("#text-c7").html()),
"open_door": { "open_door": {