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

Commit fa571f4

Browse files
committed
Adding UI for setting and unsetting key metrics.
1 parent 4113be6 commit fa571f4

File tree

3 files changed

+76
-9
lines changed

3 files changed

+76
-9
lines changed

modules/tracker/controllers/TrendController.php

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class Tracker_TrendController extends Tracker_AppController
3131
public $_components = array('Breadcrumb');
3232

3333
/** @var array */
34-
public $_moduleModels = array('Scalar', 'ThresholdNotification', 'Trend');
34+
public $_moduleModels = array('Producer', 'Scalar', 'ThresholdNotification', 'Trend');
3535

3636
/**
3737
* View a given trend.
@@ -524,4 +524,46 @@ public function notifysubmitAction()
524524

525525
echo JsonComponent::encode(array('status' => 'ok', 'message' => 'Changes saved'));
526526
}
527+
528+
/**
529+
* Change key metric status of a trend
530+
*
531+
* Request parameters:
532+
* trendId - The id of the producer to delete
533+
* state - The state of is_key_metric on the trend
534+
*
535+
* @throws Zend_Exception
536+
*/
537+
public function setkeymetricAction()
538+
{
539+
$this->disableLayout();
540+
$this->disableView();
541+
542+
/** @var int $trendId */
543+
$trendId = $this->getParam('trendId');
544+
545+
/** @var int $state */
546+
$state = $this->getParam('state');
547+
548+
if (!isset($trendId)) {
549+
throw new Zend_Exception('The required trendId parameter is missing.');
550+
}
551+
if (!isset($state)) {
552+
throw new Zend_Exception('The required state parameter is missing.');
553+
}
554+
555+
/** @var Tracker_TrendDao $trendDao */
556+
$trendDao = $this->Tracker_Trend->load($trendId);
557+
558+
/** @var Tracker_ProducerDao $producerDao */
559+
$producerDao = $trendDao->getProducer();
560+
561+
if ($this->Tracker_Producer->policyCheck($producerDao, $this->userSession->Dao, MIDAS_POLICY_ADMIN) === false
562+
) {
563+
throw new Zend_Exception('The producer does not exist or you do not have the necessary permission on its community', 403);
564+
}
565+
566+
$trendDao->setIsKeyMetric($state === 'true');
567+
$this->Tracker_Trend->save($trendDao);
568+
}
527569
}

modules/tracker/public/js/producer/producer.view.js

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,33 @@ $(document).ready(function () {
6060
$('a.visualizeSelected').unbind('click').hide();
6161
}
6262

63-
if (checked.length == 1) {
63+
/**
64+
* Toggle key metric state
65+
*/
66+
if (checked.length >= 1) {
67+
$('span.keyMetricTogglePlural').html(checked.length > 1 ? 's' : '');
6468
var isKey = $(checked[0]).attr('iskey') === '1';
6569
var verb = isKey ? 'Unset' : 'Set';
6670
$('span.keyMetricToggleVerb').html(verb);
6771
$('a.toggleKeyMetric').show().unbind('click').click(function () {
68-
72+
$.each(checked, function (idx, checkbox) {
73+
var keySpan = $(checkbox).parent().parent().find('.keyMetric');
74+
if (isKey) {
75+
keySpan.hide();
76+
$(checked[0]).attr('iskey', '0');
77+
} else {
78+
$(checked[0]).attr('iskey', '1');
79+
keySpan.show();
80+
}
81+
$.post(json.global.webroot + '/tracker/trend/setkeymetric', {
82+
trendId: $(checkbox).attr('element'),
83+
state: !isKey
84+
}, function () {
85+
verb = isKey ? 'Unset' : 'Set';
86+
$('span.keyMetricToggleVerb').html(verb);
87+
});
88+
});
89+
isKey = !isKey;
6990
});
7091
} else {
7192
$('a.toggleKeyMetric').unbind('click').hide();

modules/tracker/views/producer/view.phtml

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,11 @@ $this->headScript()->appendFile($this->moduleWebroot.'/public/js/producer/produc
7979
echo '<input type="checkbox" class="selectTrend" iskey="'.$trendDao->getIsKeyMetric().'" element="'.$this->escape($trendDao->getKey()).'" />';
8080
echo '<a class="trendLink" href="'.$this->webroot.'/tracker/trend/view?trendId='.$this->escape($trendDao->getKey()).'">';
8181
echo $this->escape($trendDao->getDisplayName());
82-
if($trendDao->getIsKeyMetric()) {
83-
echo '<span class="keyMetric"><img src="'.$this->coreWebroot.'/public/images/icons/key.png" alt="Key metric"></span>';
82+
echo '<span ';
83+
if(!$trendDao->getIsKeyMetric()) {
84+
echo 'style="display: none;" ';
8485
}
86+
echo 'class="keyMetric"><img src="'.$this->coreWebroot.'/public/images/icons/key.png" alt="Key metric"></span>';
8587
echo '<a/></div>';
8688
}
8789
?>
@@ -108,6 +110,12 @@ $this->headScript()->appendFile($this->moduleWebroot.'/public/js/producer/produc
108110
src="<?php echo $this->coreWebroot; ?>/public/images/icons/close.png"/>
109111
Delete</a>
110112
</li>
113+
<li>
114+
<a style="display: none;" class="toggleKeyMetric">
115+
<img alt="" src="<?php echo $this->coreWebroot; ?>/public/images/icons/key.png"/>
116+
<span class="keyMetricToggleVerb"></span> metric<span class="keyMetricTogglePlural"></span> as key
117+
</a>
118+
</li>
111119
<?php
112120
}
113121
?>
@@ -119,10 +127,6 @@ $this->headScript()->appendFile($this->moduleWebroot.'/public/js/producer/produc
119127
<a style="display: none;" class="visualizeDualAxis"><img alt="" src="<?php echo $this->moduleWebroot; ?>/public/images/chart_line.png"/>
120128
Dual axis plot</a>
121129
</li>
122-
<li>
123-
<a style="display: none;" class="toggleKeyMetric"><img alt="" src="<?php echo $this->coreWebroot; ?>/public/images/icons/key.png"/>
124-
<span class="keyMetricToggleVerb"></span> metric as key</a>
125-
</li>
126130
</ul>
127131
</div>
128132
</div>

0 commit comments

Comments
 (0)