From 6ec9fec5f6f2f5349a804d9622c05d708fa018d6 Mon Sep 17 00:00:00 2001 From: Stas Vilchik Date: Wed, 23 Jul 2014 12:23:49 +0200 Subject: [PATCH] SONAR-5479 Allow to filter on Lines and Lines of Code in the Component Viewer --- .../header/basic-header.coffee | 15 ++++++++ .../main/coffee/component-viewer/main.coffee | 37 ++++++++++++++++++- .../header/cw-basic-header.hbs | 10 +++-- 3 files changed, 57 insertions(+), 5 deletions(-) diff --git a/server/sonar-web/src/main/coffee/component-viewer/header/basic-header.coffee b/server/sonar-web/src/main/coffee/component-viewer/header/basic-header.coffee index 2f8a2300b39..e39ebeca502 100644 --- a/server/sonar-web/src/main/coffee/component-viewer/header/basic-header.coffee +++ b/server/sonar-web/src/main/coffee/component-viewer/header/basic-header.coffee @@ -11,3 +11,18 @@ define [ class extends BaseHeaderView template: Templates['cw-basic-header'] + + + events: + 'click .js-filter-lines': 'filterByLines' + 'click .js-filter-ncloc': 'filterByNcloc' + + + filterByLines: (e) -> + @header.filterLines e, 'filterByLines' + @state.set 'activeHeaderItem', '.js-filter-lines' + + + filterByNcloc: (e) -> + @header.filterLines e, 'filterByNcloc' + @state.set 'activeHeaderItem', '.js-filter-ncloc' diff --git a/server/sonar-web/src/main/coffee/component-viewer/main.coffee b/server/sonar-web/src/main/coffee/component-viewer/main.coffee index 737b6bd417a..a7f4c7415a2 100644 --- a/server/sonar-web/src/main/coffee/component-viewer/main.coffee +++ b/server/sonar-web/src/main/coffee/component-viewer/main.coffee @@ -47,7 +47,7 @@ define [ API_TESTS = "#{baseUrl}/api/tests/show" SOURCE_METRIC_LIST = 'accessors,classes,functions,statements,' + - 'ncloc,lines,generated_ncloc,generated_lines,' + + 'ncloc,ncloc_data,lines,generated_ncloc,generated_lines,' + 'complexity,function_complexity,' + 'comment_lines,comment_lines_density,public_api,public_undocumented_api,public_documented_api_density' @@ -204,8 +204,9 @@ define [ measuresList = data[0].msr || [] measures = @component.get 'measures' measuresList.forEach (m) -> - measures[m.key] = m.frmt_val + measures[m.key] = m.frmt_val || m.data @component.set 'measures', measures + @augmentWithNclocData() requestTrends: (key, period) -> @@ -234,6 +235,20 @@ define [ formattedSource: formattedSource + augmentWithNclocData: -> + nclocDataRaw = @component.has('measures') && @component.get('measures')['ncloc_data'] + if nclocDataRaw? + formattedSource = @source.get 'formattedSource' + nclocData = nclocDataRaw.split(';').map (item) -> + tokens = item.split '=' + lineNumber: +tokens[0] + executable: tokens[1] == '1' + nclocData.forEach (n) -> + line = _.findWhere formattedSource, lineNumber: n.lineNumber + line.executable = n.executable + @source.set 'formattedSource', formattedSource + + requestTests: (key) -> $.get API_TESTS, key: key, (data) => @state.set 'hasTests', true @@ -363,3 +378,21 @@ define [ scrollPlusDelta: (delta) -> @$(@sourceRegion.$el).scrollTop delta + + + _filterByLines: (predicate) -> + formattedSource = @source.get 'formattedSource' + @sourceView.resetShowBlocks() + formattedSource.forEach (line) => + if predicate line + ln = line.lineNumber + @sourceView.addShowBlock ln, ln + @sourceView.render() + + + filterByLines: -> + @showAllLines() + + + filterByNcloc: -> + @_filterByLines (line) -> line?.executable diff --git a/server/sonar-web/src/main/hbs/component-viewer/header/cw-basic-header.hbs b/server/sonar-web/src/main/hbs/component-viewer/header/cw-basic-header.hbs index 0e9a93367b2..32cd2c1730f 100644 --- a/server/sonar-web/src/main/hbs/component-viewer/header/cw-basic-header.hbs +++ b/server/sonar-web/src/main/hbs/component-viewer/header/cw-basic-header.hbs @@ -4,8 +4,12 @@ {{t 'component_viewer.measure_section.size'}} @@ -45,4 +49,4 @@ {{{componentViewerHeaderItem public_documented_api_density 'public_documented_api_density'}}} -{{/with}} \ No newline at end of file +{{/with}} -- 2.39.5