chat iss working
This commit is contained in:
parent
4a17d00123
commit
b13ac98c9f
3 changed files with 33 additions and 63 deletions
|
@ -2,7 +2,9 @@
|
||||||
|
|
||||||
import Active from './Active'
|
import Active from './Active'
|
||||||
import Control from './Control'
|
import Control from './Control'
|
||||||
|
import Create from './Create'
|
||||||
import DataModel from './DataModel'
|
import DataModel from './DataModel'
|
||||||
|
import Engine from './Engine'
|
||||||
import Map from './Map'
|
import Map from './Map'
|
||||||
import Mapper from './Mapper'
|
import Mapper from './Mapper'
|
||||||
import Synapse from './Synapse'
|
import Synapse from './Synapse'
|
||||||
|
@ -51,6 +53,9 @@ const Cable = {
|
||||||
node2 = topic2.get('node')
|
node2 = topic2.get('node')
|
||||||
|
|
||||||
Synapse.renderSynapse(mapping, synapse, node1, node2, false)
|
Synapse.renderSynapse(mapping, synapse, node1, node2, false)
|
||||||
|
if (Create.newSynapse.focusNode === node1) {
|
||||||
|
Engine.setFocusNode(node2)
|
||||||
|
}
|
||||||
} else if (!cancel) {
|
} else if (!cancel) {
|
||||||
setTimeout(waitThenRenderSynapse, 10)
|
setTimeout(waitThenRenderSynapse, 10)
|
||||||
}
|
}
|
||||||
|
@ -132,7 +137,7 @@ const Cable = {
|
||||||
|
|
||||||
function waitThenRenderTopic() {
|
function waitThenRenderTopic() {
|
||||||
if (topic && mapping && mapper) {
|
if (topic && mapping && mapper) {
|
||||||
Topic.renderTopic(mapping, topic, false, false)
|
Topic.renderTopic(mapping, topic, false)
|
||||||
} else if (!cancel) {
|
} else if (!cancel) {
|
||||||
setTimeout(waitThenRenderTopic, 10)
|
setTimeout(waitThenRenderTopic, 10)
|
||||||
}
|
}
|
||||||
|
@ -183,7 +188,7 @@ const Cable = {
|
||||||
},
|
},
|
||||||
topicMoved: event => {
|
topicMoved: event => {
|
||||||
var topic, node, mapping
|
var topic, node, mapping
|
||||||
if (Active.Map) {
|
/*if (Active.Map) {
|
||||||
topic = DataModel.Topics.get(event.id)
|
topic = DataModel.Topics.get(event.id)
|
||||||
mapping = DataModel.Mappings.get(event.mapping_id)
|
mapping = DataModel.Mappings.get(event.mapping_id)
|
||||||
mapping.set('xloc', event.x)
|
mapping.set('xloc', event.x)
|
||||||
|
@ -191,7 +196,7 @@ const Cable = {
|
||||||
if (topic) node = topic.get('node')
|
if (topic) node = topic.get('node')
|
||||||
if (node) node.pos.setc(event.x, event.y)
|
if (node) node.pos.setc(event.x, event.y)
|
||||||
Visualize.mGraph.plot()
|
Visualize.mGraph.plot()
|
||||||
}
|
}*/
|
||||||
},
|
},
|
||||||
topicRemoved: event => {
|
topicRemoved: event => {
|
||||||
var topic = DataModel.Topics.get(event.id)
|
var topic = DataModel.Topics.get(event.id)
|
||||||
|
|
|
@ -48,28 +48,17 @@ const Synapse = {
|
||||||
|
|
||||||
var synapseSuccessCallback = function(synapseModel, response) {
|
var synapseSuccessCallback = function(synapseModel, response) {
|
||||||
if (Active.Map) {
|
if (Active.Map) {
|
||||||
mapping.save({ mappable_id: synapseModel.id }, {
|
mapping.save({ mappable_id: synapseModel.id })
|
||||||
error: function(model, response) {
|
|
||||||
console.log('error saving mapping to database')
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!Settings.sandbox && createNewInDB) {
|
if (createNewInDB) {
|
||||||
if (synapse.isNew()) {
|
if (synapse.isNew()) {
|
||||||
synapse.save(null, {
|
synapse.save(null, {
|
||||||
success: synapseSuccessCallback,
|
success: synapseSuccessCallback
|
||||||
error: function(model, response) {
|
|
||||||
console.log('error saving synapse to database')
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
} else if (!synapse.isNew() && Active.Map) {
|
} else if (!synapse.isNew() && Active.Map) {
|
||||||
mapping.save(null, {
|
mapping.save(null)
|
||||||
error: function(model, response) {
|
|
||||||
console.log('error saving mapping to database')
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -168,22 +168,22 @@ const Topic = {
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
// opts is additional options in a hash
|
renderTopic: function(mapping, topic, createNewInDB) {
|
||||||
// TODO: move createNewInDB and permitCreateSynapseAfter into opts
|
|
||||||
renderTopic: function(mapping, topic, createNewInDB, permitCreateSynapseAfter, opts = {}) {
|
|
||||||
var nodeOnViz
|
var nodeOnViz
|
||||||
var newnode = topic.createNode()
|
var newnode = topic.createNode()
|
||||||
const connectToId = Create.newSynapse.focusNode.getData('topic').id
|
const createSynapse = !!Create.newSynapse.focusNode && createNewInDB
|
||||||
|
const connectToId = createSynapse ? Create.newSynapse.focusNode.getData('topic').id : null
|
||||||
|
|
||||||
if (!$.isEmptyObject(Visualize.mGraph.graph.nodes)) {
|
if (!$.isEmptyObject(Visualize.mGraph.graph.nodes)) {
|
||||||
// this will also add the new node
|
// this will also add the new node
|
||||||
Visualize.mGraph.graph.addAdjacence(Create.newSynapse.focusNode, newnode)
|
if (createSynapse) Visualize.mGraph.graph.addAdjacence(Create.newSynapse.focusNode, newnode)
|
||||||
|
else Visualize.mGraph.graph.addNode(newnode)
|
||||||
nodeOnViz = Visualize.mGraph.graph.getNode(newnode.id)
|
nodeOnViz = Visualize.mGraph.graph.getNode(newnode.id)
|
||||||
Engine.addNode(nodeOnViz)
|
Engine.addNode(nodeOnViz)
|
||||||
Engine.addEdge(Visualize.mGraph.graph.getAdjacence(Create.newSynapse.focusNode.id, nodeOnViz.id))
|
if (createSynapse) Engine.addEdge(Visualize.mGraph.graph.getAdjacence(Create.newSynapse.focusNode.id, nodeOnViz.id))
|
||||||
topic.set('node', nodeOnViz, {silent: true})
|
topic.set('node', nodeOnViz, {silent: true})
|
||||||
topic.updateNode() // links the topic and the mapping to the node
|
topic.updateNode() // links the topic and the mapping to the node
|
||||||
Engine.setFocusNode(nodeOnViz)
|
if (createNewInDB) Engine.setFocusNode(nodeOnViz) // means this user created it
|
||||||
nodeOnViz.setData('dim', 1, 'start')
|
nodeOnViz.setData('dim', 1, 'start')
|
||||||
nodeOnViz.setData('dim', 25, 'end')
|
nodeOnViz.setData('dim', 25, 'end')
|
||||||
nodeOnViz.setPos(new $jit.Complex(mapping.get('xloc'), mapping.get('yloc')), 'current')
|
nodeOnViz.setPos(new $jit.Complex(mapping.get('xloc'), mapping.get('yloc')), 'current')
|
||||||
|
@ -213,38 +213,20 @@ const Topic = {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
var mappingSuccessCallback = function(mappingModel, response, topicModel) {
|
|
||||||
// call a success callback if provided
|
|
||||||
if (opts.success) {
|
|
||||||
opts.success(topicModel)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
var topicSuccessCallback = function(topicModel, response) {
|
var topicSuccessCallback = function(topicModel, response) {
|
||||||
if (Active.Map) {
|
if (Active.Map) {
|
||||||
mapping.save({ mappable_id: topicModel.id }, {
|
mapping.save({ mappable_id: topicModel.id })
|
||||||
success: function(model, response) {
|
|
||||||
mappingSuccessCallback(model, response, topicModel)
|
|
||||||
},
|
|
||||||
error: function(model, response) {
|
|
||||||
console.log('error saving mapping to database')
|
|
||||||
}
|
}
|
||||||
})
|
createSynapse && Synapse.createSynapseLocally(true, connectToId, topicModel.id)
|
||||||
}
|
|
||||||
Synapse.createSynapseLocally(true, connectToId, topicModel.id)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!Settings.sandbox && createNewInDB) {
|
if (createNewInDB) {
|
||||||
if (topic.isNew()) {
|
if (topic.isNew()) {
|
||||||
topic.save(null, {
|
topic.save(null, {
|
||||||
success: topicSuccessCallback,
|
success: topicSuccessCallback
|
||||||
error: function(model, response) {
|
|
||||||
console.log('error saving topic to database')
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
} else if (!topic.isNew() && Active.Map) {
|
} else if (!topic.isNew() && Active.Map) {
|
||||||
mapping.save(null, {
|
mapping.save(null)
|
||||||
success: mappingSuccessCallback
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -278,24 +260,21 @@ const Topic = {
|
||||||
// these can't happen until the value is retrieved, which happens in the line above
|
// these can't happen until the value is retrieved, which happens in the line above
|
||||||
Create.newTopic.reset()
|
Create.newTopic.reset()
|
||||||
|
|
||||||
self.renderTopic(mapping, topic, true, true) // this function also includes the creation of the topic in the database
|
self.renderTopic(mapping, topic, true) // this function also includes the creation of the topic in the database
|
||||||
},
|
},
|
||||||
getTopicFromAutocomplete: function(id) {
|
getTopicFromAutocomplete: function(id) {
|
||||||
var self = Topic
|
var self = Topic
|
||||||
$(document).trigger(Map.events.editedByActiveMapper)
|
$(document).trigger(Map.events.editedByActiveMapper)
|
||||||
Create.newTopic.reset()
|
Create.newTopic.reset()
|
||||||
self.get(id, (topic) => {
|
self.get(id, (topic) => {
|
||||||
if (Create.newTopic.pinned) {
|
|
||||||
var nextCoords = AutoLayout.getNextCoord({ mappings: DataModel.Mappings })
|
|
||||||
}
|
|
||||||
var mapping = new DataModel.Mapping({
|
var mapping = new DataModel.Mapping({
|
||||||
xloc: nextCoords ? nextCoords.x : Create.newTopic.x,
|
xloc: Mouse.newNodeCoords.x,
|
||||||
yloc: nextCoords ? nextCoords.y : Create.newTopic.y,
|
yloc: Mouse.newNodeCoords.y,
|
||||||
mappable_type: 'Topic',
|
mappable_type: 'Topic',
|
||||||
mappable_id: topic.id
|
mappable_id: topic.id
|
||||||
})
|
})
|
||||||
DataModel.Mappings.add(mapping)
|
DataModel.Mappings.add(mapping)
|
||||||
self.renderTopic(mapping, topic, true, true)
|
self.renderTopic(mapping, topic, true)
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
getMapFromAutocomplete: function(data) {
|
getMapFromAutocomplete: function(data) {
|
||||||
|
@ -313,20 +292,17 @@ const Topic = {
|
||||||
DataModel.Topics.add(topic)
|
DataModel.Topics.add(topic)
|
||||||
|
|
||||||
var mapping = new DataModel.Mapping({
|
var mapping = new DataModel.Mapping({
|
||||||
xloc: Create.newTopic.x,
|
xloc: Mouse.newNodeCoords.x,
|
||||||
yloc: Create.newTopic.y,
|
yloc: Mouse.newNodeCoords.y,
|
||||||
mappable_id: topic.cid,
|
mappable_id: topic.cid,
|
||||||
mappable_type: 'Topic'
|
mappable_type: 'Topic'
|
||||||
})
|
})
|
||||||
DataModel.Mappings.add(mapping)
|
DataModel.Mappings.add(mapping)
|
||||||
|
|
||||||
// these can't happen until the value is retrieved, which happens in the line above
|
// these can't happen until the value is retrieved, which happens in the line above
|
||||||
if (!Create.newTopic.pinned) Create.newTopic.hide()
|
|
||||||
Create.newTopic.reset()
|
Create.newTopic.reset()
|
||||||
|
|
||||||
self.renderTopic(mapping, topic, true, true) // this function also includes the creation of the topic in the database
|
self.renderTopic(mapping, topic, true) // this function also includes the creation of the topic in the database
|
||||||
// this blocked the enterKeyHandler from creating a new topic as well
|
|
||||||
if (Create.newTopic.pinned) Create.newTopic.beingCreated = true
|
|
||||||
},
|
},
|
||||||
getTopicFromSearch: function(event, id) {
|
getTopicFromSearch: function(event, id) {
|
||||||
var self = Topic
|
var self = Topic
|
||||||
|
@ -342,8 +318,8 @@ const Topic = {
|
||||||
mappable_id: topic.id
|
mappable_id: topic.id
|
||||||
})
|
})
|
||||||
DataModel.Mappings.add(mapping)
|
DataModel.Mappings.add(mapping)
|
||||||
self.renderTopic(mapping, topic, true, true)
|
self.renderTopic(mapping, topic, true)
|
||||||
GlobalUI.notifyUser('Topic was added to your map!')
|
GlobalUI.notifyUser('Topic was added to your map')
|
||||||
})
|
})
|
||||||
|
|
||||||
event.stopPropagation()
|
event.stopPropagation()
|
||||||
|
|
Loading…
Add table
Reference in a new issue