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}', pointFormat: ''+ ''+ '', footerFormat: '
Total:{point.y}
' }, xAxis: { categories: options.categories, labels: { align: 'center' } }, yAxis: { title: { text: "Views/Relearns" }, stackLabels: { enabled: true, style: { fontWeight: 'bold', color: 'gray' } } }, plotOptions: { series: { stacking: 'normal', borderColor: 'white' } }, series: [{ type: 'column', name: 'Relearns', data: options.relearns, borderColor: 'white', shadow: false },{ type: 'column', name: 'Unique Views', data: options.uniqueViews, borderColor: 'white', shadow: false }], credits: { enabled: false }, legend: { enabled: false } }); }; PersonalReport.prototype.log = function(message) { if (!this.debugMode) { return; } console.log("[PersonalReport] " + message); }; PersonalReport.prototype.ajax = function(url, options) { $.ajax(url, options); }; this.PersonalReport = PersonalReport; })(this); ;FI"dependency_digest;F"%388c355c46a0324b43a90b50253a2046I"required_paths;F[I"o/Users/adamdoeler/Sites/bigbang/woople-theme/app/assets/javascripts/woople-theme/reports/PersonalReport.js;FI"dependency_paths;F[{I" path;FI"o/Users/adamdoeler/Sites/bigbang/woople-theme/app/assets/javascripts/woople-theme/reports/PersonalReport.js;FI" mtime;FI"2012-10-03T15:52:29-04:00;FI" digest;F"%d246a3e43a2fc339332017515d84c473I" _version;F"%9f3b95dd7ea3030dc35985c0a8020862