Skip to content

Commit

Permalink
[qa] Switched to prettier for CSS/JS formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
youhaveme9 authored Jan 27, 2025
1 parent 02c05dd commit 918faa1
Show file tree
Hide file tree
Showing 13 changed files with 194 additions and 253 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ jobs:
libspatialite-dev \
spatialite-bin \
libsqlite3-mod-spatialite
sudo npm install -g jslint stylelint jshint
sudo npm install -g prettier
pip install -U pip wheel setuptools
pip install -U -r requirements-test.txt
pip install -e .[saml,openvpn_status]
Expand Down
7 changes: 0 additions & 7 deletions .jshintrc

This file was deleted.

49 changes: 0 additions & 49 deletions .jslintrc

This file was deleted.

15 changes: 0 additions & 15 deletions .stylelintrc.json

This file was deleted.

2 changes: 1 addition & 1 deletion docs/developer/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ Install development dependencies:
pip install -e .[saml,openvpn_status]
pip install -r requirements-test.txt
sudo npm install -g jshint stylelint
sudo npm install -g prettier
Install WebDriver for Chromium for your browser version from
https://chromedriver.chromium.org/home and Extract ``chromedriver`` to one
Expand Down
Original file line number Diff line number Diff line change
@@ -1,68 +1,73 @@
(function ($) {
'use strict';
"use strict";

const onlineMsg = gettext('online');
const onlineMsg = gettext("online");

$(document).ready(function () {
if (!$('#radius-sessions').length) {
// RADIUS sessions tab should not appear on Device add page.
return;
}
// Move the "RADIUS Sessions" tab after the "Credentials" tab.
$('ul.tabs li.credentials').after($('ul.tabs li.radius-sessions'));
$(document).ready(function () {
if (!$("#radius-sessions").length) {
// RADIUS sessions tab should not appear on Device add page.
return;
}
// Move the "RADIUS Sessions" tab after the "Credentials" tab.
$("ul.tabs li.credentials").after($("ul.tabs li.radius-sessions"));

const deviceMac = encodeURIComponent($('#id_mac_address').val()),
apiEndpoint = `${radiusAccountingApiEndpoint}?called_station_id=${deviceMac}`;
const deviceMac = encodeURIComponent($("#id_mac_address").val()),
apiEndpoint = `${radiusAccountingApiEndpoint}?called_station_id=${deviceMac}`;

function getFormattedDateTimeString(dateTimeString) {
// Strip the timezone from the dateTimeString.
// This is done to show the time in server's timezone
// because RadiusAccounting admin also shows the time in server's timezone.
let strippedDateTime = new Date(dateTimeString.replace(/[-+]\d{2}:\d{2}$/, ''));
return strippedDateTime.toLocaleString();
}
function getFormattedDateTimeString(dateTimeString) {
// Strip the timezone from the dateTimeString.
// This is done to show the time in server's timezone
// because RadiusAccounting admin also shows the time in server's timezone.
let strippedDateTime = new Date(
dateTimeString.replace(/[-+]\d{2}:\d{2}$/, ""),
);
return strippedDateTime.toLocaleString();
}

function fetchRadiusSessions() {
if ($('#radius-session-tbody').children().length) {
// Don't fetch if RADIUS sessions are already present
// in the table
return;
}
$.ajax({
type: 'GET',
url: apiEndpoint,
xhrFields: {
withCredentials: true
},
crossDomain: true,
beforeSend: function() {
$('#radius-sessions .loader').show();
},
complete: function () {
$('#radius-sessions .loader').hide();
},
success: function (response) {
if (response.length === 0) {
$('#no-session-msg').show();
return;
}
// The called_station_id in the response is in the format accepted by
// RadiusAccountingAdmin. This ensures that we use the same format for
// filtering the RadiusAccountingAdmin table, avoiding any problem with
// different formats of MAC address in the backend.
let called_station_id = response[0].called_station_id,
radiusAccountingAdminUrl = `${radiusAccountingAdminPath}?called_station_id=${encodeURIComponent(called_station_id)}`;
$('#view-all-radius-session-wrapper a').attr('href', radiusAccountingAdminUrl);
function fetchRadiusSessions() {
if ($("#radius-session-tbody").children().length) {
// Don't fetch if RADIUS sessions are already present
// in the table
return;
}
$.ajax({
type: "GET",
url: apiEndpoint,
xhrFields: {
withCredentials: true,
},
crossDomain: true,
beforeSend: function () {
$("#radius-sessions .loader").show();
},
complete: function () {
$("#radius-sessions .loader").hide();
},
success: function (response) {
if (response.length === 0) {
$("#no-session-msg").show();
return;
}
// The called_station_id in the response is in the format accepted by
// RadiusAccountingAdmin. This ensures that we use the same format for
// filtering the RadiusAccountingAdmin table, avoiding any problem with
// different formats of MAC address in the backend.
let called_station_id = response[0].called_station_id,
radiusAccountingAdminUrl = `${radiusAccountingAdminPath}?called_station_id=${encodeURIComponent(called_station_id)}`;
$("#view-all-radius-session-wrapper a").attr(
"href",
radiusAccountingAdminUrl,
);

response.forEach((element, index) => {
element.start_time = getFormattedDateTimeString(element.start_time);
if (!element.stop_time) {
element.stop_time = `<strong>${onlineMsg}</strong>`;
} else {
element.stop_time = getFormattedDateTimeString(element.stop_time);
}
$('#radius-session-tbody').append(
`<tr class="form-row has_original dynamic-radiussession_set" id="radiussession_set-${index}">
response.forEach((element, index) => {
element.start_time = getFormattedDateTimeString(element.start_time);
if (!element.stop_time) {
element.stop_time = `<strong>${onlineMsg}</strong>`;
} else {
element.stop_time = getFormattedDateTimeString(element.stop_time);
}
$("#radius-session-tbody").append(
`<tr class="form-row has_original dynamic-radiussession_set" id="radiussession_set-${index}">
<td class="original"></td>
<td class="field-session_id"><p>${element.session_id}</p></td>
<td class="field-username"><p>${element.username}</p></td>
Expand All @@ -71,25 +76,25 @@
<td class="field-calling_station_id"><p>${element.calling_station_id}</p></td>
<td class="field-start_time"><p>${element.start_time}</p></td>
<td class="field-stop_time"><p>${element.stop_time}</p></td>
</tr>`
);
});
$('#no-session-msg').hide();
$('#device-radius-sessions-table').show();
$('#view-all-radius-session-wrapper').show();
}
});
}
$(document).on('tabshown', function (e) {
if (e.tabId === '#radius-sessions') {
fetchRadiusSessions();
}
});
if (window.location.hash == '#radius-sessions') {
$.event.trigger({
type: 'tabshown',
tabId: window.location.hash,
});
}
</tr>`,
);
});
$("#no-session-msg").hide();
$("#device-radius-sessions-table").show();
$("#view-all-radius-session-wrapper").show();
},
});
}
$(document).on("tabshown", function (e) {
if (e.tabId === "#radius-sessions") {
fetchRadiusSessions();
}
});
}(django.jQuery));
if (window.location.hash == "#radius-sessions") {
$.event.trigger({
type: "tabshown",
tabId: window.location.hash,
});
}
});
})(django.jQuery);
4 changes: 3 additions & 1 deletion openwisp_radius/static/openwisp-radius/css/freeradius.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
table, th, td{
table,
th,
td {
text-align: center;
padding: 10px;
}
4 changes: 3 additions & 1 deletion openwisp_radius/static/openwisp-radius/css/mode-switcher.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
.form-row:not(.field-mode){ display: none; }
.form-row:not(.field-mode) {
display: none;
}
.form-row.field-group label,
.form-row.field-groupname label,
.form-row.field-user label,
Expand Down
2 changes: 1 addition & 1 deletion openwisp_radius/static/openwisp-radius/css/radiusbatch.css
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.field-csvfile label,
.field-prefix label,
.field-number_of_users label{
.field-number_of_users label {
font-weight: bold;
color: #000;
}
60 changes: 31 additions & 29 deletions openwisp_radius/static/openwisp-radius/js/mode-switcher.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,33 @@
(function ($) {
'use strict';
$(document).ready(function () {
var mode = $('#id_mode'),
allExceptMode = $('.form-row:not(.field-mode)'),
neutral = $('.form-row:not(.field-group, .field-groupname, ' +
'.field-user, .field-username)'),
guided = $('.field-group, .field-user'),
custom = $('.field-groupname, .field-username');
mode.change(function () {
allExceptMode.hide();
if (mode.val() === 'guided') {
guided.show();
neutral.show();
$('#id_groupname').val('');
$('#id_username').val('');
} else if (mode.val() === 'custom') {
custom.show();
neutral.show();
$('#id_group').val(null).change();
$('#id_user').val(null).change();
}
});
if ($('#id_group').val() || $('#id_user').val()) {
mode.val('guided');
} else if ($('#id_groupname').val() || $('#id_username').val()) {
mode.val('custom');
}
mode.trigger('change');
"use strict";
$(document).ready(function () {
var mode = $("#id_mode"),
allExceptMode = $(".form-row:not(.field-mode)"),
neutral = $(
".form-row:not(.field-group, .field-groupname, " +
".field-user, .field-username)",
),
guided = $(".field-group, .field-user"),
custom = $(".field-groupname, .field-username");
mode.change(function () {
allExceptMode.hide();
if (mode.val() === "guided") {
guided.show();
neutral.show();
$("#id_groupname").val("");
$("#id_username").val("");
} else if (mode.val() === "custom") {
custom.show();
neutral.show();
$("#id_group").val(null).change();
$("#id_user").val(null).change();
}
});
}(django.jQuery));
if ($("#id_group").val() || $("#id_user").val()) {
mode.val("guided");
} else if ($("#id_groupname").val() || $("#id_username").val()) {
mode.val("custom");
}
mode.trigger("change");
});
})(django.jQuery);
Loading

0 comments on commit 918faa1

Please sign in to comment.