@@ -423,24 +423,89 @@ export class CommandBox {
423423 button . disabled = false ;
424424 }
425425
426- static getSelectedMinionList ( ) {
426+ static _getNodegroupsSelection ( ) {
427+ const allNodeGroups = Utils . getStorageItemObject ( "session" , "nodegroups" ) ;
428+ const allNodeGroupsKeys = Object . keys ( allNodeGroups ) ;
429+
430+ let ret = "" ;
431+ const lst_nodegroups = Utils . getStorageItem ( "session" , "select_nodegroups" , null ) ;
432+ if ( lst_nodegroups ) {
433+ for ( const nodegroup of lst_nodegroups . split ( "," ) ) {
434+ if ( nodegroup === "null" ) {
435+ ret += " or not("
436+ let grplst = "" ;
437+ for ( const grp of allNodeGroupsKeys ) {
438+ grplst += " or N@" + grp ;
439+ }
440+ ret += grplst . substring ( 4 ) + ")" ;
441+ } else if ( nodegroup ) {
442+ ret += " or N@" + nodegroup ;
443+ }
444+ }
445+ }
446+ return ret ;
447+ }
448+
449+ static _getMinionSelection ( ) {
450+ let ret = "" ;
451+ const lst_minions = Utils . getStorageItem ( "session" , "select_minions" , null ) ;
452+ if ( lst_minions ) {
453+ let minionlist = "" ;
454+ for ( const minion of lst_minions . split ( "," ) ) {
455+ if ( minion ) {
456+ minionlist += "," + minion ;
457+ }
458+ }
459+ if ( minionlist ) {
460+ // substring removes the extra ","
461+ ret += " or L@" + minionlist . substring ( 1 ) ;
462+ }
463+ }
464+ return ret ;
465+ }
466+
467+ static getSelectedItemList ( pSessionKeys ) {
427468 const selectVisible = Utils . getStorageItemBoolean ( "session" , "select_visible" , false ) ;
428469 if ( ! selectVisible ) {
429470 return null ;
430471 }
431472
432- // only when the selection is visible
433- const selectMinions = Utils . getStorageItem ( "session" , "select_minions" , "" ) ;
434- const lst = selectMinions . split ( "," ) . sort ( ) ;
435- while ( lst . length > 0 && lst [ 0 ] === "" ) {
436- lst . shift ( ) ;
473+ let target = "" ;
474+
475+ if ( pSessionKeys . includes ( "select_nodegroups" ) ) {
476+ target += CommandBox . _getNodegroupsSelection ( ) ;
437477 }
438- // and only when there is a selection
439- if ( lst . length == 0 ) {
478+
479+ if ( pSessionKeys . includes ( "select_minions" ) ) {
480+ target += CommandBox . _getMinionSelection ( ) ;
481+ }
482+
483+ if ( pSessionKeys . includes ( "select_keys" ) ) {
484+ const lst_keys = Utils . getStorageItem ( "session" , "select_keys" , null ) ;
485+ if ( lst_keys ) {
486+ let keylist = "" ;
487+ for ( const key of lst_keys . split ( "," ) ) {
488+ if ( key ) {
489+ keylist += "," + key ;
490+ }
491+ }
492+ // substring removes the extra ","
493+ target += " or " + keylist . substring ( 1 ) ;
494+ }
495+ }
496+
497+ // remove the extra " or "
498+ target = target . substring ( 4 ) ;
499+ if ( target . startsWith ( "L@" ) ) {
500+ // simplify when we only have the list of minions
501+ target = target . substring ( 2 ) ;
502+ }
503+
504+ if ( target === "" ) {
440505 return null ;
441506 }
442507
443- return lst . join ( "," ) ;
508+ return target ;
444509 }
445510
446511 static showManualRun ( pApi ) {
@@ -498,7 +563,26 @@ export class CommandBox {
498563 CommandBox . _populateTemplateTmplMenu ( ) ;
499564 CommandBox . _populateTestProviders ( pApi ) ;
500565
501- const lst = CommandBox . getSelectedMinionList ( )
566+ let lst = null ;
567+ // different pages have different selection-types
568+ // but run-command is available from every page
569+ switch ( window . location . hash ) {
570+ case "#minions" :
571+ case "#grains" :
572+ case "#schedules" :
573+ case "#pillars" :
574+ case "#beacons" :
575+ case "#highstate" :
576+ lst = CommandBox . getSelectedItemList ( [ "select_minions" ] ) ;
577+ break ;
578+ case "#keys" :
579+ lst = CommandBox . getSelectedItemList ( [ "select_keys" ] ) ;
580+ break ;
581+ case "#nodegroups" :
582+ lst = CommandBox . getSelectedItemList ( [ "select_minions" , "select_nodegroups" ] ) ;
583+ break ;
584+ }
585+
502586 if ( lst ) {
503587 const targetField = document . getElementById ( "target" ) ;
504588 targetField . value = lst ;
0 commit comments