diff options
Diffstat (limited to 'dashboard/src/services/Attribute.service.js')
-rw-r--r-- | dashboard/src/services/Attribute.service.js | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/dashboard/src/services/Attribute.service.js b/dashboard/src/services/Attribute.service.js new file mode 100644 index 00000000..a00da8f1 --- /dev/null +++ b/dashboard/src/services/Attribute.service.js @@ -0,0 +1,46 @@ +import Vue from 'vue' +import config from '../config.js' +import util from './Util.service' + +var host = config.host; + +var attributeResource; + +var attributesMap = {}; +var attributes = []; + +function loadAttributes(){ + attributeResource = Vue.resource(host + '/attributes{/id}', {}); + + attributeResource.query().then(res => { + createAttributes(res.body); + }, util.displayErrorFunction('Unable to load attributes')); +} + +function createAttributes(attributesData){ + attributes.splice(0, attributes.length); + util.cleanObject(attributesMap); + util.createInternal(attributesData.attributes, attributes, attributesMap); +} + +function getAttribute(id){ + return attributesMap[id]; +} + +function getAttributeId(name){ + for (let i = 0; i < attributes.length; i++){ + let attr = attributes[i]; + for (let j = 0; j < attr.values.length; j++){ + let value = attr.values[j]; + if (value === name){ + return attr.id; + } + } + } +} + +export default { + initialize: loadAttributes, + getAttribute: getAttribute, + getAttributeId: getAttributeId +}
\ No newline at end of file |