1
1
import { css , customElement , html , LitElement , property , TemplateResult } from 'lit-element' ;
2
2
import { get , translate } from "lit-translate" ;
3
3
4
- import { Wizard , WizardAction , WizardInput } from '../foundation.js' ;
4
+ import { patterns } from "../wizards/foundation/limits.js" ;
5
+ import { checkValidity , ComplexAction , Wizard , WizardAction , WizardInput , wizardInputSelector } from '../foundation.js' ;
5
6
import { Nsdoc } from "../foundation/nsdoc.js" ;
6
7
8
+ import '../wizard-textfield.js' ;
9
+
7
10
import {
11
+ createEditorAction ,
12
+ getInputFieldValue ,
13
+ getPrivate ,
8
14
getPrivateTextValue ,
9
15
hasPrivateElement ,
10
16
iedHeader ,
17
+ inputFieldChanged ,
11
18
lDeviceHeader ,
12
19
lnHeader ,
13
- LOCAMATION_PRIVATE
14
20
} from "./foundation.js" ;
15
- import Protocol from "devtools-protocol" ;
16
- import integer = Protocol . integer ;
17
21
18
22
@customElement ( 'locamation-ln-edit' )
19
23
export class LocamationVMUEditElement extends LitElement {
@@ -22,102 +26,121 @@ export class LocamationVMUEditElement extends LitElement {
22
26
@property ( )
23
27
nsdoc ! : Nsdoc ;
24
28
25
- save ( inputs : WizardInput [ ] ) : WizardAction [ ] {
26
- // if (!this.fieldsChanged(inputs)) {
29
+ save ( ) : WizardAction [ ] {
30
+ const inputs : WizardInput [ ] = Array . from ( this . shadowRoot ! . querySelectorAll ( wizardInputSelector ) ) ;
31
+ const locamationPrivate = getPrivate ( this . logicalNode ) ;
32
+
33
+ if ( ! this . fieldsChanged ( locamationPrivate , inputs ) || ! this . checkValidityInputs ( inputs ) ) {
27
34
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
35
}
61
- return parts [ partNr ] ;
36
+
37
+ const complexAction : ComplexAction = {
38
+ actions : [ ] ,
39
+ title : get ( 'locamation.vmu.updateAction' , { lnName : lnHeader ( this . logicalNode , this . nsdoc ) } ) ,
40
+ } ;
41
+
42
+ complexAction . actions . push ( ...createEditorAction ( locamationPrivate , 'IDENTIFIER' , getInputFieldValue ( inputs , 'Identifier' ) ) ) ;
43
+ if ( hasPrivateElement ( this . logicalNode , 'SUM' ) ) {
44
+ complexAction . actions . push ( ...createEditorAction ( locamationPrivate , 'SUM' , getInputFieldValue ( inputs , 'Sum' ) ) ) ;
45
+ } else {
46
+ complexAction . actions . push ( ...createEditorAction ( locamationPrivate , 'CHANNEL' , getInputFieldValue ( inputs , 'Channel' ) ) ) ;
47
+ }
48
+ complexAction . actions . push ( ...createEditorAction ( locamationPrivate , 'TRANSFORM-PRIMARY' , getInputFieldValue ( inputs , 'TransformPrimary' ) ) ) ;
49
+ complexAction . actions . push ( ...createEditorAction ( locamationPrivate , 'TRANSFORM-SECONDARY' , getInputFieldValue ( inputs , 'TransformSecondary' ) ) ) ;
50
+
51
+ return complexAction . actions . length ? [ complexAction ] : [ ] ;
52
+ }
53
+
54
+ private fieldsChanged ( locamationPrivate : Element , inputs : WizardInput [ ] ) : boolean {
55
+ const oldIdentifier = getPrivateTextValue ( locamationPrivate , 'IDENTIFIER' ) ;
56
+ const oldChannel = getPrivateTextValue ( locamationPrivate , 'CHANNEL' ) ;
57
+ const oldSum = getPrivateTextValue ( locamationPrivate , 'SUM' ) ;
58
+ const oldTransformPrimary = getPrivateTextValue ( locamationPrivate , 'TRANSFORM-PRIMARY' ) ;
59
+ const oldTransformSecondary = getPrivateTextValue ( locamationPrivate , 'TRANSFORM-SECONDARY' ) ;
60
+
61
+ return inputFieldChanged ( inputs , 'Identifier' , oldIdentifier )
62
+ || ( hasPrivateElement ( locamationPrivate , 'SUM' ) ? inputFieldChanged ( inputs , 'Sum' , oldSum ) : false )
63
+ || ( hasPrivateElement ( locamationPrivate , 'CHANNEL' ) ? inputFieldChanged ( inputs , 'Channel' , oldChannel ) : false )
64
+ || inputFieldChanged ( inputs , 'TransformPrimary' , oldTransformPrimary )
65
+ || inputFieldChanged ( inputs , 'TransformSecondary' , oldTransformSecondary ) ;
66
+ }
67
+
68
+ private checkValidityInputs ( inputs : WizardInput [ ] ) : boolean {
69
+ return Array . from ( inputs ) . every ( checkValidity ) ;
62
70
}
63
71
64
72
render ( ) : TemplateResult {
65
73
const lDevice = this . logicalNode . closest ( 'LDevice' ) ! ;
66
74
const ied = lDevice . closest ( 'IED' ) ! ;
75
+ const locamationPrivate = getPrivate ( this . logicalNode ) ;
76
+
77
+ // Depending on the value of the class the pattern for the CIM or VIM for SUM/CHANNEL will change.
78
+ let channelPattern = '[0-5]' ;
79
+ let sumPattern = '[0-5],[0-5],[0-5]' ;
80
+ if ( this . logicalNode . getAttribute ( 'lnClass' ) === 'TVTR' ) {
81
+ channelPattern = '[0-2]' ;
82
+ sumPattern = '[0-2],[0-2],[0-2]' ;
83
+ }
84
+
67
85
return html `
68
- < wizard-textfield label ="IED "
86
+ < wizard-textfield label ="${ translate ( 'locamation.vmu.ied.name' ) } "
69
87
.maybeValue =${ iedHeader ( ied ) }
70
- helper ="${ translate ( 'locamation.vmu.ied.name' ) } "
71
88
disabled >
72
89
</ wizard-textfield >
73
- < wizard-textfield label ="Logical Device "
90
+ < wizard-textfield label ="${ translate ( 'locamation.vmu.ldevice.name' ) } "
74
91
.maybeValue =${ lDeviceHeader ( lDevice ) }
75
- helper ="${ translate ( 'locamation.vmu.ldevice.name' ) } "
76
92
disabled >
77
93
</ wizard-textfield >
78
- < wizard-textfield label ="Logical Node "
94
+ < wizard-textfield label ="${ translate ( 'locamation.vmu.ln.name' ) } "
79
95
.maybeValue =${ lnHeader ( this . logicalNode , this . nsdoc ) }
80
- helper ="${ translate ( 'locamation.vmu.ln.name' ) } "
81
96
disabled >
82
97
</ wizard-textfield >
83
98
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 > `
99
+ < wizard-textfield label ="${ translate ( 'locamation.vmu.version' ) } "
100
+ .maybeValue =${ getPrivateTextValue ( locamationPrivate , 'VERSION' ) }
101
+ disabled >
102
+ </ wizard-textfield >
103
+
104
+ < wizard-textfield id ="Identifier "
105
+ label ="Identifier "
106
+ .maybeValue =${ getPrivateTextValue ( locamationPrivate , 'IDENTIFIER' ) }
107
+ helper ="${ translate ( 'locamation.vmu.identifierHelper' ) } "
108
+ pattern="^(([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(\\.(?!$)|$)){3}$"
109
+ required
110
+ dialogInitialFocus>
111
+ </ wizard-textfield >
112
+
113
+ ${ hasPrivateElement ( locamationPrivate , 'SUM' ) ?
114
+ html `< wizard-textfield id ="Sum "
115
+ label ="Sum "
116
+ .maybeValue =${ getPrivateTextValue ( locamationPrivate , 'SUM' ) }
117
+ helper ="The collection of three channel numbers for which the sum of currents or voltages will be calculated. The numbers are separated by commas. Values for the current sensor range from 0 - 5, for the voltage sensor 0-2."
118
+ pattern="${ sumPattern } "
119
+ required>
120
+ </ wizard-textfield > ` : html ``
112
121
}
113
- < wizard-textfield label ="TransformPrimary "
114
- .maybeValue =${ getPrivateTextValue ( this . logicalNode , LOCAMATION_PRIVATE , 'TRANSFORM-PRIMARY' ) }
115
- helper ="TransformPrimary"
122
+ ${ hasPrivateElement ( locamationPrivate , 'CHANNEL' ) ?
123
+ html `< wizard-textfield id ="Channel "
124
+ label ="Channel "
125
+ .maybeValue =${ getPrivateTextValue ( locamationPrivate , 'CHANNEL' ) }
126
+ helper ="The channel number on the sensor. Values for the current sensor range from 0 - 5, for the voltage sensor 0-2."
127
+ pattern="${ channelPattern } "
128
+ required>
129
+ </ wizard-textfield > ` : html ``
130
+ }
131
+
132
+ < wizard-textfield id ="TransformPrimary "
133
+ label ="Transform Primary "
134
+ .maybeValue =${ getPrivateTextValue ( locamationPrivate , 'TRANSFORM-PRIMARY' ) }
135
+ helper ="The nominator of the ratio of the measement transformer."
136
+ pattern="${ patterns . unsigned } "
116
137
required>
117
138
</ wizard-textfield >
118
- < wizard-textfield label ="TransformSecondary "
119
- .maybeValue =${ getPrivateTextValue ( this . logicalNode , LOCAMATION_PRIVATE , 'TRANSFORM-SECONDARY' ) }
120
- helper ="TransformSecondary"
139
+ < wizard-textfield id ="TransformSecondary "
140
+ label ="Transform Secondary "
141
+ .maybeValue =${ getPrivateTextValue ( locamationPrivate , 'TRANSFORM-SECONDARY' ) }
142
+ helper ="The denominator of the ratio of the measement transformer."
143
+ pattern="${ patterns . unsigned } "
121
144
required>
122
145
</ wizard-textfield >
123
146
` ;
@@ -139,7 +162,7 @@ export function locamationLNEditWizard(logicalNode: Element, nsdoc: Nsdoc): Wiza
139
162
function save ( ) {
140
163
return function ( inputs : WizardInput [ ] , wizard : Element ) : WizardAction [ ] {
141
164
const locamationVMUEditElement = < LocamationVMUEditElement > wizard . shadowRoot ! . querySelector ( 'locamation-ln-edit' )
142
- return locamationVMUEditElement . save ( inputs ) ;
165
+ return locamationVMUEditElement . save ( ) ;
143
166
} ;
144
167
}
145
168
0 commit comments