Polling for lesson updates (updates the menu and page navigation)

This commit is contained in:
Nanne Baars 2018-04-27 18:33:31 +02:00
parent 76daac0db5
commit e422da4c64
3 changed files with 46 additions and 35 deletions

View File

@ -40,17 +40,19 @@ public class LessonProgressService {
@RequestMapping(value = "/service/lessonprogress.mvc", produces = "application/json") @RequestMapping(value = "/service/lessonprogress.mvc", produces = "application/json")
@ResponseBody @ResponseBody
public Map getLessonInfo() { public Map getLessonInfo() {
UserTracker userTracker = userTrackerRepository.findByUser(webSession.getUserName());
LessonTracker lessonTracker = userTracker.getLessonTracker(webSession.getCurrentLesson());
Map json = Maps.newHashMap(); Map json = Maps.newHashMap();
String successMessage = ""; UserTracker userTracker = userTrackerRepository.findByUser(webSession.getUserName());
boolean lessonCompleted = false; if (webSession.getCurrentLesson() != null) {
if (lessonTracker != null) { LessonTracker lessonTracker = userTracker.getLessonTracker(webSession.getCurrentLesson());
lessonCompleted = lessonTracker.isLessonSolved(); String successMessage = "";
successMessage = "LessonCompleted"; //@todo we still use this?? boolean lessonCompleted = false;
if (lessonTracker != null) {
lessonCompleted = lessonTracker.isLessonSolved();
successMessage = "LessonCompleted"; //@todo we still use this??
}
json.put("lessonCompleted", lessonCompleted);
json.put("successMessage", successMessage);
} }
json.put("lessonCompleted", lessonCompleted);
json.put("successMessage", successMessage);
return json; return json;
} }

View File

@ -1,29 +1,33 @@
define(['jquery', define(['jquery',
'underscore', 'underscore',
'backbone', 'backbone',
'goatApp/model/MenuModel'], 'goatApp/model/MenuModel'],
function($,_,Backbone,MenuModel) { function ($, _, Backbone, MenuModel) {
return Backbone.Collection.extend({ return Backbone.Collection.extend({
model: MenuModel, model: MenuModel,
url:'service/lessonmenu.mvc', url: 'service/lessonmenu.mvc',
initialize: function () {
var self = this;
this.fetch();
},
onDataLoaded: function() { initialize: function () {
this.trigger('menuData:loaded'); var self = this;
}, this.fetch();
setInterval(function () {
this.fetch()
}.bind(this), 5000);
},
fetch: function() { onDataLoaded: function () {
var self=this; this.trigger('menuData:loaded');
Backbone.Collection.prototype.fetch.apply(this,arguments).then( },
function(data) {
this.models = data; fetch: function () {
self.onDataLoaded(); var self = this;
} Backbone.Collection.prototype.fetch.apply(this, arguments).then(
); function (data) {
} this.models = data;
}); self.onDataLoaded();
}); }
);
}
});
});

View File

@ -25,6 +25,9 @@ define(['jquery',
self.navToPage(page); self.navToPage(page);
} }
}); });
setInterval(function () {
this.updatePagination();
}.bind(this), 5000);
}, },
findPage: function(assignment) { findPage: function(assignment) {
@ -60,7 +63,9 @@ define(['jquery',
}, },
updatePagination: function() { updatePagination: function() {
this.paginationControlView.updateCollection(); if ( this.paginationControlView != undefined ) {
this.paginationControlView.updateCollection();
}
}, },
getCurrentPage: function () { getCurrentPage: function () {