Skip to content

Commit

Permalink
feat: aggiornamento info di accesso con icone
Browse files Browse the repository at this point in the history
  • Loading branch information
loviuz committed Jan 14, 2025
1 parent 0a8d4eb commit ca1c489
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 3 deletions.
10 changes: 9 additions & 1 deletion gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,14 @@ function pdfjs() {
return merge(web, build);
}

function uaparser() {
return gulp.src([
config.nodeDirectory + '/ua-parser-js/dist/icons/mono/**/*',
'!' + config.nodeDirectory + '/ua-parser-js/dist/icons/mono/LICENSE.md',
])
.pipe(gulp.dest(config.production + '/img/icons/'));
}

// Elaborazione e minificazione delle informazioni sull'internazionalizzazione
function i18n() {
return gulp.src([
Expand Down Expand Up @@ -596,7 +604,7 @@ function clean() {
}

// Operazioni di default per la generazione degli assets
const bower = gulp.series(clean, gulp.parallel(JS, CSS, images, fonts, ckeditor, colorpicker, i18n, pdfjs, hotkeys, chartjs, password_strength, csrf, leaflet, wacom));
const bower = gulp.series(clean, gulp.parallel(JS, CSS, images, fonts, ckeditor, colorpicker, i18n, pdfjs, uaparser, hotkeys, chartjs, password_strength, csrf, leaflet, wacom));

// Debug su CSS e JS
exports.srcJS = srcJS;
Expand Down
48 changes: 47 additions & 1 deletion log.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@
<script>
$(document).ready(function() {
var parser = new UAParser();
var icons_path = globals.rootdir + '/assets/dist/img/icons';

$('tr').each(function(){
user_agent_cell = $(this).find('.user-agent');
Expand All @@ -107,7 +108,52 @@
parser.setUA(user_agent);
device = parser.getResult();

user_agent_cell.html('<strong>' + (device.browser.name || '') + '</strong> ' + (device.browser.version || '') + ' | <strong>' + (device.os.name || '') + '</strong> ' + (device.os.version || ''));
var device_info = [];

// Browser
if (device.browser.name) {
device_info['browser'] = {};
device_info['browser']['text'] = '<strong>' + device.browser.name + '</strong> ' + (device.browser.version || '');
device_info['browser']['icon'] = icons_path + '/browser/' + device.browser.name.toLowerCase().replace(' ', '-');
}

// OS
if (device.os.name) {
device_info['os'] = {};
device_info['os']['text'] = '<strong>' + device.os.name + '</strong> ' + (device.os.version || '');
device_info['os']['icon'] = icons_path + '/os/' + device.os.name.toLowerCase();
}

// Device
if (device.device.name) {
device_info['device'] = {};
device_info['device']['text'] = '<strong>' + device.device.vendor + '</strong> ' + (device.device.model || '');
device_info['device']['icon'] = icons_path + '/device/' + device.device.name.toLowerCase();
}

// Preparazione user-agent riscritto
if (device_info.browser || device_info.os) {
user_agent_cell.html('');
}

// Sostituzione user-agent con formato più amichevole
for (var key in device_info) {
var icon = device_info[key]['icon'];
var text = device_info[key]['text'];

if (icon) {
var img = new Image();
img.src = icon + '.svg';

const imgElement = document.createElement('img');
imgElement.src = img.src;
imgElement.width = 14;
imgElement.height = 14;
user_agent_cell.append(imgElement).append(' ');
}

user_agent_cell.append(text + ' | ');
}
}
})
})
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"sweetalert2": "^6.11.4",
"toastr": "^2.1.4",
"tooltipster": "^4.2.5",
"ua-parser-js": "^1.0.37"
"ua-parser-js": "^2.0.0"
},
"devDependencies": {
"@babel/core": "^7.11.1",
Expand Down

0 comments on commit ca1c489

Please sign in to comment.