github.com/emate/nomad@v0.8.2-wo-binpacking/ui/app/models/node-attributes.js (about) 1 import { get, computed } from '@ember/object'; 2 import attr from 'ember-data/attr'; 3 import Fragment from 'ember-data-model-fragments/fragment'; 4 import flat from 'npm:flat'; 5 6 const { unflatten } = flat; 7 8 export default Fragment.extend({ 9 attributes: attr(), 10 11 attributesStructured: computed('attributes', function() { 12 const original = this.get('attributes'); 13 14 if (!original) { 15 return; 16 } 17 18 // `unflatten` doesn't sort keys before unflattening, so manual preprocessing is necessary. 19 const attrs = Object.keys(original) 20 .sort() 21 .reduce((obj, key) => { 22 obj[key] = original[key]; 23 return obj; 24 }, {}); 25 return unflatten(attrs, { overwrite: true }); 26 }), 27 28 unknownProperty(key) { 29 // Returns the exact value in index 0 and the subtree in index 1 30 // 31 // ex: nodeAttrs.get('driver.docker') 32 // [ "1", { version: "17.05.0-ce", volumes: { enabled: "1" } } ] 33 return get(this.get('attributesStructured'), key); 34 }, 35 });