Merge pull request #1904 from ostcar/remove-ds-dependencies

Remove DS dependencies
This commit is contained in:
Norman Jäckel 2016-01-27 20:17:44 +01:00
commit 3ba93c2352
2 changed files with 30 additions and 1 deletions

View File

@ -32,5 +32,8 @@
"angular-ckeditor": "~1.0.0", "angular-ckeditor": "~1.0.0",
"roboto-condensed": "~0.3.0", "roboto-condensed": "~0.3.0",
"open-sans-fontface": "https://github.com/OpenSlides/open-sans.git#1.4.2.post1" "open-sans-fontface": "https://github.com/OpenSlides/open-sans.git#1.4.2.post1"
},
"resolutions": {
"angular": "^1.2.x"
} }
} }

View File

@ -140,10 +140,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([ .run([
'DS', 'DS',
'autoupdate', 'autoupdate',
function(DS, autoupdate) { 'dsEject',
function (DS, autoupdate, dsEject) {
autoupdate.on_message(function(data) { autoupdate.on_message(function(data) {
// TODO: when MODEL.find() is called after this // TODO: when MODEL.find() is called after this
// a new request is fired. This could be a bug in DS // a new request is fired. This could be a bug in DS
@ -152,9 +169,18 @@ angular.module('OpenSlidesApp.core', [
// on the server side. It is an implementation detail, that tornado // on the server side. It is an implementation detail, that tornado
// sends request to wsgi, which should not concern the client. // sends request to wsgi, which should not concern the client.
console.log("Received object: " + data.collection + ", " + data.id); console.log("Received object: " + data.collection + ", " + data.id);
var instance = DS.get(data.collection, data.id);
if (data.status_code == 200) { if (data.status_code == 200) {
if (instance) {
// The instance is in the local db
dsEject(data.collection, instance);
}
DS.inject(data.collection, data.data); DS.inject(data.collection, data.data);
} else if (data.status_code == 404) { } 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); DS.eject(data.collection, data.id);
} }
// TODO: handle other statuscodes // TODO: handle other statuscodes