mirror of
https://github.com/pcottle/learnGitBranching.git
synced 2025-06-26 16:08:34 +02:00
Resolves #181 share levels easily with gist IDs and jsonp
This commit is contained in:
parent
d01f1806b4
commit
507291a0c4
3 changed files with 69 additions and 11 deletions
|
@ -202,6 +202,30 @@ var initDemo = function(sandbox) {
|
|||
tryLocaleDetect();
|
||||
}
|
||||
|
||||
if (params.gist_level_id) {
|
||||
$.ajax({
|
||||
url: 'https://api.github.com/gists/' + params.gist_level_id,
|
||||
type: 'GET',
|
||||
dataType: 'jsonp',
|
||||
success: function(response) {
|
||||
var data = response.data || {};
|
||||
var files = data.files || {};
|
||||
if (!Object.keys(files).length) {
|
||||
console.warn('no files found');
|
||||
return;
|
||||
}
|
||||
var file = files[Object.keys(files)[0]];
|
||||
if (!file.content) {
|
||||
console.warn('file empty');
|
||||
}
|
||||
eventBaton.trigger(
|
||||
'commandSubmitted',
|
||||
'importLevelNow ' + escape(file.content) + '; clear'
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (params.command) {
|
||||
var command = unescape(params.command);
|
||||
sandbox.mainVis.customEvents.on('gitEngineReady', function() {
|
||||
|
|
|
@ -120,6 +120,7 @@ var regexMap = {
|
|||
'build level': /^build +level($|\s)/,
|
||||
'export tree': /^export +tree$/,
|
||||
'importTreeNow': /^importTreeNow($|\s)/,
|
||||
'importLevelNow': /^importLevelNow($|\s)/,
|
||||
'import tree': /^import +tree$/,
|
||||
'import level': /^import +level$/,
|
||||
'undo': /^undo($|\s)/
|
||||
|
|
|
@ -249,7 +249,8 @@ var Sandbox = Backbone.View.extend({
|
|||
'export tree': this.exportTree,
|
||||
'import tree': this.importTree,
|
||||
'importTreeNow': this.importTreeNow,
|
||||
'import level': this.importLevel
|
||||
'import level': this.importLevel,
|
||||
'importLevelNow': this.importLevelNow,
|
||||
};
|
||||
|
||||
var method = commandMap[command.get('method')];
|
||||
|
@ -270,13 +271,47 @@ var Sandbox = Backbone.View.extend({
|
|||
this.mainVis.show();
|
||||
},
|
||||
|
||||
importLevelNow: function(command, deferred) {
|
||||
var options = command.get('regexResults') || [];
|
||||
if (options.length < 2) {
|
||||
command.set('error', new Errors.GitError({
|
||||
msg: intl.str('git-error-options')
|
||||
}));
|
||||
command.finishWith(deferred);
|
||||
return;
|
||||
}
|
||||
var string = options.input.replace(/importLevelNow\s+/g, '');
|
||||
var Level = require('../level').Level;
|
||||
try {
|
||||
var levelJSON = JSON.parse(unescape(string));
|
||||
console.log(levelJSON);
|
||||
var whenLevelOpen = Q.defer();
|
||||
this.currentLevel = new Level({
|
||||
level: levelJSON,
|
||||
deferred: whenLevelOpen,
|
||||
command: command
|
||||
});
|
||||
this.hide();
|
||||
|
||||
whenLevelOpen.promise.then(function() {
|
||||
command.finishWith(deferred);
|
||||
});
|
||||
} catch(e) {
|
||||
command.set('error', new Errors.GitError({
|
||||
msg: 'Something went wrong ' + String(e)
|
||||
}));
|
||||
}
|
||||
command.finishWith(deferred);
|
||||
},
|
||||
|
||||
importTreeNow: function(command, deferred) {
|
||||
var options = command.get('regexResults') || [];
|
||||
if (options.length < 2) {
|
||||
command.set('error', new Errors.GitError({
|
||||
msg: intl.str('git-error-options')
|
||||
}));
|
||||
} else {
|
||||
command.finishWith(deferred);
|
||||
}
|
||||
var string = options.input.replace(/importTreeNow\s+/g, '');
|
||||
try {
|
||||
this.mainVis.gitEngine.loadTreeFromString(string);
|
||||
|
@ -285,8 +320,6 @@ var Sandbox = Backbone.View.extend({
|
|||
msg: String(e)
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
command.finishWith(deferred);
|
||||
},
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue