1- import { i18n } from ' ../localization' ;
1+ import { i18n , getCurrentLocaleISO } from " ../localization" ;
22import GUI , { TABS } from '../../js/gui' ;
33import { get as getConfig , set as setConfig } from '../ConfigStorage' ;
44import { bit_check } from '../bit' ;
@@ -13,7 +13,7 @@ import inflection from "inflection";
1313
1414const auxiliary = { } ;
1515
16- // BF build Options mapped to build Key
16+ // BF build Options mapped to buildKey.
1717let buildMap = [
1818 { buildKey : 'cam' , buildOption : [ 'USE_CAMERA_CONTROL' ] } ,
1919 { buildKey : 'div' , buildOption : [ 'USE_ARCO_TRAINER' , 'USE_DASHBOARD' , 'USE_PINIO' ] } ,
@@ -31,10 +31,10 @@ let buildMap = [
3131const flightModes = [ "ARM" , "ANGLE" , "HORIZON" , "ANTI GRAVITY" , "MAG" , "HEADFREE" , "HEADADJ" , "SERVO1" , "SERVO2" , "SERVO3" ,
3232 "FAILSAFE" , "AIR MODE" , "FPV ANGLE MIX" , "FLIP OVER AFTER CRASH" , "USER1" , "USER2" , "USER3" , "USER4" , "ACRO TRAINER" , "LAUNCH CONTROL" ] ;
3333
34- // Categories
34+ // Categories to be mapped with buildMap. Category 'all' are virtuel and always included
3535let categoryTable = [
3636 { name : '3D' , buildKey : [ 'dshot' ] , modes : [ '3D' , '3D DISABLE / SWITCH' ] } ,
37- { name : 'BEEP' , buildKey : [ 'all' ] , modes : [ 'BEEPER' , 'BEEPER MUTE' , 'GPS BEEP SATELLITE COUNT' ] } ,
37+ { name : 'BEEP' , buildKey : [ 'all' ] , modes : [ 'BEEPERON' , ' BEEPER', 'BEEPER MUTE' , 'GPS BEEP SATELLITE COUNT' ] } ,
3838 { name : 'BLACKBOX' , buildKey : [ 'all' ] , modes : [ 'BLACKBOX' , 'BLACKBOX ERASE' ] } ,
3939 { name : 'CAM' , buildKey : [ 'cam' ] , modes : [ 'CAMERA CONTROL 1' , 'CAMERA CONTROL 2' , 'CAMERA CONTROL 3' ] } ,
4040 { name : 'FLIGHTMODE' , buildKey : [ 'all' ] , modes : flightModes } ,
@@ -48,7 +48,9 @@ let categoryTable = [
4848 { name : 'VTX' , buildKey : [ 'vtx' ] , modes : [ 'STICK COMMANDS DISABLE' , 'VTX CONTROL DISABLE' , 'VTX PIT MODE' ] } ,
4949] ;
5050
51- function isInBuildKey ( map , name ) {
51+ let modeList = [ ] ;
52+
53+ function inBuildMap ( map , name ) {
5254 if ( name == 'all' ) {
5355 return true ;
5456 }
@@ -64,46 +66,100 @@ function isInBuildKey(map, name) {
6466 return false ;
6567}
6668
67- function createCategorySelect ( table ) {
68- let categorySelect = $ ( 'select.auxiliary_category_select' ) ;
69+ function isSelectedMode ( mList , modeName ) {
70+ for ( let i = 0 ; i < mList . length ; i ++ ) {
71+ if ( mList [ i ] . includes ( modeName ) ) {
72+ return true ;
73+ }
74+ }
75+ return false ;
76+ }
6977
70- for ( let i = 0 ; i < table . length ; i ++ ) {
71- if ( isInBuildKey ( buildMap , table [ i ] . buildKey ) ) {
72- categorySelect . append ( `<option value="${ table [ i ] . name } ">${ table [ i ] . name } </option>` ) ;
78+ function resolveCategoryName ( category , choise ) {
79+ let mList = [ ] ;
80+ for ( let i = 0 ; i < choise . length ; i ++ ) {
81+ for ( let j = 0 ; j < category . length ; j ++ ) {
82+ if ( choise [ i ] == category [ j ] . name ) {
83+ mList . push ( category [ j ] . modes ) ;
84+ }
7385 }
7486 }
87+ return mList ;
88+ }
7589
76- categorySelect . multipleSelect ( {
77- filter : true ,
78- // locale: selectOptions,
79- showClear : true ,
80- // minimumCountSelected : minimumCountSelected,
81- placeholder : i18n . getMessage ( "dropDownFilterDisabled" ) ,
82- // onClick: () => { this.updateSearchResults(); },
83- // onCheckAll: () => { this.updateSearchResults(); },
84- // onUncheckAll: () => { this.updateSearchResults(); },
85- formatSelectAll ( ) { return i18n . getMessage ( "dropDownSelectAll" ) ; } ,
86- formatAllSelected ( ) { return i18n . getMessage ( "dropDownAll" ) ; } ,
87- } ) ;
90+ function isPreSelectedCategory ( categoryList , categoryName ) {
91+ for ( let i = 0 ; i < categoryList . length ; i ++ ) {
92+ if ( categoryName == categoryList [ i ] ) {
93+ return true ;
94+ }
95+ }
96+ return false ;
8897}
8998
90- function createTable ( data ) {
91- // Create a dynamic table with fixed values
92- let table = [ ] ;
99+ function updateSearchResults ( ) {
100+ let categorySelect = $ ( 'select.auxiliary_category_select' ) ;
101+
102+ const categoryNameList = categorySelect . multipleSelect ( "getSelects" , "text" ) ;
103+ setConfig ( { auxiliaryCategoryNameList : categoryNameList } ) ; // save as users choise
104+ modeList = resolveCategoryName ( categoryTable , categoryNameList ) ;
105+ // like to call, but not out of scope ---- update_ui();
106+ }
93107
94- for ( let i = 0 ; i < data . length ; i ++ ) {
95- let row = data [ i ] . modes . slice ( ) ; // Use slice to clone the array
96- table . push ( row ) ;
108+ function getCategoryNames ( table , buildKey ) {
109+ // return names for buildKey category
110+ let categoryChoise = [ ] ;
111+ for ( let i = 0 ; i < table . length ; i ++ ) {
112+ if ( buildKey == table [ i ] . name ) {
113+ categoryChoise . push ( table [ i ] . name ) ;
114+ }
97115 }
98-
99- return table ;
116+ return categoryChoise ;
100117}
101118
102- // Function to display the table in the console
103- function displayTable ( table ) {
119+ function createCategorySelect ( table , map ) {
120+ let categorySelect = $ ( 'select.auxiliary_category_select' ) ;
121+
122+ const categoryNameObj = getConfig ( 'auxiliaryCategoryNameList' ) ; // read user pre selected categories
123+ let categoryNameList = categoryNameObj . auxiliaryCategoryNameList ;
124+ if ( categoryNameList . length == 0 ) {
125+ categoryNameList = getCategoryNames ( table , 'all' ) ; // empty choise -> select names from 'all' category
126+ setConfig ( { auxiliaryCategoryNameList : categoryNameList } ) ;
127+ }
128+
104129 for ( let i = 0 ; i < table . length ; i ++ ) {
105- console . log ( `${ table [ i ] . name } : ${ table [ i ] . modes } ` ) ;
130+ if ( inBuildMap ( map , table [ i ] . buildKey ) ) {
131+ if ( isPreSelectedCategory ( categoryNameList , table [ i ] . name ) ) {
132+ categorySelect . append ( `<option value="${ table [ i ] . name } " selected="selected">${ table [ i ] . name } </option>` ) ;
133+ }
134+ else {
135+ categorySelect . append ( `<option value="${ table [ i ] . name } ">${ table [ i ] . name } </option>` ) ;
136+ }
137+ }
138+ else {
139+ categorySelect . append ( `<option value="${ table [ i ] . name } " disabled="disabled">${ table [ i ] . name } </option>` ) ;
140+ }
106141 }
142+
143+ const modeWidth = 125 ;
144+ const heightUnit = categoryTable . length ;
145+
146+ categorySelect . sortSelect ( ) . multipleSelect ( {
147+ width : modeWidth + 50 ,
148+ dropWidth : modeWidth + 165 ,
149+ minimumCountSelected : 3 , // number before we use xx of yy
150+ maxHeightUnit : heightUnit , // in px
151+ locale : getCurrentLocaleISO ( ) ,
152+ filter : false ,
153+ showClear : true ,
154+ ellipsis : true ,
155+ openOnHover : true ,
156+ placeholder : i18n . getMessage ( "dropDownFilterDisabled" ) ,
157+ onClick : ( ) => { updateSearchResults ( ) ; } ,
158+ onCheckAll : ( ) => { updateSearchResults ( ) ; } ,
159+ onUncheckAll : ( ) => { updateSearchResults ( ) ; } ,
160+ formatSelectAll ( ) { return i18n . getMessage ( "dropDownSelectAll" ) ; } ,
161+ formatAllSelected ( ) { return i18n . getMessage ( "dropDownAll" ) ; } ,
162+ } ) ;
107163}
108164
109165// Function to simulate mouseover and select an option
@@ -143,7 +199,6 @@ The simulateMouseoverAndSelectForEachOption function iterates over each option i
143199You can also add a delay between each iteration if needed (commented out in the code). Adjust the delay according to your requirements.
144200*/
145201
146-
147202auxiliary . initialize = function ( callback ) {
148203 GUI . active_tab_ref = this ;
149204 GUI . active_tab = 'auxiliary' ;
@@ -436,10 +491,6 @@ auxiliary.initialize = function (callback) {
436491 // translate to user-selected language
437492 i18n . localizePage ( ) ;
438493
439- // generate category multiple select
440- displayTable ( categoryTable ) ;
441- createCategorySelect ( categoryTable ) ;
442-
443494 const length = Math . max ( ...( FC . AUX_CONFIG . map ( el => el . length ) ) ) ;
444495 $ ( '.tab-auxiliary .mode .info' ) . css ( 'min-width' , `${ Math . round ( length * getTextWidth ( 'A' ) ) } px` ) ;
445496
@@ -455,6 +506,9 @@ auxiliary.initialize = function (callback) {
455506 addLinkedToMode ( modeElement , 0 , 0 ) ;
456507 } ) ;
457508
509+ // setup category multiple select
510+ createCategorySelect ( categoryTable , buildMap ) ;
511+
458512 // UI Hooks
459513 $ ( 'a.save' ) . click ( function ( ) {
460514
@@ -621,32 +675,19 @@ auxiliary.initialize = function (callback) {
621675 }
622676
623677 let hideUnused = hideUnusedModes && hasUsedMode ;
624- let hideNoFlight = hideNoFlightMode && hasUsedMode ;
625678
626679 for ( let i = 1 ; i < FC . AUX_CONFIG . length ; i ++ ) { // ARM has index 0
627680 let modeElement = $ ( `#mode-${ i } ` ) ;
628681
629- if ( modeElement . find ( ' .range' ) . length == 0 && modeElement . find ( ' .link' ) . length == 0 ) {
630- // unused mode
631- modeElement . toggle ( ! hideUnused ) ;
682+ if ( ! isSelectedMode ( modeList , FC . AUX_CONFIG [ i ] ) ) {
683+ modeElement . toggle ( false ) ;
632684 }
633-
634- /*
635- if ( ! isFlightMode(FC.AUX_CONFIG[i])) {
636- // not flightMode mode
637- hide = hide || !hideNoFlight;
638- style = modeElement.css('display');
639- console.log(`1 HIDE not flightmode: ${FC.AUX_CONFIG[i]} -> ${hide}`);
640- // modeElement.toggle(!hideNoFlight);
641- / *
642- if( hideNoFlight && ! style === 'none') {
685+ else {
686+ if ( ! isSelectedMode ( modeList , FC . AUX_CONFIG [ i ] ) && modeElement . find ( ' .range' ) . length == 0 && modeElement . find ( ' .link' ) . length == 0 ) {
687+ // unused mode
643688 modeElement . toggle ( ! hideUnused ) ;
644689 }
645- style = modeElement.css('display');
646- console.log(`2 NOT flightmode: ${FC.AUX_CONFIG[i]} - ${style}`);
647- * /
648690 }
649- */
650691 }
651692
652693 auto_select_channel ( FC . RC . channels , FC . RC . active_channels , FC . RSSI_CONFIG . channel ) ;
@@ -701,9 +742,8 @@ auxiliary.initialize = function (callback) {
701742 }
702743
703744 let hideUnusedModes = false ;
704- let hideNoFlightMode = false ;
705745
706- // hide unused modes
746+ // get or save hide unused modes
707747 const configUnusedModes = getConfig ( 'hideUnusedModes' ) ;
708748 $ ( "input#switch-toggle-unused" )
709749 . change ( function ( ) {
@@ -714,17 +754,6 @@ auxiliary.initialize = function (callback) {
714754 . prop ( "checked" , ! ! configUnusedModes . hideUnusedModes )
715755 . change ( ) ;
716756
717- // hide non flightmodes
718- const configNoFlightMode = getConfig ( 'hideNoFlightMode' ) ;
719- $ ( "input#switch-toggle-hideNoFlightMode" )
720- . change ( function ( ) {
721- hideNoFlightMode = $ ( this ) . prop ( "checked" ) ;
722- setConfig ( { hideNoFlightMode : hideNoFlightMode } ) ;
723- update_ui ( ) ;
724- } )
725- . prop ( "checked" , ! ! configNoFlightMode . hideNoFlightMode )
726- . change ( ) ;
727-
728757 // update ui instantly on first load
729758 update_ui ( ) ;
730759
0 commit comments