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,9 +40,10 @@ public class LessonProgressService {
@RequestMapping(value = "/service/lessonprogress.mvc", produces = "application/json")
@ResponseBody
public Map getLessonInfo() {
UserTracker userTracker = userTrackerRepository.findByUser(webSession.getUserName());
LessonTracker lessonTracker = userTracker.getLessonTracker(webSession.getCurrentLesson());
Map json = Maps.newHashMap();
UserTracker userTracker = userTrackerRepository.findByUser(webSession.getUserName());
if (webSession.getCurrentLesson() != null) {
LessonTracker lessonTracker = userTracker.getLessonTracker(webSession.getCurrentLesson());
String successMessage = "";
boolean lessonCompleted = false;
if (lessonTracker != null) {
@ -51,6 +52,7 @@ public class LessonProgressService {
}
json.put("lessonCompleted", lessonCompleted);
json.put("successMessage", successMessage);
}
return json;
}

View File

@ -2,28 +2,32 @@ define(['jquery',
'underscore',
'backbone',
'goatApp/model/MenuModel'],
function($,_,Backbone,MenuModel) {
function ($, _, Backbone, MenuModel) {
return Backbone.Collection.extend({
model: MenuModel,
url:'service/lessonmenu.mvc',
url: 'service/lessonmenu.mvc',
initialize: function () {
var self = this;
this.fetch();
setInterval(function () {
this.fetch()
}.bind(this), 5000);
},
onDataLoaded: function() {
onDataLoaded: function () {
this.trigger('menuData:loaded');
},
fetch: function() {
var self=this;
Backbone.Collection.prototype.fetch.apply(this,arguments).then(
function(data) {
fetch: function () {
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);
}
});
setInterval(function () {
this.updatePagination();
}.bind(this), 5000);
},
findPage: function(assignment) {
@ -60,7 +63,9 @@ define(['jquery',
},
updatePagination: function() {
if ( this.paginationControlView != undefined ) {
this.paginationControlView.updateCollection();
}
},
getCurrentPage: function () {