o: ActiveSupport::Cache::Entry :@compressedF:@expires_in0:@created_atf1349294162.748693:@value"µ{I"
class:EFI"ProcessedAsset; FI"logical_path; FI"+woople-theme/reports/PersonalReport.js; FI"
pathname; FI"o/Users/adamdoeler/Sites/bigbang/woople-theme/app/assets/javascripts/woople-theme/reports/PersonalReport.js; FI"content_type; FI"application/javascript; FI"
mtime; FI"2012-10-03T15:52:29-04:00; FI"length; Fi8I"digest; F"%d246a3e43a2fc339332017515d84c473I"source; FI"8(function() {
var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
var RED = '255, 0, 0';
var YELLOW = '255, 215, 0';
var GREEN = '70, 136, 71';
var YELLOW_GOAL = 4;
var GREEN_GOAL = 7;
function PersonalReport(selector) {
this.debugMode = false;
this.selector = $(selector);
this.log('initialize');
this.setupListeners();
}
PersonalReport.prototype.setupListeners = function() {
this.log('setup listeners');
this.selector.on('shown', __bind(this.shownListener, this));
};
PersonalReport.prototype.shownListener = function(event) {
this.log('tab shown: ' + $(event.target).attr('href'));
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.log('report: loading...');
this.reportType = reportType;
this.container = container;
this.ajax(path, {
type: 'GET',
success: __bind(this.successCallback, this),
error: __bind(this.errorCallback, this)
});
};
PersonalReport.prototype.successCallback = function(data, textStatus, jqXHR) {
this.log('report: loaded');
this.reportData = data;
this.buildReport();
};
PersonalReport.prototype.errorCallback = function(jqXHR, textStatus, errorThrown) {
this.log('report: error');
};
PersonalReport.prototype.buildReport = function() {
this.log('report: building');
this.renderChart({
container: this.container,
title: this.reportTitle(),
categories: this.categories(),
uniqueViews: this.uniqueViews(),
relearns: this.relearns(),
gradeColours: this.gradeColours()
});
};
PersonalReport.prototype.reportTitle = function() {
this.log('report title for: '+ this.reportType);
return $('#'+ this.reportType).data('title');
};
PersonalReport.prototype.categories = function() {
var categories = [];
for(var i in this.reportData) {
categories.push(this.formatCategoryName(this.reportData[i]));
}
return categories;
};
PersonalReport.prototype.formatCategoryName = function(data) {
return ''+ data.primary_name +'' +'
'+ data.secondary_name;
};
PersonalReport.prototype.uniqueViews = function() {
var uniqueViews = [];
for(var i in this.reportData) {
uniqueViews.push({
y: this.reportData[i].views,
color: this.gradeColour(this.reportData[i], 1)
});
}
return uniqueViews;
};
PersonalReport.prototype.relearns = function() {
var relearns = [];
for(var i in this.reportData) {
relearns.push({
y: this.reportData[i].relearns,
color: this.gradeColour(this.reportData[i], 0.5)
});
}
return relearns;
};
PersonalReport.prototype.gradeColours = function() {
var grades = [];
for(var i in this.reportData) {
var total = (parseInt(this.reportData[i].views, 10) + parseInt(this.reportData[i].relearns, 10));
if (total < (YELLOW_GOAL * this.multiplier())) {
grades.push(RED);
}
if (total < (GREEN_GOAL * this.multiplier())) {
grades.push(YELLOW);
}
if (total >= (GREEN_GOAL * this.multiplier())) {
grades.push(GREEN);
}
}
return grades;
};
PersonalReport.prototype.gradeColour = function(data, opacity) {
var total = (parseInt(data.views, 10) + parseInt(data.relearns, 10));
if (total < (YELLOW_GOAL * this.multiplier())) {
return 'rgba('+ RED +', '+ opacity +')';
}
if (total < (GREEN_GOAL * this.multiplier())) {
return 'rgba('+ YELLOW +', '+ opacity +')';
}
if (total >= (GREEN_GOAL * this.multiplier())) {
return 'rgba('+ GREEN +', '+ opacity +')';
}
};
PersonalReport.prototype.multiplier = function() {
if (this.reportType == 'week') {
return 1;
}
if (this.reportType == 'month') {
return 7;
}
if (this.reportType == 'annual') {
return 31;
}
};
PersonalReport.prototype.renderChart = function(options) {
this.log('report: rendered');
new Highcharts.Chart({
chart: {
borderRadius: 0,
renderTo: options.container,
height: 400,
type: 'column'
},
title: {
text: options.title
},
tooltip: {
borderColor: 'darkGrey',
useHTML: true,
headerFormat: '{series.name}
Total: | {point.y} |