From bd4c8920e9524edda6c871650ab0af68e4149c4f Mon Sep 17 00:00:00 2001 From: Oskar Hahn Date: Wed, 27 Jan 2016 15:33:06 +0100 Subject: [PATCH] Remove DS dependencies --- bower.json | 3 +++ openslides/core/static/js/core/base.js | 28 +++++++++++++++++++++++++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/bower.json b/bower.json index 9186d6099..29dd56e47 100644 --- a/bower.json +++ b/bower.json @@ -32,5 +32,8 @@ "angular-ckeditor": "~1.0.0", "roboto-condensed": "~0.3.0", "open-sans-fontface": "https://github.com/OpenSlides/open-sans.git#1.4.2.post1" + }, + "resolutions": { + "angular": "^1.2.x" } } diff --git a/openslides/core/static/js/core/base.js b/openslides/core/static/js/core/base.js index 83c970df6..ffd0bc71f 100644 --- a/openslides/core/static/js/core/base.js +++ b/openslides/core/static/js/core/base.js @@ -133,10 +133,27 @@ angular.module('OpenSlidesApp.core', [ } ]) +.factory('dsEject', [ + 'DS', + function (DS) { + return function (collection, instance) { + var Resource = DS.definitions[collection]; + Resource.relationList.forEach(function (relationDef) { + if (relationDef.foreignKey) { + var query = {}; + query[relationDef.foreignKey] = instance[Resource.idAttribute]; + Resource.getResource(relationDef.relation).ejectAll(query); + } + }); + } + } +]) + .run([ 'DS', 'autoupdate', - function(DS, autoupdate) { + 'dsEject', + function (DS, autoupdate, dsEject) { autoupdate.on_message(function(data) { // TODO: when MODEL.find() is called after this // a new request is fired. This could be a bug in DS @@ -145,9 +162,18 @@ angular.module('OpenSlidesApp.core', [ // on the server side. It is an implementation detail, that tornado // sends request to wsgi, which should not concern the client. console.log("Received object: " + data.collection + ", " + data.id); + var instance = DS.get(data.collection, data.id); if (data.status_code == 200) { + if (instance) { + // The instance is in the local db + dsEject(data.collection, instance); + } DS.inject(data.collection, data.data); } else if (data.status_code == 404) { + if (instance) { + // The instance is in the local db + dsEject(data.collection, instance); + } DS.eject(data.collection, data.id); } // TODO: handle other statuscodes