github.com/iqoqo/nomad@v0.11.3-0.20200911112621-d7021c74d101/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 'flat';
     5  
     6  const { unflatten } = flat;
     7  
     8  export default Fragment.extend({
     9    nodeAttributes: attr(),
    10  
    11    attributesStructured: computed('nodeAttributes', function() {
    12      const original = this.nodeAttributes;
    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      if (this.attributesStructured) {
    34        return get(this.attributesStructured, key);
    35      }
    36    },
    37  });