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
|
define([
'./issue'
], function (Issue) {
return Backbone.Collection.extend({
model: Issue,
url: function () {
return baseUrl + '/api/issues/search';
},
_injectRelational: function (issue, source, baseField, lookupField) {
var baseValue = issue[baseField];
if (baseValue != null && _.size(source)) {
var lookupValue = _.find(source, function (candidate) {
return candidate[lookupField] === baseValue;
});
if (lookupValue != null) {
Object.keys(lookupValue).forEach(function (key) {
var newKey = baseField + key.charAt(0).toUpperCase() + key.slice(1);
issue[newKey] = lookupValue[key];
});
}
}
return issue;
},
_prepareClosed: function (issue) {
if (issue.status === 'CLOSED') {
issue.secondaryLocations = [];
issue.executionFlows = [];
delete issue.textRange;
}
return issue;
},
parseIssues: function (r) {
var that = this;
return r.issues.map(function (issue, index) {
_.extend(issue, { index: index });
issue = that._injectRelational(issue, r.components, 'component', 'key');
issue = that._injectRelational(issue, r.components, 'project', 'key');
issue = that._injectRelational(issue, r.components, 'subProject', 'key');
issue = that._injectRelational(issue, r.rules, 'rule', 'key');
issue = that._injectRelational(issue, r.users, 'assignee', 'login');
issue = that._injectRelational(issue, r.users, 'reporter', 'login');
issue = that._injectRelational(issue, r.actionPlans, 'actionPlan', 'key');
issue = that._prepareClosed(issue);
return issue;
});
},
setIndex: function () {
return this.forEach(function (issue, index) {
return issue.set({ index: index });
});
},
selectByKeys: function (keys) {
var that = this;
keys.forEach(function (key) {
var issue = that.get(key);
if (issue) {
issue.set({ selected: true });
}
});
}
});
});
|