diff --git a/build/bundle.js b/build/bundle.js index d08173cb..946d56d3 100644 --- a/build/bundle.js +++ b/build/bundle.js @@ -4394,6 +4394,7 @@ var CommitCollection = Collections.CommitCollection; var BranchCollection = Collections.BranchCollection; var GitVisuals = require('../visuals').GitVisuals; +var InputWaterfall = require('../level/inputWaterfall').InputWaterfall; var Visualization = Backbone.View.extend({ initialize: function(options) { @@ -4415,6 +4416,10 @@ var Visualization = Backbone.View.extend({ var Main = require('../app'); this.events = Main.getEvents(); + // hook the git engine up to the command input + this.inputWaterfall = new InputWaterfall(); + + this.commitCollection = new CommitCollection(); this.branchCollection = new BranchCollection(); @@ -4641,7 +4646,7 @@ function GitEngine(options) { this.commandOptions = {}; this.generalArgs = []; - this.events.on('processCommand', this.dispatch, this); + this.events.on('processGitCommand', this.dispatch, this); // backbone or something uses _.uniqueId, so we make our own here this.uniqueId = (function() { @@ -10975,6 +10980,7 @@ require.define("/src/js/models/commandModel.js",function(require,module,exports, var Backbone = (!require('../util').isBrowser()) ? Backbone = require('backbone') : Backbone = window.Backbone; var Errors = require('../util/errors'); +var GitCommands = require('../git/commands'); var CommandProcessError = Errors.CommandProcessError; var GitError = Errors.GitError; @@ -11077,35 +11083,6 @@ var Command = Backbone.Model.extend({ this.set('result', this.get('error').toResult()); }, - getShortcutMap: function() { - return { - 'git commit': /^gc($|\s)/, - 'git add': /^ga($|\s)/, - 'git checkout': /^go($|\s)/, - 'git rebase': /^gr($|\s)/, - 'git branch': /^gb($|\s)/ - }; - }, - - getRegexMap: function() { - return { - // ($|\s) means that we either have to end the string - // after the command or there needs to be a space for options - commit: /^commit($|\s)/, - add: /^add($|\s)/, - checkout: /^checkout($|\s)/, - rebase: /^rebase($|\s)/, - reset: /^reset($|\s)/, - branch: /^branch($|\s)/, - revert: /^revert($|\s)/, - log: /^log($|\s)/, - merge: /^merge($|\s)/, - show: /^show($|\s)/, - status: /^status($|\s)/, - 'cherry-pick': /^cherry-pick($|\s)/ - }; - }, - getSandboxCommands: function() { return [ [/^ls/, function() { @@ -11196,7 +11173,7 @@ var Command = Backbone.Model.extend({ // then check if shortcut exists, and replace, but // preserve options if so - _.each(this.getShortcutMap(), function(regex, method) { + _.each(GitCommands.getShortcutMap(), function(regex, method) { var results = regex.exec(str); if (results) { str = method + ' ' + str.slice(results[0].length); @@ -11220,7 +11197,7 @@ var Command = Backbone.Model.extend({ var fullCommand = str.slice('git '.length); // see if we support this particular command - _.each(this.getRegexMap(), function(regex, method) { + _.each(GitCommands.getRegexMap(), function(regex, method) { if (regex.exec(fullCommand)) { this.set('options', fullCommand.slice(method.length + 1)); this.set('method', method); @@ -11350,6 +11327,40 @@ exports.Command = Command; }); +require.define("/src/js/git/commands.js",function(require,module,exports,__dirname,__filename,process,global){var getRegexMap = function() { + return { + // ($|\s) means that we either have to end the string + // after the command or there needs to be a space for options + commit: /^commit($|\s)/, + add: /^add($|\s)/, + checkout: /^checkout($|\s)/, + rebase: /^rebase($|\s)/, + reset: /^reset($|\s)/, + branch: /^branch($|\s)/, + revert: /^revert($|\s)/, + log: /^log($|\s)/, + merge: /^merge($|\s)/, + show: /^show($|\s)/, + status: /^status($|\s)/, + 'cherry-pick': /^cherry-pick($|\s)/ + }; +}; + +var getShortcutMap = function() { + return { + 'git commit': /^gc($|\s)/, + 'git add': /^ga($|\s)/, + 'git checkout': /^go($|\s)/, + 'git rebase': /^gr($|\s)/, + 'git branch': /^gb($|\s)/ + }; +}; + +exports.getRegexMap = getRegexMap; +exports.getShortcutMap = getShortcutMap; + +}); + require.define("/src/js/app/index.js",function(require,module,exports,__dirname,__filename,process,global){var _ = require('underscore'); var Backbone = require('backbone'); @@ -13728,6 +13739,47 @@ var VisEdgeCollection = Backbone.Collection.extend({ exports.VisEdgeCollection = VisEdgeCollection; exports.VisEdge = VisEdge; +}); + +require.define("/src/js/level/inputWaterfall.js",function(require,module,exports,__dirname,__filename,process,global){var _ = require('underscore'); +var Backbone = require('backbone'); + +var Main = require('../app'); + +/** + * This class supports a few things we need for levels: + ~ A disabled map (to prevent certain git commands from firing) + ~ A post-git command hook (to compare the git tree against the solution) + ~ Extra level-specific commands (like help, hint, etc) that are async +**/ + +function InputWaterfall(options) { + options = options || {}; + this.listenEvent = options.listenEvent || 'processCommand'; + this.disabledMap = options.disabledMap || {}; + + console.log('made'); + + this.listen(); +} + +InputWaterfall.prototype.listen = function() { + Main.getEvents().on(this.listenEvent, this.process, this); +}; + +InputWaterfall.prototype.mute = function() { + Main.getEvents().off(this.listenEvent, this.process, this); +}; + +InputWaterfall.prototype.process = function(command, callback) { + console.log('processing'); + // for now, just immediately fire it + Main.getEvents().trigger('processGitCommand', command, callback); +}; + +exports.InputWaterfall = InputWaterfall; + + }); require.define("/src/js/util/mock.js",function(require,module,exports,__dirname,__filename,process,global){exports.mock = function(Constructor) { @@ -14058,9 +14110,40 @@ exports.init = init; }); require("/src/js/app/index.js"); -require.define("/src/js/app/inputWaterfall.js",function(require,module,exports,__dirname,__filename,process,global){undefined +require.define("/src/js/git/commands.js",function(require,module,exports,__dirname,__filename,process,global){var getRegexMap = function() { + return { + // ($|\s) means that we either have to end the string + // after the command or there needs to be a space for options + commit: /^commit($|\s)/, + add: /^add($|\s)/, + checkout: /^checkout($|\s)/, + rebase: /^rebase($|\s)/, + reset: /^reset($|\s)/, + branch: /^branch($|\s)/, + revert: /^revert($|\s)/, + log: /^log($|\s)/, + merge: /^merge($|\s)/, + show: /^show($|\s)/, + status: /^status($|\s)/, + 'cherry-pick': /^cherry-pick($|\s)/ + }; +}; + +var getShortcutMap = function() { + return { + 'git commit': /^gc($|\s)/, + 'git add': /^ga($|\s)/, + 'git checkout': /^go($|\s)/, + 'git rebase': /^gr($|\s)/, + 'git branch': /^gb($|\s)/ + }; +}; + +exports.getRegexMap = getRegexMap; +exports.getShortcutMap = getShortcutMap; + }); -require("/src/js/app/inputWaterfall.js"); +require("/src/js/git/commands.js"); require.define("/src/js/git/headless.js",function(require,module,exports,__dirname,__filename,process,global){var _ = require('underscore'); var Backbone = require('backbone'); @@ -14149,7 +14232,7 @@ function GitEngine(options) { this.commandOptions = {}; this.generalArgs = []; - this.events.on('processCommand', this.dispatch, this); + this.events.on('processGitCommand', this.dispatch, this); // backbone or something uses _.uniqueId, so we make our own here this.uniqueId = (function() { @@ -15919,6 +16002,48 @@ exports.TreeCompare = TreeCompare; }); require("/src/js/git/treeCompare.js"); +require.define("/src/js/level/inputWaterfall.js",function(require,module,exports,__dirname,__filename,process,global){var _ = require('underscore'); +var Backbone = require('backbone'); + +var Main = require('../app'); + +/** + * This class supports a few things we need for levels: + ~ A disabled map (to prevent certain git commands from firing) + ~ A post-git command hook (to compare the git tree against the solution) + ~ Extra level-specific commands (like help, hint, etc) that are async +**/ + +function InputWaterfall(options) { + options = options || {}; + this.listenEvent = options.listenEvent || 'processCommand'; + this.disabledMap = options.disabledMap || {}; + + console.log('made'); + + this.listen(); +} + +InputWaterfall.prototype.listen = function() { + Main.getEvents().on(this.listenEvent, this.process, this); +}; + +InputWaterfall.prototype.mute = function() { + Main.getEvents().off(this.listenEvent, this.process, this); +}; + +InputWaterfall.prototype.process = function(command, callback) { + console.log('processing'); + // for now, just immediately fire it + Main.getEvents().trigger('processGitCommand', command, callback); +}; + +exports.InputWaterfall = InputWaterfall; + + +}); +require("/src/js/level/inputWaterfall.js"); + require.define("/src/js/models/collections.js",function(require,module,exports,__dirname,__filename,process,global){var _ = require('underscore'); // horrible hack to get localStorage Backbone plugin var Backbone = (!require('../util').isBrowser()) ? Backbone = require('backbone') : Backbone = window.Backbone; @@ -16033,6 +16158,7 @@ require.define("/src/js/models/commandModel.js",function(require,module,exports, var Backbone = (!require('../util').isBrowser()) ? Backbone = require('backbone') : Backbone = window.Backbone; var Errors = require('../util/errors'); +var GitCommands = require('../git/commands'); var CommandProcessError = Errors.CommandProcessError; var GitError = Errors.GitError; @@ -16135,35 +16261,6 @@ var Command = Backbone.Model.extend({ this.set('result', this.get('error').toResult()); }, - getShortcutMap: function() { - return { - 'git commit': /^gc($|\s)/, - 'git add': /^ga($|\s)/, - 'git checkout': /^go($|\s)/, - 'git rebase': /^gr($|\s)/, - 'git branch': /^gb($|\s)/ - }; - }, - - getRegexMap: function() { - return { - // ($|\s) means that we either have to end the string - // after the command or there needs to be a space for options - commit: /^commit($|\s)/, - add: /^add($|\s)/, - checkout: /^checkout($|\s)/, - rebase: /^rebase($|\s)/, - reset: /^reset($|\s)/, - branch: /^branch($|\s)/, - revert: /^revert($|\s)/, - log: /^log($|\s)/, - merge: /^merge($|\s)/, - show: /^show($|\s)/, - status: /^status($|\s)/, - 'cherry-pick': /^cherry-pick($|\s)/ - }; - }, - getSandboxCommands: function() { return [ [/^ls/, function() { @@ -16254,7 +16351,7 @@ var Command = Backbone.Model.extend({ // then check if shortcut exists, and replace, but // preserve options if so - _.each(this.getShortcutMap(), function(regex, method) { + _.each(GitCommands.getShortcutMap(), function(regex, method) { var results = regex.exec(str); if (results) { str = method + ' ' + str.slice(results[0].length); @@ -16278,7 +16375,7 @@ var Command = Backbone.Model.extend({ var fullCommand = str.slice('git '.length); // see if we support this particular command - _.each(this.getRegexMap(), function(regex, method) { + _.each(GitCommands.getRegexMap(), function(regex, method) { if (regex.exec(fullCommand)) { this.set('options', fullCommand.slice(method.length + 1)); this.set('method', method); @@ -19803,6 +19900,7 @@ var CommitCollection = Collections.CommitCollection; var BranchCollection = Collections.BranchCollection; var GitVisuals = require('../visuals').GitVisuals; +var InputWaterfall = require('../level/inputWaterfall').InputWaterfall; var Visualization = Backbone.View.extend({ initialize: function(options) { @@ -19824,6 +19922,10 @@ var Visualization = Backbone.View.extend({ var Main = require('../app'); this.events = Main.getEvents(); + // hook the git engine up to the command input + this.inputWaterfall = new InputWaterfall(); + + this.commitCollection = new CommitCollection(); this.branchCollection = new BranchCollection(); diff --git a/src/js/app/inputWaterfall.js b/src/js/app/inputWaterfall.js deleted file mode 100644 index 4dfc635e..00000000 --- a/src/js/app/inputWaterfall.js +++ /dev/null @@ -1,17 +0,0 @@ -var _ = require('underscore'); -var Backbone = require('backbone'); - -var Main = require('../main'); - -function InputWaterfall() { - - Main.getEvents().on('processCommand', this.process) - -}; - -InputWaterfall.prototype.listen = function() { - Main.getEvents(). - -}; - -exports.InputWaterfall = InputWaterfall; diff --git a/src/js/git/commands.js b/src/js/git/commands.js new file mode 100644 index 00000000..5c1508e6 --- /dev/null +++ b/src/js/git/commands.js @@ -0,0 +1,31 @@ +var getRegexMap = function() { + return { + // ($|\s) means that we either have to end the string + // after the command or there needs to be a space for options + commit: /^commit($|\s)/, + add: /^add($|\s)/, + checkout: /^checkout($|\s)/, + rebase: /^rebase($|\s)/, + reset: /^reset($|\s)/, + branch: /^branch($|\s)/, + revert: /^revert($|\s)/, + log: /^log($|\s)/, + merge: /^merge($|\s)/, + show: /^show($|\s)/, + status: /^status($|\s)/, + 'cherry-pick': /^cherry-pick($|\s)/ + }; +}; + +var getShortcutMap = function() { + return { + 'git commit': /^gc($|\s)/, + 'git add': /^ga($|\s)/, + 'git checkout': /^go($|\s)/, + 'git rebase': /^gr($|\s)/, + 'git branch': /^gb($|\s)/ + }; +}; + +exports.getRegexMap = getRegexMap; +exports.getShortcutMap = getShortcutMap; diff --git a/src/js/git/index.js b/src/js/git/index.js index f2bad6b6..71816c95 100644 --- a/src/js/git/index.js +++ b/src/js/git/index.js @@ -28,7 +28,7 @@ function GitEngine(options) { this.commandOptions = {}; this.generalArgs = []; - this.events.on('processCommand', this.dispatch, this); + this.events.on('processGitCommand', this.dispatch, this); // backbone or something uses _.uniqueId, so we make our own here this.uniqueId = (function() { diff --git a/src/js/level/inputWaterfall.js b/src/js/level/inputWaterfall.js new file mode 100644 index 00000000..6657c35c --- /dev/null +++ b/src/js/level/inputWaterfall.js @@ -0,0 +1,38 @@ +var _ = require('underscore'); +var Backbone = require('backbone'); + +var Main = require('../app'); + +/** + * This class supports a few things we need for levels: + ~ A disabled map (to prevent certain git commands from firing) + ~ A post-git command hook (to compare the git tree against the solution) + ~ Extra level-specific commands (like help, hint, etc) that are async +**/ + +function InputWaterfall(options) { + options = options || {}; + this.listenEvent = options.listenEvent || 'processCommand'; + this.disabledMap = options.disabledMap || {}; + + console.log('made'); + + this.listen(); +} + +InputWaterfall.prototype.listen = function() { + Main.getEvents().on(this.listenEvent, this.process, this); +}; + +InputWaterfall.prototype.mute = function() { + Main.getEvents().off(this.listenEvent, this.process, this); +}; + +InputWaterfall.prototype.process = function(command, callback) { + console.log('processing'); + // for now, just immediately fire it + Main.getEvents().trigger('processGitCommand', command, callback); +}; + +exports.InputWaterfall = InputWaterfall; + diff --git a/src/js/models/commandModel.js b/src/js/models/commandModel.js index 624b12f9..5a788606 100644 --- a/src/js/models/commandModel.js +++ b/src/js/models/commandModel.js @@ -3,6 +3,7 @@ var _ = require('underscore'); var Backbone = (!require('../util').isBrowser()) ? Backbone = require('backbone') : Backbone = window.Backbone; var Errors = require('../util/errors'); +var GitCommands = require('../git/commands'); var CommandProcessError = Errors.CommandProcessError; var GitError = Errors.GitError; @@ -105,35 +106,6 @@ var Command = Backbone.Model.extend({ this.set('result', this.get('error').toResult()); }, - getShortcutMap: function() { - return { - 'git commit': /^gc($|\s)/, - 'git add': /^ga($|\s)/, - 'git checkout': /^go($|\s)/, - 'git rebase': /^gr($|\s)/, - 'git branch': /^gb($|\s)/ - }; - }, - - getRegexMap: function() { - return { - // ($|\s) means that we either have to end the string - // after the command or there needs to be a space for options - commit: /^commit($|\s)/, - add: /^add($|\s)/, - checkout: /^checkout($|\s)/, - rebase: /^rebase($|\s)/, - reset: /^reset($|\s)/, - branch: /^branch($|\s)/, - revert: /^revert($|\s)/, - log: /^log($|\s)/, - merge: /^merge($|\s)/, - show: /^show($|\s)/, - status: /^status($|\s)/, - 'cherry-pick': /^cherry-pick($|\s)/ - }; - }, - getSandboxCommands: function() { return [ [/^ls/, function() { @@ -224,7 +196,7 @@ var Command = Backbone.Model.extend({ // then check if shortcut exists, and replace, but // preserve options if so - _.each(this.getShortcutMap(), function(regex, method) { + _.each(GitCommands.getShortcutMap(), function(regex, method) { var results = regex.exec(str); if (results) { str = method + ' ' + str.slice(results[0].length); @@ -248,7 +220,7 @@ var Command = Backbone.Model.extend({ var fullCommand = str.slice('git '.length); // see if we support this particular command - _.each(this.getRegexMap(), function(regex, method) { + _.each(GitCommands.getRegexMap(), function(regex, method) { if (regex.exec(fullCommand)) { this.set('options', fullCommand.slice(method.length + 1)); this.set('method', method); diff --git a/src/js/visuals/visualization.js b/src/js/visuals/visualization.js index ad1ade9c..ed2abbfb 100644 --- a/src/js/visuals/visualization.js +++ b/src/js/visuals/visualization.js @@ -7,6 +7,7 @@ var CommitCollection = Collections.CommitCollection; var BranchCollection = Collections.BranchCollection; var GitVisuals = require('../visuals').GitVisuals; +var InputWaterfall = require('../level/inputWaterfall').InputWaterfall; var Visualization = Backbone.View.extend({ initialize: function(options) { @@ -28,6 +29,10 @@ var Visualization = Backbone.View.extend({ var Main = require('../app'); this.events = Main.getEvents(); + // hook the git engine up to the command input + this.inputWaterfall = new InputWaterfall(); + + this.commitCollection = new CommitCollection(); this.branchCollection = new BranchCollection();