app.js (goaccess-1.6.5) | : | app.js (goaccess-1.7) | ||
---|---|---|---|---|
skipping to change at line 213 | skipping to change at line 213 | |||
shortNum: function (n) { | shortNum: function (n) { | |||
if (n < 1e3) return n; | if (n < 1e3) return n; | |||
if (n >= 1e3 && n < 1e6) return +(n / 1e3).toFixed(1) + "K"; | if (n >= 1e3 && n < 1e6) return +(n / 1e3).toFixed(1) + "K"; | |||
if (n >= 1e6 && n < 1e9) return +(n / 1e6).toFixed(1) + "M"; | if (n >= 1e6 && n < 1e9) return +(n / 1e6).toFixed(1) + "M"; | |||
if (n >= 1e9 && n < 1e12) return +(n / 1e9).toFixed(1) + "B"; | if (n >= 1e9 && n < 1e12) return +(n / 1e9).toFixed(1) + "B"; | |||
if (n >= 1e12) return +(n / 1e12).toFixed(1) + "T"; | if (n >= 1e12) return +(n / 1e12).toFixed(1) + "T"; | |||
}, | }, | |||
// Format field value to human readable | // Format field value to human readable | |||
fmtValue: function (value, dataType, decimals, shorten) { | fmtValue: function (value, dataType, decimals, shorten, hlregex, hlvalue) { | |||
var val = 0; | var val = 0; | |||
if (!dataType) | if (!dataType) | |||
val = value; | val = value; | |||
switch (dataType) { | switch (dataType) { | |||
case 'utime': | case 'utime': | |||
val = this.utime2str(+value); | val = this.utime2str(+value); | |||
break; | break; | |||
case 'date': | case 'date': | |||
val = this.formatDate(value); | val = this.formatDate(value); | |||
break; | break; | |||
case 'numeric': | case 'numeric': | |||
if (this.isNumeric(value)) | if (this.isNumeric(value)) | |||
val = shorten ? this.shortNum(value) : (+value).t oLocaleString(); | val = shorten ? this.shortNum(value) : (+value).t oLocaleString(); | |||
break; | break; | |||
case 'bytes': | case 'bytes': | |||
val = this.formatBytes(value, decimals); | val = this.formatBytes(value, decimals); | |||
break; | break; | |||
case 'percent': | case 'percent': | |||
val = parseFloat(value.replace(',', '.')).toFixed(2) + '% '; | val = value.replace(',', '.') + '%'; | |||
break; | break; | |||
case 'time': | case 'time': | |||
if (this.isNumeric(value)) | if (this.isNumeric(value)) | |||
val = value.toLocaleString(); | val = value.toLocaleString(); | |||
break; | break; | |||
case 'secs': | case 'secs': | |||
var t = new Date(null); | var t = new Date(null); | |||
t.setSeconds(value); | t.setSeconds(value); | |||
val = t.toISOString().substr(11, 8); | val = t.toISOString().substr(11, 8); | |||
break; | break; | |||
default: | default: | |||
val = value; | val = value; | |||
} | } | |||
if (hlregex) { | ||||
let o = JSON.parse(hlregex), tmp = ''; | ||||
for (var x in o) { | ||||
tmp = val.replace(new RegExp(x, 'gi'), o[x]); | ||||
if (tmp != val) { | ||||
val = tmp; | ||||
break; | ||||
} | ||||
val = tmp; | ||||
} | ||||
} | ||||
return value == 0 ? String(val) : (val === undefined ? '—' : val) ; | return value == 0 ? String(val) : (val === undefined ? '—' : val) ; | |||
}, | }, | |||
isPanelHidden: function (panel) { | isPanelHidden: function (panel) { | |||
return GoAccess.AppPrefs.hiddenPanels.includes(panel); | return GoAccess.AppPrefs.hiddenPanels.includes(panel); | |||
}, | }, | |||
isPanelValid: function (panel) { | isPanelValid: function (panel) { | |||
var data = GoAccess.getPanelData(), ui = GoAccess.getPanelUI(); | var data = GoAccess.getPanelData(), ui = GoAccess.getPanelUI(); | |||
return (!ui.hasOwnProperty(panel) || !data.hasOwnProperty(panel) || !ui[panel].id); | return (!ui.hasOwnProperty(panel) || !data.hasOwnProperty(panel) || !ui[panel].id); | |||
skipping to change at line 340 | skipping to change at line 352 | |||
delete GoAccess.AppCharts[panel]; | delete GoAccess.AppCharts[panel]; | |||
GoAccess.OverallStats.initialize(); | GoAccess.OverallStats.initialize(); | |||
GoAccess.Panels.initialize(); | GoAccess.Panels.initialize(); | |||
GoAccess.Charts.initialize(); | GoAccess.Charts.initialize(); | |||
GoAccess.Tables.initialize(); | GoAccess.Tables.initialize(); | |||
}, | }, | |||
}; | }; | |||
// OVERALL STATS | // OVERALL STATS | |||
GoAccess.OverallStats = { | GoAccess.OverallStats = { | |||
total_requests: 0, | ||||
// Render each overall stats box | // Render each overall stats box | |||
renderBox: function (data, ui, row, x, idx) { | renderBox: function (data, ui, row, x, idx) { | |||
var wrap = $('.wrap-general-items'); | var wrap = $('.wrap-general-items'); | |||
// create a new bootstrap row every 6 elements | // create a new bootstrap row every 6 elements | |||
if (idx % 6 == 0) { | if (idx % 6 == 0) { | |||
row = document.createElement('div'); | row = document.createElement('div'); | |||
row.setAttribute('class', 'row'); | row.setAttribute('class', 'row'); | |||
wrap.appendChild(row); | wrap.appendChild(row); | |||
} | } | |||
skipping to change at line 391 | skipping to change at line 405 | |||
continue; | continue; | |||
row = this.renderBox(data, ui, row, x, idx); | row = this.renderBox(data, ui, row, x, idx); | |||
idx++; | idx++; | |||
} | } | |||
}, | }, | |||
// Render general/overall analyzed requests. | // Render general/overall analyzed requests. | |||
initialize: function () { | initialize: function () { | |||
var ui = GoAccess.getPanelUI('general'); | var ui = GoAccess.getPanelUI('general'); | |||
var data = GoAccess.getPanelData('general'); | var data = GoAccess.getPanelData('general'); | |||
this.total_requests = data.total_requests; | ||||
this.renderData(data, ui); | this.renderData(data, ui); | |||
} | } | |||
}; | }; | |||
// RENDER PANELS | // RENDER PANELS | |||
GoAccess.Nav = { | GoAccess.Nav = { | |||
events: function () { | events: function () { | |||
$('.nav-bars').onclick = function (e) { | $('.nav-bars').onclick = function (e) { | |||
e.stopPropagation(); | e.stopPropagation(); | |||
skipping to change at line 588 | skipping to change at line 603 | |||
case 'os' : return 'desktop'; | case 'os' : return 'desktop'; | |||
case 'browsers' : return 'chrome'; | case 'browsers' : return 'chrome'; | |||
case 'visit_time' : return 'clock-o'; | case 'visit_time' : return 'clock-o'; | |||
case 'vhosts' : return 'th-list'; | case 'vhosts' : return 'th-list'; | |||
case 'referrers' : return 'external-link'; | case 'referrers' : return 'external-link'; | |||
case 'referring_sites' : return 'external-link'; | case 'referring_sites' : return 'external-link'; | |||
case 'keyphrases' : return 'google'; | case 'keyphrases' : return 'google'; | |||
case 'status_codes' : return 'warning'; | case 'status_codes' : return 'warning'; | |||
case 'remote_user' : return 'users'; | case 'remote_user' : return 'users'; | |||
case 'geolocation' : return 'map-marker'; | case 'geolocation' : return 'map-marker'; | |||
case 'asn' : return 'map-marker'; | ||||
case 'mime_type' : return 'file-o'; | case 'mime_type' : return 'file-o'; | |||
case 'tls_type' : return 'warning'; | case 'tls_type' : return 'warning'; | |||
default : return 'pie-chart'; | default : return 'pie-chart'; | |||
} | } | |||
}, | }, | |||
getItems: function () { | getItems: function () { | |||
var ui = GoAccess.getPanelUI(), menu = []; | var ui = GoAccess.getPanelUI(), menu = []; | |||
for (var panel in ui) { | for (var panel in ui) { | |||
if (GoAccess.Util.isPanelValid(panel)) | if (GoAccess.Util.isPanelValid(panel)) | |||
skipping to change at line 1469 | skipping to change at line 1485 | |||
return this.getCurPage(panel) + 1; | return this.getCurPage(panel) + 1; | |||
}, | }, | |||
getMetaCell: function (ui, o, key) { | getMetaCell: function (ui, o, key) { | |||
var val = o && (key in o) && o[key].value ? o[key].value : null; | var val = o && (key in o) && o[key].value ? o[key].value : null; | |||
var perc = o && (key in o) && o[key].percent ? o[key].percent : null; | var perc = o && (key in o) && o[key].percent ? o[key].percent : null; | |||
// use metaType if exist else fallback to dataType | // use metaType if exist else fallback to dataType | |||
var vtype = ui.metaType || ui.dataType; | var vtype = ui.metaType || ui.dataType; | |||
var className = ui.className || ''; | var className = ui.className || ''; | |||
className += ui.dataType != 'string' ? 'text-right' : ''; | className += !['string'].includes(ui.dataType) ? 'text-right' : ' '; | |||
return { | return { | |||
'className': className, | 'className': className, | |||
'value' : val ? GoAccess.Util.fmtValue(val, vtype) : n ull, | 'value' : val ? GoAccess.Util.fmtValue(val, vtype) : n ull, | |||
'percent' : perc, | 'percent' : perc, | |||
'title' : ui.meta, | 'title' : ui.meta, | |||
'label' : ui.metaLabel || null, | 'label' : ui.metaLabel || null, | |||
}; | }; | |||
}, | }, | |||
hideColumn: function (panel, col) { | hideColumn: function (panel, col) { | |||
skipping to change at line 1550 | skipping to change at line 1566 | |||
} | } | |||
} | } | |||
return out; | return out; | |||
}, | }, | |||
// Return an object that can be consumed by the table template given a us er | // Return an object that can be consumed by the table template given a us er | |||
// interface definition and a cell value object. | // interface definition and a cell value object. | |||
// e.g., value = Object {count: 14351, percent: 5.79} | // e.g., value = Object {count: 14351, percent: 5.79} | |||
getObjectCell: function (panel, ui, value) { | getObjectCell: function (panel, ui, value) { | |||
var className = ui.className || ''; | var className = ui.className || ''; | |||
className += ui.dataType != 'string' ? 'text-right' : ''; | className += !['string'].includes(ui.dataType) ? 'text-right' : ' '; | |||
return { | return { | |||
'className': className, | 'className': className, | |||
'percent': GoAccess.Util.getPercent(value), | 'percent': GoAccess.Util.getPercent(value), | |||
'value': GoAccess.Util.fmtValue(GoAccess.Util.getCount(va lue), ui.dataType) | 'value': GoAccess.Util.fmtValue(GoAccess.Util.getCount(va lue), ui.dataType, null, null, ui.hlregex, ui.hlvalue, ui.hlidx) | |||
}; | }; | |||
}, | }, | |||
// Given a data item object, set all the row cells and return a | // Given a data item object, set all the row cells and return a | |||
// table row that the template can consume. | // table row that the template can consume. | |||
renderRow: function (panel, callback, ui, dataItem, idx, subItem, parentI d, expanded) { | renderRow: function (panel, callback, ui, dataItem, idx, subItem, parentI d, expanded) { | |||
var shadeParent = ((!subItem && idx % 2 != 0) ? 'shaded' : ''); | var shadeParent = ((!subItem && idx % 2 != 0) ? 'shaded' : ''); | |||
var shadeChild = ((parentId % 2 != 0) ? 'shaded' : ''); | var shadeChild = ((parentId % 2 != 0) ? 'shaded' : ''); | |||
return { | return { | |||
'panel' : panel, | 'panel' : panel, | |||
skipping to change at line 1844 | skipping to change at line 1860 | |||
$('.container').classList.add('container-fluid'); | $('.container').classList.add('container-fluid'); | |||
$('.container-fluid').classList.remove('container'); | $('.container-fluid').classList.remove('container'); | |||
} | } | |||
}, | }, | |||
renderData: function () { | renderData: function () { | |||
// update data and charts if tab/document has focus | // update data and charts if tab/document has focus | |||
if (!this.hasFocus) | if (!this.hasFocus) | |||
return; | return; | |||
// some panels may not have been properly rendered since no data | ||||
was | ||||
// passed when bootstrapping the report, thus we do a one full | ||||
// re-render of all panels | ||||
if (GoAccess.OverallStats.total_requests == 0 && GoAccess.Overall | ||||
Stats.total_requests != GoAccess.AppData.general.total_requests) | ||||
GoAccess.Panels.initialize(); | ||||
GoAccess.OverallStats.total_requests = GoAccess.AppData.general.t | ||||
otal_requests; | ||||
this.verifySort(); | this.verifySort(); | |||
GoAccess.OverallStats.initialize(); | GoAccess.OverallStats.initialize(); | |||
// do not rerender tables/charts if data hasn't changed | // do not rerender tables/charts if data hasn't changed | |||
if (!GoAccess.AppState.updated) | if (!GoAccess.AppState.updated) | |||
return; | return; | |||
GoAccess.Charts.reloadCharts(); | GoAccess.Charts.reloadCharts(); | |||
GoAccess.Tables.reloadTables(); | GoAccess.Tables.reloadTables(); | |||
}, | }, | |||
End of changes. 10 change blocks. | ||||
5 lines changed or deleted | 31 lines changed or added |