2022-05-30 17:10:44 +00:00
|
|
|
// @ts-check
|
|
|
|
import Model from '@ember-data/model';
|
|
|
|
import { attr } from '@ember-data/model';
|
2022-06-10 14:05:34 +00:00
|
|
|
import { computed } from '@ember/object';
|
2022-05-30 17:10:44 +00:00
|
|
|
import classic from 'ember-classic-decorator';
|
|
|
|
// eslint-disable-next-line no-unused-vars
|
|
|
|
import MutableArray from '@ember/array/mutable';
|
2022-06-07 01:42:23 +00:00
|
|
|
import { trimPath } from '../helpers/trim-path';
|
2022-05-30 17:10:44 +00:00
|
|
|
|
|
|
|
/**
|
2022-06-07 01:42:23 +00:00
|
|
|
* @typedef KeyValue
|
2022-05-30 17:10:44 +00:00
|
|
|
* @type {object}
|
|
|
|
* @property {string} key
|
|
|
|
* @property {string} value
|
|
|
|
*/
|
|
|
|
|
2022-06-07 01:42:23 +00:00
|
|
|
/**
|
|
|
|
* @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
|
|
|
|
*/
|
2022-05-30 17:10:44 +00:00
|
|
|
@classic
|
|
|
|
export default class VariableModel extends Model {
|
2022-06-07 01:42:23 +00:00
|
|
|
/**
|
|
|
|
* Can be any arbitrary string, but behaves best when used as a slash-delimited file path.
|
|
|
|
*
|
|
|
|
* @type {string}
|
|
|
|
*/
|
2022-05-30 17:10:44 +00:00
|
|
|
@attr('string') path;
|
|
|
|
|
|
|
|
/**
|
2022-06-07 01:42:23 +00:00
|
|
|
* @type {MutableArray<KeyValue>}
|
2022-05-30 17:10:44 +00:00
|
|
|
*/
|
|
|
|
@attr({
|
|
|
|
defaultValue() {
|
|
|
|
return [{ key: '', value: '' }];
|
|
|
|
},
|
|
|
|
})
|
|
|
|
keyValues;
|
2022-06-07 01:42:23 +00:00
|
|
|
|
|
|
|
/** @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;
|
|
|
|
|
2022-06-10 14:05:34 +00:00
|
|
|
@computed('path')
|
2022-06-17 18:03:43 +00:00
|
|
|
get parentFolderPath() {
|
|
|
|
const split = this.path.split('/');
|
|
|
|
const [, ...folderPath] = [split.pop(), ...split];
|
|
|
|
return folderPath.join('/');
|
2022-06-10 14:05:34 +00:00
|
|
|
}
|
|
|
|
|
2022-06-07 01:42:23 +00:00
|
|
|
/**
|
|
|
|
* Removes starting and trailing slashes, and sets the ID property
|
|
|
|
*/
|
|
|
|
setAndTrimPath() {
|
2022-06-10 14:05:34 +00:00
|
|
|
this.set('path', trimPath([this.path]));
|
2022-06-20 20:29:16 +00:00
|
|
|
this.set('id', this.get('path'));
|
2022-06-07 01:42:23 +00:00
|
|
|
}
|
2022-06-21 19:49:35 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Translates the key-value pairs into an object structure.
|
|
|
|
*/
|
|
|
|
@computed('keyValues')
|
|
|
|
get items() {
|
|
|
|
return this.keyValues.reduce((acc, { key, value }) => {
|
|
|
|
acc[key] = value;
|
|
|
|
return acc;
|
|
|
|
}, {});
|
|
|
|
}
|
2022-05-30 17:10:44 +00:00
|
|
|
}
|