Переделал виджет, более читаем
This commit is contained in:
@ -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;
|
||||
|
34
backend/modules/reports/views/ajax/_gridView.php
Normal file
34
backend/modules/reports/views/ajax/_gridView.php
Normal file
@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
use yii\grid\GridView;
|
||||
|
||||
/* @var $this yii\web\View */
|
||||
/* @var $dataProvider yii\data\ActiveDataProvider */
|
||||
|
||||
echo GridView::widget([
|
||||
'dataProvider' => $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 .= "<p>$i. ($task->hours_spent ч.) $task->task</p>";
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
return $text;
|
||||
}
|
||||
],
|
||||
'difficulties',
|
||||
'tomorrow',
|
||||
['class' => 'yii\grid\ActionColumn'],
|
||||
],
|
||||
]);
|
||||
die();
|
||||
|
@ -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;
|
||||
?>
|
||||
|
||||
<?=Calendar::widget([
|
||||
<?= Calendar::widget([
|
||||
|
||||
'button' => Html::a('<i class="fas fa-long-arrow-alt-left"></i> Назад',
|
||||
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 = `<ul class='sidebar__list'>
|
||||
<table class='table table-striped table-bordered'>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>#</th>
|
||||
<th>Что было сделано сегодня?</th>
|
||||
<th>Какие сложности возникли?</th>
|
||||
<th>Что планируется сделать завтра?</th>
|
||||
<th class='action-column'> </th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>`;
|
||||
for (let k = 0, i = 0; i < content.length; i++) {
|
||||
let report = content[i];
|
||||
if (report['created_at'] == date) {
|
||||
k++;
|
||||
html += `<tr data-key='\${report['id']}'>
|
||||
<td>\${k}</td><td>`;
|
||||
|
||||
for (j = 0; j < Object.keys(report['today']).length; j++) {
|
||||
html += `<p>\${j + 1}. (\${report['today'][j]['hours_spent']} ч.)
|
||||
\${report['today'][j]['task']}</p>`
|
||||
}
|
||||
|
||||
html += `</td>
|
||||
<td>\${report['difficulties']}</td>
|
||||
<td>\${report['tomorrow']}</td>
|
||||
\${CalendarHelper._getActionColumn(`/secure/reports/reports`, report['id'])}`;
|
||||
}
|
||||
}
|
||||
if (j == 0) {
|
||||
return 'За этот день не было отчетов';
|
||||
}
|
||||
return html;
|
||||
}"
|
||||
]) ?>
|
||||
|
Reference in New Issue
Block a user