import Template from 'template'; import TypeNode from 'type/type-node'; import FieldInput from 'template/page/instance-form/type/field-input'; import InstanceNode from 'type/instance-node'; import getNodeParameters from 'utility/get-node-parameters'; interface Input extends FieldInput { readonly index: number; } class FieldRowTemplate extends Template { protected getHtml(): string { const key_html = this.getKeyHtml(); const type_html = this.getTypeHtml(); const instance_list_html = this.getInstanceListHtml(); const explicit_value_html = this.getExplicitValueHtml(); return ` ${key_html} ${type_html} ${instance_list_html} ${explicit_value_html} `; } private getKeyHtml(): string { const index = this.getIndex(); const field_key = this.getFieldKey(); return ` `; } private getTypeHtml(): string { const index = this.getIndex(); const type_url = this.getTypeUrl(); const type_label = this.getTypeLabel(); return ` ${type_label} `; } private getInstanceListHtml(): string { if (!this.hasInstanceList()) { return 'N/A'; } const index = this.getIndex(); const instance_options_html = this.getInstanceOptionsHtml(); return ` `; } private getInstanceOptionsHtml(): string { const field_instance_list = this.getInstanceList(); const serialized_options: string[] = [ ` ` ]; field_instance_list.forEach((instance) => { const url = instance.url; const parameters = getNodeParameters(url); const id = parameters.id; serialized_options.push(` `); }); return serialized_options.join('\n'); } private getExplicitValueHtml(): string { const index = this.getIndex(); return ` `; } private getFieldKey(): string { const input = this.getInput(); return input.key; } private getTypeUrl(): string { const type_node = this.getTypeNode(); return type_node.url; } private getTypeLabel(): string { const type_node = this.getTypeNode(); const parameters = getNodeParameters(type_node.url); return parameters.id; } private getIndex(): number { const input = this.getInput(); return input.index; } private getTypeNode(): TypeNode { const input = this.getInput(); return input.type_node; } private hasInstanceList(): boolean { const input = this.getInput(); if (input.instance_list === undefined) { return false; } return input.instance_list.length > 0; } private getInstanceList(): InstanceNode[] { const input = this.getInput(); if (input.instance_list === undefined) { throw new Error('Tried to read instance list, but it was not set'); } return input.instance_list; } } export default FieldRowTemplate;