-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ENG-619] Add dashboard widget for campaign delays.
- Loading branch information
heathdutton
committed
Feb 19, 2019
1 parent
2ae7d83
commit 0388d13
Showing
6 changed files
with
191 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
<?php | ||
|
||
/* | ||
* @copyright 2018 Mautic Contributors. All rights reserved | ||
* @author Digital Media Solutions, LLC | ||
* | ||
* @link http://mautic.org | ||
* | ||
* @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html | ||
*/ | ||
|
||
namespace MauticPlugin\MauticHealthBundle\EventListener; | ||
|
||
use Mautic\DashboardBundle\Event\WidgetDetailEvent; | ||
use Mautic\DashboardBundle\EventListener\DashboardSubscriber as MainDashboardSubscriber; | ||
use MauticPlugin\MauticHealthBundle\Model\HealthModel; | ||
|
||
/** | ||
* Class DashboardSubscriber. | ||
*/ | ||
class DashboardSubscriber extends MainDashboardSubscriber | ||
{ | ||
/** | ||
* Define the name of the bundle/category of the widget(s). | ||
* | ||
* @var string | ||
*/ | ||
protected $bundle = 'campaign'; | ||
|
||
/** | ||
* Define the widget(s). | ||
* | ||
* @var string | ||
*/ | ||
protected $types = [ | ||
'campaign.health' => [], | ||
]; | ||
|
||
/** | ||
* @var HealthModel | ||
*/ | ||
protected $healthModel; | ||
|
||
/** | ||
* DashboardSubscriber constructor. | ||
* | ||
* @param HealthModel $healthModel | ||
*/ | ||
public function __construct(HealthModel $healthModel) | ||
{ | ||
$this->healthModel = $healthModel; | ||
} | ||
|
||
/** | ||
* Set a widget detail when needed. | ||
* | ||
* @param WidgetDetailEvent $event | ||
*/ | ||
public function onWidgetDetailGenerate(WidgetDetailEvent $event) | ||
{ | ||
// This always pulls from cached data from the cron task. | ||
// if (!$event->isCached()) { | ||
// } | ||
$cache = $this->healthModel->getCache(); | ||
$widget = $event->getWidget(); | ||
if ($widget->getHeight() < 330) { | ||
$widget->setHeight(330); | ||
} | ||
$params = $widget->getParams(); | ||
$data['params'] = $params; | ||
$data['height'] = $widget->getHeight(); | ||
$data['delays'] = isset($cache['delays']) ? $cache['delays'] : []; | ||
$data['lastCached'] = isset($cache['lastCached']) ? $cache['lastCached'] : null; | ||
$event->setTemplateData(['data' => $data]); | ||
|
||
if ('campaign.health' == $event->getType()) { | ||
$event->setTemplate('MauticHealthBundle:Widgets:health.html.php'); | ||
} | ||
|
||
$event->stopPropagation(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
|
||
/* | ||
* @copyright 2019 Mautic Contributors. All rights reserved | ||
* @author Digital Media Solutions, LLC | ||
* | ||
* @link http://mautic.org | ||
* | ||
* @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html | ||
*/ | ||
|
||
?> | ||
|
||
<div class="chart-wrapper" style="height:<?php echo $data['height']; ?>px"> | ||
<div class="pt-sd pr-md pb-md pl-md"> | ||
<?php if (count($data['delays'])): ?> | ||
<div id="health-status-table"> | ||
<div class="responsive-table"> | ||
<table id="health-status" class="table table-striped table-bordered" width="100%" data-height="<?php echo $data['height']; ?>"> | ||
<thead> | ||
<th>Campaign</th> | ||
<th>Event</th> | ||
<th>Type</th> | ||
<th>Contacts</th> | ||
<th>Delay</th> | ||
</thead> | ||
<tbody> | ||
<?php foreach ($data['delays'] as $delay): ?> | ||
<tr> | ||
<th> | ||
<a href="/s/campaigns/view/<?php echo $delay['campaign_id']; ?>"><?php echo $delay['campaign_name']; ?></a> | ||
</th> | ||
<th><?php echo $delay['event_name']; ?> (<?php echo $delay['event_id']; ?>)</th> | ||
<th><?php echo $delay['type']; ?></th> | ||
<th><?php echo $delay['contact_count']; ?></th> | ||
<th><?php echo $delay['avg_delay_s']; ?>s</th> | ||
</tr> | ||
<?php endforeach; ?> | ||
</tbody> | ||
</table> | ||
</div> | ||
</div> | ||
<?php if (!empty($data['lastCached'])) { | ||
echo '<small>Calculated: '.(new \DateTime($data['lastCached']))->format('c').'</small>'; | ||
} | ||
?> | ||
<?php else: ?> | ||
<h3>No delays detected</h3> | ||
<?php endif; ?> | ||
</div> | ||
</div> | ||
|