chat iss working

This commit is contained in:
Connor Turland 2017-01-12 04:55:57 -05:00
parent 4a17d00123
commit b13ac98c9f
3 changed files with 33 additions and 63 deletions

View file

@ -2,7 +2,9 @@
import Active from './Active'
import Control from './Control'
import Create from './Create'
import DataModel from './DataModel'
import Engine from './Engine'
import Map from './Map'
import Mapper from './Mapper'
import Synapse from './Synapse'
@ -51,6 +53,9 @@ const Cable = {
node2 = topic2.get('node')
Synapse.renderSynapse(mapping, synapse, node1, node2, false)
if (Create.newSynapse.focusNode === node1) {
Engine.setFocusNode(node2)
}
} else if (!cancel) {
setTimeout(waitThenRenderSynapse, 10)
}
@ -132,7 +137,7 @@ const Cable = {
function waitThenRenderTopic() {
if (topic && mapping && mapper) {
Topic.renderTopic(mapping, topic, false, false)
Topic.renderTopic(mapping, topic, false)
} else if (!cancel) {
setTimeout(waitThenRenderTopic, 10)
}
@ -183,7 +188,7 @@ const Cable = {
},
topicMoved: event => {
var topic, node, mapping
if (Active.Map) {
/*if (Active.Map) {
topic = DataModel.Topics.get(event.id)
mapping = DataModel.Mappings.get(event.mapping_id)
mapping.set('xloc', event.x)
@ -191,7 +196,7 @@ const Cable = {
if (topic) node = topic.get('node')
if (node) node.pos.setc(event.x, event.y)
Visualize.mGraph.plot()
}
}*/
},
topicRemoved: event => {
var topic = DataModel.Topics.get(event.id)

View file

@ -48,28 +48,17 @@ const Synapse = {
var synapseSuccessCallback = function(synapseModel, response) {
if (Active.Map) {
mapping.save({ mappable_id: synapseModel.id }, {
error: function(model, response) {
console.log('error saving mapping to database')
}
})
mapping.save({ mappable_id: synapseModel.id })
}
}
if (!Settings.sandbox && createNewInDB) {
if (createNewInDB) {
if (synapse.isNew()) {
synapse.save(null, {
success: synapseSuccessCallback,
error: function(model, response) {
console.log('error saving synapse to database')
}
success: synapseSuccessCallback
})
} else if (!synapse.isNew() && Active.Map) {
mapping.save(null, {
error: function(model, response) {
console.log('error saving mapping to database')
}
})
mapping.save(null)
}
}
},

View file

@ -168,22 +168,22 @@ const Topic = {
})
},
// opts is additional options in a hash
// TODO: move createNewInDB and permitCreateSynapseAfter into opts
renderTopic: function(mapping, topic, createNewInDB, permitCreateSynapseAfter, opts = {}) {
renderTopic: function(mapping, topic, createNewInDB) {
var nodeOnViz
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)) {
// 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)
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.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', 25, 'end')
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) {
if (Active.Map) {
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')
}
})
mapping.save({ mappable_id: topicModel.id })
}
Synapse.createSynapseLocally(true, connectToId, topicModel.id)
createSynapse && Synapse.createSynapseLocally(true, connectToId, topicModel.id)
}
if (!Settings.sandbox && createNewInDB) {
if (createNewInDB) {
if (topic.isNew()) {
topic.save(null, {
success: topicSuccessCallback,
error: function(model, response) {
console.log('error saving topic to database')
}
success: topicSuccessCallback
})
} else if (!topic.isNew() && Active.Map) {
mapping.save(null, {
success: mappingSuccessCallback
})
mapping.save(null)
}
}
},
@ -278,24 +260,21 @@ const Topic = {
// these can't happen until the value is retrieved, which happens in the line above
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) {
var self = Topic
$(document).trigger(Map.events.editedByActiveMapper)
Create.newTopic.reset()
self.get(id, (topic) => {
if (Create.newTopic.pinned) {
var nextCoords = AutoLayout.getNextCoord({ mappings: DataModel.Mappings })
}
var mapping = new DataModel.Mapping({
xloc: nextCoords ? nextCoords.x : Create.newTopic.x,
yloc: nextCoords ? nextCoords.y : Create.newTopic.y,
xloc: Mouse.newNodeCoords.x,
yloc: Mouse.newNodeCoords.y,
mappable_type: 'Topic',
mappable_id: topic.id
})
DataModel.Mappings.add(mapping)
self.renderTopic(mapping, topic, true, true)
self.renderTopic(mapping, topic, true)
})
},
getMapFromAutocomplete: function(data) {
@ -313,20 +292,17 @@ const Topic = {
DataModel.Topics.add(topic)
var mapping = new DataModel.Mapping({
xloc: Create.newTopic.x,
yloc: Create.newTopic.y,
xloc: Mouse.newNodeCoords.x,
yloc: Mouse.newNodeCoords.y,
mappable_id: topic.cid,
mappable_type: 'Topic'
})
DataModel.Mappings.add(mapping)
// 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()
self.renderTopic(mapping, topic, true, 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
self.renderTopic(mapping, topic, true) // this function also includes the creation of the topic in the database
},
getTopicFromSearch: function(event, id) {
var self = Topic
@ -342,8 +318,8 @@ const Topic = {
mappable_id: topic.id
})
DataModel.Mappings.add(mapping)
self.renderTopic(mapping, topic, true, true)
GlobalUI.notifyUser('Topic was added to your map!')
self.renderTopic(mapping, topic, true)
GlobalUI.notifyUser('Topic was added to your map')
})
event.stopPropagation()