From 4ba094ab24a5bbb6452b557da54c6dd4d69d711a Mon Sep 17 00:00:00 2001 From: dongpd Date: Fri, 16 Oct 2020 11:35:29 +0700 Subject: [PATCH] =?UTF-8?q?update=20th=E1=BB=91ng=20k=C3=AA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- access_control.sql | 79 ++++++++++- assets/LogsAsset.php | 23 ++++ config/web.php | 6 +- controllers/LogsController.php | 123 +++++++++++++++++- controllers/SiteController.php | 2 +- controllers/UserController.php | 3 - helpers/LogsGrid.php | 62 +++++++++ models/EventType.php | 57 ++++++++ models/Logs.php | 25 +++- models/LogsSearch.php | 26 ++-- .../yiisoft/yii2-app/layouts/header.php | 4 +- .../yiisoft/yii2-app/layouts/left.php | 15 ++- views/logs/index.tpl | 97 ++++++++++++-- views/user/index.tpl | 69 +++++----- web/js/common.js | 4 + web/js/logs.js | 11 ++ 16 files changed, 526 insertions(+), 80 deletions(-) create mode 100644 assets/LogsAsset.php create mode 100644 helpers/LogsGrid.php create mode 100644 models/EventType.php create mode 100644 web/js/logs.js diff --git a/access_control.sql b/access_control.sql index 4e0146fd..fcb53b68 100644 --- a/access_control.sql +++ b/access_control.sql @@ -3,7 +3,7 @@ -- https://www.phpmyadmin.net/ -- -- Host: 127.0.0.1 --- Generation Time: Oct 14, 2020 at 11:53 AM +-- Generation Time: Oct 16, 2020 at 06:34 AM -- Server version: 10.4.8-MariaDB -- PHP Version: 7.1.33 @@ -218,7 +218,7 @@ CREATE TABLE `device` ( INSERT INTO `device` (`id`, `name`, `serial`, `ip_address`, `subnet_mask`, `gateway`, `mac_address`, `status`, `type`, `version`, `area_id`, `created_at`, `modified_at`) VALUES (4, 'Thiết bị 1', 'AJNV193560605', '192.168.1.200', '255.255.252.0', '192.168.0.1', '00:17:61:C9:6B:A4', 1, 'C3-200', 'AC Ver 4.3.4 Jan 5 2019', 1, 1602563228, 1602563228), -(5, '192.168.1.202', 'AJNV200860076', '192.168.1.202', '255.255.252.0', '192.168.0.1', '00:17:61:CA:8D:F6', 1, 'C3-200', 'AC Ver 4.3.4 Jan 5 2019', 1, 1602659429, 1602659429); +(5, '192.168.1.205', 'AJNV200860076', '192.168.1.205', '255.255.255.255', '192.168.0.1', '00:17:61:CA:8D:F6', 1, 'C3-200', 'AC Ver 4.3.4 Jan 5 2019', 1, 1602659429, 1602659429); -- -------------------------------------------------------- @@ -247,6 +247,55 @@ INSERT INTO `door` (`id`, `device_id`, `name`, `code`, `created_at`, `modified_a -- -------------------------------------------------------- +-- +-- Table structure for table `event_type` +-- + +CREATE TABLE `event_type` ( + `id` int(11) NOT NULL, + `code` int(11) NOT NULL, + `name` varchar(200) NOT NULL, + `description` text NOT NULL +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +-- +-- Dumping data for table `event_type` +-- + +INSERT INTO `event_type` (`id`, `code`, `name`, `description`) VALUES +(1, 0, 'Normal Punch Open', 'In [Card Only] verification mode, the person has open door permission punch the card and triggers this normal event of open the door.'), +(2, 27, 'Unregistered Card', 'Refers to the current card is not registered in the system, trigger this abnormal event.'); + +-- -------------------------------------------------------- + +-- +-- Table structure for table `logs` +-- + +CREATE TABLE `logs` ( + `id` int(11) NOT NULL, + `staff_id` int(11) NOT NULL DEFAULT 0, + `card_number` int(11) NOT NULL, + `device_id` int(11) NOT NULL, + `door_id` int(11) NOT NULL, + `in_out_state` int(11) NOT NULL, + `time` int(11) NOT NULL, + `event_type` int(11) NOT NULL +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +-- +-- Dumping data for table `logs` +-- + +INSERT INTO `logs` (`id`, `staff_id`, `card_number`, `device_id`, `door_id`, `in_out_state`, `time`, `event_type`) VALUES +(6, 2, 16672726, 4, 2, 1, 1602819028, 0), +(7, 2, 16672726, 4, 1, 1, 1602819033, 0), +(8, 2, 16672726, 4, 1, 0, 1602819356, 0), +(9, 3, 2430805, 4, 2, 1, 1602819665, 0), +(10, 0, 16673826, 4, 2, 1, 1602819669, 27); + +-- -------------------------------------------------------- + -- -- Table structure for table `schedule` -- @@ -2437,6 +2486,18 @@ ALTER TABLE `device` ALTER TABLE `door` ADD PRIMARY KEY (`id`); +-- +-- Indexes for table `event_type` +-- +ALTER TABLE `event_type` + ADD PRIMARY KEY (`id`); + +-- +-- Indexes for table `logs` +-- +ALTER TABLE `logs` + ADD PRIMARY KEY (`id`); + -- -- Indexes for table `schedule` -- @@ -2490,6 +2551,18 @@ ALTER TABLE `device` ALTER TABLE `door` MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=11; +-- +-- AUTO_INCREMENT for table `event_type` +-- +ALTER TABLE `event_type` + MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=3; + +-- +-- AUTO_INCREMENT for table `logs` +-- +ALTER TABLE `logs` + MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=11; + -- -- AUTO_INCREMENT for table `schedule` -- @@ -2512,7 +2585,7 @@ ALTER TABLE `system_logs` -- AUTO_INCREMENT for table `user` -- ALTER TABLE `user` - MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=202; + MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=203; -- -- Constraints for dumped tables diff --git a/assets/LogsAsset.php b/assets/LogsAsset.php new file mode 100644 index 00000000..52affc19 --- /dev/null +++ b/assets/LogsAsset.php @@ -0,0 +1,23 @@ + 'basic', - 'homeUrl' => ['/dashboard'], - 'name' => 'AIParking Traffic', - 'defaultRoute' => 'dashboard', + 'homeUrl' => ['/staff'], + 'name' => 'Access Control', + 'defaultRoute' => 'staff', 'basePath' => dirname(__DIR__), 'bootstrap' => ['log'], 'timeZone' => 'Asia/Ho_Chi_Minh', diff --git a/controllers/LogsController.php b/controllers/LogsController.php index 2899e25e..6e43f199 100644 --- a/controllers/LogsController.php +++ b/controllers/LogsController.php @@ -8,6 +8,10 @@ use app\models\LogsSearch; use yii\web\Controller; use yii\web\NotFoundHttpException; use yii\filters\VerbFilter; +use app\models\Device; +use app\models\EventType; +use app\models\Department; +use app\models\common; /** * LogsController implements the CRUD actions for Logs model. @@ -34,17 +38,132 @@ class LogsController extends Controller { ]; } - public function actionIndex() { - $this->view->title = 'Sự kiện hôm nay'; + public function actionIndex($type = "today", $from = "", $to = "") { + $f = $t = 0; + $this->view->title = 'Tất cả sự kiện'; + if ($type === "today" && $from === "" && $to === "") { + $f = date_format(date_create_from_format('H:i:s d/m/Y', "00:00:00 " . date("d/m/Y")), 'U'); + $t = date_format(date_create_from_format('H:i:s d/m/Y', "23:59:59 " . date("d/m/Y")), 'U'); + $this->view->title = 'Sự kiện hôm nay'; + } + if ($type === "3days" && $from === "" && $to === "") { + $f = date_format(date_create_from_format('H:i:s d/m/Y', "00:00:00 " . date("d/m/Y")), 'U'); + $f = $f - 60 * 60 * 24 * 2; + $t = date_format(date_create_from_format('H:i:s d/m/Y', "23:59:59 " . date("d/m/Y")), 'U'); + $this->view->title = 'Sự kiện 3 ngày gần đây'; + } + if ($type === "thisWeek" && $from === "" && $to === "") { + $dayOfWeek = date("w"); + $f = date_format(date_create_from_format('H:i:s d/m/Y', "00:00:00 " . date("d/m/Y")), 'U'); + $f = $f - 60 * 60 * 24 * ($dayOfWeek - 1); + $t = date_format(date_create_from_format('H:i:s d/m/Y', "23:59:59 " . date("d/m/Y")), 'U'); + $t = $t + 60 * 60 * 24 * (7 - $dayOfWeek); + $this->view->title = 'Sự kiện tuần này'; + } + if ($type === "lastWeek" && $from === "" && $to === "") { + $dayOfWeek = date("w"); + $f = date_format(date_create_from_format('H:i:s d/m/Y', "00:00:00 " . date("d/m/Y")), 'U'); + $f = $f - 60 * 60 * 24 * ($dayOfWeek - 1) - 60 * 60 * 24 * 7; + $t = date_format(date_create_from_format('H:i:s d/m/Y', "23:59:59 " . date("d/m/Y")), 'U'); + $t = $t + 60 * 60 * 24 * (7 - $dayOfWeek) - 60 * 60 * 24 * 7; + $this->view->title = 'Sự kiện tuần trước'; + } + if ($from !== "" && $to !== "") { + $f = date_format(date_create_from_format('H:i:s d/m/Y', $from), 'U'); + $t = date_format(date_create_from_format('H:i:s d/m/Y', $to), 'U'); + } $searchModel = new LogsSearch(); $dataProvider = $searchModel->search(Yii::$app->request->queryParams); + if ($f != 0 && $t != 0) { + $dataProvider->query->andWhere(["BETWEEN", 'time', $f, $t]); + } + $dataProvider->query->orderBy(["time" => SORT_DESC]); return $this->render('index', [ 'searchModel' => $searchModel, 'dataProvider' => $dataProvider, + 'deviceArray' => Device::deviceArray(), + 'stateArray' => Logs::$stateArray, + 'eventTypeArray' => EventType::eventTypeArray(), + 'departmentArray' => Department::departmentArray(), + 'f' => $f, + 't' => $t ]); } + public function actionExport($from = "", $to = "") { + $f = date_format(date_create_from_format('H:i:s d/m/Y', $from), 'U'); + $t = date_format(date_create_from_format('H:i:s d/m/Y', $to), 'U'); + $objPHPExcel = new \PHPExcel(); + $objPHPExcel->setActiveSheetIndex(0); + $toExcelFile[] = ["Thời gian", "Mã nhân viên", "Tên nhân viên", "Phòng ban", "Mã thẻ", "Thiết bị", "Cửa", "Trạng thái vào/ra", "Mô tả sự kiện"]; + $query = Logs::find(); + $query->andWhere(["BETWEEN", 'time', $f, $t]); + $query->orderBy(["time" => SORT_DESC]); + $logs = $query->all(); + $departmentArray = Department::departmentArray(); + $deviceArray = Device::deviceArray(); + $stateArray = Logs::$stateArray; + $eventTypeArray = EventType::eventTypeArray(); + foreach ($logs as $k => $v) { + $staff = $v->staff; + $ExportData[] = date("H:i:s d/m/Y", $v->time); + $ExportData[] = $staff ? $staff->code : ""; + $ExportData[] = $staff ? $staff->name : ""; + $ExportData[] = $staff && isset($departmentArray[$staff->department_id]) ? $departmentArray[$staff->department_id] : ""; + $ExportData[] = $v->card_number; + $ExportData[] = isset($deviceArray[$v->device_id]) ? $deviceArray[$v->device_id] : ""; + $ExportData[] = isset($deviceArray[$v->device_id]) ? $deviceArray[$v->device_id] . "-" . $v->door_id : ""; + $ExportData[] = isset($stateArray[$v->in_out_state]) ? $stateArray[$v->in_out_state] : ""; + $ExportData[] = isset($eventTypeArray[$v->event_type]) ? $eventTypeArray[$v->event_type] : ""; + $toExcelFile[] = $ExportData; + unset($ExportData); + } + $totals = count($logs) + 1; + $activeSheet = $objPHPExcel->getActiveSheet(); + $activeSheet->getStyle("A1:I" . $totals)->getFont()->setName('Time New Roman')->setSize(10); + $activeSheet->getStyle("A1:I1")->applyFromArray([ + 'fill' => array( + 'type' => \PHPExcel_Style_Fill::FILL_SOLID, + 'color' => array('rgb' => '7ac3ec') + ) + ]); + $rowCount = 1; + for ($i = 0; $i < count($toExcelFile); $i++) { + $column = 'A'; + $row = $toExcelFile[$i]; + for ($j = 0; $j < count($row); $j++) { + if (!isset($row[$j])) + $value = NULL; + elseif ($row[$j] != "") + $value = strip_tags($row[$j]); + else + $value = ""; + $activeSheet->setCellValue($column . $rowCount, $value); + $column = chr(ord($column) + 1); + } + $rowCount++; + } + $activeSheet->getStyle("A1:I" . $totals)->applyFromArray([ + 'alignment' => [ + 'vertical' => \PHPExcel_Style_Alignment::VERTICAL_CENTER, + ], + 'borders' => [ + 'allborders' => [ + 'style' => \PHPExcel_Style_Border::BORDER_THIN + ] + ] + ]); + + $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007'); + ob_end_clean(); + header('Content-type: application/vnd.ms-excel'); + header('Content-Disposition: attachment; filename="logs_' . date("YmdHis") . '.xlsx"'); + header('Cache-Control: max-age=0'); + common::SaveViaTempFile($objWriter); + exit(); + } + protected function findModel($id) { if (($model = Logs::findOne($id)) !== null) { return $model; diff --git a/controllers/SiteController.php b/controllers/SiteController.php index 7715fe1f..39fc4da4 100644 --- a/controllers/SiteController.php +++ b/controllers/SiteController.php @@ -73,7 +73,7 @@ class SiteController extends Controller { $model = new LoginForm(); if ($model->load(Yii::$app->request->post()) && $model->login()) { - return $this->redirect(["/dashboard"]); + return $this->redirect(["/staff"]); } $model->password = ''; diff --git a/controllers/UserController.php b/controllers/UserController.php index 9888a71f..39b2bb13 100644 --- a/controllers/UserController.php +++ b/controllers/UserController.php @@ -42,9 +42,6 @@ class UserController extends Controller { throw new \yii\web\HttpException(403, 'Bạn không có quyền truy cập nội dung này'); $this->view->title = 'Người dùng'; - $this->view->params['breadcrumbs'][] = 'Hệ thống'; - $this->view->params['breadcrumbs'][] = $this->view->title; - $searchModel = new UserSearch(); $dataProvider = $searchModel->search(Yii::$app->request->queryParams); diff --git a/helpers/LogsGrid.php b/helpers/LogsGrid.php new file mode 100644 index 00000000..5f3edb72 --- /dev/null +++ b/helpers/LogsGrid.php @@ -0,0 +1,62 @@ +time); + }; + } + + public static function device($array) { + return function($model) use ($array) { + return isset($array[$model->device_id]) ? $array[$model->device_id] : ""; + }; + } + + public static function door($array) { + return function($model) use ($array) { + return isset($array[$model->device_id]) ? $array[$model->device_id] . "-" . $model->door_id : ""; + }; + } + + public static function state($array) { + return function($model) use ($array) { + return isset($array[$model->in_out_state]) ? $array[$model->in_out_state] : ""; + }; + } + + public static function eventType($array) { + return function($model) use ($array) { + return isset($array[$model->event_type]) ? $array[$model->event_type] : ""; + }; + } + + public static function name() { + return function($model) { + $staff = $model->staff; + return $staff ? $staff->name : ""; + }; + } + + public static function department($array) { + return function($model) use ($array) { + $staff = $model->staff; + if ($staff) + return isset($array[$staff->department_id]) ? $array[$staff->department_id] : ""; + return ""; + }; + } + + public static function rowsColor() { + return function($model, $index, $widget, $grid) { + $color = "orange"; + if ($model->event_type == 0) + $color = "green"; + return ["class" => "text-" . $color]; + }; + } + +} diff --git a/models/EventType.php b/models/EventType.php new file mode 100644 index 00000000..f584e7ca --- /dev/null +++ b/models/EventType.php @@ -0,0 +1,57 @@ + 200], + ]; + } + + /** + * {@inheritdoc} + */ + public function attributeLabels() { + return [ + 'id' => 'ID', + 'code' => 'Code', + 'name' => 'Name', + 'description' => 'Description', + ]; + } + + public static function eventTypeArray() { + $lists = self::find()->all(); + $results = []; + foreach ($lists as $key => $value) { + $results[$value->code] = $value->name; + } + return $results; + } + +} diff --git a/models/Logs.php b/models/Logs.php index 44dac57f..ce8ebe40 100644 --- a/models/Logs.php +++ b/models/Logs.php @@ -41,22 +41,33 @@ class Logs extends \yii\db\ActiveRecord { public function attributeLabels() { return [ 'id' => 'ID', - 'staff_id' => 'Staff ID', - 'card_number' => 'card_number', - 'device_id' => 'Device ID', - 'door_id' => 'Door ID', - 'in_out_state' => 'In Out State', - 'time' => 'Time', - 'event_type' => 'Event Type', + 'staff_id' => 'Mã nhân viên', + 'card_number' => 'Mã thẻ', + 'device_id' => 'Thiết bị', + 'door_id' => 'Cửa', + 'in_out_state' => 'Trạng thái vào/ra', + 'time' => 'Thời gian', + 'event_type' => 'Mô tả sự kiện', + 'staff_name' => 'Tên nhân viên', + 'staff_department' => 'Phòng ban', ]; } + public static $stateArray = [ + 0 => "Vào", + 1 => "Ra" + ]; + public function multiCreate($datas) { $field = ['staff_id', 'card_number', 'device_id', 'door_id', 'in_out_state', 'time', 'event_type']; static::getDb()->createCommand()->batchInsert($this->tableName(), $field, $datas)->execute(); return true; } + public function getStaff() { + return $this->hasOne(Staff::className(), ["id" => "staff_id"]); + } + public static function parseTime($time) { $temp = intval($time); $second = $temp % 60; diff --git a/models/LogsSearch.php b/models/LogsSearch.php index a7980f04..d8cb2bba 100644 --- a/models/LogsSearch.php +++ b/models/LogsSearch.php @@ -10,23 +10,25 @@ use app\models\Logs; /** * LogsSearch represents the model behind the search form of `app\models\Logs`. */ -class LogsSearch extends Logs -{ +class LogsSearch extends Logs { + + public $staff_name; + public $staff_department; + /** * {@inheritdoc} */ - public function rules() - { + public function rules() { return [ - [['id', 'staff_id', 'device_id', 'door_id', 'in_out_state', 'time', 'event_type'], 'integer'], + [['id', 'staff_id', 'device_id', 'in_out_state', 'event_type', 'card_number', 'staff_department'], 'integer'], + [['staff_name'], 'safe'], ]; } /** * {@inheritdoc} */ - public function scenarios() - { + public function scenarios() { // bypass scenarios() implementation in the parent class return Model::scenarios(); } @@ -38,9 +40,9 @@ class LogsSearch extends Logs * * @return ActiveDataProvider */ - public function search($params) - { + public function search($params) { $query = Logs::find(); + $query->joinWith("staff"); // add conditions that should always apply here @@ -56,6 +58,11 @@ class LogsSearch extends Logs return $dataProvider; } + if ($this->staff_name) + $query->andFilterWhere(['LIKE', 'name', $this->staff_name]); + if ($this->staff_department) + $query->andFilterWhere(['department_id' => $this->staff_department]); + // grid filtering conditions $query->andFilterWhere([ 'id' => $this->id, @@ -69,4 +76,5 @@ class LogsSearch extends Logs return $dataProvider; } + } 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 3d024672..6b8ca2a1 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 @@ -40,8 +40,8 @@ use yii\widgets\ActiveForm; Báo cáo -
  • - +
  • "> + Hệ thống
  • diff --git a/vendor/dmstr/yii2-adminlte-asset/example-views/yiisoft/yii2-app/layouts/left.php b/vendor/dmstr/yii2-adminlte-asset/example-views/yiisoft/yii2-app/layouts/left.php index 881f9da3..49e38c1d 100644 --- a/vendor/dmstr/yii2-adminlte-asset/example-views/yiisoft/yii2-app/layouts/left.php +++ b/vendor/dmstr/yii2-adminlte-asset/example-views/yiisoft/yii2-app/layouts/left.php @@ -33,13 +33,18 @@ ['label' => 'Cấp quyền truy cập', 'url' => ['/assign'], 'icon' => 'cogs'] ]; } + if (in_array($this->context->id, ['user'])) { + $items = [ + ['label' => 'Người dùng', 'url' => ['/user'], 'icon' => 'users'] + ]; + } if (in_array($this->context->id, ['logs'])) { $items = [ - ['label' => 'Sự kiện hôm nay', 'url' => ['/logs'], 'icon' => 'clock-o'], - ['label' => 'Sự kiện 3 ngày gần đây', 'url' => ['/logs/3-days'], 'icon' => 'calendar'], - ['label' => 'Sự kiện tuần này', 'url' => ['/logs/this-week'], 'icon' => 'calendar'], - ['label' => 'Sự kiện tuần trước', 'url' => ['/logs/last-week'], 'icon' => 'calendar'], - ['label' => 'Tất cả', 'url' => ['/logs/all'], 'icon' => 'calendar'] + ['label' => 'Sự kiện hôm nay', 'url' => ['/logs', 'type' => 'today'], 'icon' => 'clock-o'], + ['label' => 'Sự kiện 3 ngày gần đây', 'url' => ['/logs', 'type' => '3days'], 'icon' => 'calendar'], + ['label' => 'Sự kiện tuần này', 'url' => ['/logs', 'type' => 'thisWeek'], 'icon' => 'calendar'], + ['label' => 'Sự kiện tuần trước', 'url' => ['/logs', 'type' => 'lastWeek'], 'icon' => 'calendar'], + ['label' => 'Tất cả', 'url' => ['/logs', 'type' => 'all'], 'icon' => 'calendar'] ]; } ?> diff --git a/views/logs/index.tpl b/views/logs/index.tpl index 2e63e448..ba1d58b9 100644 --- a/views/logs/index.tpl +++ b/views/logs/index.tpl @@ -2,17 +2,42 @@ {use class="yii\helpers\Url"} {use class="yii\grid\GridView"} {use class="yii\widgets\Pjax" type="block"} -{use class="app\assets\DepartmentAsset"} -{DepartmentAsset::register($this)|void} +{use class="app\assets\LogsAsset"} +{LogsAsset::register($this)|void} {block name='content'} +
    -
    - - +
    +
    + +
    +
    +
    +
    +
    +
    Từ
    + +
    +
    +
    +
    +
    Đến
    + +
    +
    +
    + +
    +
    +
    {Pjax id="department-list"} {GridView::widget([ @@ -23,14 +48,64 @@ 'class' => 'table table-striped table-bordered table-hover', 'style' => 'background:#fff;min-width:700px;' ], + 'rowOptions' => \app\helpers\LogsGrid::rowsColor(), 'columns' => [ [ 'class' => 'yii\grid\SerialColumn', 'contentOptions' => ['class' => 'text-center'], 'headerOptions' => ['class' => 'text-center', 'style' => 'width:3%'] ], - 'time', - 'staff_id' + [ + 'attribute' => 'time', + 'format' => 'raw', + 'headerOptions' => ['style' => 'width:10%'], + 'value' => \app\helpers\LogsGrid::time() + ], + [ + 'attribute' => 'staff_id', + 'contentOptions' => ['class' => 'text-center'], + 'headerOptions' => ['style' => 'width:5%'] + ], + [ + 'attribute' => 'staff_name', + 'format' => 'raw', + 'value' => \app\helpers\LogsGrid::name() + ], + [ + 'attribute' => 'staff_department', + 'filter' => $departmentArray, + 'format' => 'raw', + 'value' => \app\helpers\LogsGrid::department($departmentArray) + ], + 'card_number', + [ + 'attribute' => 'device_id', + 'format' => 'raw', + 'filter' => $deviceArray, + 'headerOptions' => ['style' => 'width:10%'], + 'value' => \app\helpers\LogsGrid::device($deviceArray) + ], + [ + 'attribute' => 'door_id', + 'format' => 'raw', + 'filter' => $deviceArray, + 'headerOptions' => ['style' => 'width:10%'], + 'value' => \app\helpers\LogsGrid::door($deviceArray) + ], + [ + 'attribute' => 'in_out_state', + 'format' => 'raw', + 'filter' => $stateArray, + 'headerOptions' => ['style' => 'width:8%'], + 'contentOptions' => ['class' => 'text-center'], + 'value' => \app\helpers\LogsGrid::state($stateArray) + ], + [ + 'attribute' => 'event_type', + 'format' => 'raw', + 'filter' => $eventTypeArray, + 'value' => \app\helpers\LogsGrid::eventType($eventTypeArray) + ] ] ])} {/Pjax} diff --git a/views/user/index.tpl b/views/user/index.tpl index 17f12860..c3b68c7c 100644 --- a/views/user/index.tpl +++ b/views/user/index.tpl @@ -4,41 +4,42 @@ {use class="app\assets\UserAsset"} {UserAsset::register($this)|void} {block name='content'} -
    - -
    -
    - {GridView::widget([ - 'dataProvider' => $dataProvider, - 'filterModel' => $searchModel, - 'layout'=> \app\helpers\UserGrid::getLayout(), - 'tableOptions' => [ - 'class' => 'table table-striped table-bordered', - 'style' => 'background:#fff;min-width:700px;' - ], - 'columns' => [ - ['class' => 'yii\grid\SerialColumn'], - 'username', - 'first_name', - [ - 'attribute' => 'roleName', - 'format' => 'raw', - 'value' => \app\helpers\UserGrid::roles() +
    +
    + +
    + {GridView::widget([ + 'dataProvider' => $dataProvider, + 'filterModel' => $searchModel, + 'layout'=> \app\helpers\UserGrid::getLayout(), + 'tableOptions' => [ + 'class' => 'table table-striped table-bordered', + 'style' => 'background:#fff;min-width:700px;' ], - 'phone_number', - 'email', - [ - 'template'=> \app\helpers\UserGrid::actionTemplate(), - 'class' => 'yii\grid\ActionColumn', - 'contentOptions' => ['class' => 'text-center'], - 'headerOptions' => ['style' => 'width:10%'], - 'buttons' => [ - 'update' => \app\helpers\UserGrid::update('user'), - 'delete' => \app\helpers\UserGrid::delete('Bạn có chắc chắn muốn xóa người dùng này không?') + 'columns' => [ + ['class' => 'yii\grid\SerialColumn'], + 'username', + 'first_name', + [ + 'attribute' => 'roleName', + 'format' => 'raw', + 'value' => \app\helpers\UserGrid::roles() + ], + 'phone_number', + 'email', + [ + 'template'=> \app\helpers\UserGrid::actionTemplate(), + 'class' => 'yii\grid\ActionColumn', + 'contentOptions' => ['class' => 'text-center'], + 'headerOptions' => ['style' => 'width:10%'], + 'buttons' => [ + 'update' => \app\helpers\UserGrid::update('user'), + 'delete' => \app\helpers\UserGrid::delete('Bạn có chắc chắn muốn xóa người dùng này không?') + ] ] ] - ] - ])} + ])} +
    {/block} \ No newline at end of file diff --git a/web/js/common.js b/web/js/common.js index e2c9625b..f500256b 100644 --- a/web/js/common.js +++ b/web/js/common.js @@ -186,6 +186,7 @@ common.dateTimePickerByClass = function (cls, format) { $('.' + cls).datetimepicker({ locale: 'vi', ignoreReadonly: true, + sideBySide: true, format: format }); }; @@ -251,6 +252,9 @@ common.form = function (e, obj, bigSize) { if (obj === 'schedule') { common.dateTimePickerByClass("select-picker", "HH:mm"); } + if (obj === 'user') { + $('#role').select2({tags: true, tokenSeparators: [',']}); + } }, error: function (jqXHR, textStatus, errorThrown) { common.modalBlock(false); diff --git a/web/js/logs.js b/web/js/logs.js new file mode 100644 index 00000000..63a088d6 --- /dev/null +++ b/web/js/logs.js @@ -0,0 +1,11 @@ +$(function () { + common.dateTimePickerByClass("time-picker", "HH:mm:ss DD/MM/YYYY"); +}); + +function _export(e) { + window.location = $(e).attr("data-href") + "?from=" + $("input[name='FromTime']").val() + "&to=" + $("input[name='ToTime']").val(); +} + +function search(e) { + window.location = $(e).attr("data-href") + "?type=all" + "&from=" + $("input[name='FromTime']").val() + "&to=" + $("input[name='ToTime']").val(); +} \ No newline at end of file