Keep fixing issues.

This commit is contained in:
Paulo Veiga 2011-09-09 02:22:44 -03:00
parent 0c216778e5
commit 2a4d96151b
15 changed files with 157 additions and 98 deletions

View File

@ -39,7 +39,7 @@ mindplot.ActionDispatcher = new Class({
throw "method must be implemented."; throw "method must be implemented.";
}, },
addTopic: function(model, parentTopicId, animated) { addTopic: function(nodeModel, parentTopicId, animated) {
throw "method must be implemented."; throw "method must be implemented.";
}, },

View File

@ -39,15 +39,16 @@ mindplot.BrixActionDispatcher = new Class({
return mindplot.collaboration.CollaborationManager.getInstance().getCollaborativeFramework(); return mindplot.collaboration.CollaborationManager.getInstance().getCollaborativeFramework();
}, },
addTopic : function(model, parentTopicId, animated) { addTopic : function(nodeModel, parentTopicId, animated) {
var framework = this._getFramework(); var framework = this._getFramework();
var mindmap = framework.getModel(); var cmapindmap = framework.getModel();
var centralTopic = mindmap.getCentralTopic(); var centralTopic = cmapindmap.getCentralTopic();
var newNode = mindmap.createNode(model.getType(), model.getId()); var cnode = cmapindmap.createNode(nodeModel.getType(), nodeModel.getId());
var position = model.getPosition(); var position = nodeModel.getPosition();
newNode.setPosition(position.x, position.y); cnode.setPosition(position.x, position.y);
newNode.connectTo(centralTopic);
cnode.connectTo(centralTopic);
}, },
changeFontSizeToTopic : function(topicsIds, size) { changeFontSizeToTopic : function(topicsIds, size) {

View File

@ -38,8 +38,8 @@ mindplot.LocalActionDispatcher = new Class({
this.execute(command); this.execute(command);
}, },
addTopic:function(model, parentTopicId, animated) { addTopic:function(nodeModel, parentTopicId, animated) {
var command = new mindplot.commands.AddTopicCommand(model, parentTopicId, animated); var command = new mindplot.commands.AddTopicCommand(nodeModel, parentTopicId, animated);
this.execute(command); this.execute(command);
}, },

View File

@ -25,8 +25,8 @@ mindplot.MindmapDesigner = new Class({
// Dispatcher manager ... // Dispatcher manager ...
var commandContext = new mindplot.CommandContext(this); var commandContext = new mindplot.CommandContext(this);
// this._actionDispatcher = new mindplot.BrixActionDispatcher(commandContext); this._actionDispatcher = new mindplot.BrixActionDispatcher(commandContext);
this._actionDispatcher = new mindplot.LocalActionDispatcher(commandContext); // this._actionDispatcher = new mindplot.LocalActionDispatcher(commandContext);
this._actionDispatcher.addEvent("modelUpdate", function(event) { this._actionDispatcher.addEvent("modelUpdate", function(event) {
this.fireEvent("modelUpdate", event); this.fireEvent("modelUpdate", event);
}.bind(this)); }.bind(this));

View File

@ -22,21 +22,12 @@ mindplot.collaboration.CollaborationManager = new Class({
this.collaborativeModelReady = null; this.collaborativeModelReady = null;
}, },
isCollaborationFrameworkAvailable : function() {
return (typeof goog != "undefined") && (typeof goog.collab != "undefined");
},
setCollaborativeFramework : function(framework) { setCollaborativeFramework : function(framework) {
this._collaborativeFramework = framework; this._collaborativeFramework = framework;
this.collaborativeModelReady = true;
}, },
isCollaborativeFrameworkReady:function() { buildMindmap: function() {
return this.collaborativeModelReady; return this._collaborativeFramework.buildMindmap();
},
buildWiseModel: function() {
return this._collaborativeFramework.buildWiseModel();
}, },
getCollaborativeFramework:function() { getCollaborativeFramework:function() {

View File

@ -1,5 +1,6 @@
mindplot.collaboration.framework.AbstractCollaborativeFramework = new Class({ mindplot.collaboration.framework.AbstractCollaborativeFramework = new Class({
initialize: function(model, collaborativeModelFactory) { initialize: function(model, collaborativeModelFactory)
{
this._collaborativeModelFactory = collaborativeModelFactory; this._collaborativeModelFactory = collaborativeModelFactory;
if (!$defined(model)) { if (!$defined(model)) {
model = this._buildInitialCollaborativeModel(); model = this._buildInitialCollaborativeModel();
@ -12,38 +13,26 @@ mindplot.collaboration.framework.AbstractCollaborativeFramework = new Class({
return this._model; return this._model;
}, },
buildWiseModel : function() { buildMindmap : function() {
var cmindMap = this.getModel();
var mindmap = new mindplot.model.Mindmap(); var cmind = this.getModel();
var branches = cmindMap.getBranches(); var mmind = new mindplot.model.Mindmap();
branches.forEach(function(branch) { cmind.copyTo(mmind);
var type = branch.getType();
var id = branch.getId(); return mmind;
var node = mindmap.createNode(type, id);
node.setText(branch.getText());
var position = branch.getPosition();
node.setPosition(position.x, position.y);
var children = branch.getChildren();
children.forEach(function(child) {
var node2 = new mindplot.model.NodeModel(child.getType(), mindmap, child.getId());
node2.setText(child.getText());
var pos = child.getPosition();
node2.setPosition(pos.x, pos.y);
node._appendChild(node2);
});
mindmap.addBranch(node);
}.bind(this));
return mindmap;
}, },
_buildInitialCollaborativeModel: function() { _buildInitialCollaborativeModel: function() {
var mindmap = this._collaborativeModelFactory.buildMindMap(); var mindmap = this._collaborativeModelFactory.buildMindMap();
var centralTopic = mindmap.createNode(mindplot.model.INodeModel.CENTRAL_TOPIC_TYPE); var centralTopic = mindmap.createNode(mindplot.model.INodeModel.CENTRAL_TOPIC_TYPE);
mindmap.addBranch(centralTopic, true); mindmap.addBranch(centralTopic, true);
this.addMindmap(mindmap); this.addMindmap(mindmap);
return mindmap; return mindmap;
}, },
addMindmap:function(model) { addMindmap:function(model) {
throw "method to implement";
}, },
_findTopic : function(topics, id) { _findTopic : function(topics, id) {

View File

@ -21,10 +21,15 @@ mindplot.collaboration.framework.brix.BrixCollaborativeModelFactory = new Class(
initialize:function(brixFramework) { initialize:function(brixFramework) {
this._brixFramework = brixFramework; this._brixFramework = brixFramework;
}, },
buildMindMap:function() { buildMindMap:function() {
return new mindplot.collaboration.framework.brix.model.Mindmap(null, this._brixFramework); var mindmap = new mindplot.collaboration.framework.brix.model.Mindmap(this._brixFramework);
var node = mindmap.createNode(mindplot.model.INodeModel.CENTRAL_TOPIC_TYPE, 0);
mindmap.addBranch(node);
return mindmap;
}, },
buildCollaborativeModelFor:function(model) { buildCollaborativeModelFor:function(model) {
return new mindplot.collaboration.framework.brix.model.Mindmap(model, this._brixFramework); return new mindplot.collaboration.framework.brix.model.Mindmap(this._brixFramework, model);
} }
}); });

View File

@ -24,35 +24,38 @@ mindplot.collaboration.framework.brix.BrixFramework = new Class({
var cModel = null; var cModel = null;
var root = this.getBrixModel().getRoot(); var root = this.getBrixModel().getRoot();
if (!root.isEmpty()) { if (!root.isEmpty()) {
cModel = collaborativeModelFactory.buildCollaborativeModelFor(root.get("mindmap")); var brixMap = root.get("mindmap");
cModel = collaborativeModelFactory.buildCollaborativeModelFor(brixMap);
} }
this.parent(cModel, collaborativeModelFactory); this.parent(cModel, collaborativeModelFactory);
}, },
addMindmap:function(model) { addMindmap:function(model) {
var root = this.getBrixModel().getRoot(); var root = this.getBrixModel().getRoot();
root.put("mindmap", model); root.put("mindmap", model);
}, },
getBrixModel:function() { getBrixModel:function() {
return this._app.getModel(); return this._app.getModel();
},
buildWiseModel: function() {
return this.parent();
} }
}); });
instanciated = false; instanciated = false;
mindplot.collaboration.framework.brix.BrixFramework.init = function(onload) { mindplot.collaboration.framework.brix.BrixFramework.init = function(onload) {
$assert(onload, "load function can not be null"); $assert(onload, "load function can not be null");
if ((typeof isGoogleBrix != "undefined") && !instanciated) {
instanciated = true; if (!instanciated) {
var app = new goog.collab.CollaborativeApp(); var app = new goog.collab.CollaborativeApp();
mindplot.collaboration.framework.brix.BrixFramework.buildMenu(app); mindplot.collaboration.framework.brix.BrixFramework.buildMenu(app);
app.start(); app.start();
app.addListener('modelLoad', function(model) { app.addListener('modelLoad', function(model) {
var framework = new mindplot.collaboration.framework.brix.BrixFramework(model, app); var framework = new mindplot.collaboration.framework.brix.BrixFramework(model, app);
mindplot.collaboration.CollaborationManager.getInstance().setCollaborativeFramework(framework); mindplot.collaboration.CollaborationManager.getInstance().setCollaborativeFramework(framework);
onload(); onload();
}.bind(this)); }.bind(this));
instanciated = true;
} }
}; };

View File

@ -17,21 +17,33 @@
*/ */
mindplot.collaboration.framework.brix.model.Mindmap = new Class({ mindplot.collaboration.framework.brix.model.Mindmap = new Class({
Extends:mindplot.model.IMindmap, Extends:mindplot.model.IMindmap,
initialize:function(brixModel, brixFramework) { initialize:function(brixFramework, brixModel) {
this._brixModel = brixModel; $assert(brixFramework, 'brixFramework can not be null');
this._brixFramework = brixFramework; this._brixFramework = brixFramework;
if (!$defined(this._brixModel)) { if (!$defined(brixModel)) {
this._brixModel = this._createBrixModel(); this._brixModel = this._createBrixModel();
} else { } else {
var branches = this._brixModel.get("branches"); this._brixModel = brixModel;
for (var i = 0; i < branches.size(); i++) {
var node = branches.get(i);
var nodeModel = new mindplot.collaboration.framework.brix.model.NodeModel(node, this._brixFramework, null, this);
this.addBranch(nodeModel, false);
}
} }
}, },
getVersion: function() {
return this._brixModel.get('version');
},
setVersion: function(value) {
this._brixModel.put('version', value);
},
getDescription: function() {
return this._brixModel.get('description');
},
setDescription: function(value) {
this._brixModel.put('description', value);
},
_createBrixModel:function() { _createBrixModel:function() {
var model = this._brixFramework.getBrixModel().create("Map"); var model = this._brixFramework.getBrixModel().create("Map");
var branches = this._brixFramework.getBrixModel().create("List"); var branches = this._brixFramework.getBrixModel().create("List");
@ -47,11 +59,12 @@ mindplot.collaboration.framework.brix.model.Mindmap = new Class({
getBranches : function() { getBranches : function() {
var result = []; var result = [];
var branches = this._brixModel.get("branches"); var branches = this._brixModel.get("branches");
for (var i = 0; i < branches.size(); i++) { for (var i = 0; i < branches.size(); i++) {
result.push(); var node = branches.get(i);
var nodeModel = new mindplot.collaboration.framework.brix.model.NodeModel(this._brixFramework, node, this);
result.push(nodeModel);
} }
return result;
}, },
addBranch : function(nodeModel) { addBranch : function(nodeModel) {
@ -63,12 +76,11 @@ mindplot.collaboration.framework.brix.model.Mindmap = new Class({
removeBranch : function(nodeModel) { removeBranch : function(nodeModel) {
$assert(nodeModel, "nodeModel can not be null"); $assert(nodeModel, "nodeModel can not be null");
var branches = this._brixModel.get("branches"); var branches = this._brixModel.get("branches");
branches.remove(nodeModel.getBrixModel()); var brixModel = nodeModel.getBrixModel();
branches.remove(brixModel);
}, },
connect : function(parent, child) { connect : function(parent, child) {
this.parent(parent, child);
// Remove from the branch ... // Remove from the branch ...
var branches = this._brixModel.get("branches"); var branches = this._brixModel.get("branches");
var childIndex = null; var childIndex = null;
@ -84,7 +96,8 @@ mindplot.collaboration.framework.brix.model.Mindmap = new Class({
}, },
createNode : function(type, id) { createNode : function(type, id) {
return mindplot.collaboration.framework.brix.model.NodeModel.create(this._brixFramework, type, id, this); return mindplot.collaboration.framework.brix.model.NodeModel.create(this._brixFramework, this, type, id);
} }
} }
); );

View File

@ -18,14 +18,13 @@
mindplot.collaboration.framework.brix.model.NodeModel = new Class({ mindplot.collaboration.framework.brix.model.NodeModel = new Class({
Extends: mindplot.model.INodeModel, Extends: mindplot.model.INodeModel,
initialize : function(brixModel, brixFramework, mindmap) { initialize : function(brixFramework, brixModel, mindmap) {
$assert(brixModel, "brixModel can not null");
$assert(brixFramework, "brixFramework can not null"); $assert(brixFramework, "brixFramework can not null");
$assert(brixModel, "brixModel can not null");
this.parent(mindmap); this.parent(mindmap);
this._brixModel = brixModel; this._brixModel = brixModel;
this._brixFramework = brixFramework; this._brixFramework = brixFramework;
this._injectSetAndGet();
this._addBrixListeners(); this._addBrixListeners();
}, },
@ -44,12 +43,24 @@ mindplot.collaboration.framework.brix.model.NodeModel = new Class({
actionDispatcher[funName](this.getId(), value); actionDispatcher[funName](this.getId(), value);
}.bind(this)); }.bind(this));
this._brixModel.get("children").addListener("valuesAdded", this._childAddedListener.bind(this)); var children = this._brixModel.get("children");
children.addListener("valuesAdded", this._childAddedListener.bind(this));
},
getChildren : function() {
var result = [];
var children = this._brixModel.get("children");
for (var i = 0; i < children.size(); i++) {
var node = children.get(i);
var nodeModel = new mindplot.collaboration.framework.brix.model.NodeModel(this._brixFramework, node, this);
result.push(nodeModel);
}
return result;
}, },
_childAddedListener:function(event) { _childAddedListener:function(event) {
var newValue = event.getValues().get(0); var newValue = event.getValues().get(0);
var cmodel = new mindplot.collaboration.framework.brix.model.NodeModel(newValue, this._brixFramework, null, this.getMindmap()); var cmodel = new mindplot.collaboration.framework.brix.model.NodeModel(this._brixFramework, newValue, this.getMindmap());
this._appendChild(cmodel, false); this._appendChild(cmodel, false);
var model = new mindplot.model.NodeModel(newValue.get("type"), designer.getMindmap(), newValue.get("id")); var model = new mindplot.model.NodeModel(newValue.get("type"), designer.getMindmap(), newValue.get("id"));
@ -62,13 +73,41 @@ mindplot.collaboration.framework.brix.model.NodeModel = new Class({
getBrixModel:function() { getBrixModel:function() {
return this._brixModel; return this._brixModel;
},
putProperty : function(key, value) {
$defined(key, 'key can not be null');
this._brixModel.put(key, value);
},
getProperty : function(key) {
$defined(key, 'key can not be null');
return this._brixModel.get(key);
},
getPropertiesKeys : function() {
return this._brixModel.getKeys();
},
connectTo : function(parent) {
var mindmap = this.getMindmap();
mindmap.connect(parent, this);
// @Todo: This must be persited ?Ummm...
this._parent = parent;
} }
}); });
mindplot.collaboration.framework.brix.model.NodeModel.create = function(brixFramework, type, id, mindmap) { mindplot.collaboration.framework.brix.model.NodeModel.create = function(brixFramework, mindmap, type, id) {
$assert(brixFramework, 'brixFramework can not be null');
$assert(mindmap, 'mindmap can not be null');
$assert(type, 'type can not be null');
$assert($defined(id), 'id can not be null');
var brixModel = brixFramework.getBrixModel().create("Map"); var brixModel = brixFramework.getBrixModel().create("Map");
brixModel.put("type", type); brixModel.put("type", type);
brixModel.put("id", this._id); // @todo... brixModel.put("id", this._id);
var children = brixFramework.getBrixModel().create("List"); var children = brixFramework.getBrixModel().create("List");
brixModel.put("children", children); brixModel.put("children", children);

View File

@ -110,17 +110,15 @@ mindplot.model.IMindmap = new Class({
result = '{ '; result = '{ ';
var branches = this.getBranches(); var branches = this.getBranches();
result = result + "version:" + this.getVersion();
for (var i = 0; i < branches.length; i++) { for (var i = 0; i < branches.length; i++) {
var node = branches[i]; var node = branches[i];
if (i != 0) { if (i != 0) {
result = result + ', '; result = result + ', ';
} }
result = result + this._toString(node); result = result + this._toString(node);
} }
result = result + ' } '; result = result + ' } ';
return result; return result;
}, },
@ -147,18 +145,20 @@ mindplot.model.IMindmap = new Class({
return result; return result;
}, },
copyTo : function(mindmap) { copyTo : function(target) {
var version = this.getVersion(); var source = this;
mindmap.setVersion(version); var version = source.getVersion();
target.setVersion(version);
var desc = this.getDescription(); var desc = this.getDescription();
mindmap.setDescription(desc); target.setDescription(desc);
var sbranchs = this.getBranches(); // Then the rest of the branches ...
var sbranchs = source.getBranches();
sbranchs.forEach(function(snode) { sbranchs.forEach(function(snode) {
var tnode = mindmap.createNode(snode.getType(), snode.getId()); var tnode = target.createNode(snode.getType(), snode.getId());
snode.copyTo(tnode); snode.copyTo(tnode);
mindmap.addBranch(snode); target.addBranch(tnode);
}); });
} }
}); });

View File

@ -191,11 +191,11 @@ mindplot.model.INodeModel = new Class({
}, },
putProperty: function(key, value) { getPropertiesKeys : function() {
throw "Unsupported operation"; throw "Unsupported operation";
}, },
setProperty: function(key, value) { putProperty: function(key, value) {
throw "Unsupported operation"; throw "Unsupported operation";
}, },
@ -269,6 +269,16 @@ mindplot.model.INodeModel = new Class({
inspect : function() { inspect : function() {
return '(type:' + this.getType() + ' , id: ' + this.getId() + ')'; return '(type:' + this.getType() + ' , id: ' + this.getId() + ')';
},
copyTo : function(target) {
var source = this;
var keys = source.getPropertiesKeys();
keys.forEach(function(key) {
var value = source.getProperty(key);
target.putProperty(value);
});
return target;
} }
}); });

View File

@ -28,6 +28,10 @@ mindplot.model.Mindmap = new Class({
return this._description; return this._description;
}, },
setDescription : function(value) {
this._description = value;
},
getId : function() { getId : function() {
return this._iconType; return this._iconType;
}, },

View File

@ -40,6 +40,12 @@ mindplot.model.NodeModel = new Class({
this._properties[key] = value; this._properties[key] = value;
}, },
getProperties: function()
{
return this._properties;
},
getProperty : function(key) { getProperty : function(key) {
$defined(key, 'key can not be null'); $defined(key, 'key can not be null');
var result = this._properties[key]; var result = this._properties[key];

View File

@ -5,7 +5,7 @@
<!--[if lt IE 9]> <!--[if lt IE 9]>
<meta http-equiv="X-UA-Compatible" content="chrome=1"> <meta http-equiv="X-UA-Compatible" content="chrome=1">
<![endif]--> <![endif]-->
<!--<script type="text/javascript" src="http://docs.google.com/brix/static/api/js/jsapi.nocache.js"></script>--> <script type="text/javascript" src="http://docs.google.com/brix/static/api/js/jsapi.nocache.js"></script>
<!-- Internet Explorer 8 Hack --> <!-- Internet Explorer 8 Hack -->
<meta http-equiv="Content-type" content="text/html; charset=UTF-8"/> <meta http-equiv="Content-type" content="text/html; charset=UTF-8"/>
<title>WiseMapping - Editor </title> <title>WiseMapping - Editor </title>
@ -33,13 +33,12 @@
//Google-Brix framework load callback function //Google-Brix framework load callback function
collabOnLoad = function() { collabOnLoad = function() {
isGoogleBrix = true;
$(document).fireEvent('loadcomplete', 'brix'); $(document).fireEvent('loadcomplete', 'brix');
}; };
var brixReady = false; var brixReady = false;
var mindReady = false; var mindReady = false;
var local = true; var local = false;
$(document).addEvent('loadcomplete', function(resource) { $(document).addEvent('loadcomplete', function(resource) {
brixReady = resource == 'brix' ? true : brixReady; brixReady = resource == 'brix' ? true : brixReady;
mindReady = resource == 'mind' ? true : mindReady; mindReady = resource == 'mind' ? true : mindReady;
@ -53,10 +52,9 @@
mindplot.collaboration.framework.brix.BrixFramework.init(function() { mindplot.collaboration.framework.brix.BrixFramework.init(function() {
var manager = mindplot.collaboration.CollaborationManager.getInstance(); var manager = mindplot.collaboration.CollaborationManager.getInstance();
if (manager.isCollaborativeFrameworkReady()) { var mindmap = manager.buildMindmap();
var mindmap = manager.buildWiseModel();
designer.loadMap(mindmap); designer.loadMap(mindmap);
}
// If not problem has arisen, close the dialog ... // If not problem has arisen, close the dialog ...
if (!window.hasUnexpectedErrors) { if (!window.hasUnexpectedErrors) {
waitDialog.deactivate(); waitDialog.deactivate();