Skip to content

Instantly share code, notes, and snippets.

@biagidp
Created February 11, 2015 19:56
Show Gist options
  • Save biagidp/6c08102dc32eeb84174e to your computer and use it in GitHub Desktop.
Save biagidp/6c08102dc32eeb84174e to your computer and use it in GitHub Desktop.
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