o: ActiveSupport::Cache::Entry :@compressedF:@expires_in0:@created_atf1350066502.260427:@value"H{I"
class:EFI"BundledAsset; FI"logical_path; FI",woople-theme/reports/personal_report.js; FI"
pathname; FI"i/Users/paul/Sites/woople-theme/app/assets/javascripts/woople-theme/reports/personal_report.js.coffee; FI"content_type; FI"application/javascript; FI"
mtime; FI"2012-10-11T15:20:01-04:00; FI"length; FiGI"digest; F"%d599d5dcc632797ca4b48b70d8ea7812I"source; FI"G(function() {
var PersonalReport;
PersonalReport = (function() {
function PersonalReport() {}
PersonalReport.RED = '255, 0, 0';
PersonalReport.YELLOW = '255, 215, 0';
PersonalReport.GREEN = '70, 136, 71';
PersonalReport.YELLOW_GOAL = 4;
PersonalReport.GREEN_GOAL = 7;
PersonalReport.prototype.init = function(selector, debugMode) {
this.debugMode = debugMode;
this.selector = $(selector);
this.log('initialize');
return this.setupListeners();
};
PersonalReport.prototype.setupListeners = function() {
this.log('setup listeners');
return this.selector.on('shown', $.proxy(this, 'shownListener'));
};
PersonalReport.prototype.shownListener = function(event) {
this.log('tab shown: ' + $(event.target).attr('href'));
return this.loadReport($(event.target).attr('data-type'), $(event.target).attr('data-container'), $(event.target).attr('data-path'));
};
PersonalReport.prototype.loadReport = function(reportType, container, path) {
this.reportType = reportType;
this.container = container;
this.log('report: loading...');
return $.ajax(path, {
type: 'GET',
success: $.proxy(this, 'successCallback'),
error: $.proxy(this, 'errorCallback')
});
};
PersonalReport.prototype.successCallback = function(data, textStatus, jqXHR) {
this.log('report: loaded');
this.reportData = data;
return this.buildReport();
};
PersonalReport.prototype.errorCallback = function(jqXHR, textStatus, errorThrown) {
return this.log('report: error');
};
PersonalReport.prototype.highchartOptions = function() {
var options;
options = {
chart: {
borderRadius: 0,
renderTo: this.container,
height: 400,
type: 'column'
},
title: {
text: this.reportTitle()
},
tooltip: {
borderColor: 'darkGrey',
useHMTL: true,
headerFormat: '{series.name}',
pointFormat: '
\
Total: | {point.y} |
\
',
footerFormat: ''
},
xAxis: {
categories: this.categories(),
labels: {
formatter: function() {
var index, numberOfAxisLabels, offset;
numberOfAxisLabels = this.axis.categories.length;
offset = numberOfAxisLabels % 2;
index = this.axis.categories.indexOf(this.value);
if ((index + offset) % 2 === 0 && $(window).width() <= 500) {
return '';
} else {
return this.value;
}
}
}
},
yAxis: {
title: {
text: "Views/Relearns"
},
stackLabels: {
enabled: true,
style: {
fontWeight: 'bold',
color: 'grey'
}
}
},
plotOptions: {
series: {
stacking: 'normal',
borderColor: 'white'
}
},
series: [
{
type: 'column',
name: 'Relearns',
data: this.relearns(),
borderColor: 'white',
shadow: false
}, {
type: 'column',
name: 'Unique Views',
data: this.uniqueViews(),
borderColor: 'white',
shadow: false
}
],
credits: {
enabled: false
},
legend: {
enabled: false
}
};
return options;
};
PersonalReport.prototype.buildReport = function() {
this.log('report: building');
return this.chart = new Highcharts.Chart(this.highchartOptions());
};
PersonalReport.prototype.reportTitle = function() {
this.log('report title for: ' + this.reportType);
return $('#' + this.reportType).data('title');
};
PersonalReport.prototype.categories = function() {
var categories, category, _i, _len, _ref;
categories = [];
_ref = this.reportData;
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
category = _ref[_i];
categories.push(this.formatCategoryName(category));
}
return categories;
};
PersonalReport.prototype.formatCategoryName = function(data) {
return "" + data.primary_name + "
" + data.secondary_name;
};
PersonalReport.prototype.uniqueViews = function() {
var data, uniqueViews, _i, _len, _ref;
uniqueViews = [];
_ref = this.reportData;
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
data = _ref[_i];
uniqueViews.push({
y: data.views,
color: this.gradeColour(data, 1)
});
}
return uniqueViews;
};
PersonalReport.prototype.relearns = function() {
var data, relearns, _i, _len, _ref;
relearns = [];
_ref = this.reportData;
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
data = _ref[_i];
relearns.push({
y: data.relearns,
color: this.gradeColour(data, 0.5)
});
}
return relearns;
};
PersonalReport.prototype.gradeColour = function(data, opacity) {
var total;
total = parseInt(data.views, 10) + parseInt(data.relearns, 10);
if (total < (PersonalReport.YELLOW_GOAL * this.multiplier())) {
return "rgba(" + PersonalReport.RED + ", " + opacity + ")";
}
if (total < (PersonalReport.GREEN_GOAL * this.multiplier())) {
return "rgba(" + PersonalReport.YELLOW + ", " + opacity + ")";
}
if (total >= (PersonalReport.GREEN_GOAL * this.multiplier())) {
return "rgba(" + PersonalReport.GREEN + ", " + opacity + ")";
}
};
PersonalReport.prototype.multiplier = function() {
if (this.isWeekly()) {
return 1;
}
if (this.isMonthly()) {
return 7;
}
if (this.isAnnually()) {
return 31;
}
};
PersonalReport.prototype.isWeekly = function() {
return this.reportType === 'week';
};
PersonalReport.prototype.isMonthly = function() {
return this.reportType === 'month';
};
PersonalReport.prototype.isAnnually = function() {
return this.reportType === 'annual';
};
PersonalReport.prototype.log = function(message) {
if (this.debugMode) {
return console.log("[PersonalReport] " + message);
}
};
return PersonalReport;
})();
this.PersonalReport = PersonalReport;
}).call(this);
; FI"required_assets_digest; F"%40285c46f5e73a5bbb53c3c583774ae0I"
_version; F"%9f3b95dd7ea3030dc35985c0a8020862