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
117
118
119
120
121
122
123
124
125
126
127
128
129
|
define [
'component-viewer/utils'
], (
utils
) ->
$ = jQuery
API_COMPONENT = "#{baseUrl}/api/components/app"
API_ISSUES = "#{baseUrl}/api/issues/search"
LINES_AROUND_ISSUE = 4
class IssuesMixin
requestIssues: (key) ->
options =
components: key
ps: 10000
extra_fields: 'actions,transitions,assigneeName,actionPlanName'
$.get API_ISSUES, options, (data) =>
@state.set 'hasIssues', true
@source.set
issues: data.issues
activeIssues: data.issues.filter (issue) -> !issue.resolution
showIssues: (store = false, issue) ->
@settings.set 'issues', true
@storeSettings() if store
if issue?
@currentIssue = issue.key
@source.set 'issues', [issue]
@filterByCurrentIssue()
@headerView.render()
@trigger 'sized'
else
unless @state.get 'hasIssues'
@requestIssues(@key).done =>
@sourceView.render()
@trigger 'sized'
else
@sourceView.render()
@trigger 'sized'
hideIssues: (store = false) ->
@settings.set 'issues', false
@storeSettings() if store
@sourceView.render()
requestIssuesPeriod: (key, period) ->
params = key: key
params.period = period if period?
$.get API_COMPONENT, params, (data) =>
rules = data.rules.map (r) -> key: r[0], name: r[1], count: r[2]
severities = data.severities.map (r) -> key: r[0], name: r[1], count: r[2]
@state.set
rules: _.sortBy(rules, 'name')
severities: utils.sortSeverities(severities)
filterLinesByIssues: ->
issues = @source.get 'issues'
@sourceView.resetShowBlocks()
issues.forEach (issue) =>
line = issue.line || 0
if issue.resolution == 'FIXED' || issue.resolution == 'REMOVED'
@sourceView.addShowBlock 0, 0, true
else
@sourceView.addShowBlock line - LINES_AROUND_ISSUE, line + LINES_AROUND_ISSUE, line == 0
@sourceView.render()
filterByIssues: (predicate, requestIssues = true) ->
period = @state.get('period')
if period
p = predicate
predicate = (issue) =>
(new Date(issue.creationDate) >= period.get('sinceDate')) && p issue
if requestIssues && !@state.get 'hasIssues'
@requestIssues(@key).done => @_filterByIssues(predicate)
else
@_filterByIssues(predicate)
_filterByIssues: (predicate) ->
issues = @source.get 'issues'
@settings.set 'issues', true
@sourceView.resetShowBlocks()
activeIssues = []
issues.forEach (issue) =>
if predicate issue
line = issue.line || 0
if issue.resolution == 'FIXED' || issue.resolution == 'REMOVED'
@sourceView.addShowBlock 0, 0, true
else
@sourceView.addShowBlock line - LINES_AROUND_ISSUE, line + LINES_AROUND_ISSUE, line == 0
activeIssues.push issue
@source.set 'activeIssues', activeIssues
@sourceView.render()
# Current Issue
filterByCurrentIssue: -> @filterByIssues ((issue) => issue.key == @currentIssue), false
# All Issues
filterByAllIssues: -> @filterByIssues -> true
# Resolved Issues
filterByFixedIssues: -> @filterByIssues (issue) -> issue.resolution == 'FIXED'
# Unresolved Issues
filterByUnresolvedIssues: -> @filterByIssues (issue) -> !issue.resolution
# False Positive
filterByFalsePositiveIssues: -> @filterByIssues (issue) -> issue.resolution == 'FALSE-POSITIVE'
# Rule
filterByRule: (rule) -> @filterByIssues (issue) -> issue.rule == rule && !issue.resolution
# Severity
filterByBlockerIssues: -> @filterByIssues (issue) -> issue.severity == 'BLOCKER' && !issue.resolution
filterByCriticalIssues: -> @filterByIssues (issue) -> issue.severity == 'CRITICAL' && !issue.resolution
filterByMajorIssues: -> @filterByIssues (issue) -> issue.severity == 'MAJOR' && !issue.resolution
filterByMinorIssues: -> @filterByIssues (issue) -> issue.severity == 'MINOR' && !issue.resolution
filterByInfoIssues: -> @filterByIssues (issue) -> issue.severity == 'INFO' && !issue.resolution
|