Fix autoupdate after auth

Remove data after logout
This commit is contained in:
Oskar Hahn 2016-01-09 17:32:33 +01:00
parent dba513c2fd
commit 5069649e14
2 changed files with 40 additions and 26 deletions

View File

@ -30,33 +30,42 @@ angular.module('OpenSlidesApp.core', [
DSHttpAdapterProvider.defaults.forceTrailingSlash = true; DSHttpAdapterProvider.defaults.forceTrailingSlash = true;
}]) }])
.factory('autoupdate', function() { .factory('autoupdate', [
var url = location.origin + "/sockjs"; 'DS',
function (DS) {
var url = location.origin + "/sockjs";
var socket;
var Autoupdate = {
socket: null,
message_receivers: [],
connect: function () {
var autoupdate = this;
socket = this.socket = new SockJS(url);
var Autoupdate = {
socket: null,
message_receivers: [],
connect: function() {
var autoupdate = this;
this.socket = new SockJS(url);
this.socket.onmessage = function(event) { this.socket.onmessage = function (event) {
_.forEach(autoupdate.message_receivers, function(receiver) { _.forEach(autoupdate.message_receivers, function (receiver) {
receiver(event.data); receiver(event.data);
}); });
}; };
this.socket.onclose = function() { this.socket.onclose = function () {
setTimeout(autoupdate.connect, 5000); setTimeout(autoupdate.connect, 5000);
}; };
}, },
on_message: function(receiver) { on_message: function (receiver) {
this.message_receivers.push(receiver); this.message_receivers.push(receiver);
} },
}; reconnect: function () {
Autoupdate.connect(); socket.close();
return Autoupdate; DS.clear();
}) Autoupdate.connect();
}
};
Autoupdate.connect();
return Autoupdate;
}
])
.run(['DS', 'autoupdate', function(DS, autoupdate) { .run(['DS', 'autoupdate', function(DS, autoupdate) {
autoupdate.on_message(function(data) { autoupdate.on_message(function(data) {

View File

@ -8,8 +8,9 @@ angular.module('OpenSlidesApp.users', [])
'User', 'User',
'Group', 'Group',
'loadGlobalData', 'loadGlobalData',
function(User, Group, loadGlobalData) { 'autoupdate',
var operatorChangeCallbacks = []; function (User, Group, loadGlobalData, autoupdate) {
var operatorChangeCallbacks = [autoupdate.reconnect];
var operator = { var operator = {
user: null, user: null,
perms: [], perms: [],
@ -33,6 +34,10 @@ angular.module('OpenSlidesApp.users', [])
}); });
} else { } else {
operator.user = null; operator.user = null;
operator.perms = [];
_.forEach(operatorChangeCallbacks, function (callback) {
callback();
});
Group.find(1).then(function(group) { Group.find(1).then(function(group) {
operator.perms = group.permissions; operator.perms = group.permissions;
_.forEach(operatorChangeCallbacks, function (callback) { _.forEach(operatorChangeCallbacks, function (callback) {