Skip to content

Commit

Permalink
[v1.11.2] Add support for editing aliases, fix network settings not s…
Browse files Browse the repository at this point in the history
…aving during setup (#815)

* Add (very sloppy) support for editing an alias that already exists

* Set value of selectize input to alias being edited when edit button is clicked

* Use `setBreakAfterConfig(true)` from WiFiManager to ensure that save settings callback is called even when connection is unsuccessful (or user is just change settings).
  • Loading branch information
sidoh authored Nov 25, 2023
1 parent 45c1431 commit 638aa78
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 3 deletions.
4 changes: 2 additions & 2 deletions dist/index.html.gz.h

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,10 @@ void wifiExtraSettingsChange() {
settings.wifiStaticIPGateway = wifiStaticIPGateway->getValue();
settings.wifiMode = Settings::wifiModeFromString(wifiMode->getValue());
settings.save();

// Restart the device
delay(1000);
ESP.restart();
}

// Called when a group is deleted via the REST API. Will publish an empty message to
Expand Down Expand Up @@ -383,7 +387,12 @@ void setup() {

// Allows us to have static IP config in the captive portal. Yucky pointers to pointers, just to have the settings carry through
wifiManager = new WiFiManager();

// Setting breakAfterConfig to true causes wifiExtraSettingsChange to be called whenever config params are changed
// (even when connection fails or user is just changing settings and not network)
wifiManager->setBreakAfterConfig(true);
wifiManager->setSaveConfigCallback(wifiExtraSettingsChange);

wifiManager->setConfigPortalBlocking(false);
wifiManager->setConnectTimeout(20);
wifiManager->setConnectRetries(5);
Expand Down
31 changes: 30 additions & 1 deletion web/src/js/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -797,9 +797,10 @@ var saveDeviceAliases = function() {
var deviceAliases = Object.values(aliasesSelectize.options).reduce(
function (aggregate, x, index) {
var params = x.savedGroupParams;
x.id = index + 1;

aggregate.push([
index + 1,
x.id,
x.value,
params.deviceType,
params.deviceId,
Expand Down Expand Up @@ -1170,6 +1171,26 @@ $(function() {
createOnBlur: true,
render: {
option: function(data, escape) {
// Mousedown selects an option -- prevent event from bubbling up to select option
// when delete button is clicked.
var editBtn = $('<span class="selectize-delete"><a href="#"><i class="glyphicon glyphicon-edit"></i></a></span>')
.mousedown(function(e) {
e.preventDefault();
return false;
})
.click(function(e) {
aliasesSelectize.close();
aliasesSelectize.clear();

// set value in textbox to current alias
var alias = aliasesSelectize.options[data.value];
$('.selectize-input input#deviceAliases-selectized').val(alias.text).focus();

deleteDeviceAlias.call($(this).closest('.c-selectize-item'));
e.preventDefault();
return false;
});

// Mousedown selects an option -- prevent event from bubbling up to select option
// when delete button is clicked.
var deleteBtn = $('<span class="selectize-delete"><a href="#"><i class="glyphicon glyphicon-trash"></i></a></span>')
Expand All @@ -1187,6 +1208,11 @@ $(function() {
elmt.append('<span>' + data.text + '</span>');
elmt.append(deleteBtn);

// only add edit button if item is selected
if (aliasesSelectize.getValue() === data.value) {
elmt.append(editBtn);
}

return elmt;
}
},
Expand All @@ -1198,6 +1224,7 @@ $(function() {
};

saveDeviceAliases();
aliasesSelectize.clearCache();
}
})[0].selectize;

Expand Down Expand Up @@ -1417,6 +1444,8 @@ $(function() {
if (selectizeItem && !updatingAlias) {
updateGroupId(selectizeItem.savedGroupParams);
}

aliasesSelectize.clearCache();
});

$(document).ready( function() {
Expand Down

0 comments on commit 638aa78

Please sign in to comment.