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
|
import _ from 'underscore';
import Backbone from 'backbone';
export default Backbone.Model.extend({
idAttribute: 'uuid',
defaults: function () {
return {
exist: true,
hasSource: false,
hasCoverage: false,
hasITCoverage: false,
hasDuplications: false,
hasSCM: false,
canSeeCode: true
};
},
key: function () {
return this.get('key');
},
addMeta: function (meta) {
var source = this.get('source'),
metaIdx = 0,
metaLine = meta[metaIdx];
source.forEach(function (line) {
while (metaLine != null && line.line > metaLine.line) {
metaLine = meta[++metaIdx];
}
if (metaLine != null && line.line === metaLine.line) {
_.extend(line, metaLine);
metaLine = meta[++metaIdx];
}
});
this.set({ source: source });
},
addDuplications: function (duplications) {
var source = this.get('source');
if (source != null) {
source.forEach(function (line) {
var lineDuplications = [];
duplications.forEach(function (d, i) {
var duplicated = false;
d.blocks.forEach(function (b) {
if (b._ref === '1') {
var lineFrom = b.from,
lineTo = b.from + b.size - 1;
if (line.line >= lineFrom && line.line <= lineTo) {
duplicated = true;
}
}
});
lineDuplications.push(duplicated ? i + 1 : false);
});
line.duplications = lineDuplications;
});
}
this.set({ source: source });
},
checkIfHasDuplications: function () {
var hasDuplications = false,
source = this.get('source');
if (source != null) {
source.forEach(function (line) {
if (line.duplicated) {
hasDuplications = true;
}
});
}
this.set({ hasDuplications: hasDuplications });
},
hasUTCoverage: function (source) {
return _.some(source, function (line) {
return line.utCoverageStatus != null;
});
},
hasITCoverage: function (source) {
return _.some(source, function (line) {
return line.itCoverageStatus != null;
});
}
});
|