Skip to content

Commit 28c0e09

Browse files
author
Andy Werner
committed
Streamlined the password dialog, put MrBeam forwardURL into defaultSettings and stuff
1 parent 3cb6c0e commit 28c0e09

File tree

3 files changed

+43
-21
lines changed

3 files changed

+43
-21
lines changed

octoprint_netconnectd/__init__.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,9 @@ def get_settings_defaults(self):
4444
return dict(
4545
socket="/var/run/netconnectd.sock",
4646
hostname=None,
47-
forwardUrl=None,
48-
timeout=10
47+
forwardUrl='http://find.mr-beam.org:5000',
48+
# ANDYTEST TODO: check timeouts
49+
timeout=80
4950
)
5051

5152
##~~ TemplatePlugin API
@@ -58,6 +59,7 @@ def get_template_configs(self):
5859
##~~ SimpleApiPlugin API
5960

6061
def get_api_commands(self):
62+
self._logger.info("ANDYTEST get_api_commands() ")
6163
return dict(
6264
start_ap=[],
6365
stop_ap=[],
@@ -203,7 +205,6 @@ def _send_message(self, message, data):
203205

204206
import socket
205207
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
206-
self._logger.info("ANDYTEST self._settings.get_int(['timeout']): %s", self._settings.get_int(["timeout"]))
207208
sock.settimeout(self._settings.get_int(["timeout"]))
208209
try:
209210
sock.connect(self.address)

octoprint_netconnectd/static/js/netconnectd.js

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ $(function() {
44

55
self.loginState = parameters[0];
66
self.settingsViewModel = parameters[1];
7+
8+
self.allViewModels = undefined;
79

810
self.isWizardActive = false;
911

@@ -14,9 +16,9 @@ $(function() {
1416
self.reconnectTimeout = undefined;
1517

1618
self.enableQualitySorting = ko.observable(false);
17-
18-
self.hostname = ko.observable();
19-
self.forwardUrl = ko.observable();
19+
20+
self.hostname = ko.observable(undefined);
21+
self.forwardUrl = ko.observable(undefined);
2022

2123
self.status = {
2224
link: ko.observable(),
@@ -40,6 +42,10 @@ $(function() {
4042
self.editorWifiPassphraseMismatch = ko.computed(function() {
4143
return self.editorWifiPassphrase1() != self.editorWifiPassphrase2();
4244
});
45+
self.editorWifiPassphraseNotEmpty = ko.computed(function() {
46+
47+
return self.editorWifiPassphrase1() != self.editorWifiPassphrase2();
48+
});
4349

4450
self.working = ko.observable(false);
4551
self.error = ko.observable(false);
@@ -74,6 +80,10 @@ $(function() {
7480
return text;
7581
});
7682

83+
self.onAllBound = function(allViewModels) {
84+
self.allViewModels = allViewModels;
85+
}
86+
7787
self.onWizardDetails = function(response){
7888
console.log("ANDYETST onWizardDetails() setting self.isWizardActive = true");
7989
self.isWizardActive = true;
@@ -116,8 +126,7 @@ $(function() {
116126
return 0;
117127
}
118128
},
119-
{
120-
},
129+
{},
121130
"quality",
122131
[],
123132
[],
@@ -141,7 +150,7 @@ $(function() {
141150
}
142151

143152
self.hostname(response.hostname);
144-
self.forwardUrl(response.forwardUrl);
153+
self.forwardUrl(response.forwardUrl ? response.forwardUrl : undefined);
145154

146155
self.status.link(response.status.link);
147156
self.status.connections.ap(response.status.connections.ap);
@@ -272,6 +281,17 @@ $(function() {
272281

273282
self.sendWifiConfig = function(ssid, psk, successCallback, failureCallback) {
274283
if (!self.canRun()) return;
284+
285+
// trigger onBeforeWifiConfigure event.
286+
callViewModels(self.allViewModels, "onBeforeWifiConfigure",
287+
function(viewModelCallback){
288+
if (viewModelCallback && typeof viewModelCallback === 'function') {
289+
var result = viewModelCallback();
290+
if (result && result.forwardUrl) {
291+
self.forwardUrl(result.forwardUrl);
292+
}
293+
}
294+
});
275295

276296
self.working(true);
277297
if (self.status.connections.ap()) {
@@ -306,13 +326,14 @@ $(function() {
306326
};
307327

308328
self.tryReconnect = function() {
309-
// // ANDYTEST
310-
// return
311-
// var hostname = self.hostname();
312-
313-
// var location = window.location.href
314-
// location = location.replace(location.match("https?\\://([^:@]+(:[^@]+)?@)?([^:/]+)")[3], hostname);
315-
var location = self.forwardUrl();
329+
var location = undefined;
330+
if (!self.forwardUrl()) {
331+
var hostname = self.hostname();
332+
location = window.location.href
333+
location = location.replace(location.match("https?\\://([^:@]+(:[^@]+)?@)?([^:/]+)")[3], hostname);
334+
} else {
335+
location = self.forwardUrl();
336+
}
316337

317338
var pingCallback = function(result) {
318339
if (!result) {

octoprint_netconnectd/templates/netconnectd_settings.jinja2

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,17 +65,17 @@
6565
</div>
6666
<div class="modal-body">
6767
<form class="form-horizontal">
68-
<div class="control-group">
68+
<div class="control-group" data-bind="css: {success: $root.editorWifiPassphrase2() && !$root.editorWifiPassphraseMismatch()}">
6969
<label class="control-label" for="settings_plugin_netconnectd_wificonfig_passphrase1">{{ _('Password') }}</label>
7070
<div class="controls">
71-
<input type="password" class="input-block-level" id="settings_plugin_netconnectd_wificonfig_passphrase1" data-bind="value: $root.editorWifiPassphrase1" required>
71+
<input type="password" class="input-block-level" id="settings_plugin_netconnectd_wificonfig_passphrase1" data-bind="value: $root.editorWifiPassphrase1, valueUpdate: 'input'" required>
7272
</div>
7373
</div>
74-
<div class="control-group" data-bind="css: {error: $root.editorWifiPassphraseMismatch()}">
74+
<div class="control-group" data-bind="css: {success: $root.editorWifiPassphrase2() && !$root.editorWifiPassphraseMismatch(), error: $root.editorWifiPassphrase2() && $root.editorWifiPassphraseMismatch()}">
7575
<label class="control-label" for="settings_plugin_netconnectd_wificonfig_passphrase2">{{ _('Repeat Password') }}</label>
7676
<div class="controls">
77-
<input type="password" class="input-block-level" id="settings_plugin_netconnectd_wificonfig_passphrase2" data-bind="value: $root.editorWifiPassphrase2, valueUpdate: 'afterkeydown'" required>
78-
<span class="help-inline" data-bind="visible: $root.editorWifiPassphraseMismatch()">{{ _('Passwords do not match') }}</span>
77+
<input type="password" class="input-block-level" id="settings_plugin_netconnectd_wificonfig_passphrase2" data-bind="value: $root.editorWifiPassphrase2, valueUpdate: 'input'" required>
78+
<span class="help-inline" data-bind="visible: $root.editorWifiPassphrase2() && $root.editorWifiPassphraseMismatch()">{{ _('Passwords do not match') }}</span>
7979
</div>
8080
</div>
8181
</form>

0 commit comments

Comments
 (0)