hints view fix. still a redundant call issue, but logging separately

This commit is contained in:
Jason White 2017-05-10 13:07:29 +01:00
parent 194a327ad5
commit 118079233d
5 changed files with 65 additions and 35 deletions

View File

@ -1030,10 +1030,11 @@ span.show-next-page, span.show-prev-page {
} }
#lesson-hint { #lesson-hint {
background-color: #ccc; background-color: #f1f1f1;
border-radius: 4px; border-radius: 4px;
border-color: #999; border-color: #4fa44c;
margin-top: 4px; margin-top: 4px;
border: 2px solid #24b054;
} }
#hintsViewTop{ #hintsViewTop{

View File

@ -64,13 +64,29 @@ define(['jquery',
this.menuButtonView = new MenuButtonView(); this.menuButtonView = new MenuButtonView();
this.listenTo(this.lessonContentView, 'assignment:complete', this.updateMenu); this.listenTo(this.lessonContentView, 'assignment:complete', this.updateMenu);
this.listenTo(this.lessonContentView, 'assignment:complete', this.updateLessonOverview); this.listenTo(this.lessonContentView, 'assignment:complete', this.updateLessonOverview);
this.listenTo(this.lessonContentView, 'endpoints:filtered', this.filterPageHints);
}; };
this.loadLesson = function(name,pageNum) { this.filterPageHints = function(endpoints) {
//filter hints for page by
this.lessonHintView.filterHints(endpoints);
}
this.onHideHintsButton = function() {
this.helpControlsView.hideHintsButton();
}
this.onShowHintsButton = function() {
this.helpControlsView.showHintsButton();
}
this.loadLesson = function(name,pageNum) {
if (this.name === name) { if (this.name === name) {
this.listenTo(this.lessonHintView, 'hints:showButton', this.onShowHintsButton);
this.listenTo(this.lessonHintView, 'hints:hideButton', this.onHideHintsButton);
this.lessonContentView.navToPage(pageNum); this.lessonContentView.navToPage(pageNum);
this.lessonHintView.hideHints(); this.lessonHintView.hideHints();
//this.lessonHintView.selectHints();
this.titleView.render(this.lessonInfoModel.get('lessonTitle')); this.titleView.render(this.lessonInfoModel.get('lessonTitle'));
return; return;
} }
@ -83,7 +99,7 @@ define(['jquery',
// this.planView = {}; // this.planView = {};
// this.solutionView = {}; // this.solutionView = {};
// this.sourceView = {}; // this.sourceView = {};
this.lessonHintView = {}; // this.lessonHintView = {};
this.name = name; this.name = name;
}; };
@ -96,15 +112,13 @@ define(['jquery',
this.listenTo(this.helpControlsView,'hints:show',this.showHints); this.listenTo(this.helpControlsView,'hints:show',this.showHints);
this.listenTo(this.helpControlsView,'lessonOverview:show',this.showLessonOverview) this.listenTo(this.helpControlsView,'lessonOverview:show',this.showLessonOverview)
// this.listenTo(this.helpControlsView,'solution:show',this.hideShowHelps);
// this.listenTo(this.helpControlsView,'source:show',this.hideShowHelps);
this.listenTo(this.helpControlsView,'lesson:restart',this.restartLesson); this.listenTo(this.helpControlsView,'lesson:restart',this.restartLesson);
this.listenTo(this.developerControlsView, 'dev:labels', this.restartLesson); this.listenTo(this.developerControlsView, 'dev:labels', this.restartLesson);
this.helpControlsView.render(); this.helpControlsView.render();
this.lessonOverview.hideLessonOverview(); this.lessonOverview.hideLessonOverview();
this.titleView.render(this.lessonInfoModel.get('lessonTitle')); this.titleView.render(this.lessonInfoModel.get('lessonTitle'));
this.helpControlsView.showHideHintsButton({});
}; };
this.updateMenu = function() { this.updateMenu = function() {
@ -127,6 +141,10 @@ define(['jquery',
//this.planView = new PlanView(); //this.planView = new PlanView();
//this.solutionView = new SolutionView(); //this.solutionView = new SolutionView();
//this.sourceView = new SourceView(); //this.sourceView = new SourceView();
if (this.lessonHintView) {
this.lessonHintView.stopListening();
this.lessonHintView = null;
}
this.lessonHintView = new HintView(); this.lessonHintView = new HintView();
//TODO: instantiate model with values (not sure why was not working before) //TODO: instantiate model with values (not sure why was not working before)

View File

@ -12,18 +12,14 @@ function($,_,Backbone) {
this.hasPlan = options.hasPlan; this.hasPlan = options.hasPlan;
this.hasSolution = options.hasSolution; this.hasSolution = options.hasSolution;
this.hasSource = options.hasSource; this.hasSource = options.hasSource;
var self = this;
Backbone.on('navigatedToPage', function(nav) {
self.showHideHintsButton(nav)
});
}, },
showHideHintsButton: function(nav) { showHintsButton: function(nav) {
if (typeof nav['assignmentPath'] !== 'undefined') {
this.$el.find('#show-hints-button').unbind().on('click',this.showHints.bind(this)).show(); this.$el.find('#show-hints-button').unbind().on('click',this.showHints.bind(this)).show();
} else { },
hideHintsButton: function(){
$('#show-hints-button').hide(); $('#show-hints-button').hide();
}
}, },
render:function(title) { render:function(title) {

View File

@ -19,8 +19,10 @@ function($,
this.listenTo(this.collection,'loaded',this.onModelLoaded); this.listenTo(this.collection,'loaded',this.onModelLoaded);
this.hideHints(); this.hideHints();
var self = this; var self = this;
// different way to do this?
Backbone.on('navigatedToPage', function(nav){ Backbone.on('navigatedToPage', function(nav){
self.selectHints(nav) self.selectHints(nav);
// end event delegation??
}); });
}, },
@ -61,16 +63,27 @@ function($,
* *
* @param nav the json structure for navigating * @param nav the json structure for navigating
*/ */
selectHints: function(nav) { filterHints: function(endpoints) {
this.curHint = 0; this.hintsToShow = [];
var assignmentPath = nav['assignmentPath']; _.each(endpoints, this.filterHint, this);
if (assignmentPath != null) {
this.hintsToShow = this.collection.getHintsForAssignment(assignmentPath); if (this.hintsToShow.length > 0) {
this.trigger('hints:showButton');
} else { } else {
this.hintsToShow = new Array(); this.trigger('hints:hideButton');
} }
}, },
filterHint: function(endpoint) {
var self = this;
_.each(this.collection.models, function(hintModel) {
if (endpoint.indexOf(hintModel.get('assignmentPath')) > -1) {
self.hintsToShow.push(hintModel.get('hint'));
}
});
console.log(this.hintsToShow);
},
onModelLoaded: function() { onModelLoaded: function() {
this.trigger('hints:loaded',{'helpElement':'hints','value':true}) this.trigger('hints:loaded',{'helpElement':'hints','value':true})
}, },
@ -97,7 +110,7 @@ function($,
if(this.hintsToShow.length == 0) { if(this.hintsToShow.length == 0) {
// this.hideHints(); // this.hideHints();
} else { } else {
this.$el.find('#lesson-hint-content').html(polyglot.t(this.hintsToShow[curHint].get('hint'))); this.$el.find('#lesson-hint-content').html(polyglot.t(this.hintsToShow[curHint]));
} }
}, },

View File

@ -153,13 +153,15 @@ define(['jquery',
this.$el.find(this.$contentPages[pageNum]).show(); this.$el.find(this.$contentPages[pageNum]).show();
}, },
findAssigmentEndpointOnPage: function(pageNumber) { findAssigmentEndpointsOnPage: function(pageNumber) {
var contentPage = this.$contentPages[this.currentPage]; var contentPage = this.$contentPages[pageNumber];
var form = $('form.attack-form', contentPage); var endpoints = []; //going to assume uniqueness since these are assignments
var action = form.attr('action') var pageForms = $(contentPage).find('form.attack-form');
if (action !== undefined) { for (var i=0; i<pageForms.length; i++) {
return action; endpoints.push(pageForms[i].action);
} }
console.log(endpoints);
return endpoints;
}, },
navToPage: function (pageNum) { navToPage: function (pageNum) {
@ -167,8 +169,8 @@ define(['jquery',
this.showCurContentPage(this.paginationControlView.currentPage); this.showCurContentPage(this.paginationControlView.currentPage);
this.paginationControlView.render(); this.paginationControlView.render();
this.paginationControlView.hideShowNavButtons(); this.paginationControlView.hideShowNavButtons();
var assignmentPath = this.findAssigmentEndpointOnPage(pageNum); var assignmentPaths = this.findAssigmentEndpointsOnPage(pageNum);
Backbone.trigger('navigatedToPage',{'pageNumber':pageNum, 'assignmentPath' : assignmentPath}); this.trigger('endpoints:filtered',assignmentPaths);
}, },
/* for testing */ /* for testing */