From b9c96070b71968f45cc0b4b4f149d0f76a4bcf33 Mon Sep 17 00:00:00 2001 From: Ladi Adenusi andela-ladenusi Date: Wed, 19 Aug 2015 12:29:00 +0100 Subject: [PATCH 1/2] Added double click feature to calendar challenges --- lib/controller/summer-camp-challenge.js | 1 - lib/controller/summer-camp.js | 16 ++++++++++++++++ views/summer-camp-calendar.jade | 1 + 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/controller/summer-camp-challenge.js b/lib/controller/summer-camp-challenge.js index 9e1a1e62e..a06de359c 100644 --- a/lib/controller/summer-camp-challenge.js +++ b/lib/controller/summer-camp-challenge.js @@ -37,7 +37,6 @@ app.controller('SummerCampChallengeController', function ($scope, $routeParams, // Check if the difference in the route params and the current day of summercamp is greater than 1 // Check if the id in the route params is either greater than or equal to the progress challenge number. // If both are true, then redirect the user to the summercamp calendar - console.log($scope.id, progressNo, diff); if (!config.TEST_MODE && ($scope.id - diff) > 1 && $scope.id >= progressNo) { $location.path('/summercamp'); } diff --git a/lib/controller/summer-camp.js b/lib/controller/summer-camp.js index ace62124d..6e19401f9 100644 --- a/lib/controller/summer-camp.js +++ b/lib/controller/summer-camp.js @@ -137,6 +137,22 @@ app.controller('SummerCampController', function ($interval, $timeout, $scope, $r countDownToNext(); }; + /* + * Open a challenge by double-clicking and check if it's unlocked and not a future + * challenge. + * + * @param {Number} day + * @return void + */ + $scope.openChallenge = function (day) { + $scope.isFutureChallenge = (day > currentDayIndex()) ? true : false; + + if (!$scope.isLocked(day) && !$scope.isFutureChallenge) { + day = day + 1; + $location.path('/summercamp/challenge/' + day); + } + }; + /* * Deselect a challenge and close challenge modal * diff --git a/views/summer-camp-calendar.jade b/views/summer-camp-calendar.jade index 6ce0c25b4..26f7fb4f2 100644 --- a/views/summer-camp-calendar.jade +++ b/views/summer-camp-calendar.jade @@ -48,6 +48,7 @@ ul.calendar li.day(ng-repeat='day in range(21)') a( + ng-dblClick='openChallenge(day)', ng-click='selectChallenge(day)', ng-class='{ locked: isLocked(day) && !currentDay(day), completed: isCompleted(day), current: isCurrent(day), unlocked: currentDay(day) }', ) From 8e5721db397bf947daf5932ffd9c5e24010b16df Mon Sep 17 00:00:00 2001 From: Ladi Adenusi andela-ladenusi Date: Wed, 19 Aug 2015 16:37:23 +0100 Subject: [PATCH 2/2] Refactored duplicate code into a function --- lib/controller/summer-camp.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/controller/summer-camp.js b/lib/controller/summer-camp.js index 6e19401f9..b12e83cdc 100644 --- a/lib/controller/summer-camp.js +++ b/lib/controller/summer-camp.js @@ -130,7 +130,7 @@ app.controller('SummerCampController', function ($interval, $timeout, $scope, $r $scope.selectedSummerChallengeDay = startDate.date() + day; $scope.selectedSummerChallenge = selectedChallenge; $scope.selectedSummerChallengeObj = challenges[selectedChallenge]; - $scope.isFutureChallenge = (day > currentDayIndex()) ? true : false; + $scope.isFutureChallenge = isFutureChallenge(day); analytics.track('Viewed Challenge ' + day, { category : 'Viewed Summer Camp Challenge' }); @@ -145,9 +145,7 @@ app.controller('SummerCampController', function ($interval, $timeout, $scope, $r * @return void */ $scope.openChallenge = function (day) { - $scope.isFutureChallenge = (day > currentDayIndex()) ? true : false; - - if (!$scope.isLocked(day) && !$scope.isFutureChallenge) { + if (!$scope.isLocked(day) && !isFutureChallenge(day)) { day = day + 1; $location.path('/summercamp/challenge/' + day); } @@ -197,6 +195,16 @@ app.controller('SummerCampController', function ($interval, $timeout, $scope, $r return index === (now.getDay() || 7) - 1; } + /* + * Returns true if challenge is a future challenge + * + * @param {Number} day + * @return {Boolean} + */ + function isFutureChallenge(day) { + return (day > currentDayIndex()) ? true : false; + }; + function currentDayIndex() { var today = moment(), diff = today.diff(startDate),