mirror of
https://github.com/pcottle/learnGitBranching.git
synced 2025-08-03 01:25:08 +02:00
more
This commit is contained in:
parent
a12bc276ae
commit
19b6038f55
7 changed files with 514 additions and 91 deletions
|
@ -119,7 +119,9 @@
|
|||
</div>
|
||||
</div>
|
||||
<div class="terminal-text">
|
||||
<p> yo </p>
|
||||
<p class="helperText">
|
||||
<%= text %>
|
||||
</p>
|
||||
</div>
|
||||
<div class="inside box flex1">
|
||||
</div>
|
||||
|
|
|
@ -5,6 +5,7 @@ var Q = require('q');
|
|||
var util = require('../util');
|
||||
var Main = require('../app');
|
||||
|
||||
var Errors = require('../util/errors');
|
||||
var Sandbox = require('../level/sandbox').Sandbox;
|
||||
|
||||
var Visualization = require('../visuals/visualization').Visualization;
|
||||
|
@ -16,6 +17,7 @@ var GitShim = require('../git/gitShim').GitShim;
|
|||
var ModalAlert = require('../views').ModalAlert;
|
||||
var MultiView = require('../views/multiView').MultiView;
|
||||
var CanvasTerminalHolder = require('../views').CanvasTerminalHolder;
|
||||
var ConfirmCancelTerminal = require('../views').ConfirmCancelTerminal;
|
||||
|
||||
var TreeCompare = require('../git/treeCompare').TreeCompare;
|
||||
|
||||
|
@ -23,6 +25,7 @@ var Level = Sandbox.extend({
|
|||
initialize: function(options) {
|
||||
options = options || {};
|
||||
options.level = options.level || {};
|
||||
this.level = options.level;
|
||||
|
||||
this.gitCommandsIssued = 0;
|
||||
this.commandsThatCount = this.getCommandsThatCount();
|
||||
|
@ -31,13 +34,22 @@ var Level = Sandbox.extend({
|
|||
// possible options on how stringent to be on comparisons go here
|
||||
this.treeCompare = new TreeCompare();
|
||||
|
||||
this.initGoalData(options);
|
||||
Sandbox.prototype.initialize.apply(this, [options]);
|
||||
},
|
||||
|
||||
initGoalData: function(options) {
|
||||
this.goalTreeString = options.level.goalTree;
|
||||
this.solutionCommand = options.level.solutionCommand;
|
||||
|
||||
if (!this.goalTreeString) {
|
||||
console.warn('woah no goal, using random other one');
|
||||
this.goalTreeString = '{"branches":{"master":{"target":"C1","id":"master"},"win":{"target":"C2","id":"win"}},"commits":{"C0":{"parents":[],"id":"C0","rootCommit":true},"C1":{"parents":["C0"],"id":"C1"},"C2":{"parents":["C1"],"id":"C2"}},"HEAD":{"target":"win","id":"HEAD"}}';
|
||||
this.solutionCommand = 'git checkout -b win; git commit';
|
||||
}
|
||||
if (!this.solutionCommand) {
|
||||
console.warn('no solution provided, really bad form');
|
||||
}
|
||||
|
||||
Sandbox.prototype.initialize.apply(this, [options]);
|
||||
},
|
||||
|
||||
takeControl: function() {
|
||||
|
@ -76,6 +88,67 @@ var Level = Sandbox.extend({
|
|||
});
|
||||
},
|
||||
|
||||
showSolution: function(command, defer) {
|
||||
var confirmDefer = Q.defer();
|
||||
var confirmView = new ConfirmCancelTerminal({
|
||||
modalAlert: {
|
||||
markdowns: [
|
||||
'## Are you sure you want to see the solution?',
|
||||
'',
|
||||
'I believe in you! You can do it'
|
||||
]
|
||||
},
|
||||
deferred: confirmDefer
|
||||
});
|
||||
|
||||
confirmDefer.promise
|
||||
.then(_.bind(function() {
|
||||
// it's next tick because we need to close the
|
||||
// dialog first or otherwise it will steal the event
|
||||
// baton fire
|
||||
process.nextTick(_.bind(function() {
|
||||
Main.getEventBaton().trigger(
|
||||
'commandSubmitted',
|
||||
'reset;' + this.solutionCommand
|
||||
);
|
||||
}, this));
|
||||
// we also need to defer this logic...
|
||||
var whenClosed = Q.defer();
|
||||
whenClosed.promise
|
||||
.then(function() {
|
||||
return Q.delay(700);
|
||||
})
|
||||
.then(function() {
|
||||
command.finishWith(defer);
|
||||
})
|
||||
.done();
|
||||
|
||||
this.hideGoal();
|
||||
command.setResult('Solution command added to the command queue...');
|
||||
|
||||
// start that process...
|
||||
whenClosed.resolve();
|
||||
}, this))
|
||||
.fail(function() {
|
||||
command.setResult("Great! I'll let you get back to it");
|
||||
|
||||
var whenClosed = Q.defer();
|
||||
whenClosed.promise
|
||||
.then(function() {
|
||||
return Q.delay(700);
|
||||
})
|
||||
.then(function() {
|
||||
command.finishWith(defer);
|
||||
})
|
||||
.done();
|
||||
|
||||
whenClosed.resolve();
|
||||
})
|
||||
.done(function() {
|
||||
confirmView.close();
|
||||
});
|
||||
},
|
||||
|
||||
showGoal: function(command, defer) {
|
||||
this.goalCanvasHolder.slideIn();
|
||||
setTimeout(function() {
|
||||
|
@ -85,6 +158,8 @@ var Level = Sandbox.extend({
|
|||
|
||||
hideGoal: function(command, defer) {
|
||||
this.goalCanvasHolder.slideOut();
|
||||
if (!command || !defer) { return; }
|
||||
|
||||
setTimeout(function() {
|
||||
command.finishWith(defer);
|
||||
}, this.goalCanvasHolder.getAnimationTime());
|
||||
|
@ -99,6 +174,12 @@ var Level = Sandbox.extend({
|
|||
require('../level/commands').parse
|
||||
);
|
||||
|
||||
/*
|
||||
this.parseWaterfall.addFirst(
|
||||
'instantWaterfall',
|
||||
this.getInstantCommands()
|
||||
);*/
|
||||
|
||||
// if we want to disable certain commands...
|
||||
if (options.level.disabledMap) {
|
||||
// disable these other commands
|
||||
|
@ -183,11 +264,29 @@ var Level = Sandbox.extend({
|
|||
},
|
||||
|
||||
getInstantCommands: function() {
|
||||
var hintMsg = (this.level.hint) ?
|
||||
this.level.hint :
|
||||
"Hmm, there doesn't seem to be a hint for this level :-/";
|
||||
|
||||
var instants = [
|
||||
[/^hint$/, function() {
|
||||
throw new Errors.CommandResult({
|
||||
msg: hintMsg
|
||||
});
|
||||
}]
|
||||
];
|
||||
|
||||
if (!this.solutionCommand) {
|
||||
instants.push([/^show solution$/, function() {
|
||||
throw new Errors.CommandResult({
|
||||
msg: 'No solution provided for this level :-/'
|
||||
});
|
||||
}]);
|
||||
}
|
||||
return instants;
|
||||
},
|
||||
|
||||
processLevelCommand: function(command, defer) {
|
||||
console.log('processing command...');
|
||||
var methodMap = {
|
||||
'show goal': this.showGoal,
|
||||
'hide goal': this.hideGoal,
|
||||
|
|
|
@ -90,6 +90,7 @@ EventBaton.prototype.releaseBaton = function(name, func, context) {
|
|||
|
||||
if (!found) {
|
||||
console.log('did not find that function', func, context, name, arguments);
|
||||
console.log(this.eventMap);
|
||||
throw new Error('cant releasebaton if yu dont have it');
|
||||
}
|
||||
this.eventMap[name] = newListeners;
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
var GitError = require('../util/errors').GitError;
|
||||
var _ = require('underscore');
|
||||
var Q = require('q');
|
||||
// horrible hack to get localStorage Backbone plugin
|
||||
var Backbone = (!require('../util').isBrowser()) ? require('backbone') : window.Backbone;
|
||||
|
||||
|
@ -157,11 +158,11 @@ var ModalView = Backbone.View.extend({
|
|||
},
|
||||
|
||||
onWindowFocus: function(e) {
|
||||
console.log('window focus doing nothing', e);
|
||||
//console.log('window focus doing nothing', e);
|
||||
},
|
||||
|
||||
onDocumentClick: function(e) {
|
||||
console.log('doc click doing nothing', e);
|
||||
//console.log('doc click doing nothing', e);
|
||||
},
|
||||
|
||||
onKeyDown: function(e) {
|
||||
|
@ -178,6 +179,7 @@ var ModalView = Backbone.View.extend({
|
|||
// reason if this is done immediately, chrome might combine
|
||||
// the two changes and lose the ability to animate and it looks bad.
|
||||
process.nextTick(_.bind(function() {
|
||||
console.log('STEALING KEYBOARD in modal');
|
||||
this.toggleShow(true);
|
||||
}, this));
|
||||
},
|
||||
|
@ -214,7 +216,6 @@ var ModalView = Backbone.View.extend({
|
|||
tearDown: function() {
|
||||
this.$el.html('');
|
||||
$('body')[0].removeChild(this.el);
|
||||
this.releaseKeyboard();
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -272,6 +273,35 @@ var ModalAlert = ContainedBase.extend({
|
|||
}
|
||||
});
|
||||
|
||||
var ConfirmCancelTerminal = Backbone.View.extend({
|
||||
initialize: function(options) {
|
||||
options = options || {};
|
||||
|
||||
this.deferred = options.deferred || Q.defer();
|
||||
this.modalAlert = new ModalAlert(_.extend(
|
||||
{},
|
||||
{ markdown: '#you sure?' },
|
||||
options.modalAlert
|
||||
));
|
||||
this.confirmCancel = new ConfirmCancelView({
|
||||
deferred: this.deferred,
|
||||
destination: this.modalAlert.getDestination()
|
||||
});
|
||||
|
||||
if (!options.wait) {
|
||||
this.modalAlert.show();
|
||||
}
|
||||
},
|
||||
|
||||
getPromise: function() {
|
||||
return this.deferred.promise;
|
||||
},
|
||||
|
||||
close: function() {
|
||||
this.modalAlert.die();
|
||||
}
|
||||
});
|
||||
|
||||
var ZoomAlertWindow = Backbone.View.extend({
|
||||
initialize: function(options) {
|
||||
this.grabBatons();
|
||||
|
@ -312,12 +342,16 @@ var CanvasTerminalHolder = BaseView.extend({
|
|||
tagName: 'div',
|
||||
className: 'canvasTerminalHolder box flex1',
|
||||
template: _.template($('#terminal-window-bare-template').html()),
|
||||
events: {
|
||||
'click div.wrapper': 'onClick'
|
||||
},
|
||||
|
||||
initialize: function(options) {
|
||||
options = options || {};
|
||||
this.destination = $('body');
|
||||
this.JSON = {
|
||||
title: options.title || 'Goal To Reach'
|
||||
title: options.title || 'Goal To Reach',
|
||||
text: options.text || 'You can hide this modal with "hide goal"'
|
||||
};
|
||||
|
||||
this.render();
|
||||
|
@ -325,6 +359,10 @@ var CanvasTerminalHolder = BaseView.extend({
|
|||
|
||||
getAnimationTime: function() { return 700; },
|
||||
|
||||
onClick: function() {
|
||||
this.slideOut();
|
||||
},
|
||||
|
||||
slideOut: function() {
|
||||
this.slideToggle(true);
|
||||
},
|
||||
|
@ -349,6 +387,7 @@ exports.ContainedBase = ContainedBase;
|
|||
exports.ConfirmCancelView = ConfirmCancelView;
|
||||
exports.LeftRightView = LeftRightView;
|
||||
exports.ZoomAlertWindow = ZoomAlertWindow;
|
||||
exports.ConfirmCancelTerminal = ConfirmCancelTerminal;
|
||||
|
||||
exports.CanvasTerminalHolder = CanvasTerminalHolder;
|
||||
|
||||
|
|
|
@ -153,6 +153,7 @@ div.canvasTerminalHolder div.terminal-window-holder div.wrapper {
|
|||
margin: 0 20px 0px 20px;
|
||||
height: 80%;
|
||||
box-shadow: 0 0 30px rgb(0,0,0);
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
div.canvasTerminalHolder div.terminal-window-holder div.terminal-text {
|
||||
|
@ -418,9 +419,13 @@ li.rebaseEntry,
|
|||
margin-top: 30%;
|
||||
}
|
||||
|
||||
div.terminal-text p.helperText,
|
||||
.iRebaseDialog p.helperText {
|
||||
font-size: 10px;
|
||||
}
|
||||
|
||||
.iRebaseDialog p.helperText {
|
||||
color: #999;
|
||||
font-size: 10px;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue