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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
|
import $ from 'jquery';
import _ from 'underscore';
import Backbone from 'backbone';
export default Backbone.Model.extend({
idAttribute: 'key',
defaults: {
activeRuleCount: 0,
projectCount: 0
},
fetch: function () {
var that = this;
this.fetchChanged = {};
return $.when(
this.fetchProfileRules(),
this.fetchInheritance()
).done(function () {
that.set(that.fetchChanged);
});
},
fetchProfileRules: function () {
var that = this,
url = baseUrl + '/api/rules/search',
key = this.id,
options = {
ps: 1,
facets: 'active_severities',
qprofile: key,
activation: 'true'
};
return $.get(url, options).done(function (r) {
var severityFacet = _.findWhere(r.facets, { property: 'active_severities' });
if (severityFacet != null) {
var severities = severityFacet.values,
severityComparator = function (s) {
return window.severityColumnsComparator(s.val);
},
sortedSeverities = _.sortBy(severities, severityComparator);
_.extend(that.fetchChanged, { rulesSeverities: sortedSeverities });
}
});
},
fetchInheritance: function () {
var that = this,
url = baseUrl + '/api/qualityprofiles/inheritance',
options = { profileKey: this.id };
return $.get(url, options).done(function (r) {
_.extend(that.fetchChanged, r.profile, {
ancestors: r.ancestors,
children: r.children
});
});
},
fetchChangelog: function (options) {
var that = this,
url = baseUrl + '/api/qualityprofiles/changelog',
opts = _.extend({}, options, { profileKey: this.id });
return $.get(url, opts).done(function (r) {
that.set({
events: r.events,
eventsPage: r.p,
totalEvents: r.total,
eventsParameters: _.clone(options)
});
});
},
fetchMoreChangelog: function () {
var that = this,
url = baseUrl + '/api/qualityprofiles/changelog',
page = this.get('eventsPage') || 0,
parameters = this.get('eventsParameters') || {},
opts = _.extend({}, parameters, { profileKey: this.id, p: page + 1 });
return $.get(url, opts).done(function (r) {
var events = that.get('events') || [];
that.set({
events: [].concat(events, r.events),
eventsPage: r.p,
totalEvents: r.total
});
});
},
resetChangelog: function () {
this.unset('events', { silent: true });
this.unset('eventsPage', { silent: true });
this.unset('totalEvents');
},
compareWith: function (withKey) {
var that = this,
url = baseUrl + '/api/qualityprofiles/compare',
options = { leftKey: this.id, rightKey: withKey };
return $.get(url, options).done(function (r) {
var comparison = _.extend(r, {
inLeftSize: _.size(r.inLeft),
inRightSize: _.size(r.inRight),
modifiedSize: _.size(r.modified)
});
that.set({
comparison: comparison,
comparedWith: withKey
});
});
},
resetComparison: function () {
this.unset('comparedWith', { silent: true });
this.unset('comparison');
}
});
|