blob: a686fe672340ccf508fd19b6bfa43864bd2ba000 [file] [log] [blame]
Matteo Scandolo4208f112016-08-10 17:02:02 -07001'use strict';
2
3angular.module('xos.UITutorial', [
4 'ngResource',
5 'ngCookies',
6 'ui.router',
Matteo Scandoloa81496a2016-08-16 17:29:42 -07007 'xos.helpers',
8 'ui.ace'
Matteo Scandolo4208f112016-08-10 17:02:02 -07009])
10.config(($stateProvider) => {
11 $stateProvider
12 .state('shell', {
13 url: '/',
14 template: '<js-shell></js-shell>'
15 });
16})
17.config(function($httpProvider){
18 $httpProvider.interceptors.push('NoHyperlinks');
19})
Matteo Scandoloa81496a2016-08-16 17:29:42 -070020.directive('jsShell', function($rootScope, TemplateHandler, codeToString){
Matteo Scandolo4208f112016-08-10 17:02:02 -070021 return {
22 restrict: 'E',
23 scope: {},
24 bindToController: true,
25 controllerAs: 'vm',
26 templateUrl: 'templates/js-shell.tpl.html',
Matteo Scandoloa81496a2016-08-16 17:29:42 -070027 controller: function(ExploreCmd, PlayCmd, LearnCmd){
Matteo Scandoloef969922016-08-11 13:49:12 -070028 var history = new Josh.History({ key: 'jsshell.history'});
29 this.shell = Josh.Shell({history: history});
Matteo Scandolo4208f112016-08-10 17:02:02 -070030
Matteo Scandoloef969922016-08-11 13:49:12 -070031 this.shell.onNewPrompt(done => {
Matteo Scandolo86f3f282016-08-11 11:21:33 -070032 done('[ngXosLib] $ ');
Matteo Scandolo4208f112016-08-10 17:02:02 -070033 });
34
Matteo Scandoloef969922016-08-11 13:49:12 -070035 this.shell.setCommandHandler('explore', {
Matteo Scandolo4208f112016-08-10 17:02:02 -070036 exec: (cmd, args, done) => {
Matteo Scandoloef969922016-08-11 13:49:12 -070037 ExploreCmd.setup(this.shell);
38 done(TemplateHandler.instructions({
39 title: `You can now explore the API use angular $resouces!`,
40 messages: [
41 `Use <code>resource list</code> to list all the available resources and <code>resource {resoureName} {method} {?paramters}</code> to call the API.`,
42 `An example command is <code>resource Slices query</code>`,
43 `You can also provide paramters with <code>resource Slices query {max_instances: 10}</code>`
44 ]
45 }));
Matteo Scandolo4208f112016-08-10 17:02:02 -070046 }
47 });
48
Arpit Agarwal45fd7052016-08-16 09:33:22 -070049 this.shell.setCommandHandler('learn', {
50 exec: (cmd, args, done) => {
51 LearnCmd.setup(this.shell);
52 done(TemplateHandler.instructions({
53 title: `You can now learn the API`,
54 messages: [
55 `Use <code>next</code> to move to the next lesson <code>resource {resoureName} {method} {?paramters}</code> to call the API.`,
56 `An example command is <code>resource Slices query</code>`,
57 `You can also provide paramters with <code>next</code>`
58 ]
59 }));
60 }
61 });
Matteo Scandoloa81496a2016-08-16 17:29:42 -070062
63 this.shell.setCommandHandler('play', {
64 exec: (cmd, args, done) => {
65 PlayCmd.setup(this.shell);
66 done(TemplateHandler.instructions({
67 title: `You can now play with UI components!`,
68 messages: [
69 `Use <code>component list</code> to list all the available component and <code>component {componentName}</code> to startusing it.`,
70 `An example command is <code>component xosTable</code>`
71 ]
72 }));
73 }
74 });
Arpit Agarwal45fd7052016-08-16 09:33:22 -070075
Matteo Scandoloef969922016-08-11 13:49:12 -070076 this.shell.activate();
Matteo Scandoloa81496a2016-08-16 17:29:42 -070077
78 this.componentScope = null;
79
80 $rootScope.$on('uiTutorial.attachScope', (e, scope) => {
81 this.componentScope = {
82 config: JSON.stringify(codeToString.toString(scope.config), null, 2),
83 data: JSON.stringify(codeToString.toString(scope.data), null, 2)
84 };
85 });
86
87 this.applyScope = (scope) => {
88
89 // let a = codeToString.toCode(scope.config);
90 // console.log(a);
91 const newScope = {
92 config: codeToString.toCode(scope.config),
93 data: eval(`(${scope.data})`)
94 };
95
96 $rootScope.$emit('uiTutorial.applyScope', newScope);
97 }
98
Matteo Scandolo4208f112016-08-10 17:02:02 -070099 }
100 };
101});