Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Fix metadata on undoing remove #148

Merged
merged 2 commits into from

2 participants

@jonnor
Owner

No description provided.

jonnor added some commits
@jonnor jonnor Graph: Emit metadata changes on node/edge/ports removal
Needed for the journal to be able to restore metadata when undoing removals.
Fixes noflo/noflo-ui#96, undoing node removal resets position to 0,0
6f8b16d
@jonnor jonnor Journal: Fix typo and missing implementation for changeEdge c6a2b59
@jonnor jonnor referenced this pull request in noflo/noflo-ui
Closed

Nodes lose their position when returned via undo #96

@bergie bergie merged commit 0edc0c1 into noflo:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 26, 2014
  1. @jonnor

    Graph: Emit metadata changes on node/edge/ports removal

    jonnor authored
    Needed for the journal to be able to restore metadata when undoing removals.
    Fixes noflo/noflo-ui#96, undoing node removal resets position to 0,0
  2. @jonnor
This page is out of date. Refresh to see the latest.
View
2  spec/Journal.coffee
@@ -51,8 +51,10 @@ describe 'Journal', ->
Baz(Foo)
Foo out -> in Baz
'42' -> in Foo
+ META Foo out -> in Baz
Foo out -X> in Baz
'42' -X> in Foo
+ META Foo
DEL Foo(Bar)
<<< 1: test1"""
chai.expect(j.toPrettyString(0,2)).to.equal ref
View
7 src/lib/Graph.coffee
@@ -146,6 +146,7 @@ class Graph extends EventEmitter
@checkTransactionStart()
port = @inports[publicPort]
+ @setInportMetadata publicPort, {}
delete @inports[publicPort]
@emit 'removeInport', publicPort, port
@checkTransactionEnd()
@@ -194,6 +195,7 @@ class Graph extends EventEmitter
@checkTransactionStart()
port = @outports[publicPort]
+ @setOutportMetadata publicPort, {}
delete @outports[publicPort]
@emit 'removeOutport', publicPort, port
@@ -242,6 +244,7 @@ class Graph extends EventEmitter
for group in @groups
continue unless group
continue unless group.name is groupName
+ @setGroupMetadata group.name, {}
@groups.splice @groups.indexOf(group), 1
@emit 'removeGroup', group
@@ -332,6 +335,8 @@ class Graph extends EventEmitter
continue if index is -1
group.nodes.splice index, 1
+ @setNodeMetadata id, {}
+
if -1 isnt @nodes.indexOf node
@nodes.splice @nodes.indexOf(node), 1
@@ -466,12 +471,14 @@ class Graph extends EventEmitter
if node2 and port2
unless edge.to.node is node2 and edge.to.port is port2
continue
+ @setEdgeMetadata edge.from.node, edge.from.port, edge.to.node, edge.to.port, {}
@emit 'removeEdge', edge
@edges.splice index, 1
if edge.to.node is node and edge.to.port is port
if node2 and port2
unless edge.from.node is node2 and edge.from.port is port2
continue
+ @setEdgeMetadata edge.from.node, edge.from.port, edge.to.node, edge.to.port, {}
@emit 'removeEdge', edge
@edges.splice index, 1
View
8 src/lib/Journal.coffee
@@ -20,7 +20,7 @@ entryToPrettyString = (entry) ->
when 'addNode' then "#{a.id}(#{a.component})"
when 'removeNode' then "DEL #{a.id}(#{a.component})"
when 'renameNode' then "RENAME #{a.oldId} #{a.newId}"
- when 'changeNode' then "META #{a.id}(#{a.component})"
+ when 'changeNode' then "META #{a.id}"
when 'addEdge' then "#{a.from.node} #{a.from.port} -> #{a.to.port} #{a.to.node}"
when 'removeEdge' then "#{a.from.node} #{a.from.port} -X> #{a.to.port} #{a.to.node}"
when 'changeEdge' then "META #{a.from.node} #{a.from.port} -> #{a.to.port} #{a.to.node}"
@@ -118,8 +118,8 @@ class Journal extends EventEmitter
@appendCommand 'addEdge', edge
@graph.on 'removeEdge', (edge) =>
@appendCommand 'removeEdge', edge
- @graph.on 'changeEdge', (edge) =>
- @appendCommand 'removeEdge', edge
+ @graph.on 'changeEdge', (edge, oldMeta) =>
+ @appendCommand 'changeEdge', {from: edge.from, to: edge.to, new: edge.metadata, old: oldMeta}
@graph.on 'addInitial', (iip) =>
@appendCommand 'addInitial', iip
@graph.on 'removeInitial', (iip) =>
@@ -197,6 +197,7 @@ class Journal extends EventEmitter
when 'changeNode' then @graph.setNodeMetadata a.id, calculateMeta(a.old, a.new)
when 'addEdge' then @graph.addEdge a.from.node, a.from.port, a.to.node, a.to.port
when 'removeEdge' then @graph.removeEdge a.from.node, a.from.port, a.to.node, a.to.port
+ when 'changeEdge' then @graph.setEdgeMetadata a.from.node, a.from.port, a.to.node, a.to.port, calculateMeta(a.old, a.new)
when 'addInitial' then @graph.addInitial a.from.data, a.to.node, a.to.port
when 'removeInitial' then @graph.removeInitial a.to.node, a.to.port
when 'startTransaction' then null
@@ -224,6 +225,7 @@ class Journal extends EventEmitter
when 'changeNode' then @graph.setNodeMetadata a.id, calculateMeta(a.new, a.old)
when 'addEdge' then @graph.removeEdge a.from.node, a.from.port, a.to.node, a.to.port
when 'removeEdge' then @graph.addEdge a.from.node, a.from.port, a.to.node, a.to.port
+ when 'changeEdge' then @graph.setEdgeMetadata a.from.node, a.from.port, a.to.node, a.to.port, calculateMeta(a.new, a.old)
when 'addInitial' then @graph.removeInitial a.to.node, a.to.port
when 'removeInitial' then @graph.addInitial a.from.data, a.to.node, a.to.port
when 'startTransaction' then null
Something went wrong with that request. Please try again.