Cleanup, class added to handle lesson info. Updates for plan,source and solution. Started work on cookies and params, not functioning quite yet

This commit is contained in:
Jason White
2014-09-01 22:30:46 -04:00
parent d414d1a5e4
commit d35f5e0348
7 changed files with 318 additions and 115 deletions

View File

@ -11,11 +11,17 @@ var goatConstants = {
children:null,
class:'fa-bars static'
}],
//services
lessonService: 'service/lessonmenu.mvc',
cookieService: 'service/cookies_widget.mvc',
hintService:'service/hint_widget.mvc',
cookieService: 'service/cookie.mvc', //cookies_widget.mvc
hintService:'service/hint.mvc',
sourceService:'service/source.mvc',
solutionService:'service/solution.mvc',
lessonPlanService:'service/lessonplan.mvc'
lessonPlanService:'service/lessonplan.mvc',
menuService: 'service/lessonmenu.mvc',
paramService: 'service/parms.mvc', //this is a stub .. need to discuss this
// literals
notFound: 'Could not find'
};

View File

@ -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,54 @@ 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
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) {
$scope.cookies=goat.lesson.lessonInfo.cookies;
$scope.params=goat.lesson.lessonInfo.params;
//@TODO: issue callback to track view
}
});
/* Controllers for modal instances */
/*
*DEPRECATED
//Controllers for modal instances
var showSourceController = function($scope, $modalInstance, lessonSource) {
$scope.lessonSource = lessonSource;
@ -89,7 +92,7 @@ var showSolutionController = function($scope, $modalInstance, lessonSolutionUrl)
$modalInstance.dismiss('cancel');
};
};
*/

View File

@ -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});
}
};

View File

@ -0,0 +1,108 @@
// 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);
}
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)
}
}
}
};

View File

@ -23,35 +23,71 @@ 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(goatConstants.cookieService, {}, function(reply) {
$("#lesson_cookies").html(reply);
}, "html");
},
showLessonHint: function() {
$.get(goatConstants.hintService, {}, function(reply) {
$("#lesson_hint").html(reply);
}, "html");
showLessonHints: function() {
$('.lessonHelp').hide();
$('#lesson_hint').html();
$('#lesson_hint_row').show();
},
showLessonSource: function() {
$.get(goatConstants.sourceService, {}, 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();
},
showLessonSolution: function() {
$.get(goatConstants.solutionService, {}, 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(goatConstants.lessonPlanService, {}, 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 paramObj = {};
var paramsArr = [];
for (var i=0;i< params.length;i++) {
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());