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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
|
define [
'backbone.marionette'
'templates/component-viewer'
'component-viewer/header/basic-header'
'component-viewer/header/issues-header'
'component-viewer/header/coverage-header'
'component-viewer/header/duplications-header'
'component-viewer/header/scm-header'
'component-viewer/header/tests-header'
'common/handlebars-extensions'
], (
Marionette
Templates
BasicHeaderView
IssuesHeaderView
CoverageHeaderView
DuplicationsHeaderView
SCMHeaderView
TestsHeaderView
) ->
$ = jQuery
API_FAVORITE = "#{baseUrl}/api/favourites"
BARS = [
{ scope: 'basic', view: BasicHeaderView }
{ scope: 'issues', view: IssuesHeaderView }
{ scope: 'coverage', view: CoverageHeaderView }
{ scope: 'duplications', view: DuplicationsHeaderView }
{ scope: 'scm', view: SCMHeaderView }
{ scope: 'tests', view: TestsHeaderView }
]
class extends Marionette.Layout
template: Templates['header']
regions:
barRegion: '.component-viewer-header-expanded-bar'
ui:
expandLinks: '.component-viewer-header-measures-expand'
expandedBar: '.component-viewer-header-expanded-bar'
spinnerBar: '.component-viewer-header-expanded-bar[data-scope=spinner]'
unitTests: '.js-unit-test'
events:
'click .js-favorite': 'toggleFavorite'
'click @ui.expandLinks': 'showExpandedBar'
'click .js-toggle-issues': 'toggleIssues'
'click .js-toggle-coverage': 'toggleCoverage'
'click .js-toggle-duplications': 'toggleDuplications'
'click .js-toggle-scm': 'toggleSCM'
initialize: (options) ->
options.main.settings.on 'change', => @changeSettings()
@state = options.main.state
@component = options.main.component
@settings = options.main.component
onRender: ->
@delegateEvents()
activeHeaderTab = @state.get 'activeHeaderTab'
activeHeaderItem = @state.get 'activeHeaderItem'
if activeHeaderTab
@enableBar(activeHeaderTab).done =>
if activeHeaderItem
@enableBarItem activeHeaderItem
toggleFavorite: ->
component = @component
if component.get 'fav'
$.ajax
url: "#{API_FAVORITE}/#{component.get 'key'}"
type: 'DELETE'
.done =>
component.set 'fav', false
@render()
else
$.ajax
url: API_FAVORITE
type: 'POST'
data: key: component.get 'key'
.done =>
component.set 'fav', true
@render()
showBarSpinner: ->
@ui.spinnerBar.addClass 'active'
hideBarSpinner: ->
@ui.spinnerBar.removeClass 'active'
resetBars: ->
@state.set 'activeHeaderTab', null
@ui.expandLinks.removeClass 'active'
@ui.expandedBar.removeClass 'active'
@barRegion.reset()
enableBar: (scope) ->
@ui.expandedBar.addClass 'active'
requests = []
unless @state.get 'hasMeasures'
requests.push @options.main.requestMeasures @options.main.key
if @component.get('isUnitTest') && !@state.get('hasTests')
requests.push @options.main.requestTests @options.main.key
$.when.apply($, requests).done =>
@state.set 'activeHeaderTab', scope
bar = _.findWhere BARS, scope: scope
@barRegion.show new bar.view
main: @options.main, state: @state, component: @component, settings: @settings, source: @model, header: @
@ui.expandLinks.filter("[data-scope=#{scope}]").addClass 'active'
activeHeaderItem = @state.get 'activeHeaderItem'
if activeHeaderItem
@$(activeHeaderItem).addClass 'active'
enableBarItem: (item) ->
$item = @$(item)
if $item.length > 0
@$(item).click()
else
@options.main.hideAllLines()
showExpandedBar: (e) ->
el = $(e.currentTarget)
active = el.is '.active'
@resetBars()
unless active
el.addClass 'active'
scope = el.data 'scope'
@enableBar scope
changeSettings: ->
@$('.js-toggle-issues').toggleClass 'active', @options.main.settings.get 'issues'
@$('.js-toggle-coverage').toggleClass 'active', @options.main.settings.get 'coverage'
@$('.js-toggle-duplications').toggleClass 'active', @options.main.settings.get 'duplications'
@$('.js-toggle-scm').toggleClass 'active', @options.main.settings.get 'scm'
toggleSetting: (e, show, hide) ->
@showBlocks = []
active = $(e.currentTarget).is '.active'
if active
hide.call @options.main, true
else
show.call @options.main, true
toggleIssues: (e) -> @toggleSetting e, @options.main.showIssues, @options.main.hideIssues
toggleCoverage: (e) -> @toggleSetting e, @options.main.showCoverage, @options.main.hideCoverage
toggleDuplications: (e) -> @toggleSetting e, @options.main.showDuplications, @options.main.hideDuplications
toggleSCM: (e) -> @toggleSetting e, @options.main.showSCM, @options.main.hideSCM
toggleWorkspace: (e) -> @toggleSetting e, @options.main.showWorkspace, @options.main.hideWorkspace
showTimeChangesSpinner: ->
@$('.component-viewer-header-time-changes').html '<i class="spinner spinner-margin"></i>'
filterLines: (e, methodName, extra) ->
@$('.component-viewer-header-expanded-bar-section-list .active').removeClass 'active'
$(e.currentTarget).addClass 'active'
method = @options.main[methodName]
method.call @options.main, extra
serializeData: ->
component = @component.toJSON()
if component.measures
component.measures.maxIssues = Math.max(
component.measures.fBlockerIssues || 0
component.measures.fCriticalIssues || 0
component.measures.fMajorIssues || 0
component.measures.fMinorIssues || 0
component.measures.fInfoIssues || 0
)
settings: @options.main.settings.toJSON()
state: @state.toJSON()
showSettings: @showSettings
component: component
currentIssue: @options.main.currentIssue
|