@@ -373,6 +373,157 @@ function fillTextareaWithAWSResubmitCommands() {
373373 }
374374}
375375
376+ async function fillTextareaWithGuessedConfigNames ( ) {
377+ const selectedCheckboxes = getVisibleCheckedCheckboxes ( ) ;
378+
379+ if ( selectedCheckboxes . length === 0 ) {
380+ showModalWarning (
381+ "No folders selected. Please select folders from the table first." ,
382+ ) ;
383+ document . getElementById ( "bulk-actions-textarea" ) . value = "" ;
384+ return ;
385+ }
386+
387+ // Show loading message
388+ const textarea = document . getElementById ( "bulk-actions-textarea" ) ;
389+ textarea . value = "Loading..." ;
390+ hideModalWarning ( ) ;
391+
392+ // Extract folder paths
393+ const folderPaths = Array . from ( selectedCheckboxes ) . map ( ( checkbox ) =>
394+ checkbox . getAttribute ( "data-path" ) ,
395+ ) ;
396+
397+ try {
398+ // Call backend API
399+ const response = await fetch ( "/picker/api/guess-config-names" , {
400+ method : "POST" ,
401+ headers : {
402+ "Content-Type" : "application/json" ,
403+ } ,
404+ body : JSON . stringify ( { folder_paths : folderPaths } ) ,
405+ } ) ;
406+
407+ const data = await response . json ( ) ;
408+
409+ if ( ! data . success ) {
410+ showModalWarning ( `Error: ${ data . error } ` ) ;
411+ textarea . value = "" ;
412+ return ;
413+ }
414+
415+ // Process results
416+ const successfulResults = data . results . filter (
417+ ( result ) => result . config_name ,
418+ ) ;
419+ const failedResults = data . results . filter ( ( result ) => ! result . config_name ) ;
420+
421+ if ( successfulResults . length === 0 ) {
422+ showModalWarning ( "No config names could be guessed from the metadata." ) ;
423+ textarea . value = "" ;
424+ return ;
425+ }
426+
427+ // Format output
428+ const configNames = successfulResults . map ( ( result ) => result . config_name ) ;
429+ textarea . value = configNames . join ( "\n" ) ;
430+
431+ // Show warning if some folders failed
432+ if ( failedResults . length > 0 ) {
433+ const errorMessages = failedResults . map ( ( result ) => {
434+ const folderName = result . folder . split ( "/" ) . pop ( ) ;
435+ return `${ folderName } : ${ result . error } ` ;
436+ } ) ;
437+ showModalWarning (
438+ `Warning: ${ failedResults . length } folder(s) failed:\n${ errorMessages . join ( "\n" ) } ` ,
439+ ) ;
440+ } else {
441+ hideModalWarning ( ) ;
442+ }
443+ } catch ( error ) {
444+ console . error ( "Error guessing config names:" , error ) ;
445+ showModalWarning ( `Error: ${ error . message } ` ) ;
446+ textarea . value = "" ;
447+ }
448+ }
449+
450+ async function fillTextareaWithAWSSubmitCommands ( ) {
451+ const selectedCheckboxes = getVisibleCheckedCheckboxes ( ) ;
452+
453+ if ( selectedCheckboxes . length === 0 ) {
454+ showModalWarning (
455+ "No folders selected. Please select folders from the table first." ,
456+ ) ;
457+ document . getElementById ( "bulk-actions-textarea" ) . value = "" ;
458+ return ;
459+ }
460+
461+ // Show loading message
462+ const textarea = document . getElementById ( "bulk-actions-textarea" ) ;
463+ textarea . value = "Loading..." ;
464+ hideModalWarning ( ) ;
465+
466+ // Extract folder paths
467+ const folderPaths = Array . from ( selectedCheckboxes ) . map ( ( checkbox ) =>
468+ checkbox . getAttribute ( "data-path" ) ,
469+ ) ;
470+
471+ try {
472+ // Call backend API
473+ const response = await fetch ( "/picker/api/guess-config-names" , {
474+ method : "POST" ,
475+ headers : {
476+ "Content-Type" : "application/json" ,
477+ } ,
478+ body : JSON . stringify ( { folder_paths : folderPaths } ) ,
479+ } ) ;
480+
481+ const data = await response . json ( ) ;
482+
483+ if ( ! data . success ) {
484+ showModalWarning ( `Error: ${ data . error } ` ) ;
485+ textarea . value = "" ;
486+ return ;
487+ }
488+
489+ // Process results
490+ const successfulResults = data . results . filter (
491+ ( result ) => result . config_name ,
492+ ) ;
493+ const failedResults = data . results . filter ( ( result ) => ! result . config_name ) ;
494+
495+ if ( successfulResults . length === 0 ) {
496+ showModalWarning ( "No config names could be guessed from the metadata." ) ;
497+ textarea . value = "" ;
498+ return ;
499+ }
500+
501+ // Format output as AWS submit commands
502+ const commands = successfulResults . map (
503+ ( result ) =>
504+ `aws/run_job.py -- aws/docker_and_sync.sh python main.py configs/main/${ result . config_name } ` ,
505+ ) ;
506+ textarea . value = commands . join ( "\n" ) ;
507+
508+ // Show warning if some folders failed
509+ if ( failedResults . length > 0 ) {
510+ const errorMessages = failedResults . map ( ( result ) => {
511+ const folderName = result . folder . split ( "/" ) . pop ( ) ;
512+ return `${ folderName } : ${ result . error } ` ;
513+ } ) ;
514+ showModalWarning (
515+ `Warning: ${ failedResults . length } folder(s) skipped:\n${ errorMessages . join ( "\n" ) } ` ,
516+ ) ;
517+ } else {
518+ hideModalWarning ( ) ;
519+ }
520+ } catch ( error ) {
521+ console . error ( "Error generating AWS submit commands:" , error ) ;
522+ showModalWarning ( `Error: ${ error . message } ` ) ;
523+ textarea . value = "" ;
524+ }
525+ }
526+
376527function copyFromModal ( ) {
377528 const textarea = document . getElementById ( "bulk-actions-textarea" ) ;
378529 const text = textarea . value ;
0 commit comments