#277 Re-institute admin functionality for WebGoat 8
- Report card functionality is back
This commit is contained in:
@ -55,9 +55,9 @@ define(['jquery',
|
||||
this.lessonOverviewModel = new LessonOverviewModel();
|
||||
this.lessonOverview = new LessonOverviewView(this.lessonOverviewModel);
|
||||
this.lessonContentView = options.lessonContentView;
|
||||
this.titleView = options.titleView;
|
||||
this.developerControlsView = new DeveloperControlsView();
|
||||
|
||||
|
||||
_.extend(Controller.prototype,Backbone.Events);
|
||||
|
||||
this.start = function() {
|
||||
@ -67,12 +67,13 @@ define(['jquery',
|
||||
};
|
||||
|
||||
this.loadLesson = function(name,pageNum) {
|
||||
|
||||
if (this.name === name) {
|
||||
this.lessonContentView.navToPage(pageNum)
|
||||
this.lessonContentView.navToPage(pageNum);
|
||||
this.titleView.render(this.lessonInfoModel.get('lessonTitle'));
|
||||
return;
|
||||
}
|
||||
|
||||
this.titleView = new TitleView();
|
||||
this.helpsLoaded = {};
|
||||
if (typeof(name) === 'undefined' || name === null) {
|
||||
//TODO: implement lesson not found or return to welcome page?
|
||||
|
@ -2,7 +2,7 @@ define(['jquery',
|
||||
'underscore',
|
||||
'backbone',
|
||||
'goatApp/view/MenuView'
|
||||
],
|
||||
],
|
||||
function($,
|
||||
_,
|
||||
Backbone,
|
||||
@ -11,22 +11,9 @@ define(['jquery',
|
||||
_.extend(Controller.prototype,Backbone.Events);
|
||||
options = options || {};
|
||||
this.menuView = options.menuView;
|
||||
this.titleView = options.titleView;
|
||||
|
||||
// this.initMenu = function() {
|
||||
// this.listenTo(this.menuView,'lesson:click',this.renderTitle);
|
||||
// }
|
||||
|
||||
this.updateMenu = function(){
|
||||
this.menuView.updateMenu();
|
||||
},
|
||||
|
||||
//TODO: move title rendering into lessonContent/View pipeline once data can support it
|
||||
this.renderTitle = function(title) {
|
||||
this.titleView.render(title);
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
return Controller;
|
||||
|
@ -0,0 +1,8 @@
|
||||
define([
|
||||
'backbone'],
|
||||
function(
|
||||
Backbone) {
|
||||
return Backbone.Model.extend({
|
||||
url: 'service/reportcard.mvc'
|
||||
});
|
||||
});
|
@ -0,0 +1,47 @@
|
||||
<div class="panel panel-default" style="margin-top:25px">
|
||||
<div class="panel-heading alt"><b>Overview</b></div>
|
||||
|
||||
<table class="table">
|
||||
<tbody>
|
||||
<tr>
|
||||
<td width="30%">Total number of lessons</td>
|
||||
<td width="70%"><%= totalNumberOfLessons %></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td width="30%">Total number of lessons solved</td>
|
||||
<td width="70%"><%= numberOfLessonsSolved %></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td width="30%">Total number of assignments</td>
|
||||
<td width="70%"><%= totalNumberOfAssignments %></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td width="30%">Total number of assignments solved</td>
|
||||
<td width="70%"><%= numberOfAssignmentsSolved %></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="panel panel-default" style="margin-top:25px">
|
||||
<div class="panel-heading"><b>Lesson overview</b></div>
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Lesson name</th>
|
||||
<th>Solved</th>
|
||||
<th>Number of attempts</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<% _(lessonStatistics).each(function(lesson) { %>
|
||||
<%= lesson.solved ? '<tr class="success">' : '<tr>' %>
|
||||
<td><%= lesson.name %></td>
|
||||
<td><%= lesson.solved %></td>
|
||||
<td><%= lesson.numberOfAttempts %></td>
|
||||
</tr>
|
||||
<% }) %>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
@ -5,37 +5,56 @@ define(['jquery',
|
||||
'goatApp/controller/MenuController',
|
||||
'goatApp/view/LessonContentView',
|
||||
'goatApp/view/MenuView',
|
||||
'goatApp/view/DeveloperControlsView'
|
||||
], function ($,
|
||||
_,
|
||||
Backbone,
|
||||
LessonController,
|
||||
MenuController,
|
||||
LessonContentView,
|
||||
MenuView,
|
||||
DeveloperControlsView) {
|
||||
|
||||
'goatApp/view/DeveloperControlsView',
|
||||
'goatApp/view/TitleView'
|
||||
], function ($,
|
||||
_,
|
||||
Backbone,
|
||||
LessonController,
|
||||
MenuController,
|
||||
LessonContentView,
|
||||
MenuView,
|
||||
DeveloperControlsView,
|
||||
TitleView) {
|
||||
|
||||
var lessonContentView = new LessonContentView();
|
||||
var menuView = new MenuView();
|
||||
var developerControlsView = new DeveloperControlsView();
|
||||
var titleView = new TitleView();
|
||||
|
||||
function getContentElement() {
|
||||
return $('#main-content');
|
||||
};
|
||||
|
||||
function render(view) {
|
||||
$('div.pages').hide();
|
||||
//TODO this works for now because we only have one page we should rewrite this a bit
|
||||
if (view != null) {
|
||||
$('#report-card-page').show();
|
||||
} else {
|
||||
$('#lesson-title').show();
|
||||
$('#lesson-page').show();
|
||||
}
|
||||
};
|
||||
|
||||
var GoatAppRouter = Backbone.Router.extend({
|
||||
routes: {
|
||||
'welcome':'welcomeRoute',
|
||||
'lesson/:name':'lessonRoute',
|
||||
'lesson/:name/:pageNum':'lessonPageRoute',
|
||||
'test/:param':'testRoute'
|
||||
'welcome': 'welcomeRoute',
|
||||
'lesson/:name': 'lessonRoute',
|
||||
'lesson/:name/:pageNum': 'lessonPageRoute',
|
||||
'test/:param': 'testRoute',
|
||||
'reportCard': 'reportCard'
|
||||
},
|
||||
|
||||
lessonController: new LessonController({
|
||||
lessonContentView: lessonContentView
|
||||
lessonContentView: lessonContentView,
|
||||
titleView: titleView
|
||||
}),
|
||||
|
||||
menuController: new MenuController({
|
||||
menuView: menuView
|
||||
}),
|
||||
|
||||
|
||||
setUpCustomJS: function () {
|
||||
webgoat.customjs.jquery = $; //passing jquery into custom js scope ... still klunky, but works for now
|
||||
|
||||
@ -45,19 +64,19 @@ define(['jquery',
|
||||
console.log(arguments.callee);
|
||||
//
|
||||
webgoat.customjs.jquery.ajax({
|
||||
method:"POST",
|
||||
url:"/WebGoat/CrossSiteScripting/dom-xss",
|
||||
data:{param1:42,param2:24},
|
||||
headers:{
|
||||
"webgoat-requested-by":"dom-xss-vuln"
|
||||
},
|
||||
contentType:'application/x-www-form-urlencoded; charset=UTF-8'
|
||||
method: "POST",
|
||||
url: "/WebGoat/CrossSiteScripting/dom-xss",
|
||||
data: {param1: 42, param2: 24},
|
||||
headers: {
|
||||
"webgoat-requested-by": "dom-xss-vuln"
|
||||
},
|
||||
contentType: 'application/x-www-form-urlencoded; charset=UTF-8'
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
init:function() {
|
||||
goatRouter = new GoatAppRouter();
|
||||
init: function () {
|
||||
goatRouter = new GoatAppRouter();
|
||||
this.lessonController.start();
|
||||
// this.menuController.initMenu();
|
||||
webgoat = {};
|
||||
@ -65,39 +84,48 @@ define(['jquery',
|
||||
|
||||
this.setUpCustomJS();
|
||||
|
||||
|
||||
goatRouter.on('route:lessonRoute', function(name) {
|
||||
this.lessonController.loadLesson(name,0);
|
||||
goatRouter.on('route:lessonRoute', function (name) {
|
||||
render();
|
||||
this.lessonController.loadLesson(name, 0);
|
||||
//TODO - update menu code from below
|
||||
this.menuController.updateMenu(name);
|
||||
});
|
||||
|
||||
goatRouter.on('route:lessonPageRoute', function(name,pageNum) {
|
||||
goatRouter.on('route:lessonPageRoute', function (name, pageNum) {
|
||||
render();
|
||||
pageNum = (_.isNumber(parseInt(pageNum))) ? parseInt(pageNum) : 0;
|
||||
this.lessonController.loadLesson(name,pageNum);
|
||||
this.lessonController.loadLesson(name, pageNum);
|
||||
//TODO - update menu code from below
|
||||
this.menuController.updateMenu(name);
|
||||
});
|
||||
|
||||
goatRouter.on('route:welcomeRoute', function() {
|
||||
goatRouter.on('route:welcomeRoute', function () {
|
||||
render();
|
||||
this.lessonController.loadWelcome();
|
||||
});
|
||||
|
||||
goatRouter.on('route:testRoute', function(param) {
|
||||
goatRouter.on('route:testRoute', function (param) {
|
||||
render();
|
||||
this.lessonController.testHandler(param);
|
||||
});
|
||||
|
||||
goatRouter.on("route", function(route, params) {});
|
||||
goatRouter.on("route", function (route, params) {
|
||||
});
|
||||
|
||||
Backbone.history.start();
|
||||
this.listenTo(this.lessonController, 'menu:reload',this.reloadMenu)
|
||||
this.listenTo(this.lessonController, 'menu:reload', this.reloadMenu)
|
||||
},
|
||||
|
||||
reloadMenu: function (curLesson) {
|
||||
this.menuController.updateMenu();
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
reportCard : function () {
|
||||
require(['goatApp/view/ReportCardView'], function (ReportCardView) {
|
||||
titleView.render('Report card');
|
||||
render(new ReportCardView());
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
return GoatAppRouter;
|
||||
|
@ -0,0 +1,21 @@
|
||||
define(['jquery', 'backbone', 'underscore', 'goatApp/model/ReportCardModel', 'text!templates/report_card.html'],
|
||||
function ($, Backbone, _, ReportCardModel, ReportCardTemplate) {
|
||||
return Backbone.View.extend({
|
||||
el: '#report-card-page',
|
||||
template: ReportCardTemplate,
|
||||
|
||||
initialize: function () {
|
||||
var _this = this;
|
||||
this.model = new ReportCardModel();
|
||||
this.model.fetch().then(function() {
|
||||
_this.render();
|
||||
});
|
||||
},
|
||||
|
||||
render: function () {
|
||||
var t = _.template(this.template);
|
||||
this.$el.html(t(this.model.toJSON()));
|
||||
return this;
|
||||
}
|
||||
});
|
||||
});
|
Reference in New Issue
Block a user