From: Stas Vilchik Date: Wed, 16 Apr 2014 11:18:23 +0000 (+0600) Subject: Component Viewer: add options X-Git-Tag: 4.4-RC1~1434^2~1 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=e06ba27404127cfe01c2e926c86c6028758e6b82;p=sonarqube.git Component Viewer: add options --- diff --git a/sonar-server/src/main/coffee/component-viewer/header.coffee b/sonar-server/src/main/coffee/component-viewer/header.coffee new file mode 100644 index 00000000000..0e2dbd7040a --- /dev/null +++ b/sonar-server/src/main/coffee/component-viewer/header.coffee @@ -0,0 +1,29 @@ +define [ + 'backbone.marionette' + 'templates/component-viewer' +], ( + Marionette + Templates +) -> + + $ = jQuery + + + class HeaderView extends Marionette.ItemView + template: Templates['header'] + + + events: + 'click [data-option=coverage]': 'toggleCoverage' + + + onRender: -> + @delegateEvents() + + + toggleCoverage: (e) -> + el = $(e.currentTarget) + active = el.is '.active' + el.toggleClass 'active' + if active then @options.main.hideCoverage() else @options.main.showCoverage() + diff --git a/sonar-server/src/main/coffee/component-viewer/main.coffee b/sonar-server/src/main/coffee/component-viewer/main.coffee index e89ff2ac96f..3eef7c58c28 100644 --- a/sonar-server/src/main/coffee/component-viewer/main.coffee +++ b/sonar-server/src/main/coffee/component-viewer/main.coffee @@ -2,11 +2,13 @@ define [ 'backbone' 'backbone.marionette' 'templates/component-viewer' + 'component-viewer/header' 'component-viewer/source' ], ( Backbone Marionette Templates + HeaderView SourceView ) -> @@ -22,46 +24,70 @@ define [ regions: + headerRegion: '.component-viewer-header' sourceRegion: '.component-viewer-source' initialize: -> + @component = new Backbone.Model() + @headerView = new HeaderView model: @component, main: @ + @source = new Backbone.Model() - @sourceView = new SourceView model: @source + @sourceView = new SourceView model: @source, main: @ onRender: -> + @headerRegion.show @headerView @sourceRegion.show @sourceView + requestComponent: (key, metrics) -> + $.get API_RESOURCES, resource: key, metrics: metrics, (data) => + @component.set data[0] + + requestSource: (key) -> $.get API_SOURCES, resource: key, (data) => - @source.set { source: data[0] }, { silent: true } + @source.set source: data[0] - requestCoverage: (key) -> - metrics = 'coverage_line_hits_data,covered_conditions_by_line,conditions_by_line' - - toObj = (data) -> + extractCoverage: (data) -> + toObj = (d) -> q = {} - data.split(';').forEach (item) -> + d.split(';').forEach (item) -> tokens = item.split '=' q[tokens[0]] = tokens[1] q - - $.get API_RESOURCES, resource: key, metrics: metrics, (data) => - msr = data[0].msr - coverage = toObj _.findWhere(msr, key: 'coverage_line_hits_data').data - coverageConditions = toObj _.findWhere(msr, key: 'covered_conditions_by_line').data - conditions = toObj _.findWhere(msr, key: 'conditions_by_line').data - @source.set { - coverage: coverage, - coverageConditions: coverageConditions - conditions: conditions - }, { silent: true } + msr = data[0].msr + coverage = toObj _.findWhere(msr, key: 'coverage_line_hits_data').data + coverageConditions = toObj _.findWhere(msr, key: 'covered_conditions_by_line').data + conditions = toObj _.findWhere(msr, key: 'conditions_by_line').data + @source.set + coverage: coverage + coverageConditions: coverageConditions + conditions: conditions open: (key) -> - $.when(@requestSource(key), @requestCoverage(key)).done => - @sourceView.render() \ No newline at end of file + @key = key + @sourceView.showSpinner() + source = @requestSource key + component = @requestComponent key + $.when(source, component).done => + @render() + @hideCoverage() + + + showCoverage: -> + unless @source.has 'coverage' + metrics = 'coverage_line_hits_data,covered_conditions_by_line,conditions_by_line' + @requestComponent(@key, metrics).done (data) => + @extractCoverage data + @sourceView.render() + else + @sourceView.render() + + + hideCoverage: -> + @sourceView.hideCoverage() \ No newline at end of file diff --git a/sonar-server/src/main/coffee/component-viewer/source.coffee b/sonar-server/src/main/coffee/component-viewer/source.coffee index b6c25ba860d..ae09ad17837 100644 --- a/sonar-server/src/main/coffee/component-viewer/source.coffee +++ b/sonar-server/src/main/coffee/component-viewer/source.coffee @@ -11,8 +11,12 @@ define [ template: Templates['source'] - modelEvents: - 'change': 'render' + showSpinner: -> + @$el.html '
' + + + hideCoverage: -> + @$('.coverage').hide() serializeData: -> @@ -31,7 +35,6 @@ define [ lineCoverageConditionsStatus = 'orange' if lineCoverageConditions > 0 && lineCoverageConditions < lineConditions lineCoverageConditionsStatus = 'green' if lineCoverageConditions == lineConditions - lineNumber: line code: code coverage: lineCoverage diff --git a/sonar-server/src/main/hbs/component-viewer/header.hbs b/sonar-server/src/main/hbs/component-viewer/header.hbs new file mode 100644 index 00000000000..454b8519022 --- /dev/null +++ b/sonar-server/src/main/hbs/component-viewer/header.hbs @@ -0,0 +1,7 @@ +

{{name}}

+ +
+ + + +
\ No newline at end of file diff --git a/sonar-server/src/main/hbs/component-viewer/layout.hbs b/sonar-server/src/main/hbs/component-viewer/layout.hbs index 27a90824099..78b06dad147 100644 --- a/sonar-server/src/main/hbs/component-viewer/layout.hbs +++ b/sonar-server/src/main/hbs/component-viewer/layout.hbs @@ -1 +1,2 @@ +
\ No newline at end of file diff --git a/sonar-server/src/main/less/component-viewer.less b/sonar-server/src/main/less/component-viewer.less index 7bfd425373f..e6700dac01a 100644 --- a/sonar-server/src/main/less/component-viewer.less +++ b/sonar-server/src/main/less/component-viewer.less @@ -5,6 +5,29 @@ .component-viewer { width: 100%; min-width: 600px; + border: 1px solid @barBorderColor; +} + + +.component-viewer-header { + height: 40px; + padding: 0 10px; + border-bottom: 1px solid @barBorderColor; + background-color: @barBackgroundColor; +} + + +.component-viewer-component { + float: left; + line-height: 40px; + font-weight: bold; +} + + +.component-viewer-options { + float: right; + line-height: 1; + padding-top: 9px; } diff --git a/sonar-server/src/main/less/icons.less b/sonar-server/src/main/less/icons.less index 0042c5b31fe..c2a8a7024c8 100644 --- a/sonar-server/src/main/less/icons.less +++ b/sonar-server/src/main/less/icons.less @@ -411,6 +411,14 @@ a[class^="icon-"], a[class*=" icon-"] { color: @darkGrey; font-size: @iconFontSize; } +.icon-coverage:before { + content: "\f091"; + font-size: @iconSmallFontSize; +} +.icon-duplications:before { + content: "\f0c5"; + font-size: @iconSmallFontSize; +} /* diff --git a/sonar-server/src/main/less/ui.less b/sonar-server/src/main/less/ui.less index 47468a8a12a..9d904c6aeaa 100644 --- a/sonar-server/src/main/less/ui.less +++ b/sonar-server/src/main/less/ui.less @@ -61,7 +61,7 @@ input[type=button] { color: #fff; } - &:active { + &:active, &.active { border-color: #2790c0; background: #78bdea; color: #fff; diff --git a/sonar-server/src/main/webapp/fonts/sonar.eot b/sonar-server/src/main/webapp/fonts/sonar.eot index c1f7f3604c0..0ac2e08c0dc 100755 Binary files a/sonar-server/src/main/webapp/fonts/sonar.eot and b/sonar-server/src/main/webapp/fonts/sonar.eot differ diff --git a/sonar-server/src/main/webapp/fonts/sonar.svg b/sonar-server/src/main/webapp/fonts/sonar.svg index a42e8c96720..a0159d70fe4 100755 --- a/sonar-server/src/main/webapp/fonts/sonar.svg +++ b/sonar-server/src/main/webapp/fonts/sonar.svg @@ -19,10 +19,11 @@ - - + + + @@ -50,6 +51,7 @@ + diff --git a/sonar-server/src/main/webapp/fonts/sonar.ttf b/sonar-server/src/main/webapp/fonts/sonar.ttf index d53c071c5f3..cca0a5f69b2 100755 Binary files a/sonar-server/src/main/webapp/fonts/sonar.ttf and b/sonar-server/src/main/webapp/fonts/sonar.ttf differ diff --git a/sonar-server/src/main/webapp/fonts/sonar.woff b/sonar-server/src/main/webapp/fonts/sonar.woff index 5d296e17d1a..2f3a11d0bb9 100755 Binary files a/sonar-server/src/main/webapp/fonts/sonar.woff and b/sonar-server/src/main/webapp/fonts/sonar.woff differ