aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-web/src/main/coffee/component-viewer/duplication-popup.coffee
blob: c9e6545fd2407addb6ee86ba3348e1a5a97e8607 (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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
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'


    onRender: ->
      source = @options.main.sourceView.$el
      sourceOffset = source.offset()
      trigger = @options.triggerEl
      triggerOffset = trigger.offset()
      @$el.detach().appendTo(source).css
        top: triggerOffset.top - sourceOffset.top + source.scrollTop()
        left: triggerOffset.left - sourceOffset.left + source.scrollLeft() + trigger.outerWidth()
      @attachCloseEvents()


    goToFile: (e) ->
      key = $(e.currentTarget).data 'key'
      line = $(e.currentTarget).data '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
        component:
          projectName: file.projectName
          subProjectName: file.subProjectName
        active: file.key == key
      if key == @options.main.component.get 'key'
        @options.main.scrollToLine line
        @options.main.workspaceView.render()
      else
        @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) =>
        a = d.file.projectName != @options.main.component.get 'projectName'
        b = d.file.subProjectName != @options.main.component.get 'subProjectName'
        c = d.file.key != @options.main.component.get 'key'
        '' + a + b + c

      component: @options.main.component.toJSON()
      duplications: duplications