Skip to content

Commit 0ae92f7

Browse files
committed
[fix] Show all status filter options and fix css
1 parent deba63e commit 0ae92f7

File tree

6 files changed

+57
-52
lines changed

6 files changed

+57
-52
lines changed

openwisp_monitoring/device/api/filters.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,8 @@ class Meta:
2525
}
2626

2727

28-
class DeviceFilter(filters.FilterSet):
28+
class MonitoringLocationDeviceFilter(filters.FilterSet):
2929
search = filters.CharFilter(method="filter_search")
30-
3130
status = filters.MultipleChoiceFilter(
3231
field_name="monitoring__status",
3332
choices=DeviceMonitoring.STATUS,

openwisp_monitoring/device/api/views.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@
4040
from ..signals import device_metrics_received
4141
from ..tasks import write_device_metrics
4242
from .filters import (
43-
DeviceFilter,
4443
MonitoringDeviceFilter,
44+
MonitoringLocationDeviceFilter,
4545
MonitoringNearbyDeviceFilter,
4646
WifiSessionFilter,
4747
)
@@ -251,7 +251,7 @@ class MonitoringGeoJsonLocationList(GeoJsonLocationList):
251251
class MonitoringLocationDeviceList(LocationDeviceList):
252252
serializer_class = MonitoringLocationDeviceSerializer
253253
filter_backends = [DjangoFilterBackend]
254-
filterset_class = DeviceFilter
254+
filterset_class = MonitoringLocationDeviceFilter
255255

256256
def get_queryset(self):
257257
return super().get_queryset().select_related("monitoring").order_by("name")

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
.leaflet-popup-content {
6767
display: flex;
6868
min-width: fit-content;
69-
padding: 11px 0 11px 4px;
69+
margin: 24px !important;
7070
}
7171
.leaflet-popup-close-button {
7272
top: 25px !important;
@@ -80,7 +80,7 @@
8080
box-sizing: border-box;
8181
}
8282
.map-detail h2 {
83-
margin: 10px 0;
83+
margin: 35px 0 10px 0;
8484
font-size: 18px;
8585
}
8686
.input-container {
@@ -117,6 +117,7 @@
117117
align-items: center;
118118
margin: 10px 0;
119119
gap: 10px;
120+
justify-content: space-evenly;
120121
}
121122
.status-filter {
122123
cursor: pointer;
@@ -132,7 +133,7 @@
132133
}
133134
.table-container {
134135
height: 120px;
135-
width: 400px;
136+
width: 350px;
136137
overflow-y: auto;
137138
min-width: 300px;
138139
box-sizing: border-box;
@@ -161,7 +162,7 @@
161162
}
162163
.floorplan-btn {
163164
padding: 10px 25px;
164-
margin-top: 10px;
165+
margin-top: 20px;
165166
width: fit-content;
166167
font-size: 16px;
167168
border-radius: 8px;

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

Lines changed: 38 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -67,22 +67,27 @@
6767
success: function (data) {
6868
let devices = data.results;
6969
let nextUrl = data.next;
70-
const uniqueStatus = devices.reduce((acc, device) => {
71-
const { status_label, status } = device.monitoring;
72-
acc[status_label] = status;
73-
return acc;
74-
}, {});
75-
let statusFiltersBtn = "";
76-
Object.entries(uniqueStatus).forEach(([status_label, status]) => {
70+
const statusLabelsMap = {
71+
ok: "ok",
72+
problem: "problem",
73+
critical: "critical",
74+
unknown: "unknown",
75+
deactivated: "deactivated",
76+
};
77+
devices.forEach(({ monitoring }) => {
78+
statusLabelsMap[monitoring.status] = monitoring.status_label;
79+
});
80+
let statusFilterButtons = "";
81+
Object.entries(statusLabelsMap).forEach(([status_label, status]) => {
7782
const label = gettext(status_label);
78-
statusFiltersBtn += `
79-
<span
83+
statusFilterButtons +=
84+
`<span
8085
class="health-status health-${status} status-filter"
8186
data-status="${status}"
8287
>
8388
${label}
84-
</span>
85-
`;
89+
</span>`
90+
;
8691
});
8792
const has_floorplan = data.has_floorplan;
8893
const floorplan_btn = has_floorplan
@@ -96,10 +101,10 @@
96101
data.count
97102
})</h2>
98103
<div class="input-container">
99-
<input id="device-search" placeholder="Search for devices by name or mac address" />
104+
<input id="device-search" placeholder="Search for devices" />
100105
</div>
101106
<div class="label-container">
102-
${statusFiltersBtn}
107+
${statusFilterButtons}
103108
<input id="status-filter" style="display: none;" type="text" />
104109
</div>
105110
<div class="table-container">
@@ -180,30 +185,28 @@
180185
if (url === nextUrl) fetchUrl = url;
181186
else fetchUrl = queryString ? `${url}?${queryString}` : url;
182187

183-
$.ajax(
184-
{
185-
dataType: "json",
186-
url: fetchUrl,
187-
xhrFields: { withCredentials: true },
188+
$.ajax({
189+
dataType: "json",
190+
url: fetchUrl,
191+
xhrFields: { withCredentials: true },
188192

189-
success(data) {
190-
if (url === nextUrl) {
191-
devices = devices.concat(data.results);
192-
} else {
193-
devices = data.results;
194-
}
195-
nextUrl = data.next;
196-
renderRows(devices);
197-
},
198-
error() {
199-
console.error("Could not load more devices from", url);
200-
},
201-
complete() {
202-
loading = false;
203-
spinner.hide();
204-
},
193+
success(data) {
194+
if (url === nextUrl) {
195+
devices = devices.concat(data.results);
196+
} else {
197+
devices = data.results;
198+
}
199+
nextUrl = data.next;
200+
renderRows(devices);
205201
},
206-
);
202+
error() {
203+
console.error("Could not load more devices from", url);
204+
},
205+
complete() {
206+
loading = false;
207+
spinner.hide();
208+
},
209+
});
207210
}, ms);
208211
}
209212
renderRows();

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

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,11 @@
5656
success: async (data) => {
5757
// To make this run only one time as only in the first call floor will not be provided
5858
// And sort them in decresing order so that neagtive floor show at bottom and postove at top in floor navigation
59-
if (!floor){
59+
if (!floor) {
6060
floors = data.floors.sort((a, b) => b - a);
61-
floor = data.results[0].floor
62-
}
63-
if (!allResults[floor]) allResults[floor] = []
61+
floor = data.results[0].floor;
62+
}
63+
if (!allResults[floor]) allResults[floor] = [];
6464
allResults[floor] = [...allResults[floor], ...data.results];
6565
if (!currentFloor && data.results.length) {
6666
currentFloor = data.results[0].floor;
@@ -177,7 +177,7 @@
177177

178178
await fetchData(url, floor);
179179

180-
const nodesThisFloor = {nodes: allResults[floor], links: []};
180+
const nodesThisFloor = { nodes: allResults[floor], links: [] };
181181

182182
$("#floorplan-heading").text(nodesThisFloor.nodes[0].floor_name);
183183
const imageUrl = nodesThisFloor.nodes[0].image;
@@ -253,13 +253,15 @@
253253
L.imageOverlay(imageUrl, bnds).addTo(map);
254254
map.fitBounds(bnds);
255255
map.setMaxBounds(bnds);
256-
map.setView([0,0], 0)
256+
// map.setView([0,0], 0)
257257
};
258258
// Todo: Explore some better approach if exists
259-
const fullScreen = $('#floorplan-container .leaflet-control-fullscreen-button');
259+
const fullScreen = $(
260+
"#floorplan-container .leaflet-control-fullscreen-button",
261+
);
260262
fullScreen.off("click.zoomOnFullscreen"); // avoid duplicates
261263
fullScreen.on("click.zoomOnFullscreen", () => {
262-
map.setZoom(map.getZoom() + 1);
264+
map.setZoom(map.getZoom() + 1);
263265
});
264266
},
265267
});

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<script type="text/javascript">
55
window._owGeoMapConfig = {
66
geoJsonUrl: '{{ monitoring_location_geojson_url }}',
7-
locationDeviceUrl: '{{ monitoring_device_list_url }}?page_size=5',
7+
locationDeviceUrl: '{{ monitoring_device_list_url }}',
88
indoorCoordinatesUrl: '{{ monitoring_indoor_coordinates_list }}'
99
}
1010
</script>

0 commit comments

Comments
 (0)