This commit is contained in:
dongpd 2020-05-26 11:47:51 +07:00
parent 52abd21183
commit 0656c688ec
2 changed files with 38 additions and 15 deletions

View File

@ -161,8 +161,8 @@ class ConfigController extends Controller {
$servermqtt = $t['servermqtt']; $servermqtt = $t['servermqtt'];
} }
return $this->render('index', [ return $this->render('index', [
"servermqtt" => $servermqtt, "servermqtt" => $servermqtt === "" ? $ip . ":1883" : $servermqtt,
"url" => isset($temp[2]) ? $temp[2] : "" "url" => isset($temp[2]) ? $temp[2] : $ip . ":5001"
]); ]);
} }
@ -260,16 +260,20 @@ class ConfigController extends Controller {
'method' => "POST" 'method' => "POST"
] ]
])), true); ])), true);
if (!$tempConfig['status']) if ($tempConfig['status']) {
return $this->redirect(['/config']); if ($tempConfig['data'] !== "") {
$engineConfig = json_decode($tempConfig['data'], true);
$engineConfig = json_decode($tempConfig['data'], true); if (count($engineConfig['data']['engines']) == 0) {
if (count($engineConfig['data']['engines']) == 0) { $path = "";
$path = ""; } else {
$path = $engineConfig['data']['engines'][0]['path'];
}
} else {
$path = "";
}
} else { } else {
$path = $engineConfig['data']['engines'][0]['path']; $path = "";
} }
file_get_contents("http://localhost:4004/Reset", false, stream_context_create([ file_get_contents("http://localhost:4004/Reset", false, stream_context_create([
'http' => [ 'http' => [
'header' => "Content-Type: application/json", 'header' => "Content-Type: application/json",
@ -293,7 +297,10 @@ class ConfigController extends Controller {
] ]
])), true); ])), true);
if (!$tempConfig['status']) if (!$tempConfig['status'])
return ['status' => false]; return ['status' => false, 'text' => ''];
if ($tempConfig['data'] === "")
return ['status' => false, 'text' => 'Cấu hình ip chưa đúng!'];
$engineConfig = json_decode($tempConfig['data'], true); $engineConfig = json_decode($tempConfig['data'], true);
if (count($engineConfig['data']['engines']) == 0) if (count($engineConfig['data']['engines']) == 0)
@ -310,7 +317,7 @@ class ConfigController extends Controller {
])), true); ])), true);
if (!$checkConfig['status']) { if (!$checkConfig['status']) {
return ['status' => false]; return ['status' => false, 'text' => ''];
} else { } else {
return ['status' => true, 'url' => Url::to(['cau-hinh-nhan-dien'])]; return ['status' => true, 'url' => Url::to(['cau-hinh-nhan-dien'])];
} }

View File

@ -2,13 +2,23 @@ $(function () {
}); });
function saveStep1(e) { function saveStep1(e) {
var servermqtt = $("input[name='servermqtt']").val();
if (servermqtt === "") {
alert("Hãy nhập thông tin!");
return;
}
var url = $("input[name='url']").val();
if (url === "") {
alert("Hãy nhập thông tin!");
return;
}
common.modalBlock(true); common.modalBlock(true);
$.ajax({ $.ajax({
url: $(e).attr("data-href"), url: $(e).attr("data-href"),
type: 'POST', type: 'POST',
data: { data: {
servermqtt: $("input[name='servermqtt']").val(), servermqtt: servermqtt,
url: $("input[name='url']").val() url: url
}, },
success: function (data) { success: function (data) {
setInterval(function () { setInterval(function () {
@ -16,8 +26,14 @@ function saveStep1(e) {
url: data, url: data,
type: 'POST', type: 'POST',
success: function (data) { success: function (data) {
if (data.status) if (data.status) {
window.location = data.url; window.location = data.url;
} else {
if (data.text !== "") {
alert(data.text);
window.location.reload(true);
}
}
}, },
error: function (jqXHR, textStatus, errorThrown) { error: function (jqXHR, textStatus, errorThrown) {
common.ajaxError(); common.ajaxError();