blob: cb580844622260ff786741bca30e24122e5f27f3 [file] [log] [blame]
Arpit Agarwal45fd7052016-08-16 09:33:22 -07001(function () {
2 'use strict';
3 angular.module('xos.UITutorial')
4 .service('LearnCmd', function(LessonInfo, $cookies, ErrorHandler){
5
6
7 this.getCurrentLesson = (id,done)=>{
8 var details = LessonInfo.lessonCatalogue(id);
9 $cookies.put('lessonId', id);
10 done(details.text);
11 };
12
13 this.nextLesson = (shell) => {
14 this.shell = shell;
15 shell.setCommandHandler('next', {
16 exec: this.getNextLesson,
17 });
18 }
19
20 this.printLesson = (shell) => {
21 this.shell = shell;
22 shell.setCommandHandler('print', {
23 exec: this.printCurrentLesson,
24 });
25 };
26
27 this.prevLesson = (shell) => {
28 this.shell = shell;
29 shell.setCommandHandler('prev', {
30 exec: this.getPreviousLesson,
31 });
32 }
33
34 this.getLessonIdFromCookie = ()=>{
35 return $cookies.get('lessonId') ? parseInt($cookies.get('lessonId')) : -1;
36 };
37
38 this.getNextLesson = (cmd,arg,done)=>{
39 let lessonId = this.getLessonIdFromCookie();
40 return this.getCurrentLesson(lessonId+1,done) ;
41 };
42
43 this.getPreviousLesson = (cmd,arg,done)=>{
44 let lessonId = this.getLessonIdFromCookie();
45 if(lessonId>0) {
46 this.getCurrentLesson(lessonId-1,done)
47 }
48 else {
49 ErrorHandler.print(`This is the first Lesson`, done);
50 }
51 };
52
53 this.printCurrentLesson = (cmd,args,done)=>{
54 if (args[0]){
55 this.getCurrentLesson(args[0], done);
56 }
57 else {
58 let lessonId = this.getLessonIdFromCookie();
59 if (lessonId > -1) {
60 this.getCurrentLesson(lessonId, done)
61 }
62 else {
63 ErrorHandler.print(`This is the first Lesson`, done);
64 }
65 }
66 };
67
68 this.setup = (shell) => {
69 this.shell = shell;
70 this.nextLesson(shell);
71 this.prevLesson(shell);
72 this.printLesson(shell);
73 };
74
75 });
76})();