diff options
author | Thomas Duval <thomas.duval@orange.com> | 2020-06-03 10:06:52 +0200 |
---|---|---|
committer | Thomas Duval <thomas.duval@orange.com> | 2020-06-03 10:06:52 +0200 |
commit | 7bb53c64da2dcf88894bfd31503accdd81498f3d (patch) | |
tree | 4310e12366818af27947b5e2c80cb162da93a4b5 /dashboard/src/services/Attribute.service.js | |
parent | cbea4e360e9bfaa9698cf7c61c83c96a1ba89b8c (diff) |
Update to new version 5.4HEADstable/jermamaster
Signed-off-by: Thomas Duval <thomas.duval@orange.com>
Change-Id: Idcd868133d75928a1ffd74d749ce98503e0555ea
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 |