|
| 1 | +import {css, customElement, html, LitElement, property, TemplateResult} from 'lit-element'; |
| 2 | +import {get, translate} from "lit-translate"; |
| 3 | + |
| 4 | +import {Wizard, WizardAction, WizardInput} from '../foundation.js'; |
| 5 | +import {Nsdoc} from "../foundation/nsdoc.js"; |
| 6 | + |
| 7 | +import { |
| 8 | + getPrivateTextValue, |
| 9 | + hasPrivateElement, |
| 10 | + iedHeader, |
| 11 | + lDeviceHeader, |
| 12 | + lnHeader, |
| 13 | + LOCAMATION_PRIVATE |
| 14 | +} from "./foundation.js"; |
| 15 | +import Protocol from "devtools-protocol"; |
| 16 | +import integer = Protocol.integer; |
| 17 | + |
| 18 | +@customElement('locamation-ln-edit') |
| 19 | +export class LocamationVMUEditElement extends LitElement { |
| 20 | + @property({type: Element}) |
| 21 | + logicalNode!: Element; |
| 22 | + @property() |
| 23 | + nsdoc!: Nsdoc; |
| 24 | + |
| 25 | + save(inputs: WizardInput[]): WizardAction[] { |
| 26 | + // if (!this.fieldsChanged(inputs)) { |
| 27 | + return []; |
| 28 | + // } |
| 29 | + // |
| 30 | + // cloneElement(element, { name, desc }); |
| 31 | + // |
| 32 | + // const oldPrivateElement = getPrivate(oldElement, 'compas_substation'); |
| 33 | + // const newPrivateElement = getOrCreatePrivate(oldElement, newElement, 'compas_substation'); |
| 34 | + // |
| 35 | + // const compasName = getInputFieldValue(inputs, 'compasName'); |
| 36 | + // processPrivateTextElement(newPrivateElement, EXTENSION_NAMESPACE, 'compas', 'CompasName', compasName); |
| 37 | + // |
| 38 | + // if (oldPrivateElement) { |
| 39 | + // return [{old: {element: oldPrivateElement}, new: {element: newPrivateElement}}]; |
| 40 | + // } |
| 41 | + // return [{new: {parent: newElement, element: newPrivateElement}}]; |
| 42 | + } |
| 43 | + // |
| 44 | + // private fieldsChanged(inputs: WizardInput[]): boolean { |
| 45 | + // const oldIdentifier= getPrivateTextValue(this.logicalNode, LOCAMATION_PRIVATE, 'IDENTIFIER'); |
| 46 | + // const oldChannel = getPrivateTextValue(this.logicalNode, LOCAMATION_PRIVATE, 'CHANNEL'); |
| 47 | + // const oldTransformPrimary = getPrivateTextValue(this.logicalNode, LOCAMATION_PRIVATE, 'TRANSFORM-PRIMARY'); |
| 48 | + // const oldTransformSecondary = getPrivateTextValue(this.logicalNode, LOCAMATION_PRIVATE, 'TRANSFORM-SECONDARY'); |
| 49 | + // return inputFieldChanged(inputs, 'Identifier', oldIdentifier) |
| 50 | + // || inputFieldChanged(inputs, 'Channel', oldChannel) |
| 51 | + // || inputFieldChanged(inputs, 'TransformPrimary', oldTransformPrimary) |
| 52 | + // || inputFieldChanged(inputs, 'TransformSecondary', oldTransformSecondary); |
| 53 | + // } |
| 54 | + |
| 55 | + private getIdentifierPart(partNr: integer): string { |
| 56 | + const identifier = getPrivateTextValue(this.logicalNode, LOCAMATION_PRIVATE, 'IDENTIFIER')?? ''; |
| 57 | + const parts = identifier.trim().split('.'); |
| 58 | + if (parts.length < partNr) { |
| 59 | + return ''; |
| 60 | + } |
| 61 | + return parts[partNr]; |
| 62 | + } |
| 63 | + |
| 64 | + render(): TemplateResult { |
| 65 | + const lDevice = this.logicalNode.closest('LDevice')!; |
| 66 | + const ied = lDevice.closest('IED')!; |
| 67 | + return html ` |
| 68 | + <wizard-textfield label="IED" |
| 69 | + .maybeValue=${iedHeader(ied)} |
| 70 | + helper="${translate('locamation.vmu.ied.name')}" |
| 71 | + disabled> |
| 72 | + </wizard-textfield> |
| 73 | + <wizard-textfield label="Logical Device" |
| 74 | + .maybeValue=${lDeviceHeader(lDevice)} |
| 75 | + helper="${translate('locamation.vmu.ldevice.name')}" |
| 76 | + disabled> |
| 77 | + </wizard-textfield> |
| 78 | + <wizard-textfield label="Logical Node" |
| 79 | + .maybeValue=${lnHeader(this.logicalNode, this.nsdoc)} |
| 80 | + helper="${translate('locamation.vmu.ln.name')}" |
| 81 | + disabled> |
| 82 | + </wizard-textfield> |
| 83 | +
|
| 84 | + <div id="Identifier"> |
| 85 | + <wizard-textfield label="IdentifierPart0" |
| 86 | + .maybeValue=${this.getIdentifierPart(0)} |
| 87 | + helper="Identifier" |
| 88 | + required> |
| 89 | + </wizard-textfield> |
| 90 | + <wizard-textfield label="IdentifierPart1" |
| 91 | + .maybeValue=${this.getIdentifierPart(1)} |
| 92 | + helper="Identifier" |
| 93 | + required> |
| 94 | + </wizard-textfield> |
| 95 | + <wizard-textfield label="IdentifierPart2" |
| 96 | + .maybeValue=${this.getIdentifierPart(2)} |
| 97 | + helper="Identifier" |
| 98 | + required> |
| 99 | + </wizard-textfield> |
| 100 | + </div> |
| 101 | + ${hasPrivateElement(this.logicalNode, LOCAMATION_PRIVATE, 'SUM') ? |
| 102 | + html `<wizard-textfield label="Sum" |
| 103 | + .maybeValue=${getPrivateTextValue(this.logicalNode, LOCAMATION_PRIVATE, 'SUM')} |
| 104 | + helper="Sum" |
| 105 | + required> |
| 106 | + </wizard-textfield>` : |
| 107 | + html `<wizard-textfield label="Channel" |
| 108 | + .maybeValue=${getPrivateTextValue(this.logicalNode, LOCAMATION_PRIVATE, 'CHANNEL')} |
| 109 | + helper="Channel" |
| 110 | + required> |
| 111 | + </wizard-textfield>` |
| 112 | + } |
| 113 | + <wizard-textfield label="TransformPrimary" |
| 114 | + .maybeValue=${getPrivateTextValue(this.logicalNode, LOCAMATION_PRIVATE, 'TRANSFORM-PRIMARY')} |
| 115 | + helper="TransformPrimary" |
| 116 | + required> |
| 117 | + </wizard-textfield> |
| 118 | + <wizard-textfield label="TransformSecondary" |
| 119 | + .maybeValue=${getPrivateTextValue(this.logicalNode, LOCAMATION_PRIVATE, 'TRANSFORM-SECONDARY')} |
| 120 | + helper="TransformSecondary" |
| 121 | + required> |
| 122 | + </wizard-textfield> |
| 123 | + `; |
| 124 | + } |
| 125 | + |
| 126 | + static styles = css` |
| 127 | + :host { |
| 128 | + width: 20vw; |
| 129 | + } |
| 130 | +
|
| 131 | + * { |
| 132 | + display: block; |
| 133 | + margin-top: 16px; |
| 134 | + } |
| 135 | + ` |
| 136 | +} |
| 137 | + |
| 138 | +export function locamationLNEditWizard(logicalNode: Element, nsdoc: Nsdoc): Wizard { |
| 139 | + function save() { |
| 140 | + return function (inputs: WizardInput[], wizard: Element): WizardAction[] { |
| 141 | + const locamationVMUEditElement = <LocamationVMUEditElement>wizard.shadowRoot!.querySelector('locamation-ln-edit') |
| 142 | + return locamationVMUEditElement.save(inputs); |
| 143 | + }; |
| 144 | + } |
| 145 | + |
| 146 | + return [ |
| 147 | + { |
| 148 | + title: get('locamation.vmu.ln.editTitle'), |
| 149 | + primary: { |
| 150 | + icon: 'save', |
| 151 | + label: get('save'), |
| 152 | + action: save(), |
| 153 | + }, |
| 154 | + content: [ |
| 155 | + html`<locamation-ln-edit .logicalNode="${logicalNode}" .nsdoc="${nsdoc}"></locamation-ln-edit>`, |
| 156 | + ], |
| 157 | + }, |
| 158 | + ]; |
| 159 | +} |
| 160 | + |
0 commit comments