Skip to content

Commit

Permalink
Added the ability to set default preferences for the HTML report.
Browse files Browse the repository at this point in the history
To set the default preferences, it requires a valid JSON object.
It also allows the ability to customize each panel plot.
See default configuration file for an example or the man page.
  • Loading branch information
allinurl committed Nov 6, 2016
1 parent f280958 commit 826a9f9
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 2 deletions.
9 changes: 9 additions & 0 deletions config/goaccess.conf
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,15 @@ hl-header true
#
#html-custom-js /path/file.js

# Set default HTML preferences.
#
# NOTE: A valid JSON object is required.
# DO NOT USE A MULTILINE JSON OBJECT.
# The parser will only parse the value next to `html-prefs` (single line)
# It allows the ability to customize each panel plot. See example below.
#
#html-prefs {"theme":"bright","perPage":5,"layout":"horizontal","showTables":true,"visitors":{"plot":{"chartType":"bar"}}}

# Set HTML report page title and header.
#
#html-report-title My Awesome Web Stats
Expand Down
3 changes: 3 additions & 0 deletions resources/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,15 @@ window.GoAccess = window.GoAccess || {
'perPage': 10,
'layout': 'horizontal',
};
this.AppPrefs = GoAccess.Util.merge(this.AppPrefs, this.opts.prefs);

if (GoAccess.Util.hasLocalStorage()) {
var ls = JSON.parse(localStorage.getItem('AppPrefs'));
this.AppPrefs = GoAccess.Util.merge(this.AppPrefs, ls);
}
if (Object.keys(this.AppWSConn).length)
this.setWebSocket(this.AppWSConn);

},

getPanelUI: function (panel) {
Expand Down Expand Up @@ -1510,6 +1512,7 @@ window.onload = function () {
'uiData': window.user_interface,
'panelData': window.json_data,
'wsConnection': window.connection || null,
'prefs': window.html_prefs || {},
});
GoAccess.App.initialize();
};
6 changes: 6 additions & 0 deletions src/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ struct option long_opts[] = {
{"html-custom-css" , required_argument , 0 , 0 } ,
{"html-custom-js" , required_argument , 0 , 0 } ,
{"html-report-title" , required_argument , 0 , 0 } ,
{"html-prefs" , required_argument , 0 , 0 } ,
{"ignore-crawlers" , no_argument , 0 , 0 } ,
{"ignore-panel" , required_argument , 0 , 0 } ,
{"ignore-referer" , required_argument , 0 , 0 } ,
Expand Down Expand Up @@ -169,6 +170,7 @@ cmd_help (void)
" --color-scheme=<1|2|3> - Schemes: 1 => Grey, 2 => Green, 3 => Monokai.\n"
" --html-custom-css=<path.css> - Specify a custom CSS file in the HTML report.\n"
" --html-custom-js=<path.js> - Specify a custom JS file in the HTML report.\n"
" --html-prefs=<json_obj> - Set default HTML report preferences.\n"
" --html-report-title=<title> - Set HTML report page title and header.\n"
" --json-pretty-print - Format JSON output w/ tabs & newlines.\n"
" --max-items - Maximum number of items to show per panel.\n"
Expand Down Expand Up @@ -387,6 +389,10 @@ parse_long_opt (const char *name, const char *oarg)
if (!strcmp ("html-custom-js", name))
conf.html_custom_js = oarg;

/* html JSON object containing default preferences */
if (!strcmp ("html-prefs", name))
conf.html_prefs = oarg;

/* 444 as 404 */
if (!strcmp ("444-as-404", name))
conf.code444_as_404 = 1;
Expand Down
1 change: 1 addition & 0 deletions src/output.c
Original file line number Diff line number Diff line change
Expand Up @@ -1132,6 +1132,7 @@ print_json_defs (FILE * fp, GHolder * holder)
size_t idx = 0;

fprintf (fp, "<script type='text/javascript'>");
fprintf (fp, "var html_prefs=%s;", conf.html_prefs ? conf.html_prefs : "{}");
fprintf (fp, "var user_interface=");
fpopen_obj (fp, 0);

Expand Down
5 changes: 3 additions & 2 deletions src/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,12 @@ typedef struct GConf_

const char *debug_log; /* debug log path */
const char *geoip_database; /* geoip db path */
const char *html_custom_css; /* custom CSS */
const char *html_custom_js; /* custom JS */
const char *html_prefs; /* default HTML JSON preferences */
const char *html_report_title; /* report title */
const char *iconfigfile; /* config file path */
const char *invalid_requests_log; /* invalid lines log path */
const char *html_custom_css; /* custom CSS */
const char *html_custom_js; /* custom JS */

/* HTML real-time */
const char *addr; /* IP address to bind to */
Expand Down

0 comments on commit 826a9f9

Please sign in to comment.