blob: d76b45f46166cb83b34466c24386349ec1608974 [file] [log] [blame]
Matteo Scandolod2044a42017-08-07 16:08:28 -07001
2/*
3 * Copyright 2017-present Open Networking Foundation
4
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8
9 * http://www.apache.org/licenses/LICENSE-2.0
10
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18
Arpit Agarwal45fd7052016-08-16 09:33:22 -070019(function () {
20 'use strict';
21 angular.module('xos.UITutorial')
22 .service('LearnCmd', function(LessonInfo, $cookies, ErrorHandler){
23
24
25 this.getCurrentLesson = (id,done)=>{
26 var details = LessonInfo.lessonCatalogue(id);
27 $cookies.put('lessonId', id);
28 done(details.text);
29 };
30
31 this.nextLesson = (shell) => {
32 this.shell = shell;
33 shell.setCommandHandler('next', {
34 exec: this.getNextLesson,
35 });
36 }
37
38 this.printLesson = (shell) => {
39 this.shell = shell;
40 shell.setCommandHandler('print', {
41 exec: this.printCurrentLesson,
42 });
43 };
44
45 this.prevLesson = (shell) => {
46 this.shell = shell;
47 shell.setCommandHandler('prev', {
48 exec: this.getPreviousLesson,
49 });
50 }
51
52 this.getLessonIdFromCookie = ()=>{
53 return $cookies.get('lessonId') ? parseInt($cookies.get('lessonId')) : -1;
54 };
55
56 this.getNextLesson = (cmd,arg,done)=>{
57 let lessonId = this.getLessonIdFromCookie();
58 return this.getCurrentLesson(lessonId+1,done) ;
59 };
60
61 this.getPreviousLesson = (cmd,arg,done)=>{
62 let lessonId = this.getLessonIdFromCookie();
63 if(lessonId>0) {
64 this.getCurrentLesson(lessonId-1,done)
65 }
66 else {
67 ErrorHandler.print(`This is the first Lesson`, done);
68 }
69 };
70
71 this.printCurrentLesson = (cmd,args,done)=>{
72 if (args[0]){
73 this.getCurrentLesson(args[0], done);
74 }
75 else {
76 let lessonId = this.getLessonIdFromCookie();
77 if (lessonId > -1) {
78 this.getCurrentLesson(lessonId, done)
79 }
80 else {
81 ErrorHandler.print(`This is the first Lesson`, done);
82 }
83 }
84 };
85
86 this.setup = (shell) => {
87 this.shell = shell;
88 this.nextLesson(shell);
89 this.prevLesson(shell);
90 this.printLesson(shell);
91 };
92
93 });
94})();