UNPKG

pragma-views2

Version:

49 lines (40 loc) 1.35 kB
import {getValueOnPath} from "./../../../../baremetal/lib/objectpath-helper.js"; export class SchemaHelper { constructor(schema, model) { this.schema = schema; this.model = model; } dispose() { delete this.schema; delete this.model; } getAssociatedValue(value) { if (this.schema == undefined || this.schema.variables == undefined) { return value; } let result = value; const valueStr = new String(value); if (valueStr[0] == "@") { if (valueStr == "@today") { result = new Date().toISOString().split('T')[0]; } else if (valueStr == "@null") { result = null; } else { const varName = valueStr.slice(1); result = getValueOnPath(this.schema.variables, varName); } } if (typeof result == "string" && result.indexOf("model.") != -1) { result = this.model == undefined ? null : getValueOnPath(this, result); } return result; } setAssociatedValueFor(model) { const keys = Object.keys(model); for (let key of keys) { model[key] = this.getAssociatedValue(model[key]); } } }