diff options
Diffstat (limited to 'sonar-server/src/main/coffee/component-viewer/mixins/main-scm.coffee')
-rw-r--r-- | sonar-server/src/main/coffee/component-viewer/mixins/main-scm.coffee | 62 |
1 files changed, 59 insertions, 3 deletions
diff --git a/sonar-server/src/main/coffee/component-viewer/mixins/main-scm.coffee b/sonar-server/src/main/coffee/component-viewer/mixins/main-scm.coffee index 3e92b7528b5..57833917494 100644 --- a/sonar-server/src/main/coffee/component-viewer/mixins/main-scm.coffee +++ b/sonar-server/src/main/coffee/component-viewer/mixins/main-scm.coffee @@ -8,8 +8,28 @@ define [], () -> requestSCM: (key) -> $.get API_SCM, key: key, (data) => - @state.set 'hasSCM', true - @source.set scm: data.scm + if data?.scm? + @state.set 'hasSCM', true + @source.set scm: data.scm + @augmentWithSCM data.scm + + + augmentWithSCM: (scm) -> + formattedSource = @source.get 'formattedSource' + scmLength = scm.length + if scmLength > 0 + scmIndex = 0 + scmCurrent = scm[scmIndex] + scmDetails = {} + formattedSource.forEach (line) -> + if line.lineNumber == scmCurrent[0] + scmDetails = author: scmCurrent[1], date: scmCurrent[2] + if scmIndex < scmLength - 1 + scmIndex++ + scmCurrent = scm[scmIndex] + line.scm = scmDetails + @source.set 'formattedSource', formattedSource + showSCM: (store = false) -> @@ -24,4 +44,40 @@ define [], () -> hideSCM: (store = false) -> @settings.set 'scm', false @storeSettings() if store - @sourceView.render()
\ No newline at end of file + @sourceView.render() + + + filterBySCM: -> + @requestSCM(@key).done => @_filterBySCM() + + + _filterBySCM: () -> + formattedSource = @source.get 'formattedSource' + period = @state.get 'period' + unless period? + return @showAllLines() + else + periodDate = period.get 'sinceDate' + @settings.set 'scm', true + @sourceView.resetShowBlocks() + scmBlockLine = 1 + predicate = false + formattedSource.forEach (line) => + scmBlockDate = new Date line.scm.date + if scmBlockDate >= periodDate + scmBlockLine = line.lineNumber if predicate == false + predicate = true + else if predicate == true + predicate = false + @sourceView.addShowBlock scmBlockLine, line.lineNumber - 1 + if predicate + @sourceView.addShowBlock scmBlockLine, _.size @source.get 'source' + @sourceView.render() + + + enableSCMPeriod: (periodKey) -> + period = if periodKey == '' then null else @periods.findWhere key: periodKey + @state.set 'period', period + @requestMeasures(@key, period?.get('key')).done => + @headerView.render() + @filterBySCM() unless @state.get('activeHeaderItem')
\ No newline at end of file |