security, localstorage, whitespace fixes for stats
This commit is contained in:
Родитель
325df191bb
Коммит
c6805da9f9
|
@ -1,8 +1,9 @@
|
|||
{% extends "base.html" %}
|
||||
|
||||
{% block site_css %}
|
||||
{{ super() }}
|
||||
{% block extrahead %}
|
||||
<link rel="stylesheet" href="{{ MEDIA_URL }}css/stats.css"/>
|
||||
<link rel="stylesheet"
|
||||
href="{{ MEDIA_URL }}css/zamboni/jquery-ui/custom-1.7.2.css">
|
||||
{% endblock %}
|
||||
|
||||
{% block title %}{{ _('Add-ons for Firefox') }} Statistics Dashboard {% endblock %}
|
||||
|
|
|
@ -182,6 +182,7 @@ def check_stats_permission(request, addon, for_contributions=False):
|
|||
|
||||
def stats_report(request, addon_id, report):
|
||||
addon = get_object_or_404(Addon.objects.valid(), id=addon_id)
|
||||
check_stats_permission(request, addon)
|
||||
stats_base_url = reverse('stats.overview', args=[addon.id])
|
||||
return jingo.render(request, 'stats/%s.html' % report,
|
||||
{'addon': addon,
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
$(document).ready(function () {
|
||||
|
||||
var csvTable;
|
||||
|
||||
jQuery.fn.getData = function(name) {
|
||||
return this.attr("data-" + name);
|
||||
};
|
||||
|
@ -10,24 +8,18 @@ $(document).ready(function () {
|
|||
page_state.report_name = $(".primary").getData("report");
|
||||
page_state.data_range = "30 days";
|
||||
page_state.chart_fields = $("#head-chart").getData("series").split(',') || ["count"];
|
||||
|
||||
|
||||
var stats_base_url = $(".primary").getData("base_url");
|
||||
AMO.aggregate_stats_field = $(".stats-aggregate").getData("field");
|
||||
AMO.getAddonId = function () { return page_state.addon_id };
|
||||
AMO.getReportName = function () { return page_state.report_name };
|
||||
AMO.getSeriesList = function () {
|
||||
return {
|
||||
AMO.getSeriesList = function () { return {
|
||||
"metric": page_state.report_name,
|
||||
"fields": page_state.chart_fields
|
||||
}
|
||||
};
|
||||
AMO.getStatsBaseURL = function () { return stats_base_url };
|
||||
|
||||
t.go();
|
||||
|
||||
AMO.StatsManager.init();
|
||||
|
||||
t.lap("StatsManager init");
|
||||
|
||||
var report = AMO.getReportName();
|
||||
|
@ -57,7 +49,6 @@ $(document).ready(function () {
|
|||
if (AMO.aggregate_stats_field) {
|
||||
show_aggregate_stats(AMO.aggregate_stats_field, page_state.data_range);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
e.preventDefault();
|
||||
|
@ -79,40 +70,31 @@ $(document).ready(function () {
|
|||
t.lap("events init");
|
||||
|
||||
if (report == "overview") {
|
||||
|
||||
page_state.report_name = 'downloads';
|
||||
|
||||
var series_menu = $("#series-select");
|
||||
|
||||
series_menu.click(function(e) {
|
||||
var $target = $(e.target);
|
||||
var new_report = $target.getData("report");
|
||||
var new_series = $target.getData("series");
|
||||
|
||||
if (new_series && new_report != AMO.getReportName()) {
|
||||
series_menu.children("li.selected").removeClass("selected");
|
||||
$target.parent().addClass("selected");
|
||||
|
||||
page_state.report_name = new_report;
|
||||
page_state.data_fields = new_series;
|
||||
|
||||
AMO.StatsManager.getSeries(AMO.getSeriesList(), page_state.data_range, initCharts);
|
||||
}
|
||||
e.preventDefault();
|
||||
});
|
||||
// generate_top_charts();
|
||||
}); // generate_top_charts();
|
||||
|
||||
initTopCharts();
|
||||
|
||||
} else {
|
||||
|
||||
var csv_table_el = $(".csv-table");
|
||||
if (csv_table_el.length) {
|
||||
csvTable = new PageTable(csv_table_el[0]);
|
||||
}
|
||||
|
||||
t.lap("csvtable init");
|
||||
|
||||
}
|
||||
|
||||
LoadBar.on("Loading the latest data…");
|
||||
|
@ -126,7 +108,6 @@ $(document).ready(function () {
|
|||
|
||||
AMO.StatsManager.getDataRange(AMO.getReportName(), fetchStart, today(), function () {
|
||||
t.lap("building aggregate stats")
|
||||
|
||||
if (AMO.aggregate_stats_field) {
|
||||
show_aggregate_stats(AMO.aggregate_stats_field, page_state.data_range);
|
||||
}
|
||||
|
@ -187,8 +168,8 @@ $(document).ready(function () {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
function draw_diff(el, current, previous) {
|
||||
if (current.nodata || previous.nodata) return;
|
||||
var diffel = $(el);
|
||||
var diff = Math.round((current - previous) * 100 / previous);
|
||||
if (diff > 0) {
|
||||
|
@ -200,7 +181,6 @@ $(document).ready(function () {
|
|||
diffel.text((diff >= 0 ? '+' : '') + diff + "%");
|
||||
}
|
||||
|
||||
|
||||
|
||||
function initCharts(cfg) {
|
||||
if (mainChart) {
|
||||
|
@ -258,7 +238,6 @@ $(document).ready(function () {
|
|||
}
|
||||
}
|
||||
},
|
||||
|
||||
series: cfg
|
||||
});
|
||||
|
||||
|
@ -354,26 +333,19 @@ function show_aggregate_stats (_field, range) {
|
|||
|
||||
$("#sum_range").text(Highcharts.numberFormat(sum_range, 0));
|
||||
$("#sum_prev_range").text(Highcharts.numberFormat(sum_prev_range, 0));
|
||||
|
||||
draw_diff($("#sum_diff"), sum_range, sum_prev_range);
|
||||
draw_diff($("#sum_prev_diff"), sum_prev_range, sum_3x_range);
|
||||
|
||||
|
||||
AMO.StatsManager.getMean(field, ago(range, 3), ago(range, 2) + millis("1 day"), function(mean_3x_range) {
|
||||
AMO.StatsManager.getMean(field, ago(range, 2), ago(range) + millis("1 day"), function(mean_prev_range) {
|
||||
AMO.StatsManager.getMean(field, ago(range), today(), function(mean_range) {
|
||||
|
||||
$("#mean_range").text(Highcharts.numberFormat(mean_range, 0));
|
||||
$("#mean_prev_range").text(Highcharts.numberFormat(mean_prev_range, 0));
|
||||
|
||||
draw_diff($("#mean_diff"), mean_range, mean_prev_range);
|
||||
draw_diff($("#mean_prev_diff"), mean_prev_range, mean_3x_range);
|
||||
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
// (function () {
|
||||
|
||||
// Versioning for offline storage
|
||||
var version = "2";
|
||||
var version = "4";
|
||||
|
||||
// where all the time-series data for the page is kept
|
||||
var datastore = {};
|
||||
|
@ -12,11 +12,8 @@
|
|||
mindate: 0,
|
||||
maxdate: today()
|
||||
};
|
||||
|
||||
var page_state = {
|
||||
}
|
||||
|
||||
|
||||
var capabilities = {
|
||||
localStorage : ('localStorage' in window) && window['localStorage'] !== null,
|
||||
JSON : window.JSON && typeof JSON.parse == 'function'
|
||||
|
@ -115,7 +112,7 @@
|
|||
var local_store = localStorage;
|
||||
dbg("looking for local data");
|
||||
if (local_store.getItem("statscache") && AMO.StatsManager.verify_local()) {
|
||||
var cacheObject = local_store.getItem("statscache");
|
||||
var cacheObject = local_store.getItem("statscache-" + AMO.getAddonId());
|
||||
dbg("found local data, loading...");
|
||||
datastore = JSON.parse(cacheObject);
|
||||
}
|
||||
|
@ -129,7 +126,7 @@
|
|||
if (capabilities.localStorage) {
|
||||
dbg("user has local storage");
|
||||
var local_store = localStorage;
|
||||
local_store.setItem("statscache", JSON.stringify(datastore));
|
||||
local_store.setItem("statscache-" + AMO.getAddonId(), JSON.stringify(datastore));
|
||||
local_store.setItem("stats_version", version);
|
||||
dbg("saved local data");
|
||||
} else {
|
||||
|
@ -140,7 +137,7 @@
|
|||
clear_local: function () {
|
||||
if (capabilities.localStorage) {
|
||||
var local_store = localStorage;
|
||||
local_store.removeItem("statscache");
|
||||
local_store.removeItem("statscache-" + AMO.getAddonId());
|
||||
dbg("cleared local data");
|
||||
}
|
||||
},
|
||||
|
@ -166,8 +163,6 @@
|
|||
var seriesURLStart = Highcharts.dateFormat('%Y%m%d', seriesStart),
|
||||
seriesURLEnd = Highcharts.dateFormat('%Y%m%d', seriesEnd),
|
||||
seriesURL = AMO.getStatsBaseURL() + ([metric,"day",seriesURLStart,seriesURLEnd]).join("-") + ".json";
|
||||
|
||||
|
||||
$.ajax({ url: seriesURL,
|
||||
dataType: 'text',
|
||||
success: function(raw_data, status, xhr) {
|
||||
|
@ -184,7 +179,6 @@
|
|||
}
|
||||
|
||||
var ds = datastore[metric];
|
||||
|
||||
// process the Data. We want to directly use the native JSON
|
||||
// without jQuery's costly regexes if we can.
|
||||
if (capabilities.JSON) {
|
||||
|
|
Загрузка…
Ссылка в новой задаче