From bee3921de09786acd887acc9a6c8748da9cc8b60 Mon Sep 17 00:00:00 2001 From: maxim Date: Fri, 10 Sep 2021 18:21:23 +0300 Subject: [PATCH 1/2] =?UTF-8?q?=D0=9E=D1=82=D0=BE=D0=B1=D1=80=D0=B0=D0=B6?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BA=D0=B0=D0=BB=D0=B5=D0=BD=D0=B4?= =?UTF-8?q?=D0=B0=D1=80=D1=8F=20=D1=81=20=D0=BF=D0=BE=D0=BC=D0=BE=D1=89?= =?UTF-8?q?=D1=8C=D1=8E=20=D0=B2=D0=B8=D0=B4=D0=B6=D0=B5=D1=82=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../reports/controllers/AjaxController.php | 5 +- .../reports/views/reports/calendar.php | 128 +++++++++++++++--- 2 files changed, 113 insertions(+), 20 deletions(-) diff --git a/backend/modules/reports/controllers/AjaxController.php b/backend/modules/reports/controllers/AjaxController.php index 16de037..7b81181 100644 --- a/backend/modules/reports/controllers/AjaxController.php +++ b/backend/modules/reports/controllers/AjaxController.php @@ -35,10 +35,7 @@ class AjaxController extends \yii\web\Controller $response = Yii::$app->response; $response->format = Response::FORMAT_JSON; $response->getHeaders()->set('Content-Type', 'application/json; charset=utf-8'); - $response->content = json_encode(array_merge( - ['reports' => $reports_array], - ['month' => (array)new Month($year.'-'.$month.'-01')]) - ); + $response->content = json_encode($reports_array); return $response; } diff --git a/backend/modules/reports/views/reports/calendar.php b/backend/modules/reports/views/reports/calendar.php index 1521155..54f624c 100644 --- a/backend/modules/reports/views/reports/calendar.php +++ b/backend/modules/reports/views/reports/calendar.php @@ -7,27 +7,123 @@ use yii\helpers\Url; /* @var $fio */ /* @var $USER_ID */ -$this->registerJs('let userID = '. $USER_ID); -$this->registerJs(file_get_contents(Url::base(true).'/js/calendar.js')); -$this->registerCssFile('@web/css/calendar.css'); $this->title = 'Календарь пользователя - ' . $fio; ?> - 'calendar-contain'])?> - 'calendar__sidebar'])?> - 'title-bar'])?> - Назад', Yii::$app->request->referrer, ['class' => 'btn btn-primary',]) ?> - 'form-control', 'id' => 'date',]) ?> - + Html::a(' Назад', + Yii::$app->request->referrer, ['class' => 'btn btn-primary',]), - '.date('F d'), ['class' => 'sidebar__heading'])?> + 'runBuild' => "function (date, content){ + contentDays = [] + for (let item of content){ + contentDays.push(item['created_at']) + } + this.build(date, contentDays) + }", + + '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 = `