diff --git a/assets/ListManagementAsset.php b/assets/ListManagementAsset.php
new file mode 100644
index 00000000..f8516442
--- /dev/null
+++ b/assets/ListManagementAsset.php
@@ -0,0 +1,23 @@
+all();
+ $allFeatures = [];
+ foreach ($listManagement as $key => $value) {
+ $features = json_decode($value->image, true);
+ $f = [];
+ foreach ($features as $k => $v) {
+ $f[] = $v['features'];
+ }
+ $allFeatures[] = [
+ "id" => $value->id,
+ "name" => $value->name,
+ "features" => $f
+ ];
+ }
+ Yii::$app->response->format = "json";
+ return $allFeatures;
+ }
+
public function generateRandomString($length = 10) {
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$charactersLength = strlen($characters);
diff --git a/controllers/ListManagementController.php b/controllers/ListManagementController.php
index 0c66b873..bcf77bd1 100644
--- a/controllers/ListManagementController.php
+++ b/controllers/ListManagementController.php
@@ -8,6 +8,8 @@ use app\models\ListManagementSearch;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
+use app\models\CaptureLogs;
+use app\models\common;
/**
* ListMamagementController implements the CRUD actions for ListMamagement model.
@@ -28,7 +30,7 @@ class ListManagementController extends Controller {
];
}
- public function actionIndex($from = "", $to = "") {
+ public function actionIndex($from = "", $to = "", $name = "", $type = "all", $gender = "all") {
$f = date_format(date_create_from_format('H:i d/m/Y', "00:00 " . date("d/m/Y")), 'U');
$t = date_format(date_create_from_format('H:i d/m/Y', "23:59 " . date("d/m/Y")), 'U');
if ($from !== "" && $to !== "") {
@@ -39,13 +41,20 @@ class ListManagementController extends Controller {
$searchModel = new ListManagementSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
$dataProvider->query->andWhere(["BETWEEN", "time", $f, $t]);
+ if ($name !== "")
+ $dataProvider->query->andWhere(["LIKE", "name", $name]);
+ if ($type !== "all")
+ $dataProvider->query->andWhere(["type" => $type]);
+ if ($gender !== "all")
+ $dataProvider->query->andWhere(["gender" => $gender]);
$dataProvider->query->orderBy(["time" => SORT_DESC]);
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
'f' => $f,
't' => $t,
- 'typeArray' => ListManagement::$typeArray
+ 'typeArray' => ListManagement::$typeArray,
+ 'genderArray' => ListManagement::$genderArray
]);
}
@@ -57,29 +66,95 @@ class ListManagementController extends Controller {
public function actionCreate() {
$model = new ListManagement();
+ Yii::$app->response->format = "json";
if (Yii::$app->request->post()) {
$data = Yii::$app->request->post();
- $data['image'] = \app\models\CaptureLogs::findOne($data['id'])->image;
- return $model->create($data);
+ $listManagement = ListManagement::findOne(['name' => $data['name']]);
+ $url = CaptureLogs::findOne($data['id'])->image;
+ if ($listManagement) {
+ $images = json_decode($listManagement->image, true);
+ $add = true;
+ foreach ($images as $key => $value) {
+ if ($value['url'] === $url)
+ $add = false;
+ }
+ if ($add) {
+ $features = json_decode(common::requestToEngine("/get-feature", [
+ "image_paths" => [
+ ["url" => "/home/sonhh/Pictures/10929_HongBI.jpg", "type" => "raw"]
+ ]
+ ]), true);
+ $images[] = ["url" => $url, "features" => $features['results'][0]['feature']];
+ $listManagement->image = json_encode($images);
+ $listManagement->time = time();
+ return $listManagement->save();
+ }
+ } else {
+ $features = json_decode(common::requestToEngine("/get-feature", [
+ "image_paths" => [
+ ["url" => "sex.png", "type" => "raw"]
+ ]
+ ]), true);
+ $data['image'] = json_encode([
+ ["url" => $url, "features" => $features['results'][0]['feature']]
+ ]);
+ return $model->create($data);
+ }
}
}
- public function actionUpdate($id) {
- $model = $this->findModel($id);
-
- if ($model->load(Yii::$app->request->post()) && $model->save()) {
- return $this->redirect(['view', 'id' => $model->id]);
+ public function actionFormUpdate() {
+ if (Yii::$app->request->post()) {
+ $data = Yii::$app->request->post();
+ $ListManagement = $this->findModel($data['id']);
+ $images = json_decode($ListManagement->image, true);
+ Yii::$app->response->format = "json";
+ return [
+ "type" => $ListManagement->type,
+ "name" => $ListManagement->name,
+ "gender" => $ListManagement->gender,
+ "birthday" => date("d/m/Y", $ListManagement->birthday),
+ "telephone" => $ListManagement->telephone,
+ "address" => $ListManagement->address,
+ "image" => "/BiFace/data/uploads/face/" . $images[0]['url']
+ ];
}
-
- return $this->render('update', [
- 'model' => $model,
- ]);
}
- public function actionDelete($id) {
- $this->findModel($id)->delete();
+ public function actionUpdate() {
+ if (Yii::$app->request->post()) {
+ $data = Yii::$app->request->post();
+ $model = $this->findModel($data['id']);
+ $model->type = $data['type'];
+ $model->name = $data['name'];
+ $model->gender = $data['gender'];
+ $model->birthday = $data['birthday'] === "" ? 0 : date_format(date_create_from_format('d/m/Y', $data['birthday']), 'U');
+ $model->telephone = $data['telephone'];
+ $model->address = $data['address'];
+ return $model->save();
+ }
+ }
- return $this->redirect(['index']);
+ public function actionDelete() {
+ if (Yii::$app->request->post()) {
+ $data = Yii::$app->request->post();
+ return $this->findModel($data['id'])->delete();
+ }
+ }
+
+ public function actionDeleteFeature() {
+ if (Yii::$app->request->post()) {
+ $data = Yii::$app->request->post();
+ $model = $this->findModel($data['id']);
+ $images = json_decode($model->image, true);
+ $features = [];
+ foreach ($images as $key => $value) {
+ if ($value['url'] !== $data['image'])
+ $features[] = $value;
+ }
+ $model->image = json_encode($features);
+ return $model->save();
+ }
}
protected function findModel($id) {
@@ -90,4 +165,11 @@ class ListManagementController extends Controller {
throw new NotFoundHttpException('The requested page does not exist.');
}
+ public function actionBatchDelete() {
+ if (Yii::$app->request->post()) {
+ $data = Yii::$app->request->post();
+ return ListManagement::deleteAll(["IN", "id", $data['lists']]);
+ }
+ }
+
}
diff --git a/db/app.db b/db/app.db
index c5495dcc..e50f128c 100644
Binary files a/db/app.db and b/db/app.db differ
diff --git a/helpers/ListManagementGrid.php b/helpers/ListManagementGrid.php
index 7e66248c..d7d9016a 100644
--- a/helpers/ListManagementGrid.php
+++ b/helpers/ListManagementGrid.php
@@ -42,10 +42,23 @@ class ListManagementGrid {
public static function image() {
return function($model) {
- return Html::img("/BiFace/data/uploads/face/" . $model->image, [
- "class" => "img-thumbnail",
- "style" => "width: 150px;height:150px;"
- ]);
+ $images = json_decode($model->image, true);
+ $return = [];
+ foreach ($images as $key => $value) {
+ $removeBtn = Html::button("", [
+ "class" => "btn btn-danger btn-xs",
+ "style" => "position:absolute;top:0;right:0;visibility: hidden;",
+ "onclick" => "_deleteFeature(this);",
+ "data-img" => $value['url'],
+ "data-id" => $model->id,
+ "data-href" => Url::to(["/list-management/delete-feature"])
+ ]);
+ $return[] = "
" . Html::img("/BiFace/data/uploads/face/" . $value['url'], [
+ "class" => "img-thumbnail",
+ "style" => "width: 100px;height:100px;"
+ ]) . $removeBtn . "
";
+ }
+ return implode(" ", $return);
};
}
@@ -58,11 +71,10 @@ class ListManagementGrid {
public static function rows() {
return function($model, $index, $widget, $grid) {
return [
- "ondblclick" => "_form(this);",
+ "ondblclick" => "_menu(this);",
"style" => "cursor: pointer;",
"data" => [
- "id" => $model->id,
- "img" => "/BiFace/data/uploads/face/" . $model->image
+ "id" => $model->id
]
];
};
diff --git a/models/ListManagement.php b/models/ListManagement.php
index 306c9fda..af3de96a 100644
--- a/models/ListManagement.php
+++ b/models/ListManagement.php
@@ -78,5 +78,9 @@ class ListManagement extends \yii\db\ActiveRecord {
"wl" => "Whitelist",
"bl" => "Blacklist"
];
+ public static $genderArray = [
+ "Male" => "Male",
+ "Female" => "Female"
+ ];
}
diff --git a/models/common.php b/models/common.php
index 5f8ed625..a96213e8 100644
--- a/models/common.php
+++ b/models/common.php
@@ -59,7 +59,7 @@ class common extends \yii\db\ActiveRecord {
// $now = time();
// $range = $now - $time;
// if ($range > 60 * 60 * 12) {
- return date($format, $time);
+ return date($format, $time);
// } else {
// return Yii::$app->formatter->asRelativeTime($time);
// }
@@ -171,4 +171,14 @@ class common extends \yii\db\ActiveRecord {
return $visible;
}
+ public static function requestToEngine($path, $data) {
+ return file_get_contents("http://192.168.2.158:2305" . $path, false, stream_context_create([
+ 'http' => [
+ 'header' => "Content-Type: application/json",
+ 'method' => "POST",
+ 'content' => json_encode($data)
+ ]
+ ]));
+ }
+
}
diff --git a/nbproject/private/private.xml b/nbproject/private/private.xml
index de7067d1..6807a2ba 100644
--- a/nbproject/private/private.xml
+++ b/nbproject/private/private.xml
@@ -2,8 +2,6 @@
-
- file:/E:/BiFace_Server_Lite/controllers/ConfigController.php
-
+
diff --git a/vendor/dmstr/yii2-adminlte-asset/example-views/yiisoft/yii2-app/layouts/header.php b/vendor/dmstr/yii2-adminlte-asset/example-views/yiisoft/yii2-app/layouts/header.php
index 830e6c89..ea5b0322 100644
--- a/vendor/dmstr/yii2-adminlte-asset/example-views/yiisoft/yii2-app/layouts/header.php
+++ b/vendor/dmstr/yii2-adminlte-asset/example-views/yiisoft/yii2-app/layouts/header.php
@@ -36,12 +36,12 @@ use yii\widgets\ActiveForm;
- -
+
- ">
Cấu hình
- -
+
- ">
Dữ liệu
@@ -51,12 +51,12 @@ use yii\widgets\ActiveForm;
Reset thiết bị
- -
+
- ">
List Management
- -
+
- ">
Capture log
diff --git a/views/list-management/index.tpl b/views/list-management/index.tpl
index e1b50d73..f6b9ed40 100644
--- a/views/list-management/index.tpl
+++ b/views/list-management/index.tpl
@@ -1,8 +1,8 @@
{extends file=$smarty.current_dir|cat:'/../extends.tpl'}
{use class="yii\helpers\Url"}
{use class="yii\grid\GridView"}
-{*use class="app\assets\CaptureLogsAsset"}
-{CaptureLogsAsset::register($this)|void*}
+{use class="app\assets\ListManagementAsset"}
+{ListManagementAsset::register($this)|void}
{block name='content'}
@@ -27,7 +38,7 @@
'rowOptions' => \app\helpers\ListManagementGrid::rows(),
'columns' => [
[
- 'class' => 'yii\grid\SerialColumn',
+ 'attribute' => 'id',
'contentOptions' => ['class' => 'text-center'],
'headerOptions' => ['class' => 'text-center']
],
@@ -50,8 +61,6 @@
[
'attribute' => 'image',
'format' => "raw",
- 'contentOptions' => ['class' => 'text-center'],
- 'headerOptions' => ['class' => 'text-center'],
'value' => \app\helpers\ListManagementGrid::image()
],
[
@@ -89,11 +98,56 @@
+
+
+
+
+
+
+
+
+
+
+
+
-
+
+
+
Xóa nhiều dữ liệu
+
+
+
+ Chọn toàn bộ trang
+ Bỏ chọn
+
+
+
+ Xác nhận xóa
+
+
+
+
+
+
@@ -127,8 +180,7 @@
Gender
@@ -153,8 +205,8 @@
-
- Save
+
+ Save
Cancel
diff --git a/web/js/list-management.js b/web/js/list-management.js
new file mode 100644
index 00000000..abb4db48
--- /dev/null
+++ b/web/js/list-management.js
@@ -0,0 +1,184 @@
+var x = 0, y = 0;
+$(function () {
+ common.dateTimePickerByClass("datepicker", "HH:mm DD/MM/YYYY");
+ common.dateTimePickerDay("birthday");
+ $("tr").bind("click", function (event) {
+ x = event.pageX;
+ y = event.pageY;
+ });
+ $("input[name='BatchDelete']").change(function () {
+ if (this.checked) {
+ $("#delete-btn-group").removeClass("hidden");
+ } else {
+ $("tr").removeClass("delete-choose");
+ $("#delete-btn-group").addClass("hidden");
+ }
+ });
+});
+
+function _search(e) {
+ var location = $(e).attr("data-href") + "?from=" + $("input[name='From']").val() + "&to=" + $("input[name='To']").val();
+ location = location + "&name=" + $("input[name='NameSearch']").val();
+ location = location + "&type=" + $("select[name='TypeSearch']").val();
+ location = location + "&gender=" + $("select[name='GenderSearch']").val();
+ window.location = location;
+}
+
+function _close() {
+ $("#form").addClass("hidden");
+}
+
+function _menu(e) {
+ var isDelete = $("input[name='BatchDelete']").is(':checked');
+ if (isDelete) {
+ if ($(e).hasClass("delete-choose"))
+ $(e).removeClass("delete-choose");
+ else
+ $(e).addClass("delete-choose");
+ $("#menu").addClass("hidden");
+ } else {
+ $("input[name='ListManagementID']").val($(e).attr("data-id"));
+ $("#menu").css({top: y, left: x}).removeClass("hidden");
+ }
+}
+
+function _closeMenu() {
+ $("#menu").addClass("hidden");
+}
+
+function _formModified(e) {
+ _closeMenu();
+ $("#form").removeClass("hidden");
+ common.modalBlock(true);
+ $.ajax({
+ url: $(e).attr("data-href"),
+ type: 'POST',
+ data: {
+ id: $("input[name='ListManagementID']").val()
+ },
+ success: function (data) {
+ common.modalBlock(false);
+ $("select[name='Type']").val(data.type);
+ $("input[name='Name']").val(data.name);
+ $("select[name='Gender']").val(data.gender);
+ $("input[name='Birthday']").val(data.birthday);
+ $("input[name='Telephone']").val(data.telephone);
+ $("input[name='Address']").val(data.address);
+ $("#FaceImage").attr("src", data.image);
+ },
+ error: function (jqXHR, textStatus, errorThrown) {
+ common.modalBlock(false);
+ common.ajaxError();
+ }
+ });
+}
+
+function _update(e) {
+ var name = $("input[name='Name']").val();
+ if (name === "") {
+ alert("Hãy nhập tên!");
+ return;
+ }
+ common.modalBlock(true);
+ $.ajax({
+ url: $(e).attr("data-href"),
+ type: 'POST',
+ data: {
+ name: name,
+ type: $("select[name='Type']").val(),
+ gender: $("select[name='Gender']").val(),
+ birthday: $("input[name='Birthday']").val(),
+ telephone: $("input[name='Telephone']").val(),
+ address: $("input[name='Address']").val(),
+ id: $("input[name='ListManagementID']").val()
+ },
+ success: function (data) {
+ alert("Cập nhật dữ liệu thành công!");
+ window.location.reload(true);
+ },
+ error: function (jqXHR, textStatus, errorThrown) {
+ common.modalBlock(false);
+ common.ajaxError();
+ }
+ });
+}
+
+function _delete(e) {
+ if (confirm("Bạn có chắc chắn muốn xóa không?")) {
+ common.modalBlock(true);
+ $.ajax({
+ url: $(e).attr("data-href"),
+ type: 'POST',
+ data: {
+ id: $("input[name='ListManagementID']").val()
+ },
+ success: function (data) {
+ window.location.reload(true);
+ },
+ error: function (jqXHR, textStatus, errorThrown) {
+ common.modalBlock(false);
+ common.ajaxError();
+ }
+ });
+ }
+}
+
+function _deleteFeature(e) {
+ if (confirm("Bạn có chắc chắn muốn xóa ảnh này không?")) {
+ common.modalBlock(true);
+ $.ajax({
+ url: $(e).attr("data-href"),
+ type: 'POST',
+ data: {
+ image: $(e).attr("data-img"),
+ id: $(e).attr("data-id")
+ },
+ success: function (data) {
+ common.modalBlock(false);
+ $(e).closest("div").remove();
+ },
+ error: function (jqXHR, textStatus, errorThrown) {
+ common.modalBlock(false);
+ common.ajaxError();
+ }
+ });
+ }
+}
+
+function checkAll(status) {
+ if (status)
+ $("tr").addClass("delete-choose");
+ else
+ $("tr").removeClass("delete-choose");
+}
+
+function batchDelete(e) {
+ var check = $(".delete-choose");
+ if (check.length == 0) {
+ alert("Hãy chọn dữ liệu để xóa!");
+ return;
+ }
+ var lists = [];
+ $.each($(".delete-choose"), function () {
+ if ($(this).attr("data-id") !== "")
+ lists.push($(this).attr("data-id"));
+ });
+ if (confirm("Bạn có chắc chắn muốn xóa không?")) {
+ common.modalBlock(true);
+ $.ajax({
+ url: $(e).attr("data-href"),
+ type: 'POST',
+ data: {
+ lists: lists
+ },
+ success: function (data) {
+ alert("Đã xóa dữ liệu!");
+ window.location.reload(true);
+ },
+ error: function (jqXHR, textStatus, errorThrown) {
+ common.modalBlock(false);
+ common.ajaxError();
+ }
+ });
+ }
+}
\ No newline at end of file