From 6cfefba0eef5c53d18d85280576b2e711a0ee448 Mon Sep 17 00:00:00 2001 From: Jason Date: Thu, 3 May 2018 10:25:34 -0600 Subject: [PATCH] work-arounds, fixes for page initialization and some clean-up --- .../js/goatApp/controller/LessonController.js | 43 +++---------------- .../js/goatApp/view/LessonContentView.js | 12 ++++-- .../js/goatApp/view/PaginationControlView.js | 10 ++--- 3 files changed, 20 insertions(+), 45 deletions(-) diff --git a/webgoat-container/src/main/resources/static/js/goatApp/controller/LessonController.js b/webgoat-container/src/main/resources/static/js/goatApp/controller/LessonController.js index e692e0beb..662b67702 100644 --- a/webgoat-container/src/main/resources/static/js/goatApp/controller/LessonController.js +++ b/webgoat-container/src/main/resources/static/js/goatApp/controller/LessonController.js @@ -73,6 +73,7 @@ define(['jquery', } this.loadLesson = function(name,pageNum) { + if (this.name === name) { this.listenToOnce(this.lessonHintView, 'hints:showButton', this.onShowHintsButton); this.listenTo(this.lessonHintView, 'hints:hideButton', this.onHideHintsButton); @@ -83,15 +84,15 @@ define(['jquery', return; } + if (pageNum && !this.name) { + //placeholder + } + this.helpsLoaded = {}; if (typeof(name) === 'undefined' || name === null) { //TODO: implement lesson not found or return to welcome page? } this.lessonContent.loadData({'name':name}); -// this.planView = {}; -// this.solutionView = {}; -// this.sourceView = {}; -// this.lessonHintView = {}; this.name = name; }; @@ -124,10 +125,7 @@ define(['jquery', this.helpControlsView = null; this.lessonContentView.model = this.lessonContent; this.lessonContentView.render(); - - //this.planView = new PlanView(); - //this.solutionView = new SolutionView(); - //this.sourceView = new SourceView(); + //TODO: consider moving hintView as child of lessonContentView ... if (this.lessonHintView) { this.lessonHintView.stopListening(); this.lessonHintView = null; @@ -152,35 +150,6 @@ define(['jquery', this.helpsLoaded[curHelp.helpElement] = curHelp.value; }; -// this.hideShowHelps = function(showHelp) { -// var showId = '#lesson-' + showHelp + '-row'; -// var contentId = '#lesson-' + showHelp + '-content'; -// $('.lesson-help').not(showId).hide(); -// if (!showId) { -// return; -// } -// -// if ($(showId).is(':visible')) { -// $(showId).hide(); -// return; -// } else { -// //TODO: move individual .html operations into individual help views -// switch(showHelp) { -// case 'plan': -// $(contentId).html(this.planView.model.get('content')); -// break; -// case 'solution': -// $(showId).html(this.solutionView.model.get('content')); -// break; -// case 'source': -// $(contentId).html('
' + this.sourceView.model.get('content') + '
'); -// break; -// } -// $(showId).show(); -// GoatUtils.scrollToHelp() -// } -// }; - this.showHintsView = function() { this.lessonHintView.render(); if (this.lessonHintView.getHintsCount > 0) { diff --git a/webgoat-container/src/main/resources/static/js/goatApp/view/LessonContentView.js b/webgoat-container/src/main/resources/static/js/goatApp/view/LessonContentView.js index 3fca490f0..75ff968b2 100644 --- a/webgoat-container/src/main/resources/static/js/goatApp/view/LessonContentView.js +++ b/webgoat-container/src/main/resources/static/js/goatApp/view/LessonContentView.js @@ -59,7 +59,7 @@ define(['jquery', var currentPage = (!isNaN(startPageNum) && startPageNum && startPageNum < this.$contentPages) ? startPageNum : 0; //init views & pagination this.showCurContentPage(currentPage); - this.paginationControlView = new PaginationControlView(this.$contentPages,this.model.get('lessonUrl')); + this.paginationControlView = new PaginationControlView(this.$contentPages,this.model.get('lessonUrl'),startPageNum); }, updatePagination: function() { @@ -187,13 +187,19 @@ define(['jquery', return endpoints; }, + onNavToPage: function(pageNum) { + var assignmentPaths = this.findAssigmentEndpointsOnPage(pageNum); + this.trigger('endpoints:filtered',assignmentPaths); + }, + navToPage: function (pageNum) { this.paginationControlView.setCurrentPage(pageNum);//provides validation this.showCurContentPage(this.paginationControlView.currentPage); this.paginationControlView.render(); this.paginationControlView.hideShowNavButtons(); - var assignmentPaths = this.findAssigmentEndpointsOnPage(pageNum); - this.trigger('endpoints:filtered',assignmentPaths); + this.onNavToPage(pageNum); + //var assignmentPaths = this.findAssigmentEndpointsOnPage(pageNum); + //this.trigger('endpoints:filtered',assignmentPaths); }, /* for testing */ diff --git a/webgoat-container/src/main/resources/static/js/goatApp/view/PaginationControlView.js b/webgoat-container/src/main/resources/static/js/goatApp/view/PaginationControlView.js index 2dcecf136..7dac8f063 100644 --- a/webgoat-container/src/main/resources/static/js/goatApp/view/PaginationControlView.js +++ b/webgoat-container/src/main/resources/static/js/goatApp/view/PaginationControlView.js @@ -12,14 +12,14 @@ define(['jquery', template: PaginationTemplate, el: '#lesson-page-controls', - initialize: function ($contentPages,baseLessonUrl) { + initialize: function ($contentPages,baseLessonUrl,initPageNum) { this.$contentPages = $contentPages; this.collection = new LessonOverviewCollection(); this.listenTo(this.collection, 'reset', this.render); this.numPages = this.$contentPages.length; this.baseUrl = baseLessonUrl; this.collection.fetch({reset:true}); - this.initPagination(); + this.initPagination(initPageNum); //this.render(); }, @@ -117,9 +117,9 @@ define(['jquery', $('span.glyphicon-class.glyphicon.glyphicon-circle-arrow-right.show-next-page').hide(); }, - initPagination: function() { - //track pagination state in this view ... start at 0 - this.currentPage = 0; + initPagination: function(initPageNum) { + //track pagination state in this view ... start at 0 .. unless a pageNum was provided + this.currentPage = !initPageNum ? 0 : initPageNum; }, setCurrentPage: function (pageNum) {