Skip to content
This repository has been archived by the owner on Sep 10, 2021. It is now read-only.

Commit

Permalink
Adding UI for setting and unsetting key metrics.
Browse files Browse the repository at this point in the history
  • Loading branch information
cpatrick committed Sep 28, 2015
1 parent 4113be6 commit fa571f4
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 9 deletions.
44 changes: 43 additions & 1 deletion modules/tracker/controllers/TrendController.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class Tracker_TrendController extends Tracker_AppController
public $_components = array('Breadcrumb');

/** @var array */
public $_moduleModels = array('Scalar', 'ThresholdNotification', 'Trend');
public $_moduleModels = array('Producer', 'Scalar', 'ThresholdNotification', 'Trend');

/**
* View a given trend.
Expand Down Expand Up @@ -524,4 +524,46 @@ public function notifysubmitAction()

echo JsonComponent::encode(array('status' => 'ok', 'message' => 'Changes saved'));
}

/**
* Change key metric status of a trend
*
* Request parameters:
* trendId - The id of the producer to delete
* state - The state of is_key_metric on the trend
*
* @throws Zend_Exception
*/
public function setkeymetricAction()
{
$this->disableLayout();
$this->disableView();

/** @var int $trendId */
$trendId = $this->getParam('trendId');

/** @var int $state */
$state = $this->getParam('state');

if (!isset($trendId)) {
throw new Zend_Exception('The required trendId parameter is missing.');
}
if (!isset($state)) {
throw new Zend_Exception('The required state parameter is missing.');
}

/** @var Tracker_TrendDao $trendDao */
$trendDao = $this->Tracker_Trend->load($trendId);

/** @var Tracker_ProducerDao $producerDao */
$producerDao = $trendDao->getProducer();

if ($this->Tracker_Producer->policyCheck($producerDao, $this->userSession->Dao, MIDAS_POLICY_ADMIN) === false
) {
throw new Zend_Exception('The producer does not exist or you do not have the necessary permission on its community', 403);
}

$trendDao->setIsKeyMetric($state === 'true');
$this->Tracker_Trend->save($trendDao);
}
}
25 changes: 23 additions & 2 deletions modules/tracker/public/js/producer/producer.view.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,33 @@ $(document).ready(function () {
$('a.visualizeSelected').unbind('click').hide();
}

if (checked.length == 1) {
/**
* Toggle key metric state
*/
if (checked.length >= 1) {
$('span.keyMetricTogglePlural').html(checked.length > 1 ? 's' : '');
var isKey = $(checked[0]).attr('iskey') === '1';
var verb = isKey ? 'Unset' : 'Set';
$('span.keyMetricToggleVerb').html(verb);
$('a.toggleKeyMetric').show().unbind('click').click(function () {

$.each(checked, function (idx, checkbox) {
var keySpan = $(checkbox).parent().parent().find('.keyMetric');
if (isKey) {
keySpan.hide();
$(checked[0]).attr('iskey', '0');
} else {
$(checked[0]).attr('iskey', '1');
keySpan.show();
}
$.post(json.global.webroot + '/tracker/trend/setkeymetric', {
trendId: $(checkbox).attr('element'),
state: !isKey
}, function () {
verb = isKey ? 'Unset' : 'Set';
$('span.keyMetricToggleVerb').html(verb);
});
});
isKey = !isKey;
});
} else {
$('a.toggleKeyMetric').unbind('click').hide();
Expand Down
16 changes: 10 additions & 6 deletions modules/tracker/views/producer/view.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,11 @@ $this->headScript()->appendFile($this->moduleWebroot.'/public/js/producer/produc
echo '<input type="checkbox" class="selectTrend" iskey="'.$trendDao->getIsKeyMetric().'" element="'.$this->escape($trendDao->getKey()).'" />';
echo '<a class="trendLink" href="'.$this->webroot.'/tracker/trend/view?trendId='.$this->escape($trendDao->getKey()).'">';
echo $this->escape($trendDao->getDisplayName());
if($trendDao->getIsKeyMetric()) {
echo '<span class="keyMetric"><img src="'.$this->coreWebroot.'/public/images/icons/key.png" alt="Key metric"></span>';
echo '<span ';
if(!$trendDao->getIsKeyMetric()) {
echo 'style="display: none;" ';
}
echo 'class="keyMetric"><img src="'.$this->coreWebroot.'/public/images/icons/key.png" alt="Key metric"></span>';
echo '<a/></div>';
}
?>
Expand All @@ -108,6 +110,12 @@ $this->headScript()->appendFile($this->moduleWebroot.'/public/js/producer/produc
src="<?php echo $this->coreWebroot; ?>/public/images/icons/close.png"/>
Delete</a>
</li>
<li>
<a style="display: none;" class="toggleKeyMetric">
<img alt="" src="<?php echo $this->coreWebroot; ?>/public/images/icons/key.png"/>
<span class="keyMetricToggleVerb"></span> metric<span class="keyMetricTogglePlural"></span> as key
</a>
</li>
<?php
}
?>
Expand All @@ -119,10 +127,6 @@ $this->headScript()->appendFile($this->moduleWebroot.'/public/js/producer/produc
<a style="display: none;" class="visualizeDualAxis"><img alt="" src="<?php echo $this->moduleWebroot; ?>/public/images/chart_line.png"/>
Dual axis plot</a>
</li>
<li>
<a style="display: none;" class="toggleKeyMetric"><img alt="" src="<?php echo $this->coreWebroot; ?>/public/images/icons/key.png"/>
<span class="keyMetricToggleVerb"></span> metric as key</a>
</li>
</ul>
</div>
</div>

0 comments on commit fa571f4

Please sign in to comment.