aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-web/src/main/coffee/component-viewer/duplication-popup.coffee
blob: cd24e404ac4ced8545496d12d3be9298921180fc (plain)
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
define [
  'backbone.marionette'
  'templates/component-viewer'
  'common/popup'
  'component-viewer/utils'
], (
  Marionette
  Templates
  Popup
  utils
) ->

  $ = jQuery


  class DuplicationPopupView extends Popup
    template: Templates['cw-duplication-popup']


    events:
      'click a[data-key]': 'goToFile'


    goToFile: (e) ->
      key = $(e.currentTarget).data 'key'
      line = $(e.currentTarget).data 'line'
      if key == @options.main.component.get 'key'
        return @options.main.scrollToLine line
      files = @options.main.source.get('duplicationFiles')
      @options.main.addTransition 'duplication', @collection.map (item) ->
        file = files[item.get('_ref')]
        x = utils.splitLongName file.name
        key: file.key
        name: x.name
        subname: x.dir
        active: file.key == key
      @options.main._open key
      @options.main.on 'sized', =>
        @options.main.off 'sized'
        @options.main.scrollToLine line


    serializeData: ->
      files = @options.main.source.get('duplicationFiles')
      groupedBlocks = _.groupBy @collection.toJSON(), '_ref'
      duplications = _.map groupedBlocks, (blocks, fileRef) ->
        blocks: blocks
        file: files[fileRef]
      duplications = _.sortBy duplications, (d) =>
        d.file.projectName != @options.main.component.get 'projectName'
      component: @options.main.component.toJSON()
      duplications: duplications