Skip to content

Commit 6e05fa7

Browse files
committed
more to go
1 parent f0a0a76 commit 6e05fa7

File tree

5 files changed

+141
-84
lines changed

5 files changed

+141
-84
lines changed

src/css/tabs/auxiliary.less

+14
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,20 @@
1111
color: rgb(105, 99, 99);
1212
padding: 10px 5px;
1313
}
14+
.auxiliary_category_content {
15+
width: 100%;
16+
}
17+
.auxiliary_category_header {
18+
width: 100%;
19+
margin-top: 6px;
20+
padding: 4px;
21+
padding-left: 8px;
22+
padding-right: 8px;
23+
color: white;
24+
border: 1px solid var(--subtleAccent);
25+
background-color: rgba(64, 64, 64, 1);
26+
resize: none;
27+
}
1428
.range {
1529
.marker {
1630
background: var(--accent);

src/js/localization.js

+19-2
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,31 @@ const i18n = {};
1111
window.i18n = i18n;
1212

1313

14-
const languagesAvailables = ['ca', 'da', 'de', 'en', 'es', 'eu', 'fr', 'gl', 'it', 'ja', 'ko', 'nl', 'pt', 'pt_BR', 'pl', 'ru', 'uk', 'zh_CN', 'zh_TW'];
14+
const languagesAvailables = ['ca', 'da', 'de', 'en', 'es', 'eu', 'fr', 'gl', 'it',
15+
'ja', 'ko', 'nl', 'pt', 'pt_BR', 'pl', 'ru', 'uk', 'zh_CN', 'zh_TW'];
1516

1617
const languageFallback = {
1718
'pt': ['pt_BR', 'en'],
1819
'pt_BR': ['pt', 'en'],
1920
'default': ['en'],
2021
};
2122

23+
// must be aligned with languagesAvailables
24+
const languageISOcode = ['ca-ES', 'da-DK', 'de-DE', 'en-US', 'es-ES', 'eu-ES', 'fr-FR', 'gl-ES', 'it-IT',
25+
'ja-JP', 'ko-KR', 'nl-NL', 'pt-PT', 'pt-BR', 'pl-PL', 'ru-RU', 'uk-UA', 'zh-CN', 'zh-TW'];
26+
27+
/**
28+
* Functions that return ISO Language Code Table from http://www.lingoes.net/en/translator/langcode.htm
29+
* Map between languagesAvailables and languageISOcode
30+
* Fallback to en-US
31+
*/
32+
function getCurrentLocaleISO() {
33+
const isoCodeIndex = languagesAvailables.indexOf(i18next.language);
34+
if (isoCodeIndex === -1)
35+
return 'en-US';
36+
return languageISOcode[isoCodeIndex];
37+
}
38+
2239
/**
2340
* Functions that depend on the i18n framework
2441
*/
@@ -238,4 +255,4 @@ i18n.addResources = function(bundle) {
238255
i18next.addResourceBundle(lang, ns, bundle, true, true);
239256
};
240257

241-
export { i18n };
258+
export { i18n, getCurrentLocaleISO };

src/js/tabs/auxiliary.js

+98-69
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { i18n } from '../localization';
1+
import { i18n, getCurrentLocaleISO } from "../localization";
22
import GUI, { TABS } from '../../js/gui';
33
import { get as getConfig, set as setConfig } from '../ConfigStorage';
44
import { bit_check } from '../bit';
@@ -13,7 +13,7 @@ import inflection from "inflection";
1313

1414
const auxiliary = {};
1515

16-
// BF build Options mapped to build Key
16+
// BF build Options mapped to buildKey.
1717
let 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 = [
3131
const 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
3535
let 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
143199
You 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-
147202
auxiliary.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

src/main.html

+1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
<link type="text/css" rel="stylesheet" href="./css/select2_custom.css" media="all"/>
5050
<link type="text/css" rel="stylesheet" href="./node_modules/select2/dist/css/select2.min.css" media="all"/>
5151
<link type="text/css" rel="stylesheet" href="./node_modules/multiple-select/dist/multiple-select.min.css" media="all"/>
52+
<link type="text/css" rel="stylesheet" href="./node_modules/multiple-select/dist/multiple-select-locale-all.min.js"/>
5253
<link type="text/css" rel="stylesheet" href="./components/EscDshotDirection/Styles.css" media="all"/>
5354

5455
<link type="text/css" rel="stylesheet" href="./css/dark-theme.css" media="all" disabled/>

src/tabs/auxiliary.html

+9-13
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,22 @@
77
<div class="note">
88
<p i18n="auxiliaryHelp"></p>
99
</div>
10-
1110
<table>
1211
<tr>
1312
<td>
14-
<div id="auxiliary_main_content">
15-
<div class="auxiliary_search_settings">
16-
<div class="auxiliary_filter_table_wrapper">
17-
<div class="auxiliary_filter_row">
18-
<div class = "auxiliary_fitler_table_header" i18n="auxiliaryFilterCategory"></div>
19-
<div class="line auxiliary_filter_table_value">
20-
<select id="auxiliary_category" multiple="multiple" class="auxiliary_category_select"></select>
21-
</div>
22-
</div>
13+
<div id="auxiliary_category_content">
14+
<div class="auxiliary_filter_row">
15+
<div>
16+
<div class="auxiliary_category_header" i18n="auxiliaryFilterCategory"></div>
17+
</div>
18+
<div class="line auxiliary_category_select_value">
19+
<select id="auxiliary_category" multiple="multiple" class="auxiliary_category_select" width: 100%; size='14'></select>
2320
</div>
2421
</div>
2522
</div>
2623
</td>
27-
<td>&nbsp;&nbsp;&nbsp;</td>
28-
<td vertical-align: bottom;>
24+
<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
25+
<td>
2926
<div class="toolbox">
3027
<form>
3128
<input type="checkbox" id="switch-toggle-unused" name="switch-toggle-unused" class="toggle"/>
@@ -35,7 +32,6 @@
3532
</td>
3633
</tr>
3734
</table>
38-
3935
<div class="modes"></div>
4036
</div>
4137
<div class="content_toolbar">

0 commit comments

Comments
 (0)