Skip to content

Commit

Permalink
Polling for lesson updates (updates the menu and page navigation)
Browse files Browse the repository at this point in the history
  • Loading branch information
nbaars committed Apr 27, 2018
1 parent 76daac0 commit e422da4
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,19 @@ 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();
String successMessage = "";
boolean lessonCompleted = false;
if (lessonTracker != null) {
lessonCompleted = lessonTracker.isLessonSolved();
successMessage = "LessonCompleted"; //@todo we still use this??
UserTracker userTracker = userTrackerRepository.findByUser(webSession.getUserName());
if (webSession.getCurrentLesson() != null) {
LessonTracker lessonTracker = userTracker.getLessonTracker(webSession.getCurrentLesson());
String successMessage = "";
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;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,29 +1,33 @@
define(['jquery',
'underscore',
'backbone',
'goatApp/model/MenuModel'],
function($,_,Backbone,MenuModel) {
'underscore',
'backbone',
'goatApp/model/MenuModel'],
function ($, _, Backbone, MenuModel) {

return Backbone.Collection.extend({
model: MenuModel,
url:'service/lessonmenu.mvc',
initialize: function () {
var self = this;
this.fetch();
},
return Backbone.Collection.extend({
model: MenuModel,
url: 'service/lessonmenu.mvc',

onDataLoaded: function() {
this.trigger('menuData:loaded');
},
initialize: function () {
var self = this;
this.fetch();
setInterval(function () {
this.fetch()
}.bind(this), 5000);
},

fetch: function() {
var self=this;
Backbone.Collection.prototype.fetch.apply(this,arguments).then(
function(data) {
this.models = data;
self.onDataLoaded();
}
);
}
});
});
onDataLoaded: function () {
this.trigger('menuData:loaded');
},

fetch: function () {
var self = this;
Backbone.Collection.prototype.fetch.apply(this, arguments).then(
function (data) {
this.models = data;
self.onDataLoaded();
}
);
}
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ define(['jquery',
self.navToPage(page);
}
});
setInterval(function () {
this.updatePagination();
}.bind(this), 5000);
},

findPage: function(assignment) {
Expand Down Expand Up @@ -60,7 +63,9 @@ define(['jquery',
},

updatePagination: function() {
this.paginationControlView.updateCollection();
if ( this.paginationControlView != undefined ) {
this.paginationControlView.updateCollection();
}
},

getCurrentPage: function () {
Expand Down

0 comments on commit e422da4

Please sign in to comment.