thay doi co che reset thiet bi

This commit is contained in:
dongpd 2020-12-22 17:08:56 +07:00
parent ef59255c52
commit 45be07f772
3 changed files with 48 additions and 34 deletions

View File

@ -301,36 +301,38 @@ class ConfigController extends Controller {
public function actionReset() { public function actionReset() {
if (Yii::$app->request->post()) { if (Yii::$app->request->post()) {
$tempConfig = json_decode(file_get_contents("http://localhost:4004/ReadEngineConfig", false, stream_context_create([ if (Yii::$app->request->post("resetDevice") === "true") {
'http' => [ $tempConfig = json_decode(file_get_contents("http://localhost:4004/ReadEngineConfig", false, stream_context_create([
'header' => "Content-Type: application/json", 'http' => [
'method' => "POST" 'header' => "Content-Type: application/json",
] 'method' => "POST"
])), true); ]
if ($tempConfig['status']) { ])), true);
if ($tempConfig['data'] !== "") { if ($tempConfig['status']) {
$engineConfig = json_decode($tempConfig['data'], true); if ($tempConfig['data'] !== "") {
if (count($engineConfig['data']['engines']) == 0) { $engineConfig = json_decode($tempConfig['data'], true);
$path = ""; if (count($engineConfig['data']['engines']) == 0) {
$path = "";
} else {
$path = $engineConfig['data']['engines'][0]['path'];
}
} else { } else {
$path = $engineConfig['data']['engines'][0]['path']; $path = "";
} }
} else { } else {
$path = ""; $path = "";
} }
} else { file_get_contents("http://localhost:4004/Reset", false, stream_context_create([
$path = ""; 'http' => [
'header' => "Content-Type: application/json",
'method' => "POST",
'content' => json_encode([
'path' => $path
])
]
]));
} }
file_get_contents("http://localhost:4004/Reset", false, stream_context_create([ if (Yii::$app->request->post("deleteDB") === "true") {
'http' => [
'header' => "Content-Type: application/json",
'method' => "POST",
'content' => json_encode([
'path' => $path
])
]
]));
if (Yii::$app->request->post("deleteDB") === "yes") {
\Yii::$app->db->createCommand()->truncateTable('capture_logs')->execute(); \Yii::$app->db->createCommand()->truncateTable('capture_logs')->execute();
\Yii::$app->db->createCommand()->truncateTable('list_management')->execute(); \Yii::$app->db->createCommand()->truncateTable('list_management')->execute();
array_map('unlink', glob("/var/www/html/BiFace_Server_Lite/web/data/uploads/face/*.*")); array_map('unlink', glob("/var/www/html/BiFace_Server_Lite/web/data/uploads/face/*.*"));

View File

@ -1,10 +1,11 @@
<div class="text-center"> <div class="text-left">
<h4>BẠN CÓ MUỐN XÓA DỮ LIỆU LƯU TRỮ TRONG THIẾT BỊ KHÔNG?</h4> <input type="checkbox" name="DeleteDatabase" checked="" style="width: inherit;"> Xóa dữ liệu lưu trữ trong thiết bị
<br> <br>
<button class="btn btn-danger" onclick="common.reset(this, 'yes');" data-href="{yii\helpers\Url::to(['/config/reset'])}"> <input type="checkbox" name="ResetDevice" checked="" style="width: inherit;"> Reset cấu hình thiết bị
</div>
</button> <div class="text-center">
<button class="btn btn-default" onclick="common.reset(this, 'no');" data-href="{yii\helpers\Url::to(['/config/reset'])}"> <button class="btn btn-danger" onclick="common.reset(this);" data-href="{yii\helpers\Url::to(['/config/reset'])}">
Không Đồng ý
</button> </button>
<button type="button" class="btn btn-default" data-dismiss="modal">Hủy bỏ</button>
</div> </div>

View File

@ -302,14 +302,25 @@ common.resetForm = function (e) {
} }
}); });
}; };
common.reset = function (e, deleteDB) { 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?")) { var deleteDB = false;
var resetDevice = false;
if ($("input[name='DeleteDatabase']").is(':checked'))
deleteDB = true;
if ($("input[name='ResetDevice']").is(':checked'))
resetDevice = true;
if (!deleteDB && !resetDevice) {
alert("Hãy lựa chọn thao tác!");
return;
}
if (confirm("Bạn có chắc chắn muốn reset thiết bị không?")) {
common.modalBlock(true); common.modalBlock(true);
$.ajax({ $.ajax({
url: $(e).attr("data-href"), url: $(e).attr("data-href"),
type: 'POST', type: 'POST',
data: { data: {
deleteDB: deleteDB deleteDB: deleteDB,
resetDevice: resetDevice
}, },
success: function (data) { success: function (data) {
window.location = data; window.location = data;