Skip to content

Commit e8e59c4

Browse files
committed
fix bugs for not update ui, when unselect mode
1 parent 35d0d0d commit e8e59c4

File tree

3 files changed

+83
-85
lines changed

3 files changed

+83
-85
lines changed

src/js/tabs/auxiliary.js

Lines changed: 79 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ const categoryTable = [
4646
{ name: 'VTX', buildKey: ['vtx'], modes: ['STICK COMMANDS DISABLE', 'VTX CONTROL DISABLE', 'VTX PIT MODE']},
4747
];
4848

49+
let notSorted = true;
50+
let hideUnusedModes = false;
4951
let modeList = [];
5052

5153
function inBuildMap(map, name) {
@@ -65,8 +67,8 @@ function inBuildMap(map, name) {
6567
}
6668

6769
function isSelectedMode(mList, modeName) {
68-
for (let value of mList) {
69-
if (value.includes(modeName)) {
70+
for (let i = 0; i < mList.length; i++) { // for (let value of mList) don't break on first hit
71+
if (mList[i].includes(modeName)) {
7072
return true;
7173
}
7274
}
@@ -91,6 +93,7 @@ function updateSearchResults() {
9193
const categoryNameList = categorySelect.multipleSelect("getSelects", "text");
9294
setConfig({ auxiliaryCategoryNameList: categoryNameList }); // save as users choise
9395
modeList = resolveCategoryName(categoryTable, categoryNameList);
96+
updateModes(); // update UI
9497
}
9598

9699
function getCategoryNames(table, buildKey) {
@@ -144,16 +147,83 @@ function createCategorySelect(table, map) {
144147
ellipsis: true,
145148
openOnHover: true, // open when muse over
146149
placeholder: i18n.getMessage("dropDownFilterDisabled"),
150+
onClear: () => { updateSearchResults(); },
147151
onClick: () => { updateSearchResults(); },
152+
onFilter: () => { updateSearchResults(); },
148153
onCheckAll: () => { updateSearchResults(); },
149154
onUncheckAll: () => { updateSearchResults(); },
150155
formatSelectAll() { return i18n.getMessage("dropDownSelectAll"); },
151156
formatAllSelected() { return i18n.getMessage("dropDownAll"); },
152157
});
153158
}
159+
function updateModes() {
160+
let hasUsedMode = false;
161+
162+
for (let i = 0; i < FC.AUX_CONFIG.length; i++) {
163+
let modeElement = $(`#mode-${i}`);
164+
165+
if (modeElement.find(' .range').length == 0 && modeElement.find(' .link').length == 0) {
166+
// if the mode is unused, skip it
167+
modeElement.removeClass('off').removeClass('on').removeClass('disabled');
168+
continue;
169+
}
170+
171+
if (bit_check(FC.CONFIG.mode, i)) {
172+
$('.mode .name').eq(i).data('modeElement').addClass('on').removeClass('off').removeClass('disabled');
173+
174+
// ARM mode is a special case
175+
if (i == 0) {
176+
$('.mode .name').eq(i).html(FC.AUX_CONFIG[i]);
177+
}
178+
} else {
179+
180+
// ARM mode is a special case
181+
if (i == 0) {
182+
let armSwitchActive = false;
183+
184+
if (FC.CONFIG.armingDisableCount > 0) {
185+
// check the highest bit of the armingDisableFlags. This will be the ARMING_DISABLED_ARMSWITCH flag.
186+
const armSwitchMask = 1 << (FC.CONFIG.armingDisableCount - 1);
187+
if ((FC.CONFIG.armingDisableFlags & armSwitchMask) > 0) {
188+
armSwitchActive = true;
189+
}
190+
}
191+
192+
// If the ARMING_DISABLED_ARMSWITCH flag is set then that means that arming is disabled
193+
// and the arm switch is in a valid arming range. Highlight the mode in red to indicate
194+
// that arming is disabled.
195+
if (armSwitchActive) {
196+
$('.mode .name').eq(i).data('modeElement').removeClass('on').removeClass('off').addClass('disabled');
197+
$('.mode .name').eq(i).html(`${FC.AUX_CONFIG[i]}<br>${i18n.getMessage('auxiliaryDisabled')}`);
198+
} else {
199+
$('.mode .name').eq(i).data('modeElement').removeClass('on').removeClass('disabled').addClass('off');
200+
$('.mode .name').eq(i).html(FC.AUX_CONFIG[i]);
201+
}
202+
} else {
203+
$('.mode .name').eq(i).data('modeElement').removeClass('on').removeClass('disabled').addClass('off');
204+
}
205+
}
206+
hasUsedMode = true;
207+
}
208+
209+
let hideUnused = hideUnusedModes && hasUsedMode;
210+
211+
for (let i = 1; i < FC.AUX_CONFIG.length; i++) { // ARM has index 0
212+
let modeElement = $(`#mode-${i}`);
213+
214+
if ( ! isSelectedMode(modeList, FC.AUX_CONFIG[i])) {
215+
modeElement.toggle( false);
216+
}
217+
else {
218+
modeElement.toggle( true);
219+
if ( modeElement.find(' .range').length == 0 && modeElement.find(' .link').length == 0) {
220+
modeElement.toggle(!hideUnused); // unused mode
221+
}
222+
}
223+
}
224+
}
154225

155226
auxiliary.initialize = function (callback) {
156-
GUI.active_tab_ref = this;
157227
GUI.active_tab = 'auxiliary';
158228
let prevChannelsValues = null;
159229
let hasDirtyUnusedModes = true;
@@ -413,9 +483,9 @@ auxiliary.initialize = function (callback) {
413483

414484
const modeTableBodyElement = $('.tab-auxiliary .modes');
415485
for (let modeIndex = 0; modeIndex < FC.AUX_CONFIG.length; modeIndex++) {
416-
417486
const modeId = FC.AUX_CONFIG_IDS[modeIndex];
418487
const newMode = createMode(modeIndex, modeId);
488+
419489
modeTableBodyElement.append(newMode);
420490

421491
// generate ranges from the supplied AUX names and MODE_RANGES[_EXTRA] data
@@ -579,69 +649,7 @@ auxiliary.initialize = function (callback) {
579649
}
580650

581651
function update_ui() {
582-
let hasUsedMode = false;
583-
for (let i = 0; i < FC.AUX_CONFIG.length; i++) {
584-
let modeElement = $(`#mode-${i}`);
585-
if (modeElement.find(' .range').length == 0 && modeElement.find(' .link').length == 0) {
586-
// if the mode is unused, skip it
587-
modeElement.removeClass('off').removeClass('on').removeClass('disabled');
588-
continue;
589-
}
590-
591-
if (bit_check(FC.CONFIG.mode, i)) {
592-
$('.mode .name').eq(i).data('modeElement').addClass('on').removeClass('off').removeClass('disabled');
593-
594-
// ARM mode is a special case
595-
if (i == 0) {
596-
$('.mode .name').eq(i).html(FC.AUX_CONFIG[i]);
597-
}
598-
} else {
599-
600-
// ARM mode is a special case
601-
if (i == 0) {
602-
let armSwitchActive = false;
603-
604-
if (FC.CONFIG.armingDisableCount > 0) {
605-
// check the highest bit of the armingDisableFlags. This will be the ARMING_DISABLED_ARMSWITCH flag.
606-
const armSwitchMask = 1 << (FC.CONFIG.armingDisableCount - 1);
607-
if ((FC.CONFIG.armingDisableFlags & armSwitchMask) > 0) {
608-
armSwitchActive = true;
609-
}
610-
}
611-
612-
// If the ARMING_DISABLED_ARMSWITCH flag is set then that means that arming is disabled
613-
// and the arm switch is in a valid arming range. Highlight the mode in red to indicate
614-
// that arming is disabled.
615-
if (armSwitchActive) {
616-
$('.mode .name').eq(i).data('modeElement').removeClass('on').removeClass('off').addClass('disabled');
617-
$('.mode .name').eq(i).html(`${FC.AUX_CONFIG[i]}<br>${i18n.getMessage('auxiliaryDisabled')}`);
618-
} else {
619-
$('.mode .name').eq(i).data('modeElement').removeClass('on').removeClass('disabled').addClass('off');
620-
$('.mode .name').eq(i).html(FC.AUX_CONFIG[i]);
621-
}
622-
} else {
623-
$('.mode .name').eq(i).data('modeElement').removeClass('on').removeClass('disabled').addClass('off');
624-
}
625-
}
626-
hasUsedMode = true;
627-
}
628-
629-
// setup categoryList to reflect changes when aux change
630-
updateSearchResults();
631-
632-
let hideUnused = hideUnusedModes && hasUsedMode;
633-
634-
for (let i = 1; i < FC.AUX_CONFIG.length; i++) { // ARM has index 0
635-
let modeElement = $(`#mode-${i}`);
636-
637-
if ( ! isSelectedMode(modeList, FC.AUX_CONFIG[i])) {
638-
modeElement.toggle( false);
639-
}
640-
else if ( modeElement.find(' .range').length == 0 && modeElement.find(' .link').length == 0) {
641-
// unused mode
642-
modeElement.toggle(!hideUnused);
643-
}
644-
}
652+
updateSearchResults(); // setup categoryList and show selected Modes
645653

646654
auto_select_channel(FC.RC.channels, FC.RC.active_channels, FC.RSSI_CONFIG.channel);
647655

@@ -692,23 +700,15 @@ auxiliary.initialize = function (callback) {
692700
return fillPrevChannelsValues();
693701
}
694702

695-
let hideUnusedModes = false;
696-
697703
// get or save hide unused modes
698704
const configUnusedModes = getConfig('hideUnusedModes');
699-
$("input#switch-toggle-unused")
700-
.change(function() {
701-
hideUnusedModes = $(this).prop("checked");
702-
hasDirtyUnusedModes = true;
703-
setConfig({ hideUnusedModes: hideUnusedModes });
704-
update_ui();
705-
})
705+
$("input#switch-toggle-unused").change(function() {
706+
hideUnusedModes = $(this).prop("checked");
707+
setConfig({ hideUnusedModes: hideUnusedModes });
708+
update_ui();})
706709
.prop("checked", !!configUnusedModes.hideUnusedModes)
707710
.change();
708711

709-
// setup categoryList
710-
updateSearchResults();
711-
712712
// update ui instantly on first load
713713
update_ui();
714714

src/js/utils/common.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,20 +101,19 @@ export function urlExists(url) {
101101
}
102102

103103
/**
104-
* Returns jquery sorted option list with optional value staying on top of the list.
104+
* Returns jquery sorted option list with optional value topText staying on top of the list.
105105
*
106106
* @param {string} optional value staying on top of the list.
107107
* @return {object} sorted option list.
108108
*/
109-
110-
$.fn.sortSelect = function(text = "") {
109+
$.fn.sortSelect = function(topText = "") {
111110
const op = this.children("option");
112111

113112
op.sort((a, b) => {
114-
if (a.text === text) {
113+
if (a.text === topText) {
115114
return -1;
116115
}
117-
if (b.text === text) {
116+
if (b.text === topText) {
118117
return 1;
119118
}
120119
return a.text.localeCompare(b.text, window.navigator.language, { ignorePunctuation: true });

src/main.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@
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"/>
5352
<link type="text/css" rel="stylesheet" href="./components/EscDshotDirection/Styles.css" media="all"/>
5453

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

0 commit comments

Comments
 (0)