Skip to content

Commit

Permalink
Update angular-data to js-data (angular-data 2.1)
Browse files Browse the repository at this point in the history
Also reload all data after 5 minutes
  • Loading branch information
ostcar committed Feb 13, 2015
1 parent 2859980 commit d31be54
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 4 deletions.
2 changes: 1 addition & 1 deletion bower.json
Expand Up @@ -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"
},
Expand Down
2 changes: 1 addition & 1 deletion openslides/core/static/js/app.js
@@ -1,6 +1,6 @@
angular.module('OpenSlidesApp', [
'ui.router',
'angular-data.DS',
'js-data',
'OpenSlidesApp.core',
'OpenSlidesApp.agenda',
'OpenSlidesApp.assignments',
Expand Down
16 changes: 16 additions & 0 deletions openslides/core/static/js/core.js
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions openslides/users/static/js/users/users.js
Expand Up @@ -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) {
Expand Down

0 comments on commit d31be54

Please sign in to comment.