|
6 | 6 | /** Lesson Controller (includes menu stuff)
|
7 | 7 | * prepares and updates menu topic items for the view
|
8 | 8 | */
|
9 |
| -goat.controller('goatLesson', function($scope, $http, $modal, $log, $sce) { //$templateCache |
| 9 | +//<<<<<<< Updated upstream |
| 10 | +//goat.controller('goatLesson', function($scope, $http, $modal, $log, $sce) { //$templateCache |
| 11 | +//======= |
| 12 | +var goatMenu = function($scope, $http, $modal, $log, $templateCache) { |
10 | 13 | $scope.cookies = [];
|
11 | 14 | $scope.params = [];
|
12 |
| - //TODO: implement via separate promise and use config for menu (goat.data.loadMenuData()) |
13 |
| - $http({method: 'GET', url: goatConstants.lessonService}).then( |
14 |
| - function(menuData) { |
15 |
| - var menuItems = goat.utils.addMenuClasses(goatConstants.menuPrefix.concat(menuData.data)); |
16 |
| - $scope.menuTopics = menuItems; |
17 |
| - }, |
18 |
| - function(error) { |
19 |
| - // TODO - handle this some way other than an alert |
20 |
| - console.error("Error rendering menu: " + error); |
21 |
| - } |
22 |
| - ); |
| 15 | + $scope.renderMenu = function() { |
| 16 | + goat.data.loadMenu($http).then( //$http({method: 'GET', url: goatConstants.lessonService}) |
| 17 | + function(menuData) { |
| 18 | + var menuItems = goat.utils.addMenuClasses(goatConstants.menuPrefix.concat(menuData.data)); |
| 19 | + for (var i=0;i<menuItems.length;i++) { |
| 20 | + if (menuItems[i].name) { |
| 21 | + menuItems[i].id = menuItems[i].name.replace(/\s|\(|\)/g,''); |
| 22 | + } |
| 23 | + } |
| 24 | + |
| 25 | + $scope.menuTopics = menuItems; |
| 26 | + }, |
| 27 | + function(error) { |
| 28 | + // TODO - handle this some way other than an alert |
| 29 | + console.error("Error rendering menu: " + error); |
| 30 | + } |
| 31 | + ); |
| 32 | + }; |
23 | 33 |
|
24 | 34 | $scope.renderLesson = function(url) {
|
25 | 35 | //console.log(url + ' was passed in');
|
26 | 36 | // use jquery to render lesson content to div
|
27 | 37 | $scope.hintIndex = 0;
|
28 |
| - |
29 | 38 | var curScope = $scope;
|
30 | 39 |
|
31 | 40 | curScope.parameters = goat.utils.scrapeParams(url);
|
32 |
| - goat.data.loadLessonContent(url).then( |
33 |
| - function(reply) { |
34 |
| - $("#lesson_content").html(reply); |
35 |
| - goat.data.loadLessonTitle().then( |
36 |
| - function(reply) { |
37 |
| - $("#lessonTitle").text(reply); |
38 |
| - } |
39 |
| - ); |
40 |
| - |
41 |
| - //hook forms |
42 |
| - goat.utils.makeFormsAjax(); |
43 |
| - $('#hintsView').hide(); |
44 |
| - // adjust menu to lessonContent size if necssary |
45 |
| - //@TODO: this is still clunky ... needs some TLC |
46 |
| - if ($('div.panel-body').height() > 400) { |
47 |
| - $('#leftside-navigation').height($(window).height()); |
48 |
| - } |
49 |
| - //cookies |
50 |
| - goat.data.loadCookies().then( |
51 |
| - function(resp) { |
52 |
| - curScope.cookies = resp; |
53 |
| - } |
54 |
| - ); |
55 |
| - //hints |
56 |
| - curScope.hintIndex = 0; |
57 |
| - goat.data.loadHints().then( |
58 |
| - function(resp) { |
59 |
| - curScope.hints = resp; |
60 |
| - if (curScope.hints.length > 0 && curScope.hints[0].hint.indexOf(goatConstants.noHints) === -1) { |
61 |
| - goat.utils.displayButton('showHintsBtn', true); |
62 |
| - } else { |
63 |
| - goat.utils.displayButton('showHintsBtn', false); |
64 |
| - } |
65 |
| - } |
66 |
| - ); |
67 |
| - //source |
68 |
| - goat.data.loadSource().then( |
69 |
| - function(resp) { |
70 |
| - curScope.source = resp; |
71 |
| - } |
72 |
| - ); |
73 |
| - //plan |
74 |
| - goat.data.loadPlan().then( |
75 |
| - function(resp) { |
76 |
| - curScope.plan = resp; |
77 |
| - } |
78 |
| - ); |
79 |
| - //solution |
80 |
| - goat.data.loadSolution().then( |
81 |
| - function(resp) { |
82 |
| - curScope.solution = resp; |
83 |
| - } |
84 |
| - ); |
85 |
| - goat.utils.scrollToTop(); |
86 |
| - } |
87 |
| - ); |
| 41 | + goat.data.loadLessonContent($http,url).then( |
| 42 | + function(reply) { |
| 43 | + goat.data.loadLessonTitle($http).then( |
| 44 | + function(reply) { |
| 45 | + $("#lessonTitle").text(reply.data); |
| 46 | + } |
| 47 | + ); |
| 48 | + $("#lesson_content").html(reply.data); |
| 49 | + $('#leftside-navigation').height($('#main-content').height()+15) |
| 50 | + } |
| 51 | + )}; |
| 52 | + $scope.accordionMenu = function(id) { |
| 53 | + if ($('ul#'+id).attr('isOpen') == 0) { |
| 54 | + $scope.expandMe = true; |
| 55 | + } else { |
| 56 | + $('ul#'+id).slideUp(300).attr('isOpen',0); |
| 57 | + return; |
| 58 | + } |
| 59 | + $('.lessonsAndStages').not('ul#'+id).slideUp(300).attr('isOpen',0); |
| 60 | + if ($scope.expandMe) { |
| 61 | + $('ul#'+id).slideDown(300).attr('isOpen',1); |
| 62 | + } |
| 63 | + console.log('accordion for ' + id); |
| 64 | + } |
| 65 | + $scope.renderMenu(); |
| 66 | + //can be augmented later to 'resume' for a given user ... currently kluged to start at fixed lesson |
| 67 | + var url = 'attack?Screen=32&menu=5'; |
| 68 | + angular.element($('#leftside-navigation')).scope().renderLesson(url); |
| 69 | +} |
| 70 | + |
| 71 | +/*goatMenu.animation('.slideDown', function() { |
| 72 | + var NgHideClassName = 'ng-hide'; |
| 73 | + return { |
| 74 | + beforeAddClass: function(element, className, done) { |
| 75 | + if (className === NgHideClassName) { |
| 76 | + $(element).slideUp(done); |
| 77 | + } |
| 78 | + }, |
| 79 | + removeClass: function(element, className, done) { |
| 80 | + if (className === NgHideClassName) { |
| 81 | + $(element).hide().slideDown(done); |
| 82 | + } |
| 83 | + } |
88 | 84 | };
|
89 | 85 |
|
| 86 | +
|
| 87 | +});*/ |
| 88 | + |
| 89 | +var goatLesson = function($scope,$http,$log) { |
| 90 | + //hook forms |
| 91 | + |
| 92 | + $('#hintsView').hide(); |
| 93 | + // adjust menu to lessonContent size if necssary |
| 94 | + //@TODO: this is still clunky ... needs some TLC |
| 95 | + if ($('div.panel-body').height() > 400) { |
| 96 | + $('#leftside-navigation').height($(window).height()); |
| 97 | + } |
| 98 | + //cookies |
| 99 | + goat.data.loadCookies($http).then( |
| 100 | + function(resp) { |
| 101 | + curScope.cookies = resp.data; |
| 102 | + } |
| 103 | + ); |
| 104 | + //hints |
| 105 | + curScope = $scope; //TODO .. update below, this curScope is probably not needed |
| 106 | + curScope.hintIndex = 0; |
| 107 | + goat.data.loadHints($http).then( |
| 108 | + function(resp) { |
| 109 | + curScope.hints = resp.data; |
| 110 | + if (curScope.hints.length > 0 && curScope.hints[0].hint.indexOf(goatConstants.noHints) === -1) { |
| 111 | + goat.utils.displayButton('showHintsBtn', true); |
| 112 | + } else { |
| 113 | + goat.utils.displayButton('showHintsBtn', false); |
| 114 | + } |
| 115 | + } |
| 116 | + ); |
| 117 | + //source |
| 118 | + goat.data.loadSource($http).then( |
| 119 | + function(resp) { |
| 120 | + curScope.source = resp.data; |
| 121 | + } |
| 122 | + ); |
| 123 | + //plan |
| 124 | + goat.data.loadPlan($http).then( |
| 125 | + function(resp) { |
| 126 | + curScope.plan = resp.data; |
| 127 | + } |
| 128 | + ); |
| 129 | + //solution |
| 130 | + goat.data.loadSolution($http).then( |
| 131 | + function(resp) { |
| 132 | + curScope.solution = resp.data; |
| 133 | + } |
| 134 | + ); |
| 135 | + goat.utils.scrollToTop(); |
| 136 | + |
| 137 | + |
90 | 138 | $scope.showLessonSource = function() {
|
91 | 139 | $('.lessonHelp').hide();
|
92 | 140 | $('#lesson_source_row').show();
|
@@ -164,22 +212,6 @@ goat.controller('goatLesson', function($scope, $http, $modal, $log, $sce) { //$t
|
164 | 212 | //remote: 'about.mvc'
|
165 | 213 | });
|
166 | 214 | };
|
| 215 | +} |
167 | 216 |
|
168 | 217 |
|
169 |
| -}).animation('.slideDown', function() { |
170 |
| - var NgHideClassName = 'ng-hide'; |
171 |
| - return { |
172 |
| - beforeAddClass: function(element, className, done) { |
173 |
| - if (className === NgHideClassName) { |
174 |
| - $(element).slideUp(done); |
175 |
| - } |
176 |
| - }, |
177 |
| - removeClass: function(element, className, done) { |
178 |
| - if (className === NgHideClassName) { |
179 |
| - $(element).hide().slideDown(done); |
180 |
| - } |
181 |
| - } |
182 |
| - }; |
183 |
| - |
184 |
| - |
185 |
| -}); |
|
0 commit comments