@@ -52,10 +52,10 @@ export class Models {
52
52
this . searchBox . tb . value = "" ;
53
53
this . populateModelList ( ) ;
54
54
} ) ;
55
- this . searchBox . tb . addEventListener ( "input" , ( ) => {
55
+ this . searchBox . tb . addEventListener ( "input" , util . debounce ( ( ) => {
56
56
this . searchState = this . searchBox . tb . value ;
57
57
this . populateModelList ( ) ;
58
- } ) ;
58
+ } , 400 ) ) ; // delay in ms
59
59
this . searchBox . tb . addEventListener ( "keydown" , ( ) => {
60
60
if ( event . key === 'Escape' || event . keyCode === 27 ) {
61
61
this . searchState = this . textbox_initial ;
@@ -191,6 +191,14 @@ export class ModelView {
191
191
this . error_message = "" ;
192
192
}
193
193
194
+ getFolderName ( path ) {
195
+ if ( ! path ) return null ;
196
+ // Remove trailing slash if present
197
+ path = path . replace ( / [ / \\ ] $ / , '' ) ;
198
+ // Get the last part of the path (the folder name)
199
+ return path . split ( / [ / \\ ] / ) . pop ( ) ;
200
+ }
201
+
194
202
updateView ( ) {
195
203
if ( ! this . modelID || this . modelID == "new" ) {
196
204
let model_info = { } ;
@@ -218,6 +226,12 @@ export class ModelView {
218
226
send ( post = null ) {
219
227
let packet = { } ;
220
228
packet . model_info = this . modelInfo ;
229
+ if ( this . modelID == "new" ) {
230
+ let folderName = this . getFolderName ( this . modelInfo . model_directory ) ;
231
+ if ( folderName ) {
232
+ this . modelInfo . name = folderName ;
233
+ }
234
+ }
221
235
fetch ( "/api/update_model" , { method : "POST" , headers : { "Content-Type" : "application/json" , } , body : JSON . stringify ( packet ) } )
222
236
. then ( response => response . json ( ) )
223
237
. then ( response => {
@@ -346,7 +360,15 @@ export class ModelView {
346
360
this . element . appendChild ( util . newDiv ( null , "model-view-text divider" , "" ) ) ;
347
361
this . element . appendChild ( util . newDiv ( null , "model-view-text spacer" , "" ) ) ;
348
362
349
- this . tb_model_directory = new controls . LabelTextbox ( "model-view-item-left" , "Model directory" , "model-view-item-textbox wide" , "~/models/my_model/" , this . modelInfo , "model_directory" , null , ( ) => { this . send ( ) } ) ;
363
+ this . tb_model_directory = new controls . LabelTextbox ( "model-view-item-left" , "Model directory" , "model-view-item-textbox wide" , "~/models/my_model/" , this . modelInfo , "model_directory" , null , ( ) => {
364
+ if ( this . modelID == "new" ) {
365
+ let folderName = this . getFolderName ( this . modelInfo . model_directory ) ;
366
+ if ( folderName ) {
367
+ this . modelInfo . name = folderName ;
368
+ }
369
+ }
370
+ this . send ( ) ;
371
+ } ) ;
350
372
this . element . appendChild ( this . tb_model_directory . element ) ;
351
373
352
374
this . element_model = util . newHFlex ( ) ;
0 commit comments