Update angular-data to js-data (angular-data 2.1)

Also reload all data after 5 minutes
This commit is contained in:
Oskar Hahn 2015-02-13 23:23:48 +01:00
parent 2859980922
commit d31be54817
4 changed files with 20 additions and 4 deletions

View File

@ -9,7 +9,7 @@
"datatables-bootstrap3-plugin": "~0.2.0",
"angular": "~1.3.11",
"angular-ui-router": "~0.2.13",
"angular-data": "~1.5.3",
"js-data-angular": "~2.1.0",
"sockjs": "~0.3.4",
"jed": "~1.1.0"
},

View File

@ -1,6 +1,6 @@
angular.module('OpenSlidesApp', [
'ui.router',
'angular-data.DS',
'js-data',
'OpenSlidesApp.core',
'OpenSlidesApp.agenda',
'OpenSlidesApp.assignments',

View File

@ -82,6 +82,22 @@ angular.module('OpenSlidesApp.core', [])
$locationProvider.html5Mode(true);
})
.config(function(DSProvider) {
// Reloads everything after 5 minutes.
// TODO: * find a way only to reload things that are still needed
DSProvider.defaults.maxAge = 5 * 60 * 1000; // 5 minutes
DSProvider.defaults.reapAction = 'none';
DSProvider.defaults.afterReap = function(model, items) {
if (items.length > 5) {
model.findAll({}, {bypassCache: true});
} else {
_.forEach(items, function (item) {
model.refresh(item[model.idAttribute]);
});
}
};
})
.run(function(DS, autoupdate) {
autoupdate.on_message(function(data) {
// TODO: when MODEL.find() is called after this

View File

@ -64,11 +64,11 @@ angular.module('OpenSlidesApp.users', [])
})
.controller('UserListCtrl', function($scope, User, i18n) {
User.bindAll($scope, 'users');
User.bindAll({}, $scope, 'users');
})
.controller('UserDetailCtrl', function($scope, User, user) {
User.bindOne($scope, 'user', user.id);
User.bindOne(user.id, $scope, 'user');
})
.controller('UserCreateCtrl', function($scope, User) {