Skip to content

Commit d1cf0ca

Browse files
authored
Client filtration (ngoduykhanh#330)
1 parent 9f20fe6 commit d1cf0ca

File tree

3 files changed

+73
-0
lines changed

3 files changed

+73
-0
lines changed

custom/js/helper.js

+1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ function renderClientList(data) {
5858
</div>
5959
<hr>
6060
<span class="info-box-text"><i class="fas fa-user"></i> ${obj.Client.name}</span>
61+
<span class="info-box-text" style="display: none"><i class="fas fa-key"></i> ${obj.Client.public_key}</span>
6162
<span class="info-box-text"><i class="fas fa-envelope"></i> ${obj.Client.email}</span>
6263
<span class="info-box-text"><i class="fas fa-clock"></i>
6364
${prettyDateTime(obj.Client.created_at)}</span>

templates/base.html

+7
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,13 @@
5656
</button>
5757
</div>
5858
</div>
59+
<select name="status-selector" id="status-selector" class="form-control selectpicker show-tick" style="margin-left: 10px">
60+
<option value="All">All</option>
61+
<option value="Enabled">Enabled</option>
62+
<option value="Disabled">Disabled</option>
63+
<option value="Connected">Connected</option>
64+
<option value="Disconnected">Disconnected</option>
65+
</select>
5966
</form>
6067

6168
<!-- Right navbar links -->

templates/clients.html

+65
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ <h4 class="modal-title">Remove</h4>
263263

264264
// hide all clients and display only the ones that meet the search criteria (name, email, IP)
265265
$('#search-input').keyup(function () {
266+
$("#status-selector").val("All");
266267
var query = $(this).val();
267268
$('.col-lg-4').hide();
268269
$(".info-box-text").each(function() {
@@ -274,6 +275,70 @@ <h4 class="modal-title">Remove</h4>
274275
$(".badge-secondary").filter(':contains("' + query + '")').parent().parent().parent().show();
275276
})
276277

278+
$("#status-selector").on('change', function () {
279+
$('#search-input').val("");
280+
switch ($("#status-selector").val()) {
281+
case "All":
282+
$('.col-lg-4').show();
283+
break;
284+
case "Enabled":
285+
$('.col-lg-4').hide();
286+
$('[id^="paused_"]').each(function () {
287+
if ($(this).css("visibility") === "hidden") {
288+
$(this).parent().parent().show();
289+
}
290+
});
291+
break;
292+
case "Disabled":
293+
$('.col-lg-4').hide();
294+
$('[id^="paused_"]').each(function () {
295+
if ($(this).css("visibility") !== "hidden") {
296+
$(this).parent().parent().show();
297+
}
298+
});
299+
break;
300+
case "Connected":
301+
$('.col-lg-4').hide();
302+
$.ajax({
303+
cache: false,
304+
method: 'GET',
305+
url: '{{.basePath}}/status',
306+
success: function (data) {
307+
const returnedHTML = $(data).find(".table-success").get();
308+
var returnedString = "";
309+
returnedHTML.forEach(entry => returnedString += entry.outerHTML);
310+
$(".fa-key").each(function () {
311+
if (returnedString.indexOf($(this).parent().text().trim()) != -1) {
312+
$(this).closest('.col-lg-4').show();
313+
}
314+
})
315+
}
316+
});
317+
break;
318+
case "Disconnected":
319+
$('.col-lg-4').show();
320+
$.ajax({
321+
cache: false,
322+
method: 'GET',
323+
url: '{{.basePath}}/status',
324+
success: function (data) {
325+
const returnedHTML = $(data).find(".table-success").get();
326+
var returnedString = "";
327+
returnedHTML.forEach(entry => returnedString += entry.outerHTML);
328+
$(".fa-key").each(function () {
329+
if (returnedString.indexOf($(this).parent().text().trim()) != -1) {
330+
$(this).closest('.col-lg-4').hide();
331+
}
332+
})
333+
}
334+
});
335+
break;
336+
default:
337+
$('.col-lg-4').show();
338+
break;
339+
}
340+
});
341+
277342
// modal_pause_client modal event
278343
$("#modal_pause_client").on('show.bs.modal', function (event) {
279344
const button = $(event.relatedTarget);

0 commit comments

Comments
 (0)