jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/327234 )

Change subject: Restore year selector
......................................................................


Restore year selector

Select campaigns from different years

Change-Id: I64f17d370e0fc99b619a8751f5a34207ffd140fa
---
M src/app/campaign.js
M src/components/widgets/totals-earned-chart/totals-earned-chart.html
M src/components/widgets/totals-earned-chart/totals-earned-chart.js
3 files changed, 67 insertions(+), 29 deletions(-)

Approvals:
  XenoRyet: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/src/app/campaign.js b/src/app/campaign.js
index 629d0a1..9ea0692 100644
--- a/src/app/campaign.js
+++ b/src/app/campaign.js
@@ -1,26 +1,31 @@
-define([
-       'momentjs'
-], function( moment ){
+define( function () {
 
        function msToDays( ms ) {
                return Math.round( ms / ( 24 * 60 * 60 * 1000 ) );
        }
 
        function Campaign( params ){
-               var currentYear = new Date().getFullYear();
+               var currentYear = new Date( Date.UTC() ).getFullYear();
 
-               this.startDate = params.startDate ||
-                       new Date( currentYear, 11, 1 );
-               this.endDate = params.endDate ||
-                       new Date( currentYear + 1, 0, 1 );
+               this.startDate = new Date( params.startDate ||
+                       Date.UTC( currentYear, 11, 1 ) );
+               this.endDate = new Date( params.endDate ||
+                       Date.UTC( currentYear + 1, 0, 1 ) );
+               this.name = params.name || currentYear.toString();
        }
 
        Campaign.prototype.getDayOfYearOffset = function () {
-               var diff = startOfYear = new Date( this.startDate );
+               var diff,
+                       campaignStart = new Date(
+                               this.startDate.getUTCFullYear(),
+                               this.startDate.getUTCMonth(),
+                               this.startDate.getUTCDate()
+                       ),
+                       startOfYear = new Date( campaignStart );
 
                startOfYear.setMonth(0);
                startOfYear.setDate(1);
-               diff = this.startDate.getTime() - startOfYear.getTime();
+               diff = campaignStart.getTime() - startOfYear.getTime();
 
                // Not a fencepost error - this should be 0 for Jan 1
                return msToDays( diff );
@@ -42,4 +47,4 @@
        }
 
        return Campaign;
-});
+} );
diff --git 
a/src/components/widgets/totals-earned-chart/totals-earned-chart.html 
b/src/components/widgets/totals-earned-chart/totals-earned-chart.html
index 6960fab..ba4cc63 100644
--- a/src/components/widgets/totals-earned-chart/totals-earned-chart.html
+++ b/src/components/widgets/totals-earned-chart/totals-earned-chart.html
@@ -84,8 +84,12 @@
                                          <input type="text" 
class="form-control" data-bind="textInput: majorDonationCutoff">
                                          <span 
class="input-group-addon">.00</span>
                                        </div>
-                                       <label>Year</label>
-                                       <input disabled type="number" 
min="2009" class="form-control" data-bind="textInput: year, attr: { max: new 
Date().getFullYear() }">
+                                       <label>Campaign</label>
+                                       <select data-bind="options: campaigns,
+                                               optionsText: function(item) {
+                                                       return item.name
+                                               },
+                                               value: campaign"></select>
                                </div>
                                <div class="modal-footer">
                                        <button type="button" class="btn 
btn-default" data-dismiss="modal">Cancel</button>
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 53b6746..ee66420 100644
--- a/src/components/widgets/totals-earned-chart/totals-earned-chart.js
+++ b/src/components/widgets/totals-earned-chart/totals-earned-chart.js
@@ -12,11 +12,7 @@
        function TotalsEarnedChartViewModel( params ){
 
                var self = this,
-                       timeFormat = 'dddd, MMMM Do YYYY, h:mm:ss a',
-                       campaign = ko.observable( new Campaign({
-                               startDate: new Date( 2016, 10, 29 ),
-                               endDate: new Date( 2017, 0, 1 )
-                       }) );
+                       timeFormat = 'dddd, MMMM Do YYYY, h:mm:ss a';
 
                WidgetBase.call( this, params );
 
@@ -36,11 +32,43 @@
 
                self.goal = params.sharedContext.goal = ko.observable( 
self.config.goal || 25000000 );
                self.majorDonationCutoff = ko.observable( 
self.config.majorDonationCutoff || 5000 ).extend( { throttle: 500 } );
-               self.year = ko.observable( self.config.year || new 
Date().getFullYear() ).extend( { throttle: 500 } );
+
+               self.campaigns = [
+                       new Campaign({
+                               name: '2016',
+                               startDate: Date.UTC( 2016, 10, 29 ),
+                               endDate: Date.UTC( 2017, 0, 1 )
+                       }),
+                       new Campaign({
+                               name: '2015',
+                               startDate: Date.UTC( 2015, 11, 1 ),
+                               endDate: Date.UTC( 2016, 0, 1 )
+                       }),
+                       new Campaign({
+                               name: '2014',
+                               startDate: Date.UTC( 2014, 11, 2 ),
+                               endDate: Date.UTC( 2015, 0, 1 )
+                       }),
+                       new Campaign({
+                               name: '2013',
+                               startDate: Date.UTC( 2016, 11, 1 ),
+                               endDate: Date.UTC( 2014, 0, 1 )
+                       }),
+                       new Campaign({
+                               name: '2012',
+                               startDate: Date.UTC( 2016, 11, 1 ),
+                               endDate: Date.UTC( 2013, 0, 1 )
+                       }),
+                       new Campaign({
+                               name: '2011',
+                               startDate: Date.UTC( 2016, 11, 1 ),
+                               endDate: Date.UTC( 2012, 0, 1 )
+                       })
+               ];
+               self.campaign = ko.observable( self.campaigns[0] );
+
                self.isCurrentYear = ko.computed( function() {
-                       /*jslint -W116*/
-                       return self.year() == new Date().getFullYear();
-                       /*jslint -W116*/
+                       return self.campaign() === self.campaigns[0];
                } );
 
                // FIXME: do this stuff on 'Submit', actually cancel changes on 
'Cancel'
@@ -55,8 +83,7 @@
                        self.reloadData();
                } );
 
-               self.year.subscribe( function() {
-                       self.config.year = self.year();
+               self.campaign.subscribe( function() {
                        self.logStateChange();
                        self.reloadData();
                } );
@@ -86,8 +113,8 @@
                        var runningTotal = 0,
                                currentDate = new Date(),
                                lastData = params.sharedContext.lastDataPoint,
-                               days = campaign().getLengthInDays(),
-                               offset = campaign().getDayOfYearOffset();
+                               days = self.campaign().getLengthInDays(),
+                               offset = self.campaign().getDayOfYearOffset();
 
                        currentDate.setTime( timestamp );
                        self.displayDate( moment( currentDate ).format( 
timeFormat ) );
@@ -125,9 +152,11 @@
                                // FIXME
                                lastData.day = currentDate.getUTCDate();
                                lastData.hour = currentDate.getUTCHours();
-                       } else {
-                               lastData.day = data[dataCount - 1].day;
+                       } else if ( dataCount > 0 ) {
+                               lastData.day = data[dataCount - 1].day - offset;
                                lastData.hour = data[dataCount - 1].hour;
+                       } else {
+                               lastData.day = lastData.hour = 0;
                        }
 
                        self.makeCharts();
@@ -140,7 +169,7 @@
                self.reloadData = function( automatic ){
                        // FIXME: use some common filter logic
                        var url = '/data/big-english?$filter=' +
-                                       campaign().getDateFilter() + ' and ' +
+                                       self.campaign().getDateFilter() + ' and 
' +
                                        'Amount lt \'' + 
self.majorDonationCutoff() + '\'',
                                interval = 500000,
                                firstLoad = ( self.raised() === 0 ),

-- 
To view, visit https://gerrit.wikimedia.org/r/327234
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I64f17d370e0fc99b619a8751f5a34207ffd140fa
Gerrit-PatchSet: 1
Gerrit-Project: wikimedia/fundraising/dash
Gerrit-Branch: master
Gerrit-Owner: Ejegg <eeggles...@wikimedia.org>
Gerrit-Reviewer: XenoRyet <dkozlow...@wikimedia.org>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to