Matteo Scandolo | 4208f11 | 2016-08-10 17:02:02 -0700 | [diff] [blame] | 1 | 'use strict'; |
| 2 | |
| 3 | angular.module('xos.UITutorial', [ |
| 4 | 'ngResource', |
| 5 | 'ngCookies', |
| 6 | 'ui.router', |
| 7 | 'xos.helpers' |
| 8 | ]) |
| 9 | .config(($stateProvider) => { |
| 10 | $stateProvider |
| 11 | .state('shell', { |
| 12 | url: '/', |
| 13 | template: '<js-shell></js-shell>' |
| 14 | }); |
| 15 | }) |
| 16 | .config(function($httpProvider){ |
| 17 | $httpProvider.interceptors.push('NoHyperlinks'); |
| 18 | }) |
Matteo Scandolo | ef96992 | 2016-08-11 13:49:12 -0700 | [diff] [blame] | 19 | .directive('jsShell', function(TemplateHandler){ |
Matteo Scandolo | 4208f11 | 2016-08-10 17:02:02 -0700 | [diff] [blame] | 20 | return { |
| 21 | restrict: 'E', |
| 22 | scope: {}, |
| 23 | bindToController: true, |
| 24 | controllerAs: 'vm', |
| 25 | templateUrl: 'templates/js-shell.tpl.html', |
Matteo Scandolo | 86f3f28 | 2016-08-11 11:21:33 -0700 | [diff] [blame] | 26 | controller: function(ExploreCmd){ |
Matteo Scandolo | ef96992 | 2016-08-11 13:49:12 -0700 | [diff] [blame] | 27 | var history = new Josh.History({ key: 'jsshell.history'}); |
| 28 | this.shell = Josh.Shell({history: history}); |
Matteo Scandolo | 4208f11 | 2016-08-10 17:02:02 -0700 | [diff] [blame] | 29 | |
Matteo Scandolo | ef96992 | 2016-08-11 13:49:12 -0700 | [diff] [blame] | 30 | this.shell.onNewPrompt(done => { |
Matteo Scandolo | 86f3f28 | 2016-08-11 11:21:33 -0700 | [diff] [blame] | 31 | done('[ngXosLib] $ '); |
Matteo Scandolo | 4208f11 | 2016-08-10 17:02:02 -0700 | [diff] [blame] | 32 | }); |
| 33 | |
Matteo Scandolo | ef96992 | 2016-08-11 13:49:12 -0700 | [diff] [blame] | 34 | this.shell.setCommandHandler('explore', { |
Matteo Scandolo | 4208f11 | 2016-08-10 17:02:02 -0700 | [diff] [blame] | 35 | exec: (cmd, args, done) => { |
Matteo Scandolo | ef96992 | 2016-08-11 13:49:12 -0700 | [diff] [blame] | 36 | ExploreCmd.setup(this.shell); |
| 37 | done(TemplateHandler.instructions({ |
| 38 | title: `You can now explore the API use angular $resouces!`, |
| 39 | messages: [ |
| 40 | `Use <code>resource list</code> to list all the available resources and <code>resource {resoureName} {method} {?paramters}</code> to call the API.`, |
| 41 | `An example command is <code>resource Slices query</code>`, |
| 42 | `You can also provide paramters with <code>resource Slices query {max_instances: 10}</code>` |
| 43 | ] |
| 44 | })); |
Matteo Scandolo | 4208f11 | 2016-08-10 17:02:02 -0700 | [diff] [blame] | 45 | } |
| 46 | }); |
| 47 | |
Matteo Scandolo | ef96992 | 2016-08-11 13:49:12 -0700 | [diff] [blame] | 48 | this.shell.activate(); |
Matteo Scandolo | 4208f11 | 2016-08-10 17:02:02 -0700 | [diff] [blame] | 49 | } |
| 50 | }; |
| 51 | }); |