diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3098eea4..c120dccf 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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] diff --git a/.jshintrc b/.jshintrc deleted file mode 100644 index 99b4b79c..00000000 --- a/.jshintrc +++ /dev/null @@ -1,7 +0,0 @@ -{ - "unused": true, - "esversion": 6, - "curly": true, - "strict": "global", - "browser": true -} diff --git a/.jslintrc b/.jslintrc deleted file mode 100644 index 7141f331..00000000 --- a/.jslintrc +++ /dev/null @@ -1,49 +0,0 @@ -{ - "predef": [ - "document", - "navigator", - "console", - "alert", - "django", - "gettext" - ], - - "adsafe": false, - "safe": false, - - "bitwise": false, - "cap": false, - "confusion": true, - "continue": true, - "css": true, - "debug": false, - "eqeq": false, - "es5": true, - "evil": false, - "forin": false, - "fragment": true, - "newcap": false, - "nomen": false, - "on": false, - "plusplus": false, - "regexp": true, - "sloppy": false, - "sub": false, - "undef": false, - "unparam": true, - "vars": true, - "white": false, - "validthis": true, - "strict_mode":true, - - "browser": false, - "devel": false, - "node": false, - "rhino": false, - "widget": false, - "windows": false, - "indent": 4, - "maxerr": 50, - "maxlen": 120, - "passfail": false -} diff --git a/.stylelintrc.json b/.stylelintrc.json deleted file mode 100644 index 2fba2ab0..00000000 --- a/.stylelintrc.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "rules": { - "block-no-empty": null, - "color-no-invalid-hex": true, - "comment-empty-line-before": ["always", { - "ignore": ["stylelint-commands", "after-comment"] - }], - "rule-empty-line-before": ["never-multi-line", { - "except": ["first-nested"], - "ignore": ["after-comment", "inside-block"] - }], - "unit-allowed-list": ["em", "rem", "%", "s", "px", "vh", "deg", "dpi", "fr"], - "property-no-unknown": true - } -} diff --git a/docs/developer/installation.rst b/docs/developer/installation.rst index e8aaf526..59a5fc6a 100644 --- a/docs/developer/installation.rst +++ b/docs/developer/installation.rst @@ -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 diff --git a/openwisp_radius/integrations/monitoring/static/radius-monitoring/js/device-change.js b/openwisp_radius/integrations/monitoring/static/radius-monitoring/js/device-change.js index 47aac605..3dd01478 100644 --- a/openwisp_radius/integrations/monitoring/static/radius-monitoring/js/device-change.js +++ b/openwisp_radius/integrations/monitoring/static/radius-monitoring/js/device-change.js @@ -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 = `${onlineMsg}`; - } else { - element.stop_time = getFormattedDateTimeString(element.stop_time); - } - $('#radius-session-tbody').append( - ` + response.forEach((element, index) => { + element.start_time = getFormattedDateTimeString(element.start_time); + if (!element.stop_time) { + element.stop_time = `${onlineMsg}`; + } else { + element.stop_time = getFormattedDateTimeString(element.stop_time); + } + $("#radius-session-tbody").append( + `

${element.session_id}

${element.username}

@@ -71,25 +76,25 @@

${element.calling_station_id}

${element.start_time}

${element.stop_time}

- ` - ); - }); - $('#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, - }); - } + `, + ); + }); + $("#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); diff --git a/openwisp_radius/static/openwisp-radius/css/freeradius.css b/openwisp_radius/static/openwisp-radius/css/freeradius.css index 6703fdda..b7fbe8db 100644 --- a/openwisp_radius/static/openwisp-radius/css/freeradius.css +++ b/openwisp_radius/static/openwisp-radius/css/freeradius.css @@ -1,4 +1,6 @@ -table, th, td{ +table, +th, +td { text-align: center; padding: 10px; } diff --git a/openwisp_radius/static/openwisp-radius/css/mode-switcher.css b/openwisp_radius/static/openwisp-radius/css/mode-switcher.css index 6f2d5641..5c3612dc 100644 --- a/openwisp_radius/static/openwisp-radius/css/mode-switcher.css +++ b/openwisp_radius/static/openwisp-radius/css/mode-switcher.css @@ -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, diff --git a/openwisp_radius/static/openwisp-radius/css/radiusbatch.css b/openwisp_radius/static/openwisp-radius/css/radiusbatch.css index d5701109..c7f92389 100644 --- a/openwisp_radius/static/openwisp-radius/css/radiusbatch.css +++ b/openwisp_radius/static/openwisp-radius/css/radiusbatch.css @@ -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; } diff --git a/openwisp_radius/static/openwisp-radius/js/mode-switcher.js b/openwisp_radius/static/openwisp-radius/js/mode-switcher.js index 780844fc..99d38eda 100644 --- a/openwisp_radius/static/openwisp-radius/js/mode-switcher.js +++ b/openwisp_radius/static/openwisp-radius/js/mode-switcher.js @@ -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); diff --git a/openwisp_radius/static/openwisp-radius/js/organization-setting-inline.js b/openwisp_radius/static/openwisp-radius/js/organization-setting-inline.js index 32d55c7e..64090e85 100644 --- a/openwisp_radius/static/openwisp-radius/js/organization-setting-inline.js +++ b/openwisp_radius/static/openwisp-radius/js/organization-setting-inline.js @@ -1,21 +1,23 @@ (function ($) { - 'use strict'; - $(document).ready(function () { - $('#id_radius_settings-0-sms_verification').on('change', function () { - var smsVerificationEnabled = $(this).val(), - smsOptions = $('.org-sms-options:visible .form-row:not(.field-sms_verification)'); - if (smsVerificationEnabled === '') { - smsVerificationEnabled = $(this).data('default-value'); - } - switch (smsVerificationEnabled) { - case 'True': - smsOptions.show(); - break; - case 'False': - smsOptions.hide(); - break; - } - }); - $('#id_radius_settings-0-sms_verification').trigger('change'); + "use strict"; + $(document).ready(function () { + $("#id_radius_settings-0-sms_verification").on("change", function () { + var smsVerificationEnabled = $(this).val(), + smsOptions = $( + ".org-sms-options:visible .form-row:not(.field-sms_verification)", + ); + if (smsVerificationEnabled === "") { + smsVerificationEnabled = $(this).data("default-value"); + } + switch (smsVerificationEnabled) { + case "True": + smsOptions.show(); + break; + case "False": + smsOptions.hide(); + break; + } }); -}(django.jQuery)); + $("#id_radius_settings-0-sms_verification").trigger("change"); + }); +})(django.jQuery); diff --git a/openwisp_radius/static/openwisp-radius/js/strategy-switcher.js b/openwisp_radius/static/openwisp-radius/js/strategy-switcher.js index e070bf91..ac5ba94f 100644 --- a/openwisp_radius/static/openwisp-radius/js/strategy-switcher.js +++ b/openwisp_radius/static/openwisp-radius/js/strategy-switcher.js @@ -1,53 +1,55 @@ (function ($) { - 'use strict'; - $(document).ready(function () { - var strategy = $('#id_strategy'), - prefixRows = $('#id_prefix, #id_name, ' + - '#id_expiration_date, #id_number_of_users').parents('.form-row'), - csvRows = $('#id_csvfile, #id_name, ' + - '#id_expiration_date').parents('.form-row'), - prefixField = $('.form-row.field-prefix'), - pdfField = $('.form-row.field-pdf'), - csvField = $('.form-row.field-csvfile'), - strategyField = $('.form-row.field-strategy .readonly')["0"]; + "use strict"; + $(document).ready(function () { + var strategy = $("#id_strategy"), + prefixRows = $( + "#id_prefix, #id_name, " + "#id_expiration_date, #id_number_of_users", + ).parents(".form-row"), + csvRows = $("#id_csvfile, #id_name, " + "#id_expiration_date").parents( + ".form-row", + ), + prefixField = $(".form-row.field-prefix"), + pdfField = $(".form-row.field-pdf"), + csvField = $(".form-row.field-csvfile"), + strategyField = $(".form-row.field-strategy .readonly")["0"]; - function csv_strategy() { - prefixRows.hide(); - prefixField.hide(); - pdfField.hide(); - csvRows.show(); - csvField.show(); - } + function csv_strategy() { + prefixRows.hide(); + prefixField.hide(); + pdfField.hide(); + csvRows.show(); + csvField.show(); + } - function prefix_strategy() { - csvRows.hide(); - csvField.hide(); - prefixRows.show(); - prefixField.show(); - pdfField.show(); - } + function prefix_strategy() { + csvRows.hide(); + csvField.hide(); + prefixRows.show(); + prefixField.show(); + pdfField.show(); + } - if (strategyField !== undefined) { - if (strategyField.innerHTML === "Import from CSV") { - csv_strategy(); - } else if (strategyField.innerHTML === "Generate from prefix") { - prefix_strategy(); - } - } + if (strategyField !== undefined) { + if (strategyField.innerHTML === "Import from CSV") { + csv_strategy(); + } else if (strategyField.innerHTML === "Generate from prefix") { + prefix_strategy(); + } + } - strategy.change(function () { - if (strategy.val() === 'prefix') { - prefix_strategy(); - } else if (strategy.val() === 'csv') { - csv_strategy(); - } else { - prefixRows.hide(); - prefixField.hide(); - pdfField.hide(); - csvRows.hide(); - csvField.hide(); - } - }); - strategy.trigger('change'); + strategy.change(function () { + if (strategy.val() === "prefix") { + prefix_strategy(); + } else if (strategy.val() === "csv") { + csv_strategy(); + } else { + prefixRows.hide(); + prefixField.hide(); + pdfField.hide(); + csvRows.hide(); + csvField.hide(); + } }); -}(django.jQuery)); + strategy.trigger("change"); + }); +})(django.jQuery); diff --git a/run-qa-checks b/run-qa-checks index 5dde1520..f55dc5cb 100755 --- a/run-qa-checks +++ b/run-qa-checks @@ -2,9 +2,6 @@ set -e -echo 'Check JavaScript Linting' -jslint ./openwisp_radius/static/openwisp-radius/js/*.js - echo '' echo 'Compiling translations' cd openwisp_radius