доработан виджет, добавлен календарь отчетов всех за месяц
This commit is contained in:
parent
d642e32811
commit
2dbc33a8f3
@ -11,7 +11,11 @@ echo GridView::widget([
|
||||
['class' => 'yii\grid\SerialColumn'],
|
||||
'fio',
|
||||
'dob',
|
||||
['class' => 'yii\grid\ActionColumn'],
|
||||
['class' => 'yii\grid\ActionColumn',
|
||||
'urlCreator' => function ($action, $model, $key, $index) {
|
||||
return \yii\helpers\Url::base(true) . '/calendar/calendar/' . $action . '?id=' . $model->id;
|
||||
}
|
||||
],
|
||||
],
|
||||
]);
|
||||
die();
|
||||
|
@ -10,17 +10,22 @@ use yii\web\Response;
|
||||
class AjaxController extends \yii\web\Controller
|
||||
{
|
||||
|
||||
public function actionGetReportsForDayByDate($user_id, $date)
|
||||
public function actionGetReportsForDayByDate($date, $user_id = null)
|
||||
{
|
||||
$searchModel = new ReportsSearch();
|
||||
$params = ['ReportsSearch' => ['created_at' => $date], 'user_id' => $user_id];
|
||||
$params = ['ReportsSearch' => ['created_at' => $date]];
|
||||
$view = '_gridViewAllUsers';
|
||||
if ($user_id){
|
||||
$params['user_id'] = $user_id;
|
||||
$view = '_gridViewOneUser';
|
||||
}
|
||||
$dataProvider = $searchModel->search($params);
|
||||
return $this->render('_gridView', [
|
||||
'dataProvider' => $dataProvider
|
||||
return $this->render($view, [
|
||||
'dataProvider' => $dataProvider,
|
||||
]);
|
||||
}
|
||||
|
||||
public function actionGetReportsForMonthByIdYearMonth($user_id, $year, $month)
|
||||
public function actionGetReportsForMonthByIdYearMonth($year, $month, $user_id=null)
|
||||
{
|
||||
$searchModel = new ReportsSearch();
|
||||
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
|
||||
|
@ -58,7 +58,23 @@ class ReportsController extends Controller
|
||||
]),'user_card_id', 'fio');
|
||||
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
|
||||
|
||||
return $this->render('index', [
|
||||
return $this->render('index');
|
||||
}
|
||||
|
||||
public function actionList()
|
||||
{
|
||||
$searchModel = new ReportsSearch();
|
||||
$user_id__fio = ArrayHelper::map(ArrayHelper::toArray($searchModel->search([])->getModels(), [
|
||||
'common\models\Reports' => [
|
||||
'user_card_id',
|
||||
'fio' => function ($report) {
|
||||
return Reports::getFio($report);
|
||||
}
|
||||
],
|
||||
]),'user_card_id', 'fio');
|
||||
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
|
||||
|
||||
return $this->render('list', [
|
||||
'searchModel' => $searchModel,
|
||||
'dataProvider' => $dataProvider,
|
||||
'user_id__fio' => $user_id__fio,
|
||||
@ -94,7 +110,7 @@ class ReportsController extends Controller
|
||||
if (!$dataProvider->getCount()){
|
||||
return $this->render('non-exist_user_id', ['id' => $user_id]);
|
||||
}
|
||||
return $this->render('calendar', [
|
||||
return $this->render('calendarOneUser', [
|
||||
'reports' => $reports_array,
|
||||
'fio' => Reports::getFio($searchModel),
|
||||
'USER_ID' => $user_id
|
||||
|
51
backend/modules/reports/views/ajax/_gridViewAllUsers.php
Normal file
51
backend/modules/reports/views/ajax/_gridViewAllUsers.php
Normal file
@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
use common\models\Reports;
|
||||
use yii\grid\GridView;
|
||||
use yii\helpers\Html;
|
||||
|
||||
/* @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',
|
||||
[
|
||||
'format' => 'raw',
|
||||
'attribute' => 'user_card_id',
|
||||
'value' => function ($model) {
|
||||
return Html::a(Reports::getFio($model) . ' ' . Html::tag('i', null, ['class' => 'far fa-calendar-alt']),
|
||||
\yii\helpers\Url::base(true) . '/reports/reports/calendar?user_id=' . $model['user_card_id'], ['data-pjax' => 0]);
|
||||
},
|
||||
],
|
||||
[
|
||||
'class' => 'yii\grid\ActionColumn',
|
||||
'urlCreator' => function ($action, $model, $key, $index) {
|
||||
return \yii\helpers\Url::base(true) . '/reports/reports/' . $action . '?id=' . $model->id;
|
||||
}
|
||||
],
|
||||
],
|
||||
|
||||
]);
|
||||
die();
|
||||
|
@ -3,6 +3,7 @@
|
||||
use yii\grid\GridView;
|
||||
|
||||
/* @var $this yii\web\View */
|
||||
/* @var $searchModel backend\modules\reports\models\ReportsSearch */
|
||||
/* @var $dataProvider yii\data\ActiveDataProvider */
|
||||
|
||||
echo GridView::widget([
|
||||
@ -27,7 +28,12 @@ echo GridView::widget([
|
||||
],
|
||||
'difficulties',
|
||||
'tomorrow',
|
||||
['class' => 'yii\grid\ActionColumn'],
|
||||
[
|
||||
'class' => 'yii\grid\ActionColumn',
|
||||
'urlCreator' => function ($action, $model, $key, $index) {
|
||||
return \yii\helpers\Url::base(true) . '/reports/reports/' . $action . '?id=' . $model->id;
|
||||
}
|
||||
],
|
||||
],
|
||||
]);
|
||||
die();
|
@ -1,127 +1,29 @@
|
||||
<?php
|
||||
|
||||
|
||||
use common\models\Reports;
|
||||
use backend\widgets\Calendar;
|
||||
use yii\helpers\Html;
|
||||
use yii\grid\GridView;
|
||||
use yii\widgets\ActiveForm;
|
||||
use yii\widgets\Pjax;
|
||||
|
||||
use yii\helpers\Url;
|
||||
|
||||
/* @var $this yii\web\View */
|
||||
/* @var $searchModel backend\modules\reports\models\ReportsSearch */
|
||||
/* @var $dataProvider yii\data\ActiveDataProvider */
|
||||
/* @var $user_id__fio */
|
||||
|
||||
$this->title = 'Отчеты';
|
||||
$this->params['breadcrumbs'][] = $this->title;
|
||||
$this->registerCss('.row * {margin-right: 10px;}');
|
||||
define('TODAY', date('Y-m-d'));
|
||||
define('WEEK_AGO', date('Y-m-d', time() - 3600 * 24 * 7));
|
||||
function next_day($date, $number)
|
||||
{
|
||||
return date('Y-m-d', strtotime($date) + 3600 * 24 * $number);
|
||||
}
|
||||
$this->title = 'Календарь отчетов';
|
||||
?>
|
||||
|
||||
<?= Html::beginTag('div', ['class' => 'reports-index'])?>
|
||||
<?=Html::beginTag('p')?>
|
||||
<?= Calendar::widget([
|
||||
|
||||
<?= Html::a('Добавить', ['create'], ['class' => 'btn btn-success']) ?>
|
||||
<?= Html::a('Сгрупированный по пользователям вид', ['group'], ['class' => 'btn btn-success']) ?>
|
||||
'button' => Html::a('<i class="fas fa-long-arrow-alt-left"></i> Назад',
|
||||
Yii::$app->request->referrer, ['class' => 'btn btn-primary',]).
|
||||
Html::a('<i class="fa fa-list" aria-hidden="true"></i> Список',
|
||||
['list'], ['class' => 'btn btn-success', 'style ' => 'margin: 0 5px']),
|
||||
|
||||
<?=Html::endTag('p')?>
|
||||
|
||||
<?=Html::beginTag('p')?>
|
||||
|
||||
<?php for ($date = TODAY; $date != WEEK_AGO; $date = next_day($date, -1)): ?>
|
||||
<?= Html::a($date, ['index', 'ReportsSearch[created_at]' => $date], ['class' => 'btn btn-primary']) ?>
|
||||
|
||||
<?php endfor; ?>
|
||||
<?=Html::endTag('p')?>
|
||||
<?= Html::endTag('div')?>
|
||||
|
||||
<?= Html::beginTag('div', ['class' => 'row'])?>
|
||||
<?= Html::beginTag('div', ['class' => 'col-xs-6'])?>
|
||||
<?php $form = ActiveForm::begin(['method' => 'get', 'options' => ['style' => 'display: inline-flex;'] ])?>
|
||||
|
||||
<?php foreach (array_keys($searchModel->attributes )as $attribute): ?>
|
||||
<?php if($attribute == 'user_card_id'):?>
|
||||
<?php if($searchModel->user_card_id):?>
|
||||
<?php foreach ($searchModel->user_card_id as $i => $id):?>
|
||||
<?= $form->field($searchModel, 'user_card_id['.$i.']')->hiddenInput()->label(false)?>
|
||||
<?php endforeach;?>
|
||||
<?php endif;?>
|
||||
<?php continue?>
|
||||
<?php endif;?>
|
||||
|
||||
<?php if($attribute == 'created_at'):?>
|
||||
<?= Html::input('date', 'ReportsSearch[created_at]',
|
||||
$searchModel->created_at ? $searchModel->created_at : date('Y-m-d'),
|
||||
['class' => 'form-control']) ?>
|
||||
|
||||
<?= Html::submitButton('Сортировка по дате', ['class' => 'btn btn-danger']) ?>
|
||||
<?= Html::a('Все дни', ['index'], ['class' => 'btn btn-primary']) ?>
|
||||
<?php continue?>
|
||||
<?php endif?>
|
||||
|
||||
<?php endforeach; ?>
|
||||
|
||||
<?php ActiveForm::end() ?>
|
||||
<?= Html::endTag('div')?>
|
||||
<?= Html::endTag('div')?>
|
||||
<?php Pjax::begin();?>
|
||||
<?= GridView::widget([
|
||||
'dataProvider' => $dataProvider,
|
||||
'filterModel' => $searchModel,
|
||||
'columns' => [
|
||||
['class' => 'yii\grid\SerialColumn'],
|
||||
[
|
||||
'format' => 'raw',
|
||||
'attribute' => 'created_at',
|
||||
'filter' => Html::input('date', 'ReportsSearch[created_at]', null, [
|
||||
'class' => 'form-control',
|
||||
'style' => 'display:',
|
||||
'id' => 'date'
|
||||
|
||||
]),
|
||||
'value' => 'created_at',
|
||||
],
|
||||
// [
|
||||
// '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',
|
||||
[
|
||||
'format' => 'raw',
|
||||
'attribute' => 'user_card_id',
|
||||
'filter' => kartik\select2\Select2::widget([
|
||||
'model' => $searchModel,
|
||||
'attribute' => 'user_card_id',
|
||||
'data' => $user_id__fio,
|
||||
'options' => ['multiple' => true, 'class' => 'form-control'],
|
||||
]),
|
||||
'value' => function ($model) {
|
||||
return Html::a(Reports::getFio($model).' '.Html::tag('i', null, ['class' => 'far fa-calendar-alt']),
|
||||
['calendar', 'user_id' => $model['user_card_id']]);
|
||||
|
||||
},
|
||||
],
|
||||
|
||||
['class' => 'yii\grid\ActionColumn'],
|
||||
'monthUpdate' => [
|
||||
'url' => Url::base() . '/reports/ajax/get-reports-for-month-by-id-year-month'
|
||||
],
|
||||
]);?>
|
||||
<?php Pjax::end();?>
|
||||
'dayUpdate' => [
|
||||
'url' => Url::base() . '/reports/ajax/get-reports-for-day-by-date'
|
||||
],
|
||||
'colorClasses' => ['accept' => 'success', 'default' => 'danger', 'offDay' => ''],
|
||||
'offDaysShow' => 1,
|
||||
|
||||
]) ?>
|
||||
|
125
backend/modules/reports/views/reports/list.php
Normal file
125
backend/modules/reports/views/reports/list.php
Normal file
@ -0,0 +1,125 @@
|
||||
<?php
|
||||
|
||||
|
||||
use common\models\Reports;
|
||||
use yii\helpers\Html;
|
||||
use yii\grid\GridView;
|
||||
use yii\widgets\ActiveForm;
|
||||
|
||||
|
||||
/* @var $this yii\web\View */
|
||||
/* @var $searchModel backend\modules\reports\models\ReportsSearch */
|
||||
/* @var $dataProvider yii\data\ActiveDataProvider */
|
||||
/* @var $user_id__fio */
|
||||
|
||||
$this->title = 'Отчеты';
|
||||
$this->params['breadcrumbs'][] = $this->title;
|
||||
$this->registerCss('.row * {margin-right: 10px;}');
|
||||
define('TODAY', date('Y-m-d'));
|
||||
define('WEEK_AGO', date('Y-m-d', time() - 3600 * 24 * 7));
|
||||
function next_day($date, $number)
|
||||
{
|
||||
return date('Y-m-d', strtotime($date) + 3600 * 24 * $number);
|
||||
}
|
||||
?>
|
||||
|
||||
<?= Html::beginTag('div', ['class' => 'reports-index'])?>
|
||||
<?=Html::beginTag('p')?>
|
||||
<?=Html::a('<i class="fas fa-long-arrow-alt-left"></i> Назад',
|
||||
Yii::$app->request->referrer, ['class' => 'btn btn-success',])?>
|
||||
<?= Html::a('Добавить', ['create'], ['class' => 'btn btn-success']) ?>
|
||||
<?= Html::a('Сгрупированный по пользователям вид', ['group'], ['class' => 'btn btn-success']) ?>
|
||||
|
||||
<?=Html::endTag('p')?>
|
||||
|
||||
<?=Html::beginTag('p')?>
|
||||
|
||||
<?php for ($date = TODAY; $date != WEEK_AGO; $date = next_day($date, -1)): ?>
|
||||
<?= Html::a($date, ['list', 'ReportsSearch[created_at]' => $date], ['class' => 'btn btn-primary']) ?>
|
||||
|
||||
<?php endfor; ?>
|
||||
<?=Html::endTag('p')?>
|
||||
<?= Html::endTag('div')?>
|
||||
|
||||
<?= Html::beginTag('div', ['class' => 'row'])?>
|
||||
<?= Html::beginTag('div', ['class' => 'col-xs-6'])?>
|
||||
<?php $form = ActiveForm::begin(['method' => 'get', 'options' => ['style' => 'display: inline-flex;'] ])?>
|
||||
|
||||
<?php foreach (array_keys($searchModel->attributes )as $attribute): ?>
|
||||
<?php if($attribute == 'user_card_id'):?>
|
||||
<?php if($searchModel->user_card_id):?>
|
||||
<?php foreach ($searchModel->user_card_id as $i => $id):?>
|
||||
<?= $form->field($searchModel, 'user_card_id['.$i.']')->hiddenInput()->label(false)?>
|
||||
<?php endforeach;?>
|
||||
<?php endif;?>
|
||||
<?php continue?>
|
||||
<?php endif;?>
|
||||
|
||||
<?php if($attribute == 'created_at'):?>
|
||||
<?= Html::input('date', 'ReportsSearch[created_at]',
|
||||
$searchModel->created_at ? $searchModel->created_at : date('Y-m-d'),
|
||||
['class' => 'form-control']) ?>
|
||||
|
||||
<?= Html::submitButton('Сортировка по дате', ['class' => 'btn btn-danger']) ?>
|
||||
<?= Html::a('Все дни', ['list'], ['class' => 'btn btn-primary']) ?>
|
||||
<?php continue?>
|
||||
<?php endif?>
|
||||
|
||||
<?php endforeach; ?>
|
||||
|
||||
<?php ActiveForm::end() ?>
|
||||
<?= Html::endTag('div')?>
|
||||
<?= Html::endTag('div')?>
|
||||
<?= GridView::widget([
|
||||
'dataProvider' => $dataProvider,
|
||||
'filterModel' => $searchModel,
|
||||
'columns' => [
|
||||
['class' => 'yii\grid\SerialColumn'],
|
||||
[
|
||||
'format' => 'raw',
|
||||
'attribute' => 'created_at',
|
||||
'filter' => Html::input('date', 'ReportsSearch[created_at]', null, [
|
||||
'class' => 'form-control',
|
||||
'style' => 'display:',
|
||||
'id' => 'date'
|
||||
|
||||
]),
|
||||
'value' => 'created_at',
|
||||
],
|
||||
// [
|
||||
// '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',
|
||||
[
|
||||
'format' => 'raw',
|
||||
'attribute' => 'user_card_id',
|
||||
'filter' => kartik\select2\Select2::widget([
|
||||
'model' => $searchModel,
|
||||
'attribute' => 'user_card_id',
|
||||
'data' => $user_id__fio,
|
||||
'options' => ['multiple' => true, 'class' => 'form-control'],
|
||||
]),
|
||||
'value' => function ($model) {
|
||||
return Html::a(Reports::getFio($model).' '.Html::tag('i', null, ['class' => 'far fa-calendar-alt']),
|
||||
['calendar', 'user_id' => $model['user_card_id']]);
|
||||
|
||||
},
|
||||
],
|
||||
|
||||
['class' => 'yii\grid\ActionColumn'],
|
||||
],
|
||||
]);?>
|
@ -6,6 +6,7 @@ namespace backend\widgets;
|
||||
use common\classes\Debug;
|
||||
use yii\base\Widget;
|
||||
use yii\helpers\Html;
|
||||
use yii\widgets\Pjax;
|
||||
|
||||
|
||||
class Calendar extends Widget
|
||||
@ -51,8 +52,10 @@ class Calendar extends Widget
|
||||
echo Html::input('date', null, date('Y-m-d'), ['class' => 'form-control', 'id' => 'date',]);
|
||||
echo Html::endTag('section');
|
||||
echo Html::tag('h2', date('l') . '<br>' . date('F d'), ['class' => 'sidebar__heading']);
|
||||
echo Html::beginTag('ul', ['class' => 'sidebar__list']);
|
||||
echo Html::endTag('ul');
|
||||
echo '<div class="table-responsive" style="height: 77%">';
|
||||
Pjax::begin(['enablePushState' => false, 'class' => 'sidebar__list']);
|
||||
Pjax::end();
|
||||
echo '</div>';
|
||||
echo Html::endTag('aside');
|
||||
echo Html::beginTag('section', ['class' => 'calendar__days']);
|
||||
echo Html::endTag('section');
|
||||
|
@ -220,6 +220,12 @@
|
||||
padding-left: 1rem;
|
||||
padding-right: 1rem;
|
||||
}
|
||||
#p0 {
|
||||
list-style: none;
|
||||
margin: 0;
|
||||
padding-left: 1rem;
|
||||
padding-right: 1rem;
|
||||
}
|
||||
|
||||
.sidebar__list-item {
|
||||
margin: 1.2rem 0;
|
||||
|
@ -46,11 +46,10 @@ class CalendarHelper {
|
||||
let oldDate = datePicker.value.substr(0, 7);
|
||||
|
||||
let nameDateBoard = document.querySelector('.sidebar__heading');
|
||||
let contentBoard = document.querySelector('.sidebar__list');
|
||||
|
||||
|
||||
this._getMonth(datePicker.value.substr(5, 2), datePicker.value.substr(0, 4))
|
||||
.then(dates => {
|
||||
|
||||
this.build(DateHelper.stringToDate(datePicker.value), dates)
|
||||
|
||||
datePicker.onchange = async function (day = null) {
|
||||
@ -75,7 +74,7 @@ class CalendarHelper {
|
||||
let monthName = date.toLocaleString('default', {month: 'long'});
|
||||
let dayWeekName = date.toLocaleString('default', {weekday: 'long'});
|
||||
nameDateBoard.innerHTML = `${dayWeekName} <br>${monthName} ${datePicker.value.substr(8, 2)}`;
|
||||
contentBoard.innerHTML = CalendarHelper._getHtmlContentForDate(dates, datePicker.value)
|
||||
document.querySelector('#p0').innerHTML = CalendarHelper._getHtmlContentForDate(dates, datePicker.value)
|
||||
})
|
||||
|
||||
}
|
||||
@ -85,7 +84,7 @@ class CalendarHelper {
|
||||
let monthName = date.toLocaleString('default', {month: 'long'});
|
||||
let dayWeekName = date.toLocaleString('default', {weekday: 'long'});
|
||||
nameDateBoard.innerHTML = `${dayWeekName} <br>${monthName} ${datePicker.value.substr(8, 2)}`;
|
||||
contentBoard.innerHTML = await CalendarHelper._getDayContent(date)
|
||||
document.querySelector('#p0').innerHTML = await CalendarHelper._getDayContent(date)
|
||||
}
|
||||
|
||||
let days = document.querySelectorAll('.calendar__day');
|
||||
@ -111,6 +110,7 @@ class CalendarHelper {
|
||||
}
|
||||
}
|
||||
|
||||
datePicker.onchange()
|
||||
|
||||
})
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user