networks: Overhaul Wi-Fi network scan page

Fixes: #1725.

- Show multiple Wi-Fi devices in separate tables so that users can pick them
understanding what they are. Also avoids some confusion related to why APs are
duplicated.

- Request scanning if the last scan time was long ago.

- Show the last scanned time.

- Refresh page in 10 seconds if scan has been requested so that the results of
scan can be shown without user explicitly refreshing the page. Show spinner when
scan has been requested and we are awaiting results.

- Refresh page every 60 seconds in other cases.

- When an SSID can't be decoded into a string, don't show it.

- Don't show hidden networks with no SSID set.

- Improve the styling for signal strength.

- Show a message when no Wi-Fi devices are present.

- Show a message when no Wi-Fi networks are found for a device.

Tests:

- Test on a machine with Wi-Fi device available.

- When page is loaded is for the first time, spinner is shown and refresh
happens in 10 seconds. After refresh if the scan has not completed, again,
spinner is shown and page is reloaded in 10 seconds. Otherwise, spinner is not
shown and page is reloaded in 60 seconds.

- Hidden networks are not shown.

- On a machine with no Wi-Fi devices, 'No Wi-Fi device detected.' message is
shown.

- Clicking on a network takes us to new Wi-Fi network connection page with
'connection name', 'network interface' and SSID filled in correctly.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
This commit is contained in:
Sunil Mohan Adapa authored and Veiko Aasa committed 2024-11-11 13:28:34 +02:00
1 parent a32a226492
commit 064f3c6c0c
3 files changed
+120 -37

No files matched your search

@@ -10,28 +10,52 @@
<h3>{{ title }}</h3>
<div class="row">
<div class="col-md-6">
<div class="list-group list-group-two-column">
{% for access_point in access_points %}
<div class="list-group-item">
<span class="primary">
{% if access_point.ssid %}
<a href="{% url 'networks:add_wifi' access_point.ssid access_point.interface_name %}">
{{ access_point.ssid }}
</a>
{% else %}
--
{% endif %}
</span>
{% if not device_access_points %}
<p>{% trans "No Wi-Fi device detected." %}</p>
{% else %}
<div class="row">
<div class="col-md-6">
{% for device in device_access_points %}
{% if device_access_points|length > 1 %}
<h4>
{% blocktrans trimmed with interface_name=device.interface_name %}
Device: {{ interface_name }}
{% endblocktrans %}
</h4>
{% endif %}
<p>
{% trans "Last scanned: " %}
{% if device.last_scan_time %}
{{ device.last_scan_time|timesince }}
{% else %}
{% trans "never" %}
{% endif %}
{% if device.scan_requested %}
<span class="fa fa-spinner fa-spin"></span>
{% endif %}
</p>
<div class="list-group list-group-two-column">
{% for access_point in device.access_points %}
<div class="list-group-item">
<span class="primary">
<a href="{% url 'networks:add_wifi' access_point.ssid_string device.interface_name %}">
{{ access_point.ssid_string }}
</a>
</span>
<span class="btn btn-primary btn-sm secondary">
{{ access_point.strength }}%
</span>
<span class="badge badge-secondary secondary">
{{ access_point.strength }}%
</span>
</div>
{% empty %}
<p>
{% trans "No Wi-Fi networks found." %}
</p>
{% endfor %}
</div>
{% endfor %}
</div>
</div>
</div>
{% endif %}
{% endblock %}
+11 -5
View File
@@ -385,11 +385,17 @@ def deactivate(request, uuid):
def scan(request):
"""Show a list of nearby visible Wi-Fi access points."""
access_points = network.wifi_scan()
return TemplateResponse(request, 'wifi_scan.html', {
'title': _('Nearby Wi-Fi Networks'),
'access_points': access_points
})
device_access_points = network.wifi_scan()
scanning = any(
(device['scan_requested'] for device in device_access_points))
# Refresh page in 10s if scanning, 60s otherwise
refresh_page_sec = 10 if scanning else 60
return TemplateResponse(
request, 'wifi_scan.html', {
'title': _('Nearby Wi-Fi Networks'),
'device_access_points': device_access_points,
'refresh_page_sec': refresh_page_sec
})
def add(request):