Files
nomad/ui/app/models/variable.js
Phil Renaud 8cf81a9ee8 Secure Variables: Build a path tree and traverse it at /variables/*path (#13202)
* Recursive trie-building with variable paths

* tree structure applied to new path routes and a new util class

* Breadcrumbs for SV paths and prompt when nothing exists at a path

* Lint and test cleanup

* Pre-review cleanup

* lintfix

* Abstracted pathtree each-ins into a new component class

* Path tree component styles

* Types added and PR feedback addressed

* Path tree to variable paths

* Slightly simpler path QP mods

* More pr feedback handling

* Trim moved into a function on variable model

* Traversal and compaction tests for PathTree

* Trim Path tests

* Variable-paths component tests

* Lint fixup for tests
2022-07-11 13:34:04 -04:00

65 lines
1.4 KiB
JavaScript

// @ts-check
import Model from '@ember-data/model';
import { attr } from '@ember-data/model';
import classic from 'ember-classic-decorator';
// eslint-disable-next-line no-unused-vars
import MutableArray from '@ember/array/mutable';
import { trimPath } from '../helpers/trim-path';
/**
* @typedef KeyValue
* @type {object}
* @property {string} key
* @property {string} value
*/
/**
* @typedef SecureVariable
* @type {object}
*/
/**
* A Secure Variable has a path, namespace, and an array of key-value pairs within the client.
* On the server, these key-value pairs are serialized into object structure.
* @class
* @extends Model
*/
@classic
export default class VariableModel extends Model {
/**
* Can be any arbitrary string, but behaves best when used as a slash-delimited file path.
*
* @type {string}
*/
@attr('string') path;
/**
* @type {MutableArray<KeyValue>}
*/
@attr({
defaultValue() {
return [{ key: '', value: '' }];
},
})
keyValues;
/** @type {number} */
@attr('number') createIndex;
/** @type {number} */
@attr('number') modifyIndex;
/** @type {string} */
@attr('string') createTime;
/** @type {string} */
@attr('string') modifyTime;
/** @type {string} */
@attr('string') namespace;
/**
* Removes starting and trailing slashes, and sets the ID property
*/
setAndTrimPath() {
this.path = trimPath([this.path]);
this.id = this.path;
}
}