1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
define([
'./condition',
'./gate-condition-view',
'./gate-conditions-empty-view',
'./templates'
], function (Condition, ConditionView, ConditionsEmptyView) {
return Marionette.CompositeView.extend({
template: Templates['quality-gate-detail-conditions'],
childView: ConditionView,
emptyView: ConditionsEmptyView,
childViewContainer: '.js-conditions',
ui: {
metricSelect: '#quality-gate-new-condition-metric'
},
events: {
'click .js-show-more': 'showMoreIntroduction',
'change @ui.metricSelect': 'addCondition'
},
childViewOptions: function () {
return {
canEdit: this.options.canEdit,
gate: this.model,
collectionView: this,
metrics: this.options.metrics,
periods: this.options.periods
};
},
onRender: function () {
this.ui.metricSelect.select2({
allowClear: false,
width: '250px',
placeholder: t('alerts.select_metric')
});
},
showMoreIntroduction: function () {
this.$('.js-show-more').addClass('hidden');
this.$('.js-more').removeClass('hidden');
},
addCondition: function () {
var metric = this.ui.metricSelect.val();
this.ui.metricSelect.select2('val', '');
var condition = new Condition({ metric: metric });
this.collection.add(condition);
},
groupedMetrics: function () {
var metrics = this.options.metrics.filter(function (metric) {
return !metric.hidden;
});
metrics = _.groupBy(metrics, 'domain');
metrics = _.map(metrics, function (list, domain) {
return {
domain: domain,
metrics: _.sortBy(list, 'short_name')
};
});
return _.sortBy(metrics, 'domain');
},
serializeData: function () {
return _.extend(Marionette.CompositeView.prototype.serializeData.apply(this, arguments), {
canEdit: this.options.canEdit,
metricGroups: this.groupedMetrics()
});
}
});
});
|