|
| 1 | +import {css, customElement, html, LitElement, property, TemplateResult} from 'lit-element'; |
| 2 | +import {get, translate} from "lit-translate"; |
| 3 | + |
| 4 | +import {patterns} from "../wizards/foundation/limits.js"; |
| 5 | +import {checkValidity, ComplexAction, Wizard, WizardAction, WizardInput, wizardInputSelector} from '../foundation.js'; |
| 6 | +import {Nsdoc} from "../foundation/nsdoc.js"; |
| 7 | + |
| 8 | +import '../wizard-textfield.js'; |
| 9 | + |
| 10 | +import { |
| 11 | + createEditorAction, |
| 12 | + getInputFieldValue, |
| 13 | + getPrivate, |
| 14 | + getPrivateTextValue, |
| 15 | + hasPrivateElement, |
| 16 | + iedHeader, |
| 17 | + inputFieldChanged, |
| 18 | + lDeviceHeader, |
| 19 | + lnHeader, |
| 20 | +} from "./foundation.js"; |
| 21 | + |
| 22 | +@customElement('locamation-ln-edit') |
| 23 | +export class LocamationVMUEditElement extends LitElement { |
| 24 | + @property({type: Element}) |
| 25 | + logicalNode!: Element; |
| 26 | + @property() |
| 27 | + nsdoc!: Nsdoc; |
| 28 | + |
| 29 | + get inputs(): WizardInput[] { |
| 30 | + return Array.from(this.shadowRoot!.querySelectorAll(wizardInputSelector)); |
| 31 | + } |
| 32 | + |
| 33 | + save(): WizardAction[] { |
| 34 | + const locamationPrivate = getPrivate(this.logicalNode); |
| 35 | + |
| 36 | + if (!this.fieldsChanged(locamationPrivate, this.inputs) || !this.checkValidityInputs(this.inputs)) { |
| 37 | + return []; |
| 38 | + } |
| 39 | + |
| 40 | + const complexAction: ComplexAction = { |
| 41 | + actions: [], |
| 42 | + title: get('locamation.vmu.updateAction', {lnName: lnHeader(this.logicalNode, this.nsdoc)}), |
| 43 | + }; |
| 44 | + |
| 45 | + complexAction.actions.push(...createEditorAction(locamationPrivate, 'IDENTIFIER', getInputFieldValue(this.inputs, 'identifier'))); |
| 46 | + if (hasPrivateElement(this.logicalNode, 'SUM')) { |
| 47 | + complexAction.actions.push(...createEditorAction(locamationPrivate, 'SUM', getInputFieldValue(this.inputs, 'sum'))); |
| 48 | + } else { |
| 49 | + complexAction.actions.push(...createEditorAction(locamationPrivate, 'CHANNEL', getInputFieldValue(this.inputs, 'channel'))); |
| 50 | + } |
| 51 | + complexAction.actions.push(...createEditorAction(locamationPrivate, 'TRANSFORM-PRIMARY', getInputFieldValue(this.inputs, 'transformPrimary'))); |
| 52 | + complexAction.actions.push(...createEditorAction(locamationPrivate, 'TRANSFORM-SECONDARY', getInputFieldValue(this.inputs, 'transformSecondary'))); |
| 53 | + |
| 54 | + return complexAction.actions.length ? [complexAction] : []; |
| 55 | + } |
| 56 | + |
| 57 | + private fieldsChanged(locamationPrivate: Element | null, inputs: WizardInput[]): boolean { |
| 58 | + const oldIdentifier= getPrivateTextValue(locamationPrivate, 'IDENTIFIER'); |
| 59 | + const oldChannel = getPrivateTextValue(locamationPrivate, 'CHANNEL'); |
| 60 | + const oldSum = getPrivateTextValue(locamationPrivate, 'SUM'); |
| 61 | + const oldTransformPrimary = getPrivateTextValue(locamationPrivate, 'TRANSFORM-PRIMARY'); |
| 62 | + const oldTransformSecondary = getPrivateTextValue(locamationPrivate, 'TRANSFORM-SECONDARY'); |
| 63 | + |
| 64 | + return inputFieldChanged(inputs, 'identifier', oldIdentifier) |
| 65 | + || (hasPrivateElement(locamationPrivate, 'SUM') ? inputFieldChanged(inputs, 'sum', oldSum) : false) |
| 66 | + || (hasPrivateElement(locamationPrivate, 'CHANNEL') ? inputFieldChanged(inputs, 'channel', oldChannel) : false) |
| 67 | + || inputFieldChanged(inputs, 'transformPrimary', oldTransformPrimary) |
| 68 | + || inputFieldChanged(inputs, 'transformSecondary', oldTransformSecondary); |
| 69 | + } |
| 70 | + |
| 71 | + private checkValidityInputs(inputs: WizardInput[]): boolean { |
| 72 | + return Array.from(inputs).every(checkValidity); |
| 73 | + } |
| 74 | + |
| 75 | + render(): TemplateResult { |
| 76 | + const lDevice = this.logicalNode.closest('LDevice')!; |
| 77 | + const ied = lDevice.closest('IED')!; |
| 78 | + const locamationPrivate = getPrivate(this.logicalNode); |
| 79 | + |
| 80 | + // Depending on the value of the class the pattern for the CIM or VIM for SUM/CHANNEL will change. |
| 81 | + let channelPattern = '[0-5]'; |
| 82 | + let sumPattern = '[0-5],[0-5],[0-5]'; |
| 83 | + if (this.logicalNode.getAttribute('lnClass') === 'TVTR') { |
| 84 | + channelPattern = '[0-2]'; |
| 85 | + sumPattern = '[0-2],[0-2],[0-2]'; |
| 86 | + } |
| 87 | + |
| 88 | + return html ` |
| 89 | + <wizard-textfield label="${translate('locamation.vmu.ied.name')}" |
| 90 | + .maybeValue=${iedHeader(ied)} |
| 91 | + disabled> |
| 92 | + </wizard-textfield> |
| 93 | + <wizard-textfield label="${translate('locamation.vmu.ldevice.name')}" |
| 94 | + .maybeValue=${lDeviceHeader(lDevice)} |
| 95 | + disabled> |
| 96 | + </wizard-textfield> |
| 97 | + <wizard-textfield label="${translate('locamation.vmu.ln.name')}" |
| 98 | + .maybeValue=${lnHeader(this.logicalNode, this.nsdoc)} |
| 99 | + disabled> |
| 100 | + </wizard-textfield> |
| 101 | +
|
| 102 | + <wizard-textfield label="${translate('locamation.vmu.version')}" |
| 103 | + .maybeValue=${getPrivateTextValue(locamationPrivate, 'VERSION')} |
| 104 | + disabled> |
| 105 | + </wizard-textfield> |
| 106 | +
|
| 107 | + <wizard-textfield id="identifier" |
| 108 | + label="${translate('locamation.vmu.identifier')}" |
| 109 | + .maybeValue=${getPrivateTextValue(locamationPrivate, 'IDENTIFIER')} |
| 110 | + helper="${translate('locamation.vmu.identifierHelper')}" |
| 111 | + placeholder="134.12.213" |
| 112 | + pattern="^(([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(\\.(?!$)|$)){3}$" |
| 113 | + required |
| 114 | + dialogInitialFocus> |
| 115 | + </wizard-textfield> |
| 116 | +
|
| 117 | + ${hasPrivateElement(locamationPrivate, 'SUM') ? |
| 118 | + html `<wizard-textfield id="sum" |
| 119 | + label="${translate('locamation.vmu.sum')}" |
| 120 | + .maybeValue=${getPrivateTextValue(locamationPrivate, 'SUM')} |
| 121 | + helper="${translate('locamation.vmu.sumHelper')}" |
| 122 | + placeholder="0,1,2" |
| 123 | + pattern="${sumPattern}" |
| 124 | + required> |
| 125 | + </wizard-textfield>` : html `` |
| 126 | + } |
| 127 | + ${hasPrivateElement(locamationPrivate, 'CHANNEL') ? |
| 128 | + html `<wizard-textfield id="channel" |
| 129 | + label="${translate('locamation.vmu.channel')}" |
| 130 | + .maybeValue=${getPrivateTextValue(locamationPrivate, 'CHANNEL')} |
| 131 | + helper="${translate('locamation.vmu.channelHelper')}" |
| 132 | + pattern="${channelPattern}" |
| 133 | + required> |
| 134 | + </wizard-textfield>` : html `` |
| 135 | + } |
| 136 | +
|
| 137 | + <wizard-textfield id="transformPrimary" |
| 138 | + label="${translate('locamation.vmu.transformPrimary')}" |
| 139 | + .maybeValue=${getPrivateTextValue(locamationPrivate, 'TRANSFORM-PRIMARY')} |
| 140 | + helper="${translate('locamation.vmu.transformPrimaryHelper')}" |
| 141 | + pattern="${patterns.unsigned}" |
| 142 | + required> |
| 143 | + </wizard-textfield> |
| 144 | + <wizard-textfield id="transformSecondary" |
| 145 | + label="${translate('locamation.vmu.transformSecondary')}" |
| 146 | + .maybeValue=${getPrivateTextValue(locamationPrivate, 'TRANSFORM-SECONDARY')} |
| 147 | + helper="${translate('locamation.vmu.transformSecondaryHelper')}" |
| 148 | + pattern="${patterns.unsigned}" |
| 149 | + required> |
| 150 | + </wizard-textfield> |
| 151 | + `; |
| 152 | + } |
| 153 | + |
| 154 | + static styles = css` |
| 155 | + :host { |
| 156 | + width: 20vw; |
| 157 | + } |
| 158 | +
|
| 159 | + * { |
| 160 | + display: block; |
| 161 | + margin-top: 16px; |
| 162 | + } |
| 163 | + ` |
| 164 | +} |
| 165 | + |
| 166 | +export function locamationLNEditWizard(logicalNode: Element, nsdoc: Nsdoc): Wizard { |
| 167 | + function save() { |
| 168 | + return function (inputs: WizardInput[], wizard: Element): WizardAction[] { |
| 169 | + const locamationVMUEditElement = <LocamationVMUEditElement>wizard.shadowRoot!.querySelector('locamation-ln-edit') |
| 170 | + return locamationVMUEditElement.save(); |
| 171 | + }; |
| 172 | + } |
| 173 | + |
| 174 | + return [ |
| 175 | + { |
| 176 | + title: get('locamation.vmu.ln.editTitle'), |
| 177 | + primary: { |
| 178 | + icon: 'save', |
| 179 | + label: get('save'), |
| 180 | + action: save(), |
| 181 | + }, |
| 182 | + content: [ |
| 183 | + html`<locamation-ln-edit .logicalNode="${logicalNode}" .nsdoc="${nsdoc}"></locamation-ln-edit>`, |
| 184 | + ], |
| 185 | + }, |
| 186 | + ]; |
| 187 | +} |
| 188 | + |
0 commit comments