From 358ffbf79462cb8e6f0efd44769d814b7cef37ad Mon Sep 17 00:00:00 2001 From: maxim Date: Mon, 13 Sep 2021 16:40:37 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=B5=D1=80=D0=B5=D0=B4=D0=B5=D0=BB?= =?UTF-8?q?=D0=B0=D0=BB=20=D0=B2=D0=B8=D0=B4=D0=B6=D0=B5=D1=82,=20=D0=B1?= =?UTF-8?q?=D0=BE=D0=BB=D0=B5=D0=B5=20=D1=87=D0=B8=D1=82=D0=B0=D0=B5=D0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../calendar/controllers/AjaxController.php | 25 ++++-- .../controllers/CalendarController.php | 8 +- .../modules/calendar/views/ajax/_gridView.php | 18 ++++ .../calendar/views/calendar/calendar.php | 59 ------------- .../modules/calendar/views/calendar/index.php | 62 +++++--------- .../modules/calendar/views/calendar/table.php | 45 ++++++++++ .../modules/card/models/UserCardSearch.php | 7 ++ .../reports/controllers/AjaxController.php | 34 ++++---- .../modules/reports/views/ajax/_gridView.php | 34 ++++++++ .../reports/views/reports/calendar.php | 83 +++---------------- backend/widgets/Calendar.php | 82 ++++++++++++------ .../Calendar/assets/js/src/CalendarHelper.js | 47 ++++++----- 12 files changed, 255 insertions(+), 249 deletions(-) create mode 100644 backend/modules/calendar/views/ajax/_gridView.php delete mode 100644 backend/modules/calendar/views/calendar/calendar.php create mode 100644 backend/modules/calendar/views/calendar/table.php create mode 100644 backend/modules/reports/views/ajax/_gridView.php diff --git a/backend/modules/calendar/controllers/AjaxController.php b/backend/modules/calendar/controllers/AjaxController.php index 85530c3..e4fd7dc 100644 --- a/backend/modules/calendar/controllers/AjaxController.php +++ b/backend/modules/calendar/controllers/AjaxController.php @@ -4,22 +4,29 @@ namespace backend\modules\calendar\controllers; use backend\modules\card\models\UserCardSearch; use Yii; -use yii\helpers\ArrayHelper; use yii\web\Response; class AjaxController extends \yii\web\Controller { - public function actionGetBirthdayByMonth($month ) + + public function actionGetBirthdayDate($date) + { + $searchModel = new UserCardSearch(); + $dataProvider = $searchModel->search(['date' => $date]); + + return $this->render('_gridView', [ + 'dataProvider' => $dataProvider + ]); + } + + public function actionGetBirthdayDatesByMonth($month ) { $searchModel = new UserCardSearch(); $models = $searchModel->search(Yii::$app->request->queryParams)->getModels(); - $models_array = ArrayHelper::toArray($models, [ - 'backend\modules\card\models\UserCard' => [ - 'id', - 'dob', - 'fio' - ], - ]); + $models_array = array_map(function ($date){return date('Y').substr($date, 4,6);}, + array_column($models, 'dob') + ); + $response = Yii::$app->response; $response->format = Response::FORMAT_JSON; diff --git a/backend/modules/calendar/controllers/CalendarController.php b/backend/modules/calendar/controllers/CalendarController.php index 352efac..eac83ea 100644 --- a/backend/modules/calendar/controllers/CalendarController.php +++ b/backend/modules/calendar/controllers/CalendarController.php @@ -42,11 +42,11 @@ class CalendarController extends Controller * Renders the index view for the module * @return string */ - public function actionCalendar(){ - return $this->render('calendar'); + public function actionIndex(){ + return $this->render('index'); } - public function actionIndex() + public function actionTable() { $searchModel = new UserCardSearch(); $user_card = \common\models\UserCard::find()->all(); @@ -67,7 +67,7 @@ class CalendarController extends Controller $dataProvider = $searchModel->search(Yii::$app->request->queryParams); } - return $this->render('index', [ + return $this->render('table', [ 'searchModel' => $searchModel, 'dataProvider' => $dataProvider, ]); diff --git a/backend/modules/calendar/views/ajax/_gridView.php b/backend/modules/calendar/views/ajax/_gridView.php new file mode 100644 index 0000000..301bad7 --- /dev/null +++ b/backend/modules/calendar/views/ajax/_gridView.php @@ -0,0 +1,18 @@ + $dataProvider, + 'columns' => [ + ['class' => 'yii\grid\SerialColumn'], + 'fio', + 'dob', + ['class' => 'yii\grid\ActionColumn'], + ], +]); +die(); + diff --git a/backend/modules/calendar/views/calendar/calendar.php b/backend/modules/calendar/views/calendar/calendar.php deleted file mode 100644 index ca050c5..0000000 --- a/backend/modules/calendar/views/calendar/calendar.php +++ /dev/null @@ -1,59 +0,0 @@ -title = 'Календарь ДР'; -?> - '.success{color: orange;}', - - 'button' => Html::a(' Назад', - Yii::$app->request->referrer, ['class' => 'btn btn-primary',]), - 'runBuild' => "function (date, content){ - this.build(date, content) - }", - 'updateContent' => "function(date){ - let monthNumber = date.substr(5, 2); - return fetch('../ajax/get-birthday-by-month?' + - 'month=' + monthNumber) - .then((res) => { - return res.json() - }) - }", - 'getColor' => "function (date, dates = null) { - for (let contentDate of dates) { - if (contentDate['dob'].substr(8, 2) == DateHelper.intToDate(date.getDate())) { - return 'success'; - } - } - }", - 'getHtmlContentForDate' => 'function (content, date) { - let flag = false - let html = ` - - - - - - - - `; - for (let i = 1; i <= content.length; i++) { - let model = content[i - 1]; - if (model["dob"].substr(8, 2) == date.substr(8, 2)) { - flag = true; - html += `` - html += `` - html += `` - html += `` - html += CalendarHelper._getActionColumn(`secure/calendar/calendar`,model[`id`]) - html += `` - } - } - html += `
#ФИОДата рождения 
${i}${model["fio"]}${model["dob"]}
` - if (flag) return html; - return "empty" - }' -]) ?> - - diff --git a/backend/modules/calendar/views/calendar/index.php b/backend/modules/calendar/views/calendar/index.php index 1783f5f..9200277 100644 --- a/backend/modules/calendar/views/calendar/index.php +++ b/backend/modules/calendar/views/calendar/index.php @@ -1,45 +1,25 @@ title = 'Календарь ДР'; ?> -
-

- -

- 'far fa-calendar-alt']), - ['calendar'], ['class' => 'btn btn-success', 'style' => 'margin-left: 10px'])?> -
- 'reload']); -echo GridView::widget([ - 'dataProvider' => $dataProvider, - 'filterModel' => $searchModel, - 'columns' => [ - ['class' => 'yii\grid\SerialColumn'], - 'fio', - 'dob', - ['class' => 'yii\grid\ActionColumn'], + '.success{color: orange;}', + + 'button' => Html::a(' Таблица', + ['table'], ['class' => 'btn btn-primary',]), + + 'monthUpdate' => [ + 'url' => Url::base() . '/calendar/ajax/get-birthday-dates-by-month' ], -]); -Pjax::end(); -?> \ No newline at end of file + 'dayUpdate' => [ + 'url' => Url::base() . '/calendar/ajax/get-birthday-date' + ], + 'colorClasses' => ['accept' => 'success', 'default' => '', 'offDay' => ''], + 'offDaysShow' => 0, + +]) ?> + + diff --git a/backend/modules/calendar/views/calendar/table.php b/backend/modules/calendar/views/calendar/table.php new file mode 100644 index 0000000..3a7b23d --- /dev/null +++ b/backend/modules/calendar/views/calendar/table.php @@ -0,0 +1,45 @@ + +
+

+ +

+ 'far fa-calendar-alt']), + ['index'], ['class' => 'btn btn-success', 'style' => 'margin-left: 10px'])?> +
+ 'reload']); +echo GridView::widget([ + 'dataProvider' => $dataProvider, + 'filterModel' => $searchModel, + 'columns' => [ + ['class' => 'yii\grid\SerialColumn'], + 'fio', + 'dob', + ['class' => 'yii\grid\ActionColumn'], + ], +]); +Pjax::end(); +?> \ No newline at end of file diff --git a/backend/modules/card/models/UserCardSearch.php b/backend/modules/card/models/UserCardSearch.php index 4fd7e0a..cae6b3b 100755 --- a/backend/modules/card/models/UserCardSearch.php +++ b/backend/modules/card/models/UserCardSearch.php @@ -66,6 +66,13 @@ class UserCardSearch extends UserCard if (isset($params['month'])) { $query->andFilterWhere(['=', 'MONTH(dob)', $params['month']]); } + if (isset($params['day'])) { + $query->andFilterWhere(['=', 'DAY(dob)', $params['day']]); + } + if (isset($params['date'])) { + $query->andFilterWhere(['=', 'MONTH(dob)', substr($params['date'], 5,2)]); + $query->andFilterWhere(['=', 'DAY(dob)', substr($params['date'],8,2)]); + } // grid filtering conditions $query->andFilterWhere([ diff --git a/backend/modules/reports/controllers/AjaxController.php b/backend/modules/reports/controllers/AjaxController.php index 7b81181..ebcd2da 100644 --- a/backend/modules/reports/controllers/AjaxController.php +++ b/backend/modules/reports/controllers/AjaxController.php @@ -2,35 +2,29 @@ namespace backend\modules\reports\controllers; -use backend\modules\reports\models\Month; + use Yii; use backend\modules\reports\models\ReportsSearch; -use yii\helpers\ArrayHelper; use yii\web\Response; class AjaxController extends \yii\web\Controller { - public function actionGetReportsForMonthByIdYearMonth($user_id, $year, $month){ + public function actionGetReportsForDayByDate($user_id, $date) + { + $searchModel = new ReportsSearch(); + $params = ['ReportsSearch' => ['created_at' => $date], 'user_id' => $user_id]; + $dataProvider = $searchModel->search($params); + return $this->render('_gridView', [ + 'dataProvider' => $dataProvider + ]); + } + + public function actionGetReportsForMonthByIdYearMonth($user_id, $year, $month) + { $searchModel = new ReportsSearch(); $dataProvider = $searchModel->search(Yii::$app->request->queryParams); - $reports_array = ArrayHelper::toArray($dataProvider->getModels(), [ - 'common\models\Reports' => [ - 'id', - 'created_at', - 'difficulties', - 'tomorrow', - 'user_card_id', - 'today' => function ($report) { - return ArrayHelper::toArray($report->task, [ - 'common\models\ReportsTask' => [ - 'hours_spent', - 'task' - ], - ]); - } - ], - ]); + $reports_array = array_column($dataProvider->getModels(), 'created_at'); $response = Yii::$app->response; $response->format = Response::FORMAT_JSON; diff --git a/backend/modules/reports/views/ajax/_gridView.php b/backend/modules/reports/views/ajax/_gridView.php new file mode 100644 index 0000000..9d1a0e6 --- /dev/null +++ b/backend/modules/reports/views/ajax/_gridView.php @@ -0,0 +1,34 @@ + $dataProvider, + 'columns' => [ + ['class' => 'yii\grid\SerialColumn'], + [ + 'attribute' => 'today', + 'format' => 'raw', + 'value' => function ($model) { + + $text = ''; + if ($model->task) { + $i = 1; + foreach ($model->task as $task) { + $text .= "

$i. ($task->hours_spent ч.) $task->task

"; + $i++; + } + } + return $text; + } + ], + 'difficulties', + 'tomorrow', + ['class' => 'yii\grid\ActionColumn'], + ], +]); +die(); + diff --git a/backend/modules/reports/views/reports/calendar.php b/backend/modules/reports/views/reports/calendar.php index 2496e4b..7ae4024 100644 --- a/backend/modules/reports/views/reports/calendar.php +++ b/backend/modules/reports/views/reports/calendar.php @@ -2,6 +2,7 @@ use backend\widgets\Calendar; use yii\helpers\Html; +use yii\helpers\Url; /* @var $this yii\web\View */ /* @var $fio */ @@ -10,80 +11,20 @@ use yii\helpers\Html; $this->title = 'Календарь пользователя - ' . $fio; ?> - Html::a(' Назад', Yii::$app->request->referrer, ['class' => 'btn btn-primary',]), - 'runBuild' => "function (date, content){ - contentDays = [] - for (let item of content){ - contentDays.push(item['created_at']) - } - this.build(date, contentDays) - }", + 'monthUpdate' => [ + 'url' => Url::base() . '/reports/ajax/get-reports-for-month-by-id-year-month', + 'data' => ['user_id' => $USER_ID] + ], + 'dayUpdate' => [ + 'url' => Url::base() . '/reports/ajax/get-reports-for-day-by-date', + 'data' => ['user_id' => $USER_ID] + ], + 'colorClasses' => ['accept' => 'success', 'default' => 'danger', 'offDay' => ''], + 'offDaysShow' => 1, - 'updateContent' => "function(date){ - let monthNumber = date.substr(5, 2); - let yearNumber = date.substr(0, 4); - return fetch('../ajax/get-reports-for-month-by-id-year-month?user_id='+".$USER_ID."+ - '&month=' + monthNumber + - '&year=' + yearNumber) - .then((res) => { - return res.json() - }) - }", - - 'getColor' => "function (date, dates = null) { - let d = date; - if ([6, 0].includes(d.getDay())) - return; - for (let i = 0; i < dates.length; i++) { - if (dates[i] == DateHelper.dateToString(date)) { - return 'success'; - } - } - return 'danger'; - }", - - 'getHtmlContentForDate' => "function (content, date) { - if ([0, 6].includes(new Date(date).getDay())) { - return 'Выходной день'; - } - let j = 0; - let html = `