@@ -6,31 +6,16 @@ import {
6
6
property ,
7
7
TemplateResult ,
8
8
} from 'lit-element' ;
9
- import { translate , get } from 'lit-translate' ;
10
9
11
- import {
12
- createElement ,
13
- EditorAction ,
14
- getReference ,
15
- getValue ,
16
- newActionEvent ,
17
- newWizardEvent ,
18
- Wizard ,
19
- WizardActor ,
20
- WizardInput ,
21
- } from '../../foundation.js' ;
10
+ import { newActionEvent , newWizardEvent } from '../../foundation.js' ;
22
11
23
- import {
24
- isCreateOptions ,
25
- selectors ,
26
- startMove ,
27
- updateNamingAction ,
28
- WizardOptions ,
29
- } from './foundation.js' ;
30
- import { typeIcon , typeName , types } from './conducting-equipment-types.js' ;
31
- import { editlNode } from './lnodewizard.js' ;
12
+ import { startMove } from './foundation.js' ;
32
13
import { BayEditor } from './bay-editor.js' ;
33
14
15
+ import { typeIcon } from './conducting-equipment-types.js' ;
16
+
17
+ import { wizards } from '../../wizards/wizard-library.js' ;
18
+
34
19
/** [[`SubstationEditor`]] subeditor for a `ConductingEquipment` element. */
35
20
@customElement ( 'conducting-equipment-editor' )
36
21
export class ConductingEquipmentEditor extends LitElement {
@@ -47,15 +32,14 @@ export class ConductingEquipmentEditor extends LitElement {
47
32
}
48
33
49
34
openEditWizard ( ) : void {
50
- this . dispatchEvent (
51
- newWizardEvent (
52
- ConductingEquipmentEditor . wizard ( { element : this . element } )
53
- )
54
- ) ;
35
+ const wizard = wizards [ 'ConductingEquipment' ] . edit ( this . element ) ;
36
+ if ( wizard ) this . dispatchEvent ( newWizardEvent ( wizard ) ) ;
55
37
}
56
38
39
+ /** Opens a [[`WizardDialog`]] for editing `LNode` connections. */
57
40
openLNodeWizard ( ) : void {
58
- this . dispatchEvent ( newWizardEvent ( editlNode ( this . element ) ) ) ;
41
+ const wizard = wizards [ 'LNode' ] . edit ( this . element ) ;
42
+ if ( wizard ) this . dispatchEvent ( newWizardEvent ( wizard ) ) ;
59
43
}
60
44
61
45
remove ( ) : void {
@@ -105,135 +89,6 @@ export class ConductingEquipmentEditor extends LitElement {
105
89
` ;
106
90
}
107
91
108
- static createAction ( parent : Element ) : WizardActor {
109
- return ( inputs : WizardInput [ ] ) : EditorAction [ ] => {
110
- const name = getValue ( inputs . find ( i => i . label === 'name' ) ! ) ;
111
- const desc = getValue ( inputs . find ( i => i . label === 'desc' ) ! ) ;
112
- const proxyType = getValue ( inputs . find ( i => i . label === 'type' ) ! ) ;
113
- const type = proxyType === 'ERS' ? 'DIS' : proxyType ;
114
-
115
- const element = createElement (
116
- parent . ownerDocument ,
117
- 'ConductingEquipment' ,
118
- { name, type, desc }
119
- ) ;
120
-
121
- if ( proxyType === 'ERS' )
122
- element . appendChild (
123
- createElement ( parent . ownerDocument , 'Terminal' , {
124
- name : 'T1' ,
125
- cNodeName : 'grounded' ,
126
- } )
127
- ) ;
128
-
129
- const action = {
130
- new : {
131
- parent,
132
- element,
133
- reference : getReference ( parent , 'ConductingEquipment' ) ,
134
- } ,
135
- } ;
136
-
137
- return [ action ] ;
138
- } ;
139
- }
140
-
141
- static wizard ( options : WizardOptions ) : Wizard {
142
- const [
143
- heading ,
144
- actionName ,
145
- actionIcon ,
146
- action ,
147
- name ,
148
- desc ,
149
- reservedNames ,
150
- element ,
151
- ] = isCreateOptions ( options )
152
- ? [
153
- get ( 'conductingequipment.wizard.title.add' ) ,
154
- get ( 'add' ) ,
155
- 'add' ,
156
- ConductingEquipmentEditor . createAction ( options . parent ) ,
157
- '' ,
158
- '' ,
159
- Array . from (
160
- options . parent . querySelectorAll ( selectors . ConductingEquipment )
161
- ) . map ( condEq => condEq . getAttribute ( 'name' ) ?? '' ) ,
162
- undefined ,
163
- ]
164
- : [
165
- get ( 'conductingequipment.wizard.title.edit' ) ,
166
- get ( 'save' ) ,
167
- 'edit' ,
168
- updateNamingAction ( options . element ) ,
169
- options . element . getAttribute ( 'name' ) ,
170
- options . element . getAttribute ( 'desc' ) ,
171
- Array . from (
172
- options . element . parentNode ! . querySelectorAll (
173
- selectors . ConductingEquipment
174
- )
175
- )
176
- . map ( condEq => condEq . getAttribute ( 'name' ) ?? '' )
177
- . filter ( name => name !== options . element . getAttribute ( 'name' ) ) ,
178
- options . element ,
179
- ] ;
180
-
181
- return [
182
- {
183
- title : heading ,
184
- element,
185
- primary : {
186
- icon : actionIcon ,
187
- label : actionName ,
188
- action : action ,
189
- } ,
190
- content : [
191
- ConductingEquipmentEditor . renderTypeSelector ( options ) ,
192
- html `<wizard- textfield
193
- label= "name"
194
- .maybeValue = ${ name }
195
- helper= "${ translate ( 'conductingequipment.wizard.nameHelper' ) } "
196
- required
197
- validationMessage= "${ translate ( 'textfield.required' ) } "
198
- dialogInitialFocus
199
- .reservedValues = ${ reservedNames }
200
- > </ wizard- textfield> ` ,
201
- html `<wizard- textfield
202
- label= "desc"
203
- .maybeValue = ${ desc }
204
- nullable
205
- helper= "${ translate ( 'conductingequipment.wizard.descHelper' ) } "
206
- > </ wizard- textfield> ` ,
207
- ] ,
208
- } ,
209
- ] ;
210
- }
211
-
212
- static renderTypeSelector ( options : WizardOptions ) : TemplateResult {
213
- return isCreateOptions ( options )
214
- ? html `<mwc- select
215
- style= "--mdc-menu-max-height: 196px;"
216
- required
217
- label = "type"
218
- helper= "${ translate ( 'conductingequipment.wizard.typeHelper' ) } "
219
- validationMessage= "${ translate ( 'textfield.required' ) } "
220
- >
221
- ${ Object . keys ( types ) . map (
222
- v => html `<mwc- lis t- item value= "${ v } " > ${ types [ v ] } </ mwc- lis t- item> `
223
- ) }
224
- </ mwc- select> `
225
- : html `<mwc- select
226
- label= "type"
227
- helper = "${ translate ( 'conductingequipment.wizard.typeHelper' ) } "
228
- validationMessage= "${ translate ( 'textfield.required' ) } "
229
- dis abled
230
- >
231
- <mwc- lis t- item selected value= "0"
232
- > ${ typeName ( options . element ) } </ mwc- lis t- item
233
- >
234
- </ mwc- select> ` ;
235
- }
236
-
237
92
static styles = css `
238
93
# container {
239
94
color : var (--mdc-theme-on-surface );
0 commit comments