update mở tất cả + đóng tất cả cửa

This commit is contained in:
dongpd 2020-11-11 13:39:46 +07:00
parent 096be1a116
commit c4e631befe
4 changed files with 119 additions and 5 deletions

View File

@ -707,8 +707,9 @@ class DeviceController extends Controller {
}
common::requestToCardService("/ControlDevice", [
"DeviceIP" => $device->ip_address,
"DoorID" => $model->code,
"Duration" => $duration
"DoorID" => [
"Door" . $model->code => $duration
]
]);
}
$model->modified_at = time();
@ -752,7 +753,49 @@ class DeviceController extends Controller {
$doors = Door::find()->andWhere(['device_id' => $device->id])->all();
$doorOpen = [];
foreach ($doors as $key => $value) {
$doorOpen["Door" . $value->code] = "5";
$doorOpen["Door" . $value->code] = 255;
}
$response = json_decode(common::requestToCardService("/ControlDevice", [
"DeviceIP" => $device->ip_address,
"DoorID" => $doorOpen
]), true);
return [
"totals" => count($doors),
"IP" => $device->ip_address,
"response" => $response
];
}
}
public function actionCloseAllDoors() {
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-remove"]) . " Đóng tất cả cửa",
"form" => $this->renderPartial("openDoor"),
"lists" => $lists
];
}
}
public function actionCloseDoorsOfDevice() {
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] = 0;
}
$response = json_decode(common::requestToCardService("/ControlDevice", [
"DeviceIP" => $device->ip_address,

View File

@ -35,10 +35,10 @@
<button class="btn btn-primary" onclick="openDoor(this);" data-href="{yii\helpers\Url::to(['open-door', 'id' => $model->id, 'door' => $d->code])}">
Mở
</button>
{*<button id="always-open-{$d->id}" class="change-duration-{$d->id} btn btn-{if $d->always_open}warning{else}default{/if}" onclick="changeDuration(this);" data-href="{yii\helpers\Url::to(['change-duration', 'id' => $d->id, 'duration' => 255])}">
<button id="always-open-{$d->id}" class="change-duration-{$d->id} btn btn-{if $d->always_open}warning{else}default{/if}" onclick="changeDuration(this);" data-href="{yii\helpers\Url::to(['change-duration', 'id' => $d->id, 'duration' => 255])}">
Luôn mở
</button>
<button id="always-close-{$d->id}" class="change-duration-{$d->id} btn btn-{if $d->always_close}warning{else}default{/if}" onclick="changeDuration(this);" data-href="{yii\helpers\Url::to(['change-duration', 'id' => $d->id, 'duration' => 0])}">
{*<button id="always-close-{$d->id}" class="change-duration-{$d->id} btn btn-{if $d->always_close}warning{else}default{/if}" onclick="changeDuration(this);" data-href="{yii\helpers\Url::to(['change-duration', 'id' => $d->id, 'duration' => 0])}">
Luôn đóng
</button>*}
</td>

View File

@ -9,6 +9,7 @@
<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='URL_close_door' value="{Url::to(['close-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'])}">
@ -55,6 +56,9 @@
<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="closeAllDoors(this);" data-href="{Url::to(['close-all-doors'])}">
<i class="fa fa-close fa-1-5x"></i> Đóng tất cả cửa
</label>
{/if}
<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

View File

@ -673,3 +673,70 @@ function openAllDoorOfDevice(data) {
}
});
}
var progressCloseDoor = 0;
var totalsDoorToClose = 0;
function closeAllDoors(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();
totalsDoorToClose = data.lists.length;
for (var i = 0; i < data.lists.length; i++) {
closeAllDoorOfDevice(data.lists[i]);
}
},
error: function (jqXHR, textStatus, errorThrown) {
common.modalBlock(false);
common.ajaxError();
}
});
}
function closeAllDoorOfDevice(data) {
$.ajax({
url: $("input[name='URL_close_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> Đóng <b>" + data.totals + "</b> cửa từ thiết bị <b>" + data.IP + "</b>.</span><br>";
$("#logs-response").prepend(html);
progressCloseDoor++;
var percent = parseInt(progressCloseDoor / totalsDoorToClose * 100);
$("#progress").attr("aria-valuenow", percent);
$("#progress").attr("style", "width: " + percent + "%");
$("#progress").html(percent + "%");
if (percent >= 100) {
progressCloseDoor = 0;
$("#close-modal").attr("disabled", false);
}
},
error: function (jqXHR, textStatus, errorThrown) {
common.ajaxError();
}
});
}