mirror of
https://github.com/pcottle/learnGitBranching.git
synced 2025-06-26 16:08:34 +02:00
import export tree done
This commit is contained in:
parent
aa9cfea3a4
commit
45aa088796
6 changed files with 262 additions and 34 deletions
|
@ -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) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue