Last active
February 28, 2017 10:05
-
-
Save noherczeg/f0a7632ba4b5d0b7c4982539434aa386 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * @param {*} class Class of instance | |
| * @param {*} root Data holder instance | |
| * @param {*} relationName name of Meta relation, gets mapped to e.g. Single, List | |
| */ | |
| SomeService.prototype.fetchRecursive = function (clazz, root, relationName) { | |
| let vm = this; | |
| let deferred = this.$q.defer(); | |
| let service = this.$injector.get(clazz.serviceInstanceId()); | |
| let relation = clazz.getAttributeByName(relationName); | |
| service | |
| .getListItems(relation, root.id) | |
| .then(function(response){ | |
| vm.$q | |
| .all(response.data.map((child) => { | |
| if (!root.hasOwnProperty(relation.name)) { | |
| root[relation.name] = []; | |
| } | |
| root[relation.name].push(child); | |
| child.parent = root; | |
| let childClass = vm.metaContainer.getFromUniquesById(child.xmiid); | |
| return vm.fetchRecursive(childClass, child, relationName); | |
| })) | |
| .then(() => { | |
| deferred.resolve(root); | |
| }, (err) => { | |
| deferred.reject(err); | |
| }); | |
| }); | |
| return deferred.promise; | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment