From d31be5481748a505a9604385a2a0357771c2a8cf Mon Sep 17 00:00:00 2001 From: Oskar Hahn Date: Fri, 13 Feb 2015 23:23:48 +0100 Subject: [PATCH] Update angular-data to js-data (angular-data 2.1) Also reload all data after 5 minutes --- bower.json | 2 +- openslides/core/static/js/app.js | 2 +- openslides/core/static/js/core.js | 16 ++++++++++++++++ openslides/users/static/js/users/users.js | 4 ++-- 4 files changed, 20 insertions(+), 4 deletions(-) diff --git a/bower.json b/bower.json index 839d98d77..6f7e3adde 100644 --- a/bower.json +++ b/bower.json @@ -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" }, diff --git a/openslides/core/static/js/app.js b/openslides/core/static/js/app.js index 9d1259697..f8ef10063 100644 --- a/openslides/core/static/js/app.js +++ b/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', diff --git a/openslides/core/static/js/core.js b/openslides/core/static/js/core.js index 1c24d545f..2f60f596f 100644 --- a/openslides/core/static/js/core.js +++ b/openslides/core/static/js/core.js @@ -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 diff --git a/openslides/users/static/js/users/users.js b/openslides/users/static/js/users/users.js index 251363466..6fff8ad87 100644 --- a/openslides/users/static/js/users/users.js +++ b/openslides/users/static/js/users/users.js @@ -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) {