update mở tất cả cửa các thiết bị được chọn

This commit is contained in:
dongpd 2020-11-05 13:57:18 +07:00
parent d420323d4b
commit 05545bafc9
4 changed files with 129 additions and 1 deletions

View File

@ -626,7 +626,9 @@ class DeviceController extends Controller {
$model = $this->findModel($id);
return json_decode(common::requestToCardService("/ControlDevice", [
"DeviceIP" => $model->ip_address,
"DoorID" => $door
"DoorID" => [
"Door" . $door => "5"
]
]), true);
}
}
@ -722,4 +724,46 @@ class DeviceController extends Controller {
}
}
public function actionOpenAllDoors() {
if (Yii::$app->request->post()) {
Yii::$app->response->format = "json";
$post = Yii::$app->request->post();
$lists = $post["lists"];
if ($post["all"] === "true") {
$temp = [];
$devices = Device::find()->all();
foreach ($devices as $key => $value) {
$temp[] = $value->id;
}
$lists = $temp;
}
return [
"title" => Html::tag("i", "", ["class" => "fa fa-reply"]) . " Mở tất cả cửa",
"form" => $this->renderPartial("openDoor"),
"lists" => $lists
];
}
}
public function actionOpenDoorsOfDevice() {
if (Yii::$app->request->post()) {
Yii::$app->response->format = "json";
$device = $this->findModel(Yii::$app->request->post("data"));
$doors = Door::find()->andWhere(['device_id' => $device->id])->all();
$doorOpen = [];
foreach ($doors as $key => $value) {
$doorOpen["Door" . $value->code] = "5";
}
$response = json_decode(common::requestToCardService("/ControlDevice", [
"DeviceIP" => $device->ip_address,
"DoorID" => $doorOpen
]), true);
return [
"totals" => count($doors),
"IP" => $device->ip_address,
"response" => $response
];
}
}
}

View File

@ -8,6 +8,7 @@
<div class="device-index">
<input type='hidden' name='URL_sync_schedule' value="{Url::to(['sync-schedule'])}">
<input type='hidden' name='URL_sync_staff' value="{Url::to(['sync-staff'])}">
<input type='hidden' name='URL_open_door' value="{Url::to(['open-doors-of-device'])}">
<input type='hidden' name='pageSize' value="{Yii::$app->params["pageSize"]}">
<input type='hidden' name='get_data_sync_url' value="{Url::to(['get-data-sync'])}">
@ -50,6 +51,9 @@
<i class="fa fa-download fa-1-5x"></i> Xuất
</label>
{/if}
<label class="action-button" onclick="openAllDoors(this);" data-href="{Url::to(['open-all-doors'])}">
<i class="fa fa-reply fa-1-5x"></i> Mở tất cả cửa
</label>
<label class="action-button" onclick="_logs(this);" data-href="{Url::to(['logs'])}">
<i class="fa fa-file fa-1-5x"></i> Ghi nhận hệ thống
</label>

13
views/device/openDoor.tpl Normal file
View File

@ -0,0 +1,13 @@
<div class="well" style="height: 300px;overflow-y: scroll;" id="logs-response">
</div>
<div class="progress">
<div class="progress-bar progress-bar-primary progress-bar-striped" id='progress' role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" style="width: 0%">
0%
</div>
</div>
<div class="text-right">
<button class="btn btn-default" data-dismiss="modal" disabled="" id="close-modal">
<span class="fa fa-remove"></span> Đóng
</button>
</div>

View File

@ -605,4 +605,71 @@ function changeDuration(e) {
common.ajaxError();
}
});
}
var progressOpenDoor = 0;
var totalsDoor = 0;
function openAllDoors(e) {
var all = false;
if ($("#checkbox-device-all:checked").length > 0)
all = true;
var lists = [];
$.each($("input[name='checkbox-device']:checked"), function () {
lists.push($(this).val());
});
if (lists.length == 0) {
alert("Vui lòng lựa chọn đối tượng!");
return;
}
common.modalBlock(true);
$.ajax({
url: $(e).attr('data-href'),
type: 'POST',
data: {
lists: lists,
all: all
},
success: function (data) {
common.modalBlock(false);
common.modalOpen(data.form, false, data.title);
$("#close-modal").attr("disabled", true);
$("#modalHeader").find("button").remove();
totalsDoor = data.lists.length;
for (var i = 0; i < data.lists.length; i++) {
openAllDoorOfDevice(data.lists[i]);
}
},
error: function (jqXHR, textStatus, errorThrown) {
common.modalBlock(false);
common.ajaxError();
}
});
}
function openAllDoorOfDevice(data) {
$.ajax({
url: $("input[name='URL_open_door']").val(),
type: 'POST',
data: {
data: data
},
success: function (data) {
console.log(data.response);
var html = "";
html = "<span class='text-green'><i class='fa fa-check'></i> Mở <b>" + data.totals + "</b> cửa từ thiết bị <b>" + data.IP + "</b>.</span><br>";
$("#logs-response").prepend(html);
progressOpenDoor++;
var percent = parseInt(progressOpenDoor / totalsDoor * 100);
$("#progress").attr("aria-valuenow", percent);
$("#progress").attr("style", "width: " + percent + "%");
$("#progress").html(percent + "%");
if (percent >= 100) {
progressOpenDoor = 0;
$("#close-modal").attr("disabled", false);
}
},
error: function (jqXHR, textStatus, errorThrown) {
common.ajaxError();
}
});
}