2015-04-22 22:09:12 +00:00
|
|
|
Demo.DemoStepController = Ember.ObjectController.extend({
|
2015-04-23 18:23:19 +00:00
|
|
|
needs: ['demo'],
|
|
|
|
socket: Ember.computed.alias('controllers.demo.socket'),
|
2015-04-23 01:48:24 +00:00
|
|
|
logs: Ember.computed.alias('controllers.demo.logs'),
|
|
|
|
isLoading: Ember.computed.alias('controllers.demo.isLoading'),
|
2015-04-22 22:09:12 +00:00
|
|
|
|
|
|
|
currentText: "",
|
|
|
|
commandLog: [],
|
|
|
|
cursor: 0,
|
|
|
|
notCleared: true,
|
2015-04-23 19:16:17 +00:00
|
|
|
fullscreen: false,
|
2015-04-23 01:48:24 +00:00
|
|
|
|
|
|
|
renderedLogs: function() {
|
|
|
|
return this.get('logs');
|
|
|
|
}.property('logs.length'),
|
2015-04-22 22:09:12 +00:00
|
|
|
|
|
|
|
setFromHistory: function() {
|
|
|
|
var index = this.get('commandLog.length') + this.get('cursor');
|
|
|
|
var previousMessage = this.get('commandLog')[index];
|
|
|
|
|
|
|
|
this.set('currentText', previousMessage);
|
|
|
|
}.observes('cursor'),
|
|
|
|
|
|
|
|
logCommand: function(command) {
|
|
|
|
var commandLog = this.get('commandLog');
|
|
|
|
|
|
|
|
commandLog.push(command);
|
|
|
|
|
|
|
|
this.set('commandLog', commandLog);
|
|
|
|
},
|
|
|
|
|
|
|
|
actions: {
|
|
|
|
submitText: function() {
|
|
|
|
// Send the actual request (fake for now)
|
|
|
|
this.sendCommand();
|
2015-04-23 01:48:24 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
close: function() {
|
|
|
|
this.transitionTo('index');
|
|
|
|
},
|
|
|
|
|
|
|
|
next: function() {
|
2015-04-23 18:28:12 +00:00
|
|
|
var nextStepNumber = parseInt(this.get('model.id'), 10) + 1;
|
2015-04-23 01:48:24 +00:00
|
|
|
this.transitionTo('demo.step', nextStepNumber);
|
|
|
|
},
|
|
|
|
|
|
|
|
previous: function() {
|
2015-04-23 18:28:12 +00:00
|
|
|
var prevStepNumber = parseInt(this.get('model.id'), 10) - 1;
|
2015-04-23 01:48:24 +00:00
|
|
|
this.transitionTo('demo.step', prevStepNumber);
|
|
|
|
},
|
2015-04-22 22:09:12 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
sendCommand: function() {
|
|
|
|
var command = this.getWithDefault('currentText', '');
|
|
|
|
var log = this.get('log');
|
|
|
|
|
|
|
|
this.set('currentText', '');
|
2015-04-23 01:48:24 +00:00
|
|
|
this.logCommand(command);
|
|
|
|
this.get('controllers.demo').appendLog(command, true);
|
2015-04-22 22:09:12 +00:00
|
|
|
|
|
|
|
switch(command) {
|
|
|
|
case "":
|
|
|
|
break;
|
2015-04-23 01:48:24 +00:00
|
|
|
case "next":
|
|
|
|
case "forward":
|
|
|
|
this.set('notCleared', true);
|
|
|
|
this.send('next');
|
|
|
|
break;
|
|
|
|
case "previous":
|
|
|
|
case "back":
|
2015-04-23 19:16:17 +00:00
|
|
|
case "prev":
|
2015-04-23 01:48:24 +00:00
|
|
|
this.set('notCleared', true);
|
|
|
|
this.send('previous');
|
|
|
|
break;
|
2015-04-23 16:44:33 +00:00
|
|
|
case "quit":
|
|
|
|
case "exit":
|
|
|
|
this.send('close');
|
|
|
|
break;
|
2015-04-22 22:09:12 +00:00
|
|
|
case "clear":
|
|
|
|
this.set('logs', "");
|
|
|
|
this.set('notCleared', false);
|
|
|
|
break;
|
2015-04-23 19:16:17 +00:00
|
|
|
case "fu":
|
|
|
|
case "fullscreen":
|
|
|
|
this.set('fullscreen', true);
|
|
|
|
break;
|
2015-04-23 01:48:24 +00:00
|
|
|
case "help":
|
2015-07-13 10:12:09 +00:00
|
|
|
this.get('controllers.demo').appendLog('You can use `vault path-help <command>` ' +
|
2015-04-23 18:28:12 +00:00
|
|
|
'to learn more about specific Vault commands, or `next` ' +
|
2015-04-23 19:16:17 +00:00
|
|
|
'and `previous` to navigate. Or, `fu` to go fullscreen.', false);
|
2015-04-23 01:48:24 +00:00
|
|
|
break;
|
2015-04-22 22:09:12 +00:00
|
|
|
default:
|
|
|
|
this.set('isLoading', true);
|
|
|
|
var data = JSON.stringify({type: "cli", data: {command: command}});
|
|
|
|
this.get('socket').send(data);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
});
|