Skip to content

Instantly share code, notes, and snippets.

@techwraith
Created November 30, 2012 21:37
Show Gist options
  • Save techwraith/4178846 to your computer and use it in GitHub Desktop.
Save techwraith/4178846 to your computer and use it in GitHub Desktop.
//=========================================================================
// controller
//=========================================================================
this.showOutput = function(req, res, params) {
console.log('+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++');
console.log(params);
params['errorMessage'] = this.session.get('errorMessage');
params['command'] = this.session.get('command');
params['output'] = this.session.get('output');
this.respond(params, {
format: 'html'
, template: 'app/views/main/index'
});
};
this.handleCommand = function(req, res, params) {
var self = this;
child_process.exec(params['command-textbox'], function(err, output) {
if (err) {
// params['errorMessage'] = '\n\nInvalid command';
// params['command'] = params['command-textbox'];
// params['output'] = 'No output';
self.session.set('errorMessage', params['\n\nInvalid command']);
self.session.set('command', params['command-textbox']);
self.session.set('output', params['No output']);
} else {
// params['command'] = params['command-textbox'];
// params['output'] = output;
self.session.set('command', params['command-textbox']);
self.session.set('output', output);
}
// self.transfer('showOutput');
self.redirect('/result');
});
};
//=========================================================================
// routes
//=========================================================================
router.get('/').to('Main.index');
router.get('/info').to('Main.info');
router.post('/').to('Main.handleCommand');
router.post('/submit').to('Main.handleCommand');
router.get('/result').to('Main.showOutput');
Requirements:
1) start at Main.index action
2) enter command in the main index view
3) post to '/'
4) get redirected back to '/' while rendering the main index view, this time with the resulting output included
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment