Add JSONification of WebStats module. Adds a '?json' query parameter

to the fetch URL to return the data in JSON format. Also adds a simple
'sim.html' that uses JavaScript to display the JSON data. Not pretty
but an example.
This commit is contained in:
Robert Adams
2013-01-24 10:44:57 -08:00
parent d5b950633d
commit 427ab219b8
13 changed files with 660 additions and 14 deletions

View File

@@ -121,6 +121,10 @@ namespace OpenSim.Region.UserStatistics
reports.Add("clients.report", clientReport);
reports.Add("sessions.report", sessionsReport);
reports.Add("sim.css", new Prototype_distributor("sim.css"));
reports.Add("sim.html", new Prototype_distributor("sim.html"));
reports.Add("jquery.js", new Prototype_distributor("jquery.js"));
////
// Add Your own Reports here (Do Not Modify Lines here Devs!)
////
@@ -255,9 +259,12 @@ namespace OpenSim.Region.UserStatistics
string regpath = request["uri"].ToString();
int response_code = 404;
string contenttype = "text/html";
bool jsonFormatOutput = false;
string strOut = string.Empty;
// The request patch should be "/SStats/reportName" where 'reportName'
// is one of the names added to the 'reports' hashmap.
regpath = regpath.Remove(0, 8);
if (regpath.Length == 0) regpath = "default.report";
if (reports.ContainsKey(regpath))
@@ -265,6 +272,9 @@ namespace OpenSim.Region.UserStatistics
IStatsController rep = reports[regpath];
Hashtable repParams = new Hashtable();
if (request.ContainsKey("json"))
jsonFormatOutput = true;
if (request.ContainsKey("requestvars"))
repParams["RequestVars"] = request["requestvars"];
else
@@ -284,13 +294,26 @@ namespace OpenSim.Region.UserStatistics
concurrencyCounter++;
strOut = rep.RenderView(rep.ProcessModel(repParams));
if (jsonFormatOutput)
{
strOut = rep.RenderJson(rep.ProcessModel(repParams));
contenttype = "text/json";
}
else
{
strOut = rep.RenderView(rep.ProcessModel(repParams));
}
if (regpath.EndsWith("js"))
{
contenttype = "text/javascript";
}
if (regpath.EndsWith("css"))
{
contenttype = "text/css";
}
concurrencyCounter--;
response_code = 200;