Ejegg has uploaded a new change for review. https://gerrit.wikimedia.org/r/195655
Change subject: Whitespace ...................................................................... Whitespace Change-Id: If10dc6bf5b642cad7ccf7ed8052790be8755a9c8 --- M defaults.js M server.js M src/app/widgetBase.js M src/components/widgets/ABTesting/ABTestingMain.js M src/components/widgets/amt-per-second-chart/amt-per-second-chart.js M src/components/widgets/distance-to-goal-chart/distance-to-goal-chart.js M src/components/widgets/totals-earned-chart/totals-earned-chart.js M src/components/widgets/x-by-y/x-by-y.js 8 files changed, 652 insertions(+), 652 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/wikimedia/fundraising/dash refs/changes/55/195655/1 diff --git a/defaults.js b/defaults.js index 5e73b05..7a1b81e 100644 --- a/defaults.js +++ b/defaults.js @@ -1,18 +1,18 @@ module.exports = { - listen: '8080', - dbserver: 'localhost', - db: 'fredge', - civicrmDb: 'civicrm', - dblogin: 'testuser', - dbpwd: 'testpassword', + listen: '8080', + dbserver: 'localhost', + db: 'fredge', + civicrmDb: 'civicrm', + dblogin: 'testuser', + dbpwd: 'testpassword', // URL to redirect the user's browser to - providerURL: 'https://civi.dev/civi', + providerURL: 'https://civi.dev/civi', // BackendURL will be used for direct Dash->Drupal requests - providerBackendURL: 'http://localhost/civi', - // If providerBackendIP is set, we override DNS resolution for the hostname - // given in providerBackendURL. This can be useful for SSL behind firewalls - consumerKey: 'kKq6LbU4ctDUzubSUdHJ7Pn9NvVWwQ2f', - consumerSecret: 'JfGs4nnfyoRQ9i9JQeTYP7geCEKQrenX', - sessionSecret: 'ds87naowiy3icaywri73tcin7eyyeI8634I71NYFIEA764', - cacheDuration: 300000 // 5 min in ms + providerBackendURL: 'http://localhost/civi', + // If providerBackendIP is set, we override DNS resolution for the hostname + // given in providerBackendURL. This can be useful for SSL behind firewalls + consumerKey: 'kKq6LbU4ctDUzubSUdHJ7Pn9NvVWwQ2f', + consumerSecret: 'JfGs4nnfyoRQ9i9JQeTYP7geCEKQrenX', + sessionSecret: 'ds87naowiy3icaywri73tcin7eyyeI8634I71NYFIEA764', + cacheDuration: 300000 // 5 min in ms }; diff --git a/server.js b/server.js index 565b3b2..13663ce 100644 --- a/server.js +++ b/server.js @@ -1,15 +1,15 @@ -var express = require( 'express' ), - app = express(), - routes = require( './routes'), - passport = require( 'passport' ), - DrupalStrategy = require( 'passport-drupal' ).DrupalStrategy, - evilDns = require( 'evil-dns' ), - url = require( 'url' ), - logger = require( './logger.js' ), - config = require( './config.js' ), - persistence = require( './persistence.js' ), - server, - serverConfig; +var express = require( 'express' ), + app = express(), + routes = require( './routes'), + passport = require( 'passport' ), + DrupalStrategy = require( 'passport-drupal' ).DrupalStrategy, + evilDns = require( 'evil-dns' ), + url = require( 'url' ), + logger = require( './logger.js' ), + config = require( './config.js' ), + persistence = require( './persistence.js' ), + server, + serverConfig; logger.debug( 'Dash starting up' ); @@ -20,8 +20,8 @@ serverConfig = /(([0-9\.]*|\[[0-9a-fA-F\:]*\]):)?([0-9]+)/.exec(config.listen); if (!serverConfig) { - logger.error( 'Server cannot listen on "' + config.listen + '", invalid format.' ); - process.exit(1); + logger.error( 'Server cannot listen on "' + config.listen + '", invalid format.' ); + process.exit(1); } logger.debug( 'Will try to listen on IP address: ' + serverConfig[2] ); @@ -121,9 +121,9 @@ }); server = app.listen( - serverConfig[3], - serverConfig[2], - function() { - logger.info( 'Dash listening on port ' + server.address().port ); - } + serverConfig[3], + serverConfig[2], + function() { + logger.info( 'Dash listening on port ' + server.address().port ); + } ); diff --git a/src/app/widgetBase.js b/src/app/widgetBase.js index f1dd56b..2eb161f 100644 --- a/src/app/widgetBase.js +++ b/src/app/widgetBase.js @@ -1,7 +1,7 @@ define([ 'jquery', - 'knockout', - 'momentjs' + 'knockout', + 'momentjs' ], function( $, ko, moment ){ function WidgetBase( params ){ @@ -15,20 +15,20 @@ self.widgetCode = params.widgetCode; self.preDataLoading = ko.observable(true); self.dataLoading = ko.observable(!!self.config); - self.chartSaved = ko.observable(!!self.config); - self.optionStateChanged = ko.observable(false); - self.chartWidth = ko.observable('900'); - self.chartHeight = ko.observable('550'); - self.chartLoaded = ko.observable(false); + self.chartSaved = ko.observable(!!self.config); + self.optionStateChanged = ko.observable(false); + self.chartWidth = ko.observable('900'); + self.chartHeight = ko.observable('550'); + self.chartLoaded = ko.observable(false); self.getChartData = function( qs ){ - self.dataLoading(true); + self.dataLoading(true); return $.ajax({ url: '/data/' + self.widgetCode + '?' + ( qs ).replace( /\+/g, '%20' ), success: function ( dataget ) { - self.retrievedResults( dataget.results ); - self.queryStringSQL( dataget.sqlQuery ); - } + self.retrievedResults( dataget.results ); + self.queryStringSQL( dataget.sqlQuery ); + } }); }; @@ -36,31 +36,31 @@ if( self.instanceID ){ $.ajax({ - method: 'PUT', - url: '/widget-instance/' + self.instanceID, - contentType: 'application/json; charset=UTF-8', - data: JSON.stringify({ - configuration: self.config, - isShared: false - }), - success: function( data ) { - self.chartSaved(true); - } - }); + method: 'PUT', + url: '/widget-instance/' + self.instanceID, + contentType: 'application/json; charset=UTF-8', + data: JSON.stringify({ + configuration: self.config, + isShared: false + }), + success: function( data ) { + self.chartSaved(true); + } + }); } else { $.ajax({ - method: 'POST', - url: '/widget-instance/', - contentType: 'application/json; charset=UTF-8', - data: JSON.stringify({ - configuration: self.config, - isShared: false - }), - success: function( data ) { - self.instanceID = data.id; - self.chartSaved(true); - } - }); + method: 'POST', + url: '/widget-instance/', + contentType: 'application/json; charset=UTF-8', + data: JSON.stringify({ + configuration: self.config, + isShared: false + }), + success: function( data ) { + self.instanceID = data.id; + self.chartSaved(true); + } + }); } }; @@ -141,71 +141,71 @@ self.convertToQuery = function( userChoices ){ - var timeBreakout = 'group=' + userChoices.timeBreakout; - //groupStr = timeBreakout + '&group=' + userChoices.xSlice; + var timeBreakout = 'group=' + userChoices.timeBreakout; + //groupStr = timeBreakout + '&group=' + userChoices.xSlice; - // if( userChoices.additionalFilters.length > 0 ){ + // if( userChoices.additionalFilters.length > 0 ){ - // var filterStr = '$filter=', filterObj = {}, haveMultipleSubfilters = []; + // var filterStr = '$filter=', filterObj = {}, haveMultipleSubfilters = []; - // $.each( userChoices.additionalFilters, function( el, subfilter ){ - // var filter = subfilter.substr(0, subfilter.indexOf(' ')); - // if(!filterObj[ filter ]){ - // filterObj[ filter ] = subfilter; - // } else { - // filterObj[ filter ] += ' or ' + subfilter; - // haveMultipleSubfilters.push( filter ); - // } - // }); + // $.each( userChoices.additionalFilters, function( el, subfilter ){ + // var filter = subfilter.substr(0, subfilter.indexOf(' ')); + // if(!filterObj[ filter ]){ + // filterObj[ filter ] = subfilter; + // } else { + // filterObj[ filter ] += ' or ' + subfilter; + // haveMultipleSubfilters.push( filter ); + // } + // }); - // $.each( filterObj, function( el, s ){ - // if( haveMultipleSubfilters.indexOf( el ) > -1){ - // filterStr += '(' + filterObj[ el ] + ')'; - // } else { - // filterStr += filterObj[ el ]; - // } - // filterStr += ' and '; - // }); + // $.each( filterObj, function( el, s ){ + // if( haveMultipleSubfilters.indexOf( el ) > -1){ + // filterStr += '(' + filterObj[ el ] + ')'; + // } else { + // filterStr += filterObj[ el ]; + // } + // filterStr += ' and '; + // }); - // if( filterStr !== '$filter=' ){ - // return groupStr + '&' + ( filterStr.slice(0, -5) ); - // } else { - // return groupStr; - // } - // } else { - // return groupStr; - // } - return timeBreakout; - }; + // if( filterStr !== '$filter=' ){ + // return groupStr + '&' + ( filterStr.slice(0, -5) ); + // } else { + // return groupStr; + // } + // } else { + // return groupStr; + // } + return timeBreakout; + }; // Generate chart label arrays for time increment types self.chartLabels = function(type){ var chartLabels; switch(type){ - case 'Year': - chartLabels = ['Year']; - break; - case 'Month': - chartLabels = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']; - break; - case 'Day': - chartLabels = [ '01', '02', '03', '04', '05', '06', '07', '08', '09', '10', - '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', - '21', '22', '23', '24', '25', '26', '27', '28', '29', '30', '31']; - break; - case 'Hour': - chartLabels = [ '00:00', '01:00', '02:00', '03:00', '04:00', '05:00', '06:00', '07:00', '08:00', '09:00', '10:00', - '11:00', '12:00', '13:00', '14:00', '15:00', '16:00', '17:00', '18:00', '19:00', '20:00', '21:00', - '22:00', '23:00']; - break; - } + case 'Year': + chartLabels = ['Year']; + break; + case 'Month': + chartLabels = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']; + break; + case 'Day': + chartLabels = [ '01', '02', '03', '04', '05', '06', '07', '08', '09', '10', + '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', + '21', '22', '23', '24', '25', '26', '27', '28', '29', '30', '31']; + break; + case 'Hour': + chartLabels = [ '00:00', '01:00', '02:00', '03:00', '04:00', '05:00', '06:00', '07:00', '08:00', '09:00', '10:00', + '11:00', '12:00', '13:00', '14:00', '15:00', '16:00', '17:00', '18:00', '19:00', '20:00', '21:00', + '22:00', '23:00']; + break; + } return chartLabels; }; self.logStateChange = function(n){ - self.optionStateChanged(n); - self.chartSaved(false); - }; + self.optionStateChanged(n); + self.chartSaved(false); + }; return(this); } diff --git a/src/components/widgets/ABTesting/ABTestingMain.js b/src/components/widgets/ABTesting/ABTestingMain.js index 88d646d..700ef89 100644 --- a/src/components/widgets/ABTesting/ABTestingMain.js +++ b/src/components/widgets/ABTesting/ABTestingMain.js @@ -1,142 +1,142 @@ define([ - 'knockout', - 'text!components/widgets/ABTesting/ABTestingMain.html', - 'gauge', - 'bootstrap-datepicker'], -function( ko, template, datePickersTemplate ){ + 'knockout', + 'text!components/widgets/ABTesting/ABTestingMain.html', + 'gauge', + 'bootstrap-datepicker'], + function( ko, template, datePickersTemplate ){ - var ABTestingViewModel = function ( params ) { + var ABTestingViewModel = function ( params ) { - var self = this; - self.title = 'A/B Test Results'; + var self = this; + self.title = 'A/B Test Results'; - //get the data for the tests - self.table1 = ko.observableArray([ - { - 'name':'leafy.green', - 'donations':147, - 'impressions':'502,813', - 'don/K bi':0.29, - '$/K bi':'$6.98 ', - 'clicks':216, - 'amount':'$3,510 ', - 'amount20/K bi':'$4.84 ', - 'avgDonation':'$23.88 ', - 'avg20':'$16.56 ', - 'median':'$20 ', - 'max':'$100 ', - 'conversionrate':'0.68%', - 'mode':'$20 ', - 'mode_s':'$20 ' - }, - { - 'name':'green', - 'donations':143, - 'impressions':'503,249', - 'don/K bi':0.28, - '$/K bi':'$7.76 ', - 'clicks':201, - 'amount':'$3,905 ', - 'amount20/K bi':'$4.58 ', - 'avgDonation':'$27.31 ', - 'avg20':'$16.13 ', - 'median':'$20 ', - 'max':'$250 ', - 'conversionrate':'0.71%', - 'mode':'$20 ', - 'mode_s':'$20 ' - }, - { - 'name':'Absolute change:', - 'donations':4, - 'impressions':'-436', - 'don/K bi':0.01, - '$/K bi':'($0.78)', - 'clicks':15, - 'amount':'($395)', - 'amount20/K bi':'$0.26 ', - 'avgDonation':'($3.43)', - 'avg20':'$0.44 ', - 'median':'$0 ', - 'max':'($150)', - 'conversionrate':'-0.03%', - 'mode':'$0 ', - 'mode_s':'$0 ' - } - ]); + //get the data for the tests + self.table1 = ko.observableArray([ + { + 'name':'leafy.green', + 'donations':147, + 'impressions':'502,813', + 'don/K bi':0.29, + '$/K bi':'$6.98 ', + 'clicks':216, + 'amount':'$3,510 ', + 'amount20/K bi':'$4.84 ', + 'avgDonation':'$23.88 ', + 'avg20':'$16.56 ', + 'median':'$20 ', + 'max':'$100 ', + 'conversionrate':'0.68%', + 'mode':'$20 ', + 'mode_s':'$20 ' + }, + { + 'name':'green', + 'donations':143, + 'impressions':'503,249', + 'don/K bi':0.28, + '$/K bi':'$7.76 ', + 'clicks':201, + 'amount':'$3,905 ', + 'amount20/K bi':'$4.58 ', + 'avgDonation':'$27.31 ', + 'avg20':'$16.13 ', + 'median':'$20 ', + 'max':'$250 ', + 'conversionrate':'0.71%', + 'mode':'$20 ', + 'mode_s':'$20 ' + }, + { + 'name':'Absolute change:', + 'donations':4, + 'impressions':'-436', + 'don/K bi':0.01, + '$/K bi':'($0.78)', + 'clicks':15, + 'amount':'($395)', + 'amount20/K bi':'$0.26 ', + 'avgDonation':'($3.43)', + 'avg20':'$0.44 ', + 'median':'$0 ', + 'max':'($150)', + 'conversionrate':'-0.03%', + 'mode':'$0 ', + 'mode_s':'$0 ' + } + ]); - self.table2 = ko.observableArray([ - { - 'winner':'leafy.green', - 'donations/impression':'2.89%', - 'Donation increase / 1000bi':0.01, - '$/impression':'-10.05%', - 'Dollar increase / 1000bi':'($0.78)', - 'Impression Anomaly':'-0.09%', - 'a20diff':'$0.26 ', - 'p':0.85, - 'power':0.05, - 'lower 95% confidence (donation)':'-20.62%', - 'upper 95% confidence (donations)':'26.39%', - 'lower 95% confidence ($)':'-41.90%', - 'upper 95% confidence ($)':'21.80%' - } - ]); + self.table2 = ko.observableArray([ + { + 'winner':'leafy.green', + 'donations/impression':'2.89%', + 'Donation increase / 1000bi':0.01, + '$/impression':'-10.05%', + 'Dollar increase / 1000bi':'($0.78)', + 'Impression Anomaly':'-0.09%', + 'a20diff':'$0.26 ', + 'p':0.85, + 'power':0.05, + 'lower 95% confidence (donation)':'-20.62%', + 'upper 95% confidence (donations)':'26.39%', + 'lower 95% confidence ($)':'-41.90%', + 'upper 95% confidence ($)':'21.80%' + } + ]); - self.table3 = ko.observableArray([ - { - 'name':'leafy.green', - 'amount3/1000bi':'$0.88 ', - 'avg3':'$3 ', - 'amount5/1000bi':'$1.46 ', - 'avg5':'$5 ', - 'amount10/1000bi':'$2.80 ', - 'avg10':'$9.59 ', - 'amount50/1000bi':'$6.48 ', - 'avg50':'$22.18 ' - }, - { - 'name':'green', - 'amount3/1000bi':'$0.85 ', - 'avg3':'$2.98 ', - 'amount5/1000bi':'$1.41 ', - 'avg5':'$4.95 ', - 'amount10/1000bi':'$2.69 ', - 'avg10':'$9.48 ', - 'amount50/1000bi':'$6.37 ', - 'avg50':'$22.41 ' - } - ]); + self.table3 = ko.observableArray([ + { + 'name':'leafy.green', + 'amount3/1000bi':'$0.88 ', + 'avg3':'$3 ', + 'amount5/1000bi':'$1.46 ', + 'avg5':'$5 ', + 'amount10/1000bi':'$2.80 ', + 'avg10':'$9.59 ', + 'amount50/1000bi':'$6.48 ', + 'avg50':'$22.18 ' + }, + { + 'name':'green', + 'amount3/1000bi':'$0.85 ', + 'avg3':'$2.98 ', + 'amount5/1000bi':'$1.41 ', + 'avg5':'$4.95 ', + 'amount10/1000bi':'$2.69 ', + 'avg10':'$9.48 ', + 'amount50/1000bi':'$6.37 ', + 'avg50':'$22.41 ' + } + ]); - self.table4 = ko.observableArray([ - { - 'name':'cc', - 'donations':123, - 'clicks':195, - 'conversion':'63.08%', - 'avg':'$30.90 ', - 'amount':'$3,801 ' - }, - { - 'name':'pp', - 'donations':167, - 'clicks':222, - 'conversion':'75.23%', - 'avg':'$21.64 ', - 'amount':'$3,614 ' - } - ]); + self.table4 = ko.observableArray([ + { + 'name':'cc', + 'donations':123, + 'clicks':195, + 'conversion':'63.08%', + 'avg':'$30.90 ', + 'amount':'$3,801 ' + }, + { + 'name':'pp', + 'donations':167, + 'clicks':222, + 'conversion':'75.23%', + 'avg':'$21.64 ', + 'amount':'$3,614 ' + } + ]); - self.winner = ko.observable(self.table1()[0].name); - self.runnerUp = ko.observable(self.table1()[1].name); + self.winner = ko.observable(self.table1()[0].name); + self.runnerUp = ko.observable(self.table1()[1].name); - //put the data into objects for use on screen + //put the data into objects for use on screen - }; + }; - return { viewModel: ABTestingViewModel, template: template }; + return { viewModel: ABTestingViewModel, template: template }; }); diff --git a/src/components/widgets/amt-per-second-chart/amt-per-second-chart.js b/src/components/widgets/amt-per-second-chart/amt-per-second-chart.js index bf4824b..e48d9db 100644 --- a/src/components/widgets/amt-per-second-chart/amt-per-second-chart.js +++ b/src/components/widgets/amt-per-second-chart/amt-per-second-chart.js @@ -1,20 +1,20 @@ define( [ - 'knockout', - 'text!components/widgets/amt-per-second-chart/amt-per-second-chart.html', - 'c3', - 'numeraljs', - 'momentjs' + 'knockout', + 'text!components/widgets/amt-per-second-chart/amt-per-second-chart.html', + 'c3', + 'numeraljs', + 'momentjs' ], function( ko, template, c3, numeral, moment ){ - function AmtPerSecondChartViewModel( params ){ + function AmtPerSecondChartViewModel( params ){ - var self = this; + var self = this; - //TODO: make dayObj (and other params) come from data - self.dayObj = []; + //TODO: make dayObj (and other params) come from data + self.dayObj = []; - self.loadData = function ( decemberData, timestamp ) { + self.loadData = function ( decemberData, timestamp ) { var runningTotal = 0, currentDate = new Date(), timeFormat = 'dddd, MMMM Do YYYY, h:mm:ss a'; @@ -142,8 +142,8 @@ } ); }; self.makeChart(); - } + } - return { viewModel: AmtPerSecondChartViewModel, template: template }; + return { viewModel: AmtPerSecondChartViewModel, template: template }; }); diff --git a/src/components/widgets/distance-to-goal-chart/distance-to-goal-chart.js b/src/components/widgets/distance-to-goal-chart/distance-to-goal-chart.js index bd52553..8ce31e1 100644 --- a/src/components/widgets/distance-to-goal-chart/distance-to-goal-chart.js +++ b/src/components/widgets/distance-to-goal-chart/distance-to-goal-chart.js @@ -1,21 +1,21 @@ define( [ - 'knockout', - 'text!components/widgets/distance-to-goal-chart/distance-to-goal-chart.html', - 'c3', - 'momentjs' + 'knockout', + 'text!components/widgets/distance-to-goal-chart/distance-to-goal-chart.html', + 'c3', + 'momentjs' ], function( ko, template, c3, moment ){ - function DistanceToGoalChartViewModel( params ){ + function DistanceToGoalChartViewModel( params ){ - var self = this; - self.goal = ko.observable('20,000,000'); - self.dailyDataArray = [ 'Daily Total' ]; + var self = this; + self.goal = ko.observable('20,000,000'); + self.dailyDataArray = [ 'Daily Total' ]; - self.loadData = function ( decemberData, timestamp ) { + self.loadData = function ( decemberData, timestamp ) { var runningTotal = 0, currentDate = new Date(), - timeFormat = 'dddd, MMMM Do YYYY, h:mm:ss a'; + timeFormat = 'dddd, MMMM Do YYYY, h:mm:ss a'; currentDate.setTime( timestamp ); self.displayDate( moment( currentDate ).format( timeFormat ) ); self.lastDataPoint.day = currentDate.getUTCDate(); @@ -54,16 +54,16 @@ self.raised(runningTotal); }; - // $.get('data/big-english', function(dtgData){ + // $.get('data/big-english', function(dtgData){ - // console.log('dtgData', dtgData); + // console.log('dtgData', dtgData); - // self.dailyDataArray; + // self.dailyDataArray; - // }); + // }); - self.title = ko.observable(params.title); + self.title = ko.observable(params.title); self.makeCharts = function() { if ( self.dailyDataArray.length < 2 ) { return; @@ -117,6 +117,6 @@ //self.makeCharts(); } - return { viewModel: DistanceToGoalChartViewModel, template: template }; + return { viewModel: DistanceToGoalChartViewModel, template: template }; }); diff --git a/src/components/widgets/totals-earned-chart/totals-earned-chart.js b/src/components/widgets/totals-earned-chart/totals-earned-chart.js index bd48cf8..ae3257f 100644 --- a/src/components/widgets/totals-earned-chart/totals-earned-chart.js +++ b/src/components/widgets/totals-earned-chart/totals-earned-chart.js @@ -1,55 +1,55 @@ define( [ - 'knockout', - 'text!components/widgets/totals-earned-chart/totals-earned-chart.html', - 'c3', - 'numeraljs', - 'momentjs' + 'knockout', + 'text!components/widgets/totals-earned-chart/totals-earned-chart.html', + 'c3', + 'numeraljs', + 'momentjs' ], function( ko, template, c3, numeral, moment ){ - function TotalsEarnedChartViewModel( params ){ + function TotalsEarnedChartViewModel( params ){ - var self = this, - timeFormat = 'dddd, MMMM Do YYYY, h:mm:ss a'; + var self = this, + timeFormat = 'dddd, MMMM Do YYYY, h:mm:ss a'; - self.title = ko.observable(params.title); + self.title = ko.observable(params.title); //self.title = ko.observable(params.title); self.widgetWidth = ko.observable(params.configuration.width); self.dataLoading = ko.observable(true); //initialize day/hour data - self.dayObj = []; + self.dayObj = []; self.dailyDataArray = ['Daily Total']; - self.dailyCountArray = ['Daily Count']; + self.dailyCountArray = ['Daily Count']; self.lastDataPoint = { day: 1, hour: 0 }; self.secondsByHourDonationData = ['Donations Per Second']; // Get the date - self.displayDate = ko.observable( moment().format( timeFormat ) ); + self.displayDate = ko.observable( moment().format( timeFormat ) ); - self.goal = ko.observable(20000000); - self.raised = ko.observable(0); + self.goal = ko.observable(20000000); + self.raised = ko.observable(0); - self.bigEnglishGoal = ko.computed(function(){ - return numeral(self.goal()).format('$0,0'); - }); + self.bigEnglishGoal = ko.computed(function(){ + return numeral(self.goal()).format('$0,0'); + }); - self.totalRaisedToDate = ko.computed(function(){ - return numeral(self.raised()).format('$0,0'); - }); + self.totalRaisedToDate = ko.computed(function(){ + return numeral(self.raised()).format('$0,0'); + }); - self.totalRemainingToDate = ko.computed( function(){ - var trtd = self.goal() - self.raised(); - return numeral(trtd >= 0 ? trtd : 0).format('$0,0'); - }); + self.totalRemainingToDate = ko.computed( function(){ + var trtd = self.goal() - self.raised(); + return numeral(trtd >= 0 ? trtd : 0).format('$0,0'); + }); // params.dataChanged.subscribe(function() { // self.makeCharts(); // }); //get the data needed for this chart - self.loadData = function ( decemberData, timestamp ) { + self.loadData = function ( decemberData, timestamp ) { var runningTotal = 0, currentDate = new Date(); currentDate.setTime( timestamp ); @@ -93,14 +93,14 @@ // Reload the data. For the automatic reload, we're fine getting // something from the cache. self.reloadData = function( automatic ){ - self.dataLoading(true); + self.dataLoading(true); var url = '/data/big-english'; if ( automatic !== true ) { url += '/?cache=false'; } $.get( url , function ( dataget ) { self.loadData( dataget.results, dataget.timestamp ); - self.dataLoading(false); + self.dataLoading(false); }); // Do it every 5 minutes as well setTimeout( function () { @@ -170,19 +170,19 @@ } }, tooltip: { - format: { - title: function (d) { return 'Hour ' + d; }, - value: function (value, ratio, id) { - var display; - if(id === 'Hourly Total'){ - display = numeral(value).format('$0,0'); - } else { - display = numeral(value).format('0,0'); - } - return display; - } - } - }, + format: { + title: function (d) { return 'Hour ' + d; }, + value: function (value, ratio, id) { + var display; + if(id === 'Hourly Total'){ + display = numeral(value).format('$0,0'); + } else { + display = numeral(value).format('0,0'); + } + return display; + } + } + }, bar: { width: { ratio: 0.5 @@ -238,19 +238,19 @@ } }, tooltip: { - format: { - title: function (d) { return 'Day ' + (d+1); }, - value: function (value, ratio, id) { - var display; - if(id === 'Daily Total'){ - display = numeral(value).format('$0,0'); - } else { - display = numeral(value).format('0,0'); - } - return display; - } - } - }, + format: { + title: function (d) { return 'Day ' + (d+1); }, + value: function (value, ratio, id) { + var display; + if(id === 'Daily Total'){ + display = numeral(value).format('$0,0'); + } else { + display = numeral(value).format('0,0'); + } + return display; + } + } + }, bar: { width: { ratio: 0.5 @@ -261,8 +261,8 @@ self.totalsEarnedChart = c3.generate(self.dailyChart()); }; self.makeCharts(); - } + } - return { viewModel: TotalsEarnedChartViewModel, template: template }; + return { viewModel: TotalsEarnedChartViewModel, template: template }; -}); \ No newline at end of file +}); diff --git a/src/components/widgets/x-by-y/x-by-y.js b/src/components/widgets/x-by-y/x-by-y.js index 44dcffe..e12e694 100644 --- a/src/components/widgets/x-by-y/x-by-y.js +++ b/src/components/widgets/x-by-y/x-by-y.js @@ -1,374 +1,374 @@ define( [ - 'knockout', - 'text!components/widgets/x-by-y/x-by-y.html', - 'momentjs', - 'numeraljs', - 'c3', - 'select2', - 'WidgetBase' + 'knockout', + 'text!components/widgets/x-by-y/x-by-y.html', + 'momentjs', + 'numeraljs', + 'c3', + 'select2', + 'WidgetBase' ], function( ko, template, moment, numeral, c3, select2, WidgetBase ){ - function XByYChartViewModel( params ){ + function XByYChartViewModel( params ){ - WidgetBase.call( this, params ); - var self = this; + WidgetBase.call( this, params ); + var self = this; - var chartDataCall = self.getChartData(params.configuration.queryString); + var chartDataCall = self.getChartData(params.configuration.queryString); - $.when( chartDataCall ).then( function( dataArray ){ - self.retrievedResults(dataArray.results); - self.dataLoading(false); - self.preDataLoading(false); + $.when( chartDataCall ).then( function( dataArray ){ + self.retrievedResults(dataArray.results); + self.dataLoading(false); + self.preDataLoading(false); - self.chartData = self.processData(self.retrievedResults(), params.configuration.timeBreakout); + self.chartData = self.processData(self.retrievedResults(), params.configuration.timeBreakout); - self.makeChart(self.chartData); - }); + self.makeChart(self.chartData); + }); - self.showSlice = ko.observable(); - self.bySlice = ko.observable(); - self.timeChoice = ko.observable(); - self.queryRequest = {}; - self.queryString = ''; - self.chosenFilters = ko.observableArray(); - self.subChoices = ko.observableArray(); - self.chartWidth(950); + self.showSlice = ko.observable(); + self.bySlice = ko.observable(); + self.timeChoice = ko.observable(); + self.queryRequest = {}; + self.queryString = ''; + self.chosenFilters = ko.observableArray(); + self.subChoices = ko.observableArray(); + self.chartWidth(950); - self.title = ko.computed(function(){ - return self.showSlice(); //+ ' by ' + self.bySlice(); - }); + self.title = ko.computed(function(){ + return self.showSlice(); //+ ' by ' + self.bySlice(); + }); - self.makeChart = function(data){ + self.makeChart = function(data){ - self.chartLoaded(true); + self.chartLoaded(true); - self.monthlyChart = function(d,i){ + self.monthlyChart = function(d,i){ - var monthNamesArray = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']; + var monthNamesArray = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']; - return { - bindto: '#x-by-yChart', - size: { - height: 450, - width: window.width - }, - zoom: { enabled: true }, - data: { - columns: [ data.monthlyCountArray, data.monthlyDataArray ], - type: 'bar', - colors: { 'Monthly Total': 'rgb(92,184,92)', 'Monthly Count': '#f0ad4e' }, - axes: { - 'Monthly Total': 'y', - 'Monthly Count': 'y2' - } - }, - grid: { - x: { - show: true - }, - y: { - show: true - } - }, - axis: { - x: { - tick: { - format: function(x){ return monthNamesArray[x]; } - } - }, - y: { - tick: { - format: function(x){ return numeral(x).format('$0,0'); } - } - }, - y2: { - tick: { - format: function(x){ return numeral(x).format('0,0'); } - }, - show: true - } - }, - tooltip: { - format: { - title: function (d) { - return monthNamesArray[d]; - }, - value: function (value, ratio, id) { - var display; - if(id === 'Monthly Total'){ - display = numeral(value).format('$0,0'); - } else { - display = numeral(value).format('0,0'); - } - return display; - } - } - }, - bar: { - width: { - ratio: 0.5 - } - } - }; - }; + return { + bindto: '#x-by-yChart', + size: { + height: 450, + width: window.width + }, + zoom: { enabled: true }, + data: { + columns: [ data.monthlyCountArray, data.monthlyDataArray ], + type: 'bar', + colors: { 'Monthly Total': 'rgb(92,184,92)', 'Monthly Count': '#f0ad4e' }, + axes: { + 'Monthly Total': 'y', + 'Monthly Count': 'y2' + } + }, + grid: { + x: { + show: true + }, + y: { + show: true + } + }, + axis: { + x: { + tick: { + format: function(x){ return monthNamesArray[x]; } + } + }, + y: { + tick: { + format: function(x){ return numeral(x).format('$0,0'); } + } + }, + y2: { + tick: { + format: function(x){ return numeral(x).format('0,0'); } + }, + show: true + } + }, + tooltip: { + format: { + title: function (d) { + return monthNamesArray[d]; + }, + value: function (value, ratio, id) { + var display; + if(id === 'Monthly Total'){ + display = numeral(value).format('$0,0'); + } else { + display = numeral(value).format('0,0'); + } + return display; + } + } + }, + bar: { + width: { + ratio: 0.5 + } + } + }; + }; - self.hourlyChart = function(d,i){ - var hourlyData = data.dayObj[d.x + 1 ], - hourlyCountArray = ['Hourly Count'], - hourlyTotalArray = ['Hourly Total']; - for(var j=1; j<25; j++){ - hourlyCountArray.push(hourlyData[j].count); - hourlyTotalArray.push(hourlyData[j].total); - } - return { - bindto: '#x-by-yChart', - size: { - height: 450, - width: window.width - }, - zoom: { enabled: true }, - data: { - columns: [ hourlyTotalArray, hourlyCountArray ], - type: 'bar', - colors: { 'Hourly Total': 'rgb(92,184,92)', 'Hourly Count': '#f0ad4e' }, - onclick: function (d, i) { c3.generate(self.dailyChart()); }, - axes: { - 'Hourly Total': 'y', - 'Hourly Count': 'y2' - } - }, - grid: { - x: { - show: true - }, - y: { - show: true - } - }, - axis: { - x: { - label: { - text: 'December ' + ( d.x + 1 ), - position: 'outer-left' - }, - tick: { - format: function(x){ return x + ':00'; } - } - }, - y: { - tick: { - format: function(x){ return numeral(x).format('$0,0'); } - } - }, - y2: { - tick: { - format: function(x){ return numeral(x).format('0,0'); } - }, - show: true - } - }, - tooltip: { - format: { - title: function (d) { return 'Hour ' + d; }, - value: function (value, ratio, id) { - var display; - if(id === 'Hourly Total'){ - display = numeral(value).format('$0,0'); - } else { - display = numeral(value).format('0,0'); - } - return display; - } - } - }, - bar: { - width: { - ratio: 0.5 - } - } - }; - }; + self.hourlyChart = function(d,i){ + var hourlyData = data.dayObj[d.x + 1 ], + hourlyCountArray = ['Hourly Count'], + hourlyTotalArray = ['Hourly Total']; + for(var j=1; j<25; j++){ + hourlyCountArray.push(hourlyData[j].count); + hourlyTotalArray.push(hourlyData[j].total); + } + return { + bindto: '#x-by-yChart', + size: { + height: 450, + width: window.width + }, + zoom: { enabled: true }, + data: { + columns: [ hourlyTotalArray, hourlyCountArray ], + type: 'bar', + colors: { 'Hourly Total': 'rgb(92,184,92)', 'Hourly Count': '#f0ad4e' }, + onclick: function (d, i) { c3.generate(self.dailyChart()); }, + axes: { + 'Hourly Total': 'y', + 'Hourly Count': 'y2' + } + }, + grid: { + x: { + show: true + }, + y: { + show: true + } + }, + axis: { + x: { + label: { + text: 'December ' + ( d.x + 1 ), + position: 'outer-left' + }, + tick: { + format: function(x){ return x + ':00'; } + } + }, + y: { + tick: { + format: function(x){ return numeral(x).format('$0,0'); } + } + }, + y2: { + tick: { + format: function(x){ return numeral(x).format('0,0'); } + }, + show: true + } + }, + tooltip: { + format: { + title: function (d) { return 'Hour ' + d; }, + value: function (value, ratio, id) { + var display; + if(id === 'Hourly Total'){ + display = numeral(value).format('$0,0'); + } else { + display = numeral(value).format('0,0'); + } + return display; + } + } + }, + bar: { + width: { + ratio: 0.5 + } + } + }; + }; - self.dailyChart = function(d,i){ - return { - bindto: '#x-by-yChart', - size: { - height: 450, - width: window.width - }, - zoom: { enabled: true }, - data: { - columns: [ data.dailyDataArray, data.dailyCountArray ], - type: 'bar', - colors: { 'Daily Total': 'rgb(49,176,213)', 'Daily Count': '#f0ad4e' }, - onclick: function (d, i) { - self.xByYChart = c3.generate(self.hourlyChart(d,i)); - }, - axes: { - 'Daily Total': 'y', - 'Daily Count': 'y2' - } - }, - grid: { - x: { - show: true - }, - y: { - show: true - } - }, - axis: { - x: { - tick: { - format: function(x){ return 'Dec ' + (x+1); } - } - }, - y: { - tick: { - format: function(x){ return numeral(x).format('$0,0'); } - } - }, - y2: { - tick: { - format: function(x){ return numeral(x).format('0,0'); } - }, - show: true - } - }, - tooltip: { - format: { - title: function (d) { return 'Day ' + (d+1); }, - value: function (value, ratio, id) { - var display; - if(id === 'Daily Total'){ - display = numeral(value).format('$0,0'); - } else { - display = numeral(value).format('0,0'); - } - return display; - } - } - }, - bar: { - width: { - ratio: 0.5 - } - } - }; - }; + self.dailyChart = function(d,i){ + return { + bindto: '#x-by-yChart', + size: { + height: 450, + width: window.width + }, + zoom: { enabled: true }, + data: { + columns: [ data.dailyDataArray, data.dailyCountArray ], + type: 'bar', + colors: { 'Daily Total': 'rgb(49,176,213)', 'Daily Count': '#f0ad4e' }, + onclick: function (d, i) { + self.xByYChart = c3.generate(self.hourlyChart(d,i)); + }, + axes: { + 'Daily Total': 'y', + 'Daily Count': 'y2' + } + }, + grid: { + x: { + show: true + }, + y: { + show: true + } + }, + axis: { + x: { + tick: { + format: function(x){ return 'Dec ' + (x+1); } + } + }, + y: { + tick: { + format: function(x){ return numeral(x).format('$0,0'); } + } + }, + y2: { + tick: { + format: function(x){ return numeral(x).format('0,0'); } + }, + show: true + } + }, + tooltip: { + format: { + title: function (d) { return 'Day ' + (d+1); }, + value: function (value, ratio, id) { + var display; + if(id === 'Daily Total'){ + display = numeral(value).format('$0,0'); + } else { + display = numeral(value).format('0,0'); + } + return display; + } + } + }, + bar: { + width: { + ratio: 0.5 + } + } + }; + }; - switch(data.timescale){ - case 'Year': - case 'Month': - self.xByYChart = c3.generate(self.monthlyChart()); - break; - case 'Day': - self.xByYChart = c3.generate(self.dailyChart()); - break; - case 'Hour': - self.xByYChart = c3.generate(self.hourlyChart()); - break; - } - }; + switch(data.timescale){ + case 'Year': + case 'Month': + self.xByYChart = c3.generate(self.monthlyChart()); + break; + case 'Day': + self.xByYChart = c3.generate(self.dailyChart()); + break; + case 'Hour': + self.xByYChart = c3.generate(self.hourlyChart()); + break; + } + }; - if(params.configuration){ - self.chartSaved(true); - //self.makeChart(self.retrievedResults()); + if(params.configuration){ + self.chartSaved(true); + //self.makeChart(self.retrievedResults()); - } else { - self.chartSaved(false); - } + } else { + self.chartSaved(false); + } - self.showPanelBody = function(area){ - $('#'+area+'body').toggleClass('hide'); - }; + self.showPanelBody = function(area){ + $('#'+area+'body').toggleClass('hide'); + }; - //saved charts - //TODO: these will trigger a saved set of parameters to draw the chart with. - self.presetTitles = ko.observableArray([ - 'This does not work yet.', - 'Donations During Big English 2014', - 'Donations for Fiscal Year 2014' - ]); - /////// + //saved charts + //TODO: these will trigger a saved set of parameters to draw the chart with. + self.presetTitles = ko.observableArray([ + 'This does not work yet.', + 'Donations During Big English 2014', + 'Donations for Fiscal Year 2014' + ]); + /////// - self.ySlices = ko.observableArray([ - 'Donations' - //'Failed Donations' - ]); + self.ySlices = ko.observableArray([ + 'Donations' + //'Failed Donations' + ]); - self.xSlices = ko.observableArray(); - self.timeChoices = ko.observableArray(); - self.groupChoices = ko.observableArray(); + self.xSlices = ko.observableArray(); + self.timeChoices = ko.observableArray(); + self.groupChoices = ko.observableArray(); - //populate user choices dynamically - self.populateChoices = (function(){ - //populate y slices - $.get( 'metadata/x-by-y', function(reqData){ - self.metadata = reqData; + //populate user choices dynamically + self.populateChoices = (function(){ + //populate y slices + $.get( 'metadata/x-by-y', function(reqData){ + self.metadata = reqData; - var xArray = [], timeArray = ['Year', 'Month', 'Day'], groupArray = []; + var xArray = [], timeArray = ['Year', 'Month', 'Day'], groupArray = []; - $.each(self.metadata.filters, function(prop, obj){ + $.each(self.metadata.filters, function(prop, obj){ - if(obj.type !== 'number' || prop === 'Amount'){ + if(obj.type !== 'number' || prop === 'Amount'){ - if(obj.canGroup){ - if(obj.values){ - groupArray.push({ 'name': prop, 'choices': obj.values }); - } + if(obj.canGroup){ + if(obj.values){ + groupArray.push({ 'name': prop, 'choices': obj.values }); + } - $('select #'+prop).select2(); + $('select #'+prop).select2(); - //TODO: later this will do something different/more specific. - xArray.push(prop); - } + //TODO: later this will do something different/more specific. + xArray.push(prop); + } - } - }); - self.xSlices(xArray); - self.timeChoices(timeArray); - self.groupChoices(groupArray); + } + }); + self.xSlices(xArray); + self.timeChoices(timeArray); + self.groupChoices(groupArray); - }); + }); - })(); + })(); - self.submitXY = function(){ + self.submitXY = function(){ - $('#loadingModal').modal('show'); - self.queryRequest.ySlice = self.showSlice(); - //self.queryRequest.xSlice = self.bySlice(); - //self.queryRequest.additionalFilters = self.chosenFilters(); - self.queryRequest.timeBreakout = self.timeChoice(); + $('#loadingModal').modal('show'); + self.queryRequest.ySlice = self.showSlice(); + //self.queryRequest.xSlice = self.bySlice(); + //self.queryRequest.additionalFilters = self.chosenFilters(); + self.queryRequest.timeBreakout = self.timeChoice(); - self.queryString = self.convertToQuery(self.queryRequest); - self.config.queryString = self.queryString; - self.config.timeBreakout = self.queryRequest.timeBreakout; - self.config.chartData = self.chartData; + self.queryString = self.convertToQuery(self.queryRequest); + self.config.queryString = self.queryString; + self.config.timeBreakout = self.queryRequest.timeBreakout; + self.config.chartData = self.chartData; - var chartDataCall = self.getChartData(self.queryString); + var chartDataCall = self.getChartData(self.queryString); - $.when( chartDataCall ).then( function( dataArray ){ - self.retrievedResults(dataArray.results); - self.dataLoading(false); + $.when( chartDataCall ).then( function( dataArray ){ + self.retrievedResults(dataArray.results); + self.dataLoading(false); - self.chartData = self.processData(self.retrievedResults(), self.timeChoice()); + self.chartData = self.processData(self.retrievedResults(), self.timeChoice()); - self.makeChart(self.chartData); - $('#loadingModal').modal('hide'); + self.makeChart(self.chartData); + $('#loadingModal').modal('hide'); - self.chartSaved(false); - }); + self.chartSaved(false); + }); - }; + }; - return(this); + return(this); - } + } - return { viewModel: XByYChartViewModel, template: template }; + return { viewModel: XByYChartViewModel, template: template }; }); -- To view, visit https://gerrit.wikimedia.org/r/195655 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: If10dc6bf5b642cad7ccf7ed8052790be8755a9c8 Gerrit-PatchSet: 1 Gerrit-Project: wikimedia/fundraising/dash Gerrit-Branch: master Gerrit-Owner: Ejegg <eeggles...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits