Skip to content

Commit 5fe5f09

Browse files
committed
Add country dropdown
1 parent 739af5e commit 5fe5f09

File tree

3 files changed

+44
-7
lines changed

3 files changed

+44
-7
lines changed

octoprint_netconnectd/__init__.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ def initialize(self):
3434
self._analytics = Analytics(self)
3535
self.address = self._settings.get(["socket"])
3636
self.forwardUrl = self._settings.get(["forwardUrl"])
37+
self.country = self._settings.get(["country"])
3738
self._log_state_timed(self.LOG_STATE_DELAY)
3839

3940
@property
@@ -50,6 +51,7 @@ def hostname(self):
5051

5152
def on_settings_save(self, data):
5253
octoprint.plugin.SettingsPlugin.on_settings_save(self, data)
54+
self.country = self._settings.get(["country"])
5355
self.address = self._settings.get(["socket"])
5456

5557
def get_settings_defaults(self):
@@ -58,6 +60,7 @@ def get_settings_defaults(self):
5860
hostname=None,
5961
forwardUrl="http://find.mr-beam.org",
6062
timeout=80,
63+
country=None,
6164
)
6265

6366
##~~ TemplatePlugin API
@@ -90,6 +93,13 @@ def on_api_get(self, request):
9093
except Exception as e:
9194
return jsonify(dict(error=str(e)))
9295

96+
try:
97+
data = self._get_country_list()
98+
countries = data["countries"]
99+
country = data["country"]
100+
except Exception as e:
101+
return jsonify(dict(error=str(e)))
102+
93103
return jsonify(
94104
dict(
95105
wifis=wifis,
@@ -100,6 +110,8 @@ def on_api_get(self, request):
100110
eth0=self._get_ip_address("eth0"),
101111
wlan0=self._get_ip_address("wlan0"),
102112
),
113+
country=country,
114+
countries=countries,
103115
)
104116
)
105117

@@ -183,6 +195,19 @@ def _get_wifi_list(self, force=False):
183195
)
184196
return result
185197

198+
def _get_country_list(self, force=False):
199+
payload = {}
200+
201+
flag, content = self._send_message("country_list", payload)
202+
if not flag:
203+
raise RuntimeError("Error while getting countries wifi: " + content)
204+
205+
countries = []
206+
for country in content["countries"]:
207+
countries.append(country)
208+
return {"country": content["country"],
209+
"countries": countries}
210+
186211
def _get_status(self):
187212
payload = dict()
188213

octoprint_netconnectd/static/js/netconnectd.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ $(function() {
1919

2020
self.hostname = ko.observable(undefined);
2121
self.forwardUrl = ko.observable(undefined);
22+
self.countries = ko.observableArray([]);
23+
self.country = ko.observable(undefined);
2224

2325
self.status = {
2426
link: ko.observable(),
@@ -237,6 +239,9 @@ $(function() {
237239
self.requestData();
238240
}, 30000)
239241
}
242+
243+
self.countries(response.countries)
244+
self.country(response.country)
240245
};
241246

242247
self.configureWifi = function(data) {
@@ -415,13 +420,10 @@ $(function() {
415420
self.pollingTimeoutId = undefined;
416421
}
417422

418-
$.ajax({
419-
url: API_BASEURL + "plugin/netconnectd",
420-
// url: self.isWizardActive ? "/plugin/mrbeam/wifi" : API_BASEURL + "plugin/netconnectd",
421-
type: "GET",
422-
dataType: "json",
423-
success: self.fromResponse
424-
});
423+
OctoPrint.simpleApiGet("netconnectd")
424+
.done(function(response) {
425+
self.fromResponse(response);
426+
});
425427
};
426428

427429
self.onUserLoggedIn = function(user) {

octoprint_netconnectd/templates/netconnectd_settings.jinja2

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,16 @@
77
<p>
88
<strong>{{ _('Wifi') }}:</strong> <span data-bind="text: connectionStateTextWifi"></span>
99
</p>
10+
<div class="control-group">
11+
<label class="control-labelt"><strong>Country</strong></label>
12+
<div class="controls">
13+
<select data-bind="options: countries,
14+
optionsText: 'country',
15+
optionsValue: 'code',
16+
optionsCaption: 'Select Country...',
17+
value: country"></select>
18+
</div>
19+
</div>
1020
<div class="pull-right" data-bind="visible: enableQualitySorting">
1121
<small>
1222
{{ _('Sort by') }}: <a href="#" data-bind="click: function() { listHelper.changeSorting('ssid'); }">{{ _('SSID') }} ({{ _('ascending') }})</a> | <a href="#" data-bind="click: function() { listHelper.changeSorting('quality'); }">{{ _('Quality') }} ({{ _('descending') }})</a>

0 commit comments

Comments
 (0)