mirror of
https://github.com/pcottle/learnGitBranching.git
synced 2025-06-27 00:18:56 +02:00
import export tree done
This commit is contained in:
parent
aa9cfea3a4
commit
45aa088796
6 changed files with 262 additions and 34 deletions
176
build/bundle.js
176
build/bundle.js
|
@ -4506,8 +4506,9 @@ var Command = require('../models/commandModel').Command;
|
|||
var GitShim = require('../git/gitShim').GitShim;
|
||||
|
||||
var Views = require('../views');
|
||||
var ModalTerminal = require('../views').ModalTerminal;
|
||||
var ModalAlert = require('../views').ModalAlert;
|
||||
var ModalTerminal = Views.ModalTerminal;
|
||||
var ModalAlert = Views.ModalAlert;
|
||||
var BuilderViews = require('../views/builderViews');
|
||||
var MultiView = require('../views/multiView').MultiView;
|
||||
|
||||
var Sandbox = Backbone.View.extend({
|
||||
|
@ -4684,6 +4685,8 @@ var Sandbox = Backbone.View.extend({
|
|||
},
|
||||
|
||||
processSandboxCommand: function(command, deferred) {
|
||||
// I'm tempted to do camcel case conversion, but there are
|
||||
// some exceptions to the rule
|
||||
var commandMap = {
|
||||
'reset solved': this.resetSolved,
|
||||
'help general': this.helpDialog,
|
||||
|
@ -4696,7 +4699,9 @@ var Sandbox = Backbone.View.extend({
|
|||
'sandbox': this.exitLevel,
|
||||
'levels': this.showLevels,
|
||||
'iosAlert': this.iosAlert,
|
||||
'build level': this.buildLevel
|
||||
'build level': this.buildLevel,
|
||||
'export tree': this.exportTree,
|
||||
'import tree': this.importTree
|
||||
};
|
||||
|
||||
var method = commandMap[command.get('method')];
|
||||
|
@ -4717,6 +4722,59 @@ var Sandbox = Backbone.View.extend({
|
|||
this.mainVis.show();
|
||||
},
|
||||
|
||||
importTree: function(command, deferred) {
|
||||
var jsonGrabber = new BuilderViews.MarkdownPresenter({
|
||||
previewText: "Paste a tree JSON blob below!",
|
||||
fillerText: ' '
|
||||
});
|
||||
jsonGrabber.deferred.promise
|
||||
.then(_.bind(function(treeJSON) {
|
||||
try {
|
||||
this.mainVis.gitEngine.loadTree(JSON.parse(treeJSON));
|
||||
} catch(e) {
|
||||
this.mainVis.reset();
|
||||
new MultiView({
|
||||
childViews: [{
|
||||
type: 'ModalAlert',
|
||||
options: {
|
||||
markdowns: [
|
||||
'## Error!',
|
||||
'',
|
||||
'Something is wrong with that JSON! Here is the error:',
|
||||
'',
|
||||
String(e)
|
||||
]
|
||||
}
|
||||
}]
|
||||
});
|
||||
}
|
||||
}, this))
|
||||
.fail(function() { })
|
||||
.done(function() {
|
||||
command.finishWith(deferred);
|
||||
});
|
||||
},
|
||||
|
||||
exportTree: function(command, deferred) {
|
||||
var treeJSON = JSON.stringify(this.mainVis.gitEngine.exportTree(), null, 2);
|
||||
|
||||
var showJSON = new MultiView({
|
||||
childViews: [{
|
||||
type: 'MarkdownPresenter',
|
||||
options: {
|
||||
previewText: 'Share this tree with friends! They can load it with "import tree"',
|
||||
fillerText: treeJSON,
|
||||
noConfirmCancel: true
|
||||
}
|
||||
}]
|
||||
});
|
||||
showJSON.getPromise()
|
||||
.then(function() {
|
||||
command.finishWith(deferred);
|
||||
})
|
||||
.done();
|
||||
},
|
||||
|
||||
clear: function(command, deferred) {
|
||||
Main.getEvents().trigger('clearOldCommands');
|
||||
if (command && deferred) {
|
||||
|
@ -13159,7 +13217,9 @@ var regexMap = {
|
|||
'level': /^level\s?([a-zA-Z0-9]*)/,
|
||||
'levels': /^levels($|\s)/,
|
||||
'iosAlert': /^iOS alert($|\s)/,
|
||||
'build level': /^build level($|\s)/
|
||||
'build level': /^build level($|\s)/,
|
||||
'export tree': /^export tree$/,
|
||||
'import tree': /^import tree$/
|
||||
};
|
||||
|
||||
exports.instantCommands = instantCommands;
|
||||
|
@ -13654,6 +13714,9 @@ var LeftRightView = require('../views').LeftRightView;
|
|||
var ModalAlert = require('../views').ModalAlert;
|
||||
var GitDemonstrationView = require('../views/gitDemonstrationView').GitDemonstrationView;
|
||||
|
||||
var BuilderViews = require('../views/builderViews');
|
||||
var MarkdownPresenter = BuilderViews.MarkdownPresenter;
|
||||
|
||||
var KeyboardListener = require('../util/keyboard').KeyboardListener;
|
||||
var GitError = require('../util/errors').GitError;
|
||||
|
||||
|
@ -13667,7 +13730,8 @@ var MultiView = Backbone.View.extend({
|
|||
// a simple mapping of what childViews we support
|
||||
typeToConstructor: {
|
||||
ModalAlert: ModalAlert,
|
||||
GitDemonstrationView: GitDemonstrationView
|
||||
GitDemonstrationView: GitDemonstrationView,
|
||||
MarkdownPresenter: MarkdownPresenter
|
||||
},
|
||||
|
||||
initialize: function(options) {
|
||||
|
@ -14231,6 +14295,7 @@ var MarkdownPresenter = ContainedBase.extend({
|
|||
|
||||
initialize: function(options) {
|
||||
options = options || {};
|
||||
this.deferred = options.deferred || Q.defer();
|
||||
this.JSON = {
|
||||
previewText: options.previewText || 'Here is something for you',
|
||||
fillerText: options.fillerText || '# Yay'
|
||||
|
@ -14241,14 +14306,25 @@ var MarkdownPresenter = ContainedBase.extend({
|
|||
});
|
||||
this.render();
|
||||
|
||||
if (!options.noConfirmCancel) {
|
||||
var confirmCancel = new Views.ConfirmCancelView({
|
||||
destination: this.getDestination()
|
||||
});
|
||||
confirmCancel.deferred.promise
|
||||
.fail(function() { })
|
||||
.then(_.bind(function() {
|
||||
this.deferred.resolve(this.grabText());
|
||||
}, this))
|
||||
.fail(_.bind(function() {
|
||||
this.deferred.reject();
|
||||
}, this))
|
||||
.done(_.bind(this.die, this));
|
||||
}
|
||||
|
||||
this.show();
|
||||
},
|
||||
|
||||
grabText: function() {
|
||||
return this.$('textarea').val();
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -21851,8 +21927,9 @@ var Command = require('../models/commandModel').Command;
|
|||
var GitShim = require('../git/gitShim').GitShim;
|
||||
|
||||
var Views = require('../views');
|
||||
var ModalTerminal = require('../views').ModalTerminal;
|
||||
var ModalAlert = require('../views').ModalAlert;
|
||||
var ModalTerminal = Views.ModalTerminal;
|
||||
var ModalAlert = Views.ModalAlert;
|
||||
var BuilderViews = require('../views/builderViews');
|
||||
var MultiView = require('../views/multiView').MultiView;
|
||||
|
||||
var Sandbox = Backbone.View.extend({
|
||||
|
@ -22029,6 +22106,8 @@ var Sandbox = Backbone.View.extend({
|
|||
},
|
||||
|
||||
processSandboxCommand: function(command, deferred) {
|
||||
// I'm tempted to do camcel case conversion, but there are
|
||||
// some exceptions to the rule
|
||||
var commandMap = {
|
||||
'reset solved': this.resetSolved,
|
||||
'help general': this.helpDialog,
|
||||
|
@ -22041,7 +22120,9 @@ var Sandbox = Backbone.View.extend({
|
|||
'sandbox': this.exitLevel,
|
||||
'levels': this.showLevels,
|
||||
'iosAlert': this.iosAlert,
|
||||
'build level': this.buildLevel
|
||||
'build level': this.buildLevel,
|
||||
'export tree': this.exportTree,
|
||||
'import tree': this.importTree
|
||||
};
|
||||
|
||||
var method = commandMap[command.get('method')];
|
||||
|
@ -22062,6 +22143,59 @@ var Sandbox = Backbone.View.extend({
|
|||
this.mainVis.show();
|
||||
},
|
||||
|
||||
importTree: function(command, deferred) {
|
||||
var jsonGrabber = new BuilderViews.MarkdownPresenter({
|
||||
previewText: "Paste a tree JSON blob below!",
|
||||
fillerText: ' '
|
||||
});
|
||||
jsonGrabber.deferred.promise
|
||||
.then(_.bind(function(treeJSON) {
|
||||
try {
|
||||
this.mainVis.gitEngine.loadTree(JSON.parse(treeJSON));
|
||||
} catch(e) {
|
||||
this.mainVis.reset();
|
||||
new MultiView({
|
||||
childViews: [{
|
||||
type: 'ModalAlert',
|
||||
options: {
|
||||
markdowns: [
|
||||
'## Error!',
|
||||
'',
|
||||
'Something is wrong with that JSON! Here is the error:',
|
||||
'',
|
||||
String(e)
|
||||
]
|
||||
}
|
||||
}]
|
||||
});
|
||||
}
|
||||
}, this))
|
||||
.fail(function() { })
|
||||
.done(function() {
|
||||
command.finishWith(deferred);
|
||||
});
|
||||
},
|
||||
|
||||
exportTree: function(command, deferred) {
|
||||
var treeJSON = JSON.stringify(this.mainVis.gitEngine.exportTree(), null, 2);
|
||||
|
||||
var showJSON = new MultiView({
|
||||
childViews: [{
|
||||
type: 'MarkdownPresenter',
|
||||
options: {
|
||||
previewText: 'Share this tree with friends! They can load it with "import tree"',
|
||||
fillerText: treeJSON,
|
||||
noConfirmCancel: true
|
||||
}
|
||||
}]
|
||||
});
|
||||
showJSON.getPromise()
|
||||
.then(function() {
|
||||
command.finishWith(deferred);
|
||||
})
|
||||
.done();
|
||||
},
|
||||
|
||||
clear: function(command, deferred) {
|
||||
Main.getEvents().trigger('clearOldCommands');
|
||||
if (command && deferred) {
|
||||
|
@ -22164,7 +22298,9 @@ var regexMap = {
|
|||
'level': /^level\s?([a-zA-Z0-9]*)/,
|
||||
'levels': /^levels($|\s)/,
|
||||
'iosAlert': /^iOS alert($|\s)/,
|
||||
'build level': /^build level($|\s)/
|
||||
'build level': /^build level($|\s)/,
|
||||
'export tree': /^export tree$/,
|
||||
'import tree': /^import tree$/
|
||||
};
|
||||
|
||||
exports.instantCommands = instantCommands;
|
||||
|
@ -23114,6 +23250,7 @@ var MarkdownPresenter = ContainedBase.extend({
|
|||
|
||||
initialize: function(options) {
|
||||
options = options || {};
|
||||
this.deferred = options.deferred || Q.defer();
|
||||
this.JSON = {
|
||||
previewText: options.previewText || 'Here is something for you',
|
||||
fillerText: options.fillerText || '# Yay'
|
||||
|
@ -23124,14 +23261,25 @@ var MarkdownPresenter = ContainedBase.extend({
|
|||
});
|
||||
this.render();
|
||||
|
||||
if (!options.noConfirmCancel) {
|
||||
var confirmCancel = new Views.ConfirmCancelView({
|
||||
destination: this.getDestination()
|
||||
});
|
||||
confirmCancel.deferred.promise
|
||||
.fail(function() { })
|
||||
.then(_.bind(function() {
|
||||
this.deferred.resolve(this.grabText());
|
||||
}, this))
|
||||
.fail(_.bind(function() {
|
||||
this.deferred.reject();
|
||||
}, this))
|
||||
.done(_.bind(this.die, this));
|
||||
}
|
||||
|
||||
this.show();
|
||||
},
|
||||
|
||||
grabText: function() {
|
||||
return this.$('textarea').val();
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -24986,6 +25134,9 @@ var LeftRightView = require('../views').LeftRightView;
|
|||
var ModalAlert = require('../views').ModalAlert;
|
||||
var GitDemonstrationView = require('../views/gitDemonstrationView').GitDemonstrationView;
|
||||
|
||||
var BuilderViews = require('../views/builderViews');
|
||||
var MarkdownPresenter = BuilderViews.MarkdownPresenter;
|
||||
|
||||
var KeyboardListener = require('../util/keyboard').KeyboardListener;
|
||||
var GitError = require('../util/errors').GitError;
|
||||
|
||||
|
@ -24999,7 +25150,8 @@ var MultiView = Backbone.View.extend({
|
|||
// a simple mapping of what childViews we support
|
||||
typeToConstructor: {
|
||||
ModalAlert: ModalAlert,
|
||||
GitDemonstrationView: GitDemonstrationView
|
||||
GitDemonstrationView: GitDemonstrationView,
|
||||
MarkdownPresenter: MarkdownPresenter
|
||||
},
|
||||
|
||||
initialize: function(options) {
|
||||
|
|
|
@ -13,8 +13,9 @@ var Command = require('../models/commandModel').Command;
|
|||
var GitShim = require('../git/gitShim').GitShim;
|
||||
|
||||
var Views = require('../views');
|
||||
var ModalTerminal = require('../views').ModalTerminal;
|
||||
var ModalAlert = require('../views').ModalAlert;
|
||||
var ModalTerminal = Views.ModalTerminal;
|
||||
var ModalAlert = Views.ModalAlert;
|
||||
var BuilderViews = require('../views/builderViews');
|
||||
var MultiView = require('../views/multiView').MultiView;
|
||||
|
||||
var Sandbox = Backbone.View.extend({
|
||||
|
@ -191,6 +192,8 @@ var Sandbox = Backbone.View.extend({
|
|||
},
|
||||
|
||||
processSandboxCommand: function(command, deferred) {
|
||||
// I'm tempted to do camcel case conversion, but there are
|
||||
// some exceptions to the rule
|
||||
var commandMap = {
|
||||
'reset solved': this.resetSolved,
|
||||
'help general': this.helpDialog,
|
||||
|
@ -203,7 +206,9 @@ var Sandbox = Backbone.View.extend({
|
|||
'sandbox': this.exitLevel,
|
||||
'levels': this.showLevels,
|
||||
'iosAlert': this.iosAlert,
|
||||
'build level': this.buildLevel
|
||||
'build level': this.buildLevel,
|
||||
'export tree': this.exportTree,
|
||||
'import tree': this.importTree
|
||||
};
|
||||
|
||||
var method = commandMap[command.get('method')];
|
||||
|
@ -224,6 +229,59 @@ var Sandbox = Backbone.View.extend({
|
|||
this.mainVis.show();
|
||||
},
|
||||
|
||||
importTree: function(command, deferred) {
|
||||
var jsonGrabber = new BuilderViews.MarkdownPresenter({
|
||||
previewText: "Paste a tree JSON blob below!",
|
||||
fillerText: ' '
|
||||
});
|
||||
jsonGrabber.deferred.promise
|
||||
.then(_.bind(function(treeJSON) {
|
||||
try {
|
||||
this.mainVis.gitEngine.loadTree(JSON.parse(treeJSON));
|
||||
} catch(e) {
|
||||
this.mainVis.reset();
|
||||
new MultiView({
|
||||
childViews: [{
|
||||
type: 'ModalAlert',
|
||||
options: {
|
||||
markdowns: [
|
||||
'## Error!',
|
||||
'',
|
||||
'Something is wrong with that JSON! Here is the error:',
|
||||
'',
|
||||
String(e)
|
||||
]
|
||||
}
|
||||
}]
|
||||
});
|
||||
}
|
||||
}, this))
|
||||
.fail(function() { })
|
||||
.done(function() {
|
||||
command.finishWith(deferred);
|
||||
});
|
||||
},
|
||||
|
||||
exportTree: function(command, deferred) {
|
||||
var treeJSON = JSON.stringify(this.mainVis.gitEngine.exportTree(), null, 2);
|
||||
|
||||
var showJSON = new MultiView({
|
||||
childViews: [{
|
||||
type: 'MarkdownPresenter',
|
||||
options: {
|
||||
previewText: 'Share this tree with friends! They can load it with "import tree"',
|
||||
fillerText: treeJSON,
|
||||
noConfirmCancel: true
|
||||
}
|
||||
}]
|
||||
});
|
||||
showJSON.getPromise()
|
||||
.then(function() {
|
||||
command.finishWith(deferred);
|
||||
})
|
||||
.done();
|
||||
},
|
||||
|
||||
clear: function(command, deferred) {
|
||||
Main.getEvents().trigger('clearOldCommands');
|
||||
if (command && deferred) {
|
||||
|
|
|
@ -54,7 +54,9 @@ var regexMap = {
|
|||
'level': /^level\s?([a-zA-Z0-9]*)/,
|
||||
'levels': /^levels($|\s)/,
|
||||
'iosAlert': /^iOS alert($|\s)/,
|
||||
'build level': /^build level($|\s)/
|
||||
'build level': /^build level($|\s)/,
|
||||
'export tree': /^export tree$/,
|
||||
'import tree': /^import tree$/
|
||||
};
|
||||
|
||||
exports.instantCommands = instantCommands;
|
||||
|
|
|
@ -140,6 +140,7 @@ var MarkdownPresenter = ContainedBase.extend({
|
|||
|
||||
initialize: function(options) {
|
||||
options = options || {};
|
||||
this.deferred = options.deferred || Q.defer();
|
||||
this.JSON = {
|
||||
previewText: options.previewText || 'Here is something for you',
|
||||
fillerText: options.fillerText || '# Yay'
|
||||
|
@ -150,14 +151,25 @@ var MarkdownPresenter = ContainedBase.extend({
|
|||
});
|
||||
this.render();
|
||||
|
||||
if (!options.noConfirmCancel) {
|
||||
var confirmCancel = new Views.ConfirmCancelView({
|
||||
destination: this.getDestination()
|
||||
});
|
||||
confirmCancel.deferred.promise
|
||||
.fail(function() { })
|
||||
.then(_.bind(function() {
|
||||
this.deferred.resolve(this.grabText());
|
||||
}, this))
|
||||
.fail(_.bind(function() {
|
||||
this.deferred.reject();
|
||||
}, this))
|
||||
.done(_.bind(this.die, this));
|
||||
}
|
||||
|
||||
this.show();
|
||||
},
|
||||
|
||||
grabText: function() {
|
||||
return this.$('textarea').val();
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -10,6 +10,9 @@ var LeftRightView = require('../views').LeftRightView;
|
|||
var ModalAlert = require('../views').ModalAlert;
|
||||
var GitDemonstrationView = require('../views/gitDemonstrationView').GitDemonstrationView;
|
||||
|
||||
var BuilderViews = require('../views/builderViews');
|
||||
var MarkdownPresenter = BuilderViews.MarkdownPresenter;
|
||||
|
||||
var KeyboardListener = require('../util/keyboard').KeyboardListener;
|
||||
var GitError = require('../util/errors').GitError;
|
||||
|
||||
|
@ -23,7 +26,8 @@ var MultiView = Backbone.View.extend({
|
|||
// a simple mapping of what childViews we support
|
||||
typeToConstructor: {
|
||||
ModalAlert: ModalAlert,
|
||||
GitDemonstrationView: GitDemonstrationView
|
||||
GitDemonstrationView: GitDemonstrationView,
|
||||
MarkdownPresenter: MarkdownPresenter
|
||||
},
|
||||
|
||||
initialize: function(options) {
|
||||
|
|
2
todo.txt
2
todo.txt
|
@ -1,7 +1,6 @@
|
|||
Big Things
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
[ ] import random level JSON
|
||||
[ ] export / import tree from JSON
|
||||
[ ] compare settings for a level!!! integrated into builder...
|
||||
|
||||
Medium things:
|
||||
|
@ -28,6 +27,7 @@ Ideas for cleaning
|
|||
Done things:
|
||||
(I only started this on Dec 17th 2012 to get a better sense of what was done)
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
[x] export / import tree from JSON
|
||||
[x] rebase bug... ugh
|
||||
[x] bug with weird tree string:
|
||||
[x] optimistic parsing of level and level builder commands, man that was toughwith circular imports
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue