Created
February 11, 2015 19:56
-
-
Save biagidp/6c08102dc32eeb84174e to your computer and use it in GitHub Desktop.
This file contains 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
angular.module('schemaService', []) | |
.service('schemaService', function($http, $q){ | |
var _schema = {}; | |
this.loadSchema = function(){ | |
var deferred = $q.defer(); | |
$http.get('schema.json') | |
.success(function(data){ | |
deferred.resolve(data); | |
}); | |
deferred.promise.then(function(data){ | |
_schema = data; | |
}); | |
}; | |
this.getSchema = function(){ | |
return _schema; | |
}; | |
this.getValues = function(moduleName, fieldName){ | |
var module = getModule(moduleName); | |
var field = getField(module, fieldName); | |
var values = field.enum; | |
return values; | |
}; | |
var getField = function(module, fieldName){ | |
console.log('getting field...'); | |
var field = $.grep(module.schematic.children, function(item){ return item.name === fieldName; })[0]; | |
return field | |
}; | |
var getModule = function(moduleName){ | |
console.log('getting module '+moduleName); | |
var module = $.grep(_schema.collections, function(item){ | |
return item.name === moduleName; | |
})[0]; | |
return module; | |
}; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment