Skip to content

Commit

Permalink
Refactor dashboard items
Browse files Browse the repository at this point in the history
  • Loading branch information
tafid committed Nov 13, 2020
1 parent ee406a7 commit a0eb04e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 16 deletions.
4 changes: 4 additions & 0 deletions src/controllers/TicketController.php
Expand Up @@ -20,6 +20,7 @@
use hipanel\actions\SmartPerformAction;
use hipanel\actions\SmartUpdateAction;
use hipanel\actions\ValidateFormAction;
use hipanel\actions\VariantsAction;
use hipanel\actions\ViewAction;
use hipanel\filters\EasyAccessControl;
use hipanel\modules\client\models\Client;
Expand Down Expand Up @@ -79,6 +80,9 @@ public function actions()
'index' => [
'class' => IndexAction::class,
'data' => $this->prepareRefs(),
'responseVariants' => [
'get-total-count' => fn(VariantsAction $action): int => Thread::find()->count(),
],
],
'view' => [
'class' => ViewAction::class,
Expand Down
23 changes: 13 additions & 10 deletions src/menus/DashboardItem.php
Expand Up @@ -10,27 +10,30 @@

namespace hipanel\modules\ticket\menus;

use hipanel\modules\dashboard\DashboardInterface;
use hipanel\helpers\Url;
use hipanel\modules\client\ClientWithCounters;
use hiqdev\yii2\menus\Menu;
use Yii;

class DashboardItem extends \hiqdev\yii2\menus\Menu
class DashboardItem extends Menu
{
protected $dashboard;
protected ClientWithCounters $clientWithCounters;

public function __construct(DashboardInterface $dashboard, $config = [])
public function __construct(ClientWithCounters $clientWithCounters, $config = [])
{
$this->dashboard = $dashboard;
$this->clientWithCounters = $clientWithCounters;
parent::__construct($config);
}

public function items()
{
return [
'tickets' => [
'label' => $this->render('dashboardItem', $this->dashboard->mget(['totalCount','model'])),
return Yii::$app->user->can('ticket.read') ? [
'ticket' => [
'label' => $this->render('dashboardItem', array_merge($this->clientWithCounters->getWidgetData('ticket'), [
'route' => Url::toRoute('@ticket/index'),
])),
'encode' => false,
'visible' => Yii::$app->user->can('ticket.read'),
],
];
] : [];
}
}
7 changes: 1 addition & 6 deletions src/views/menus/dashboardItem.php
Expand Up @@ -16,12 +16,7 @@
'boxColor' => SmallBox::COLOR_ORANGE,
]) ?>
<?php $box->beginBody() ?>
<?= ObjectsCountWidget::widget([
'totalCount' => $totalCount['tickets'],
'ownCount' => $model->count['tickets'],
]) ?>
<br>
<br>
<?= ObjectsCountWidget::widget(compact('route', 'ownCount', 'entityName')) ?>
<?= SearchForm::widget([
'formOptions' => [
'id' => 'ticket-search',
Expand Down

0 comments on commit a0eb04e

Please sign in to comment.