Skip to content

Commit fdd5a71

Browse files
committed
[fix] Add loaders and button tags
1 parent b489d33 commit fdd5a71

File tree

6 files changed

+50
-19
lines changed

6 files changed

+50
-19
lines changed

openwisp_monitoring/device/static/monitoring/css/device-map.css

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,22 @@
2727
font-weight: bold;
2828
text-transform: uppercase;
2929
}
30-
#device-map-container {
31-
height: 430px;
32-
width: 90%;
33-
margin: 30px auto 0px auto;
30+
#dashboard-map-overlay {
3431
position: relative;
35-
border: 1px solid rgba(0, 0, 0, 0.3);
3632
}
37-
#device-map-container .ow-loading-spinner {
33+
#dashboard-map-overlay .ow-loading-spinner {
3834
position: absolute;
3935
z-index: 9999;
4036
top: 41%;
4137
left: 49%;
4238
}
39+
#device-map-container {
40+
height: 430px;
41+
width: 90%;
42+
margin: 30px auto 0px auto;
43+
position: relative;
44+
border: 1px solid rgba(0, 0, 0, 0.3);
45+
}
4346
#device-map-container .leaflet-interactive:focus {
4447
outline: none;
4548
}
@@ -230,6 +233,7 @@
230233
min-height: 375px;
231234
}
232235
#floorplan-container {
236+
position: relative;
233237
background: white;
234238
z-index: 99999;
235239
padding: 16px;
@@ -270,6 +274,12 @@
270274
height: 100%;
271275
flex: 1;
272276
}
277+
.floorplan-loading-spinner {
278+
position: absolute;
279+
top: 40%;
280+
left: 50%;
281+
z-index: 1000;
282+
}
273283
.floor-content {
274284
width: 100%;
275285
height: 100%;

openwisp_monitoring/device/static/monitoring/js/device-map.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"use strict";
22

33
(function ($) {
4-
const loadingOverlay = $("#device-map-container .ow-loading-spinner");
4+
const loadingOverlay = $("#dashboard-map-overlay .ow-loading-spinner");
55
const localStorageKey = "ow-map-shown";
66
const mapContainer = $("#device-map-container");
77
const statuses = ["critical", "problem", "ok", "unknown", "deactivated"];
@@ -51,6 +51,7 @@
5151
};
5252

5353
let currentPopup = null;
54+
let currentPopupLocationId = null;
5455

5556
const loadPopUpContent = function (nodeData, netjsongraphInstance, url) {
5657
loadingOverlay.show();
@@ -61,7 +62,6 @@
6162
if (currentPopup) {
6263
currentPopup.remove();
6364
}
64-
loadingOverlay.show();
6565

6666
$.ajax({
6767
dataType: "json",
@@ -137,6 +137,7 @@
137137
</div>
138138
`;
139139

140+
currentPopupLocationId = locationId;
140141
currentPopup = L.popup({
141142
autoPan: true,
142143
autoPanPadding: [25, 25],
@@ -262,6 +263,8 @@
262263
el.find(".leaflet-popup-close-button").on("click", function () {
263264
const id = netjsongraphInstance.config.bookmarkableActions.id;
264265
netjsongraphInstance.utils.removeUrlFragment(id);
266+
currentPopup = null;
267+
currentPopupLocationId = null;
265268
});
266269
loadingOverlay.hide();
267270
},
@@ -599,11 +602,11 @@
599602
ws.onmessage = function (e) {
600603
const data = JSON.parse(e.data);
601604
const [lng, lat] = data.geometry.coordinates;
602-
if (currentPopup) {
605+
if (currentPopup && data.id === currentPopupLocationId) {
603606
$(".leaflet-popup").hide();
604607
}
605608
map.utils.moveNodeInRealTime(data.id, { lng, lat });
606-
if (currentPopup) {
609+
if (currentPopup && data.id === currentPopupLocationId) {
607610
currentPopup.setLatLng([lat, lng]);
608611
$(".leaflet-popup").show();
609612
}

openwisp_monitoring/device/static/monitoring/js/floorplan.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@
181181

182182
$nav.off("click");
183183
$nav.on("click", ".floor-btn", async (e) => {
184+
$(".floorplan-loading-spinner").show();
184185
selectedIndex = +e.currentTarget.dataset.index;
185186
const center = Math.floor(NAV_WINDOW_SIZE / 2);
186187
navWindowStart = Math.max(0, Math.min(selectedIndex - center, maxStart));
@@ -191,6 +192,7 @@
191192
});
192193

193194
$nav.on("click", ".right-arrow:not(.disabled)", async () => {
195+
$(".floorplan-loading-spinner").show();
194196
if (selectedIndex < floors.length - 1) {
195197
selectedIndex++;
196198
const center = Math.floor(NAV_WINDOW_SIZE / 2);
@@ -203,6 +205,7 @@
203205
});
204206

205207
$nav.on("click", ".left-arrow:not(.disabled)", async () => {
208+
$(".floorplan-loading-spinner").show();
206209
if (selectedIndex > 0) {
207210
selectedIndex--;
208211
const center = Math.floor(NAV_WINDOW_SIZE / 2);
@@ -221,7 +224,6 @@
221224
.filter(`[data-floor="${floor}"]`)
222225
.addClass("active selected");
223226

224-
$(".floorplan-loading-spinner").hide();
225227
await fetchData(url, floor);
226228

227229
const nodesThisFloor = { nodes: allResults[floor], links: [] };
@@ -342,6 +344,7 @@
342344
map.eachLayer((layer) => layer._url && map.removeLayer(layer));
343345
const img = new Image();
344346
img.src = imageUrl;
347+
$(".floorplan-loading-spinner").show();
345348
await img.decode();
346349
let initialZoom;
347350

@@ -395,6 +398,7 @@
395398
map.setMaxBounds(bnds.pad(1));
396399
initialZoom = map.getZoom();
397400
map.invalidateSize();
401+
$(".floorplan-loading-spinner").hide();
398402

399403
map.on("fullscreenchange", () => {
400404
const floorNavigation = $("#floorplan-navigation");

openwisp_monitoring/device/static/monitoring/js/location-inline.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,20 @@
1414
}
1515

1616
const openLocationBtn = `
17-
<div class="form-row field-location-view-button" style="display: block;">
17+
<div class="form-row field-location-view-button" style="display: flex;">
1818
<div>
1919
<div class="flex-container">
20+
<label for="id_devicelocation-0-map">Map:</label>
2021
<a href="/admin/device_monitoring/map#${geoMapId}"
2122
id="open-location-btn"
2223
class="default-btn"
2324
style="color: white; text-decoration: none;">
24-
Open Location on Map
25+
View on General Map
2526
</a>
2627
</div>
28+
<div class="help" id="id_devicelocation-0-type_helptext">
29+
<div>Opens the general map view focused on this location</div>
30+
</div>
2731
</div>
2832
</div>
2933
`;
@@ -38,13 +42,17 @@
3842
<div class="form-row field-indoor-view-button" style="display: block;">
3943
<div>
4044
<div class="flex-container">
45+
<label for="id_devicelocation-0-map">Map:</label>
4146
<a href="/admin/device_monitoring/map#${geoMapId};${indoorMapId}"
4247
id="open-indoor-device-btn"
4348
class="default-btn"
4449
style="color: white; text-decoration: none;">
45-
Open Device on Map
50+
View on General Indoor Map
4651
</a>
4752
</div>
53+
<div class="help" id="id_devicelocation-0-type_helptext">
54+
<div>Opens the general indoor map view focused on this device</div>
55+
</div>
4856
</div>
4957
</div>
5058
`;

openwisp_monitoring/device/templates/admin/dashboard/device_map.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@
2020
<p>{% trans 'No map data to show' %}.</p>
2121
<p><a class="button submit" href="#close">Close</a></p>
2222
</div>
23-
<div class="ow-loading-spinner"></div>
2423
</div>
24+
<div class="ow-loading-spinner"></div>
2525
</div>

openwisp_monitoring/tests/test_selenium.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -744,11 +744,17 @@ def test_url_fragment_actions_on_indoor_map(self):
744744
self.web_driver.switch_to.window(tabs[0])
745745

746746
def test_dashboard_map_without_permissions(self):
747+
org = self._get_org()
747748
user = self._create_user(
748-
username="testuser", password="password", is_staff=True, is_superuser=True
749-
)
750-
permissions = Permission.objects.filter(codename__endswith="devicelocation")
751-
user.user_permissions.remove(*permissions)
749+
username="testuser",
750+
password="password",
751+
is_staff=True,
752+
is_superuser=False,
753+
754+
)
755+
self._create_org_user(user=user, organization=org, is_admin=True)
756+
permissions = Permission.objects.filter(codename__endswith="location")
757+
user.user_permissions.add(*permissions)
752758
self.login(username="testuser", password="password")
753759
no_data_div = self.find_element(By.CSS_SELECTOR, ".no-data")
754760
self.assertTrue(no_data_div.is_displayed())

0 commit comments

Comments
 (0)