Skip to content

Commit

Permalink
Reformat ticket index
Browse files Browse the repository at this point in the history
  • Loading branch information
tafid committed Aug 21, 2015
1 parent 9abce4a commit c674569
Show file tree
Hide file tree
Showing 3 changed files with 174 additions and 117 deletions.
163 changes: 163 additions & 0 deletions src/grid/TicketGridView.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
<?php

namespace hipanel\modules\ticket\grid;

use common\components\Lang;
use hipanel\grid\ActionColumn;
use hipanel\grid\BoxedGridView;
use hipanel\modules\client\grid\ClientColumn;
use hipanel\modules\ticket\widgets\Topic;
use hipanel\widgets\ClientSellerLink;
use hipanel\widgets\Gravatar;
use Yii;
use yii\helpers\Html;

class TicketGridView extends BoxedGridView
{
public static function defaultColumns()
{
return [
'subject' => [
'attribute' => 'subject',
'format' => 'raw',
'value' => function ($data) {
$ava = Html::tag('div', Gravatar::widget([
'emailHash' => $data->author_email,
'defaultImage' => 'identicon',
'options' => [
'alt' => '',
'class' => 'img-circle',
],
'size' => 40,
]), ['class' => 'pull-right']);
$state = $data->state === 'opened'
? Html::tag('div', '<span class="fa fa-circle-o text-muted"></span>', ['class' => 'table-list-cell table-list-cell-type'])
: Html::tag('div', '<span class="fa fa-check-circle text-muted"></span>', ['class' => 'table-list-cell table-list-cell-type']);
$t = Html::tag('b', Html::a($data->subject, $data->threadUrl)) . Topic::widget(['topics' => $data->topics]) .
Html::tag('div', sprintf('#%s %s %s', $data->id, Lang::t($data->state_label), Yii::$app->formatter->asDatetime($data->create_time)), ['class' => 'text-muted']);

return $ava . $state . Html::tag('div', $t, ['class' => 'table-list-cell table-list-title']);
},

],
'author_id' => [
'class' => ClientColumn::className(),
'idAttribute' => 'author_id',
'attribute' => 'author_id',
'value' => function ($model) {
return ClientSellerLink::widget(compact('model'));
},
],
'responsible_id' => [
'class' => ClientColumn::className(),
'idAttribute' => 'responsible_id',
'attribute' => 'responsible_id',
'value' => function ($model) {
return Html::a($model['responsible'], ['/client/client/view', 'id' => $model->responsible_id]);
},
],
'recipient_id' => [
'class' => ClientColumn::className(),
'idAttribute' => 'recipient_id',
'attribute' => 'recipient_id',
'value' => function ($model) {
return Html::a($model->recipient, ['/client/client/view', 'id' => $model->recipient_id]);

},
],
'answer_count' => [
'attribute' => 'answer_count',
'label' => Yii::t('app', 'Answers'),
'format' => 'raw',
'filter' => false,
'enableSorting' => false,
'value' => function ($model) {
return Html::tag('span', '', ['class' => 'glyphicon glyphicon-comment text-muted']) . '&nbsp;&nbsp;' . $model->answer_count;
},
'contentOptions' => [
'style' => 'font-size: larger;',
],
],
'actions' => [
'class' => ActionColumn::className(),
'template' => '{view}',
'header' => Yii::t('app', 'Actions'),
],
// [
// 'attribute' => 'responsible_id',
// 'format' => 'html',
// // 'filterInputOptions' => ['id' => 'responsible_id'],
// 'value' => function ($data) {
// return Html::a($data['responsible'], ['/client/client/view', 'id' => $data->responsible_id]);
// },
// 'filter' => \hipanel\modules\client\widgets\combo\ClientCombo::widget([
// 'attribute' => 'responsible_id',
// 'model' => $model,
// 'formElementSelector' => 'td',
// 'inputOptions' => [
// 'id' => 'responsible_id',
// ],
// ]),
// ],
// [
// 'attribute' => 'recipient_id',
// 'format' => 'html',
// 'label' => Yii::t('app', 'Recipient'),
// 'value' => function ($data) {
// return Html::a($data->recipient, ['/client/client/view', 'id' => $data->recipient_id]);
//
// },
// 'filter' => \hipanel\modules\client\widgets\combo\ClientCombo::widget([
// 'attribute' => 'recipient_id',
// 'model' => $model,
// 'formElementSelector' => 'td',
// 'inputOptions' => [
// 'id' => 'recipient_id',
// ],
// ]),
// ],
// [
// 'attribute' => 'answer_count',
// 'label' => Yii::t('app', 'Answers'),
// 'format' => 'raw',
// 'filter' => false,
// 'enableSorting' => false,
// 'value' => function ($data) {
// return Html::tag('span', '', ['class' => 'glyphicon glyphicon-comment text-muted']) . '&nbsp;&nbsp;' . $data->answer_count;
// },
// 'contentOptions' => [
// 'style' => 'font-size: larger;',
// ],
// ],
// [
// 'class' => ActionColumn::className(),
// 'template' => '{view}',
// 'header' => Yii::t('app', 'Actions'),
// 'buttons' => [
// // 'view' => function ($url, $model, $key) {
// // return GridActionButton::widget([
// // 'url' => $url,
// // 'icon' => '<i class="fa fa-eye"></i>',
// // 'label' => Yii::t('app', 'Details'),
// // ]);
// // },
// 'state' => function ($url, $model, $key) {
// if ($model->state === 'opened') {
// // $title = Yii::t('app', 'Close');
// // return Html::a('<i class="fa fa-times"></i>&nbsp;&nbsp;'.$title,
// // ['close', 'id' => $model->id],
// // ['title' => $title, 'class' => 'btn btn-default btn-xs', 'data-pjax' => 0]
// // );
// return Html::a('Close', ['close', 'id' => $model->id]);
// // GridActionButton::widget([
// // 'url' => ['close', 'id' => $model->id],
// // 'icon' => '<i class="fa fa-times"></i>',
// // 'label' => Yii::t('app', 'Close'),
// // ]);
// }
// },
// ],
// ],
];
}
}
3 changes: 2 additions & 1 deletion src/models/Thread.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ public function attributes()
public function rules()
{
return [
[['author_id'], 'safe'],
[['subject', 'message'], 'required', 'on' => ['create']],
[['id'], 'required', 'on' => ['answer']],
[
Expand Down Expand Up @@ -161,9 +162,9 @@ public function attributeLabels()
'is_private' => Yii::t('app', 'Make private'),
'state' => Yii::t('app', 'State'),
'state_label' => Yii::t('app', 'State'),
'author_id' => Yii::t('app', 'Author'),
'responsible_id' => Yii::t('app', 'Assignee'),
'author' => Yii::t('app', 'Author'),
'author_id' => Yii::t('app', 'Author'),
'author_seller' => Yii::t('app', 'Seller'),
'recipient_id' => Yii::t('app', 'Recipient'),
'recipient' => Yii::t('app', 'Recipient'),
Expand Down
125 changes: 9 additions & 116 deletions src/views/ticket/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use common\components\Lang;
use hipanel\grid\ActionColumn;
use hipanel\grid\BoxedGridView;
use hipanel\modules\ticket\grid\TicketGridView;
use hipanel\modules\ticket\widgets\Topic;
use hipanel\widgets\ActionBox;
use hipanel\widgets\ClientSellerLink;
Expand Down Expand Up @@ -65,131 +66,23 @@
<?php $box::end() ?>

<?php $box->beginBulkForm() ?>
<?= BoxedGridView::widget([
<?= TicketGridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $model,
'id' => 'ticket-grid',
'striped' => false,
'hover' => false,
'rowOptions' => function ($model, $key, $index, $grid) {
return ['class' => ($model['priority'] === 'high') ? 'bg-danger' : ''];
},
'columns' => [
'checkbox',
[
'attribute' => 'subject',
'format' => 'raw',
'value' => function ($data) {
$ava = Html::tag('div', Gravatar::widget([
'emailHash' => $data->author_email,
'defaultImage' => 'identicon',
'options' => [
'alt' => '',
'class' => 'img-circle',
],
'size' => 40,
]), ['class' => 'pull-right']);
$state = $data->state === 'opened'
? Html::tag('div', '<span class="fa fa-circle-o text-muted"></span>', ['class' => 'table-list-cell table-list-cell-type'])
: Html::tag('div', '<span class="fa fa-check-circle text-muted"></span>', ['class' => 'table-list-cell table-list-cell-type'])
;
$t = Html::tag('b', Html::a($data->subject, $data->threadUrl)) . Topic::widget(['topics' => $data->topics]) .
Html::tag('div', sprintf('#%s %s %s', $data->id, Lang::t($data->state_label), Yii::$app->formatter->asDatetime($data->create_time)), ['class' => 'text-muted']);
// '#' . $data->id . '&nbsp;' . Lang::t($data->state_label) . ' ' . Yii::$app->formatter->asDatetime($data->create_time)
return $ava . $state . Html::tag('div', $t, ['class' => 'table-list-cell table-list-title']);
},

],
[
'attribute' => 'author_id',
'value' => function ($model) {
return ClientSellerLink::widget(compact('model'));
},
'format' => 'html',
'label' => Yii::t('app', 'Author'),
'filter' => \hipanel\modules\client\widgets\combo\ClientCombo::widget([
'attribute' => 'author_id',
'model' => $model,
'formElementSelector' => 'td',
'inputOptions' => [
'id' => 'author_id',
],
]),
],
[
'attribute' => 'responsible_id',
'format' => 'html',
// 'filterInputOptions' => ['id' => 'responsible_id'],
'value' => function ($data) {
return Html::a($data['responsible'], ['/client/client/view', 'id' => $data->responsible_id]);
},
'filter' => \hipanel\modules\client\widgets\combo\ClientCombo::widget([
'attribute' => 'responsible_id',
'model' => $model,
'formElementSelector' => 'td',
'inputOptions' => [
'id' => 'responsible_id',
],
]),
],
[
'attribute' => 'recipient_id',
'format' => 'html',
'label' => Yii::t('app', 'Recipient'),
'value' => function ($data) {
return Html::a($data->recipient, ['/client/client/view', 'id' => $data->recipient_id]);

},
'filter' => \hipanel\modules\client\widgets\combo\ClientCombo::widget([
'attribute' => 'recipient_id',
'model' => $model,
'formElementSelector' => 'td',
'inputOptions' => [
'id' => 'recipient_id',
],
]),
],
[
'attribute' => 'answer_count',
'label' => Yii::t('app', 'Answers'),
'format' => 'raw',
'filter' => false,
'enableSorting' => false,
'value' => function ($data) {
return Html::tag('span', '', ['class' => 'glyphicon glyphicon-comment text-muted']) . '&nbsp;&nbsp;' . $data->answer_count;
},
'contentOptions' => [
'style' => 'font-size: larger;',
],
],
[
'class' => ActionColumn::className(),
'template' => '{view}',
'header' => Yii::t('app', 'Actions'),
'buttons' => [
// 'view' => function ($url, $model, $key) {
// return GridActionButton::widget([
// 'url' => $url,
// 'icon' => '<i class="fa fa-eye"></i>',
// 'label' => Yii::t('app', 'Details'),
// ]);
// },
'state' => function ($url, $model, $key) {
if ($model->state === 'opened') {
// $title = Yii::t('app', 'Close');
// return Html::a('<i class="fa fa-times"></i>&nbsp;&nbsp;'.$title,
// ['close', 'id' => $model->id],
// ['title' => $title, 'class' => 'btn btn-default btn-xs', 'data-pjax' => 0]
// );
return Html::a('Close', ['close', 'id' => $model->id]);
// GridActionButton::widget([
// 'url' => ['close', 'id' => $model->id],
// 'icon' => '<i class="fa fa-times"></i>',
// 'label' => Yii::t('app', 'Close'),
// ]);
}
},
],
],
'subject',
'author_id',
'responsible_id',
'recipient_id',
'answer_count',
'actions',
],
]); ?>
<?php $box::endBulkForm() ?>

0 comments on commit c674569

Please sign in to comment.