Merge branch 'next' of https://github.com/WebGoat/WebGoat into next
Conflicts: src/main/webapp/WEB-INF/pages/main_new.jsp src/main/webapp/css/main.css overrode the local with the remote version
This commit is contained in:
@ -11,6 +11,16 @@ var goatConstants = {
|
||||
children:null,
|
||||
class:'fa-bars static'
|
||||
}],
|
||||
lessonService: 'service/lessonmenu.mvc'
|
||||
//services
|
||||
lessonService: 'service/lessonmenu.mvc',
|
||||
cookieService: 'service/cookie.mvc', //cookies_widget.mvc
|
||||
hintService:'service/hint.mvc',
|
||||
sourceService:'service/source.mvc',
|
||||
solutionService:'service/solution.mvc',
|
||||
lessonPlanService:'service/lessonplan.mvc',
|
||||
menuService: 'service/lessonmenu.mvc',
|
||||
// literals
|
||||
notFound: 'Could not find'
|
||||
};
|
||||
|
||||
|
||||
|
@ -6,7 +6,7 @@
|
||||
/** Menu Controller
|
||||
* prepares and updates menu topic items for the view
|
||||
*/
|
||||
goat.controller('goatLesson', function($scope, $http, $modal, $log, $templateCache) {
|
||||
goat.controller('goatLessonMenu', function($scope, $http, $modal, $log, $templateCache) {
|
||||
//TODO: implement via separate promise and use config for menu (goat.data.loadMenuData())
|
||||
$http({method: 'GET', url: goatConstants.lessonService}).then(
|
||||
function(menuData) {
|
||||
@ -19,51 +19,58 @@ goat.controller('goatLesson', function($scope, $http, $modal, $log, $templateCac
|
||||
}
|
||||
);
|
||||
$scope.renderLesson = function(url) {
|
||||
console.log(url + ' was passed in');
|
||||
//console.log(url + ' was passed in');
|
||||
// use jquery to render lesson content to div
|
||||
goat.data.loadLessonContent(url).then(
|
||||
function(reply) {
|
||||
$("#lesson_content").html(reply);
|
||||
// hook forms
|
||||
goat.utils.makeFormsAjax();
|
||||
//render lesson title
|
||||
$('#lessonTitle').text(goat.utils.extractLessonTitle($(reply)));
|
||||
// adjust menu to lessonContent size if necssary
|
||||
//@TODO: this is still clunky ... needs some TLC
|
||||
if ($('div.panel-body').height() > 400) {
|
||||
$('#leftside-navigation').height($(window).height());
|
||||
}
|
||||
// hook into our pseudo service calls
|
||||
// @TODO make these real services during phase 2
|
||||
// show cookies and params
|
||||
goat.utils.showLessonCookiesAndParams();
|
||||
// show hints
|
||||
goat.utils.showLessonHint();
|
||||
// show plan
|
||||
goat.utils.showLessonPlan();
|
||||
// show solution
|
||||
goat.utils.showLessonSolution();
|
||||
// show source
|
||||
goat.utils.showLessonSource();
|
||||
goat.lesson.lessonInfo = new goat.lesson.CurLesson(url);
|
||||
goat.lesson.lessonInfo.loadInfo(); //uses pseudo and actual service calls
|
||||
// @TODO: convert to real services (and more angularjs, likely ... in phase 2)
|
||||
}
|
||||
);
|
||||
};
|
||||
}).animation('.slideDown', function() {
|
||||
var NgHideClassName = 'ng-hide';
|
||||
return {
|
||||
beforeAddClass: function(element, className, done) {
|
||||
if (className === NgHideClassName) {
|
||||
$(element).slideUp(done);
|
||||
}
|
||||
},
|
||||
removeClass: function(element, className, done) {
|
||||
if (className === NgHideClassName) {
|
||||
$(element).hide().slideDown(done);
|
||||
}
|
||||
}
|
||||
);
|
||||
};
|
||||
}).animation('.slideDown', function() {
|
||||
var NgHideClassName = 'ng-hide';
|
||||
return {
|
||||
beforeAddClass: function(element, className, done) {
|
||||
if (className === NgHideClassName) {
|
||||
$(element).slideUp(done);
|
||||
}
|
||||
},
|
||||
removeClass: function(element, className, done) {
|
||||
if (className === NgHideClassName) {
|
||||
$(element).hide().slideDown(done);
|
||||
}
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
goat.controller('lessonHelpController', function($scope) {
|
||||
$scope.cookies=[];
|
||||
$scope.params=[];
|
||||
$scope.viewCookiesAndParams = function() {
|
||||
$scope.cookies=goat.lesson.lessonInfo.cookies;
|
||||
console.log($scope.cookies);
|
||||
$scope.params=goat.lesson.lessonInfo.params;
|
||||
|
||||
//@TODO: issue callback to track view
|
||||
};
|
||||
//$scope.watch()
|
||||
});
|
||||
|
||||
|
||||
/* Controllers for modal instances */
|
||||
/*
|
||||
*DEPRECATED
|
||||
//Controllers for modal instances
|
||||
var showSourceController = function($scope, $modalInstance, lessonSource) {
|
||||
|
||||
$scope.lessonSource = lessonSource;
|
||||
@ -89,7 +96,7 @@ var showSolutionController = function($scope, $modalInstance, lessonSolutionUrl)
|
||||
$modalInstance.dismiss('cancel');
|
||||
};
|
||||
};
|
||||
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
@ -1,13 +1,34 @@
|
||||
/* ### GOAT DATA/PROMISES ### */
|
||||
|
||||
goat.data = {
|
||||
/**** jQuery loads ... ****/
|
||||
loadLessonContent: function (_url) {
|
||||
//TODO: switch to $http (angular) later
|
||||
//return $http({method:'GET', url: _url});
|
||||
|
||||
return $.get(_url, {}, null, "html");
|
||||
},
|
||||
loadCookies: function() {
|
||||
return $.get(goatConstants.cookieService, {});
|
||||
},
|
||||
loadHints: function () {
|
||||
return $.get(goatConstants.hintService, {});
|
||||
},
|
||||
loadSource: function() {
|
||||
return $.get(goatConstants.sourceService, {});
|
||||
},
|
||||
loadSolution: function () {
|
||||
return $.get(goatConstants.solutionService, {})
|
||||
},
|
||||
loadPlan: function () {
|
||||
return $.get(goatConstants.lessonPlanService, {});
|
||||
},
|
||||
loadParams: function() {
|
||||
return $.get(goatConstants.paramsService,{});
|
||||
},
|
||||
/*** angular data grabs ***/
|
||||
loadMenuData: function() {
|
||||
//TODO use goatConstants var for url
|
||||
return $http({method: 'GET', url: 'service/lessonmenu.mvc'});
|
||||
return $http({method: 'GET', url: goatConstants.menuService});
|
||||
}
|
||||
};
|
||||
|
110
src/main/webapp/js/goatLesson.js
Normal file
110
src/main/webapp/js/goatLesson.js
Normal file
@ -0,0 +1,110 @@
|
||||
// goat.lesson name space
|
||||
goat.lesson = {
|
||||
CurLesson: function(_lessonUrl) {
|
||||
return {
|
||||
hints:[],
|
||||
hintIndex:0,
|
||||
solution:null,
|
||||
plan:null,
|
||||
cookiesAndParams:[],
|
||||
params:[],
|
||||
source:null,
|
||||
lessonUrl:(_lessonUrl || null),
|
||||
clearInfo: function() {
|
||||
this.hints = null;
|
||||
this.solution = null;
|
||||
this.plan = null;
|
||||
this.cookies = null;
|
||||
this.source = null;
|
||||
this.params = null;
|
||||
},
|
||||
loadInfo: function() {
|
||||
this.getHints();
|
||||
this.getPlan();
|
||||
this.getSolution();
|
||||
this.getCookies();
|
||||
this.getSource();
|
||||
this.getParams();
|
||||
},
|
||||
getHints:function() {
|
||||
var scope = this;
|
||||
goat.data.loadHints().then(
|
||||
function(resp) {
|
||||
scope.hints = resp;
|
||||
if (scope.hints.length > 0) {
|
||||
goat.utils.displayButton('showHintsBtn',true);
|
||||
} else {
|
||||
goat.utils.displayButton('showHintsBtn',false);
|
||||
}
|
||||
return scope;
|
||||
},
|
||||
function(err){
|
||||
goat.utils.displayButton('showHintsBtn',false);
|
||||
//TODO handle errors
|
||||
}
|
||||
);
|
||||
},
|
||||
getSolution:function() {
|
||||
var scope = this;
|
||||
goat.data.loadSolution().then(
|
||||
function(resp) {
|
||||
scope.solution = resp;
|
||||
goat.utils.displayButton('showSolutionBtn',true);
|
||||
$('#showSolutionBtn').unbind().click(goat.utils.showLessonSolution);
|
||||
return scope;
|
||||
},
|
||||
function(err){
|
||||
scope.solution = null;
|
||||
goat.utils.displayButton('showSolutionBtn',false);
|
||||
//TODO handle errors
|
||||
}
|
||||
);
|
||||
},
|
||||
getPlan: function() {
|
||||
var scope = this;
|
||||
goat.data.loadPlan().then(
|
||||
function(resp) {
|
||||
scope.plan = resp;
|
||||
goat.utils.displayButton('showPlanBtn',true);
|
||||
$('#showPlanBtn').unbind().click(goat.utils.showLessonPlan);
|
||||
return scope;
|
||||
},
|
||||
function(err){
|
||||
goat.utils.displayButton('showPlanBtn',false);
|
||||
//TODO handle errors
|
||||
}
|
||||
);
|
||||
},
|
||||
getSource: function() {
|
||||
var scope = this;
|
||||
goat.data.loadSource().then(
|
||||
function(resp) {
|
||||
scope.source = resp;
|
||||
goat.utils.displayButton('showSourceBtn',true);
|
||||
$('#showSourceBtn').unbind().click(goat.utils.showLessonSource);
|
||||
return scope;
|
||||
},
|
||||
function(err){
|
||||
goat.utils.displayButton('showSourceBtn',false);
|
||||
//TODO handle errors
|
||||
}
|
||||
);
|
||||
},
|
||||
getCookies: function() {
|
||||
var scope = this;
|
||||
goat.data.loadCookies().then(
|
||||
function(resp) {
|
||||
scope.cookies = resp;
|
||||
return scope;
|
||||
},
|
||||
function(err){
|
||||
//TODO handle errors
|
||||
}
|
||||
);
|
||||
},
|
||||
getParams: function() {
|
||||
this.params = goat.utils.scrapeParams(this.lessonUrl)
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
@ -23,35 +23,72 @@ goat.utils = {
|
||||
var title = $('h1', el).text();
|
||||
return title;
|
||||
},
|
||||
displayButton: function(id,show) {
|
||||
if ($('#'+id)) {
|
||||
if (show) {
|
||||
$('#'+id).show();
|
||||
} else {
|
||||
$('#'+id).hide();
|
||||
}
|
||||
}
|
||||
},
|
||||
showLessonCookiesAndParams: function() {
|
||||
$.get("service/cookies_widget.mvc", {}, function(reply) {
|
||||
$.get(goatConstants.cookieService, {}, function(reply) {
|
||||
$("#lesson_cookies").html(reply);
|
||||
}, "html");
|
||||
},
|
||||
showLessonHint: function() {
|
||||
$.get("service/hint_widget.mvc", {}, function(reply) {
|
||||
$("#lesson_hint").html(reply);
|
||||
}, "html");
|
||||
showLessonHints: function() {
|
||||
$('.lessonHelp').hide();
|
||||
$('#lesson_hint').html();
|
||||
$('#lesson_hint_row').show();
|
||||
},
|
||||
showLessonSource: function() {
|
||||
$.get("service/source.mvc", {}, function(reply) {
|
||||
$("#lesson_source").html("<pre>"+reply+"</pre>");
|
||||
}, "html");
|
||||
showLessonSource: function(source) {
|
||||
$('.lessonHelp').hide();
|
||||
$('#lesson_source').html("<pre>"+goat.lesson.lessonInfo.source+"</pre>");
|
||||
$('#lesson_source_row').show();
|
||||
goat.utils.scrollToHelp();
|
||||
},
|
||||
showLessonSolution: function() {
|
||||
$.get("service/solution.mvc", {}, function(reply) {
|
||||
$("#lesson_solution").html(reply);
|
||||
}, "html");
|
||||
$('.lessonHelp').hide();
|
||||
$('#lesson_solution').html(goat.lesson.lessonInfo.solution);
|
||||
$('#lesson_solution_row').show();
|
||||
goat.utils.scrollToHelp();
|
||||
},
|
||||
showLessonPlan: function() {
|
||||
$.get("service/lessonplan.mvc", {}, function(reply) {
|
||||
$("#lesson_plan").html(reply);
|
||||
}, "html");
|
||||
showLessonPlan: function(plan) {
|
||||
$('.lessonHelp').hide();
|
||||
$("#lesson_plan").html(goat.lesson.lessonInfo.plan);
|
||||
$('#lesson_plan_row').show();
|
||||
goat.utils.scrollToHelp();
|
||||
},
|
||||
scrollToHelp:function() {
|
||||
var target = $('#lessonHelpsWrapper');
|
||||
goat.utils.scrollEasy(target);
|
||||
},
|
||||
scrollToTop: function() {
|
||||
var target= $('#container');
|
||||
goat.utils.scrollEasy(target);
|
||||
},
|
||||
scrollEasy:function(target) {
|
||||
$('html,body').animate({
|
||||
scrollTop: target.offset().top
|
||||
}, 1000);
|
||||
},
|
||||
scrapeParams: function(url) {
|
||||
if (!url) {
|
||||
return;
|
||||
}
|
||||
var params = url.split('?')[1].split('&');
|
||||
var paramsArr = [];
|
||||
for (var i=0;i< params.length;i++) {
|
||||
var paramObj = {};
|
||||
paramObj.name = params[i].split('=')[0];
|
||||
paramObj.value = params[i].split('=')[1];
|
||||
paramsArr.push(paramObj);
|
||||
}
|
||||
return paramsArr;
|
||||
}
|
||||
};
|
||||
|
||||
// ### GLOBAL FUNCTIONS ## //
|
||||
|
||||
|
||||
$(window).resize(function() {
|
||||
//$('#leftside-navigation').css('height',$('div.panel-body').height());
|
||||
|
Reference in New Issue
Block a user