2014-04-09 19:09:35 -04:00
|
|
|
CocoView = require 'views/kinds/CocoView'
|
|
|
|
template = require 'templates/editor/delta'
|
|
|
|
deltaLib = require 'lib/deltas'
|
|
|
|
|
|
|
|
module.exports = class DeltaListView extends CocoView
|
2014-04-09 22:07:44 -04:00
|
|
|
@deltaCounter: 0
|
|
|
|
className: "delta-list-view"
|
2014-04-09 19:09:35 -04:00
|
|
|
template: template
|
|
|
|
|
|
|
|
constructor: (options) ->
|
|
|
|
super(options)
|
2014-04-09 22:07:44 -04:00
|
|
|
@model = options.model
|
2014-04-09 19:09:35 -04:00
|
|
|
|
|
|
|
getRenderData: ->
|
|
|
|
c = super()
|
2014-04-09 22:07:44 -04:00
|
|
|
c.deltas = @processedDeltas = @model.getExpandedDelta()
|
|
|
|
c.counter = DeltaListView.deltaCounter
|
|
|
|
DeltaListView.deltaCounter += c.deltas.length
|
2014-04-09 19:09:35 -04:00
|
|
|
c
|
|
|
|
|
|
|
|
afterRender: ->
|
|
|
|
deltas = @$el.find('.delta')
|
|
|
|
for delta, i in deltas
|
|
|
|
deltaEl = $(delta)
|
|
|
|
deltaData = @processedDeltas[i]
|
|
|
|
if _.isObject(deltaData.left) and leftEl = deltaEl.find('.old-value')
|
|
|
|
options =
|
|
|
|
data: deltaData.left
|
|
|
|
schema: deltaData.schema
|
|
|
|
readOnly: true
|
|
|
|
treema = TreemaNode.make(leftEl, options)
|
|
|
|
treema.build()
|
|
|
|
|
2014-04-09 22:07:44 -04:00
|
|
|
if _.isObject(deltaData.right) and rightEl = deltaEl.find('.new-value')
|
2014-04-09 19:09:35 -04:00
|
|
|
options =
|
|
|
|
data: deltaData.right
|
|
|
|
schema: deltaData.schema
|
|
|
|
readOnly: true
|
|
|
|
treema = TreemaNode.make(rightEl, options)
|
|
|
|
treema.build()
|
2014-04-10 13:24:14 -04:00
|
|
|
|
|
|
|
if deltaData.action is 'text-diff'
|
|
|
|
left = difflib.stringAsLines deltaData.left
|
|
|
|
right = difflib.stringAsLines deltaData.right
|
|
|
|
sm = new difflib.SequenceMatcher(left, right)
|
|
|
|
opcodes = sm.get_opcodes()
|
|
|
|
el = deltaEl.find('.text-diff')
|
|
|
|
args = {
|
|
|
|
baseTextLines: left
|
|
|
|
newTextLines: right
|
|
|
|
opcodes: opcodes
|
|
|
|
baseTextName: "Old"
|
|
|
|
newTextName: "New"
|
|
|
|
contextSize: 5
|
|
|
|
viewType: 1
|
|
|
|
}
|
|
|
|
el.append(diffview.buildView(args))
|