@@ -23,6 +23,7 @@ export interface LNData {
2323 lnType : string ;
2424 lnClass : string ;
2525 amount : number ;
26+ prefix ?: string ;
2627}
2728
2829/** Dialog for adding a new LN to a LDevice. */
@@ -46,6 +47,9 @@ export class AddLnDialog extends LitElement {
4647 @state ( )
4748 filterText = '' ;
4849
50+ @state ( )
51+ prefix : string = '' ;
52+
4953 private get lNodeTypes ( ) : Array < {
5054 id : string ;
5155 lnClass : string ;
@@ -74,21 +78,31 @@ export class AddLnDialog extends LitElement {
7478 this . lnType = '' ;
7579 this . amount = 1 ;
7680 this . filterText = '' ;
81+ this . prefix = '' ;
7782 this . dialog . show ( ) ;
7883 }
7984
8085 private close ( ) : void {
8186 this . dialog . close ( ) ;
8287 }
8388
89+ private isPrefixValid ( prefix : string ) : boolean {
90+ if ( prefix === '' ) return true ;
91+ if ( prefix . length > 11 ) return false ;
92+ return / ^ [ A - Z a - z ] [ 0 - 9 A - Z a - z _ ] * $ / . test ( prefix ) ;
93+ }
94+
8495 private handleCreate ( ) : void {
8596 const selectedType = this . lNodeTypes . find ( t => t . id === this . lnType ) ;
8697 if ( ! selectedType ) return ;
87- this . onConfirm ( {
98+ const data : LNData = {
8899 lnType : selectedType . id ,
89100 lnClass : selectedType . lnClass ,
90101 amount : this . amount ,
91- } ) ;
102+ ...( this . prefix && { prefix : this . prefix } ) ,
103+ } ;
104+
105+ this . onConfirm ( data ) ;
92106 this . close ( ) ;
93107 }
94108
@@ -145,6 +159,19 @@ export class AddLnDialog extends LitElement {
145159 </ mwc- lis t>
146160 </ div>
147161 </ div>
162+ <mwc- textfield
163+ label= "${ translate ( 'iededitor.addLnDialog.prefix' ) } "
164+ type = "text"
165+ maxlength = "11"
166+ .value = ${ this . prefix }
167+ @input = ${ ( e : Event ) => {
168+ e . stopPropagation ( ) ;
169+ this . prefix = ( e . target as HTMLInputElement ) . value ;
170+ } }
171+ pattern= "[A-Za-z][0-9A-Za-z_]*"
172+ style = "width: 100%; margin-top: 12px;"
173+ data-testid = "prefix"
174+ > </ mwc- textfield>
148175 <mwc- textfield
149176 label= ${ translate ( 'iededitor.addLnDialog.amount' ) }
150177 type= "number"
@@ -174,13 +201,17 @@ export class AddLnDialog extends LitElement {
174201 trailingIcon
175202 data-testid = "add-ln-button"
176203 @click = ${ this . handleCreate }
177- ?dis abled= ${ ! this . lnType || this . amount < 1 || this . amount % 1 != 0 }
204+ ?dis abled= ${ ! this . lnType ||
205+ this . amount < 1 ||
206+ this . amount % 1 != 0 ||
207+ ! this . isPrefixValid ( this . prefix ) }
178208 >
179209 ${ translate ( 'add' ) }
180210 </ mwc- butto n>
181211 </ mwc- dialog>
182212 ` ;
183213 }
214+
184215 static styles = css `
185216 .dialog-content {
186217 margin-top : 16px ;
0 commit comments