Skip to content
This repository was archived by the owner on Mar 4, 2025. It is now read-only.

update-listings #1010

Merged
merged 2 commits into from
Feb 16, 2017
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
update-listings
Signed-off-by: Tom Ladendorf <tom@tomladendorf.com>
  • Loading branch information
nomo-kazza authored and tladendo committed Feb 15, 2017
commit c08637e7f8cdf85ee11a11bd32e4efcdb556cd49
77 changes: 72 additions & 5 deletions app/listings/listings.controller.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import angular from 'angular'
import { loadUser } from '../services/userv3.service.js'
import { loadUser, getCurrentUser } from '../services/userv3.service.js'

(function () {
'use strict'
Expand All @@ -8,29 +8,96 @@ import { loadUser } from '../services/userv3.service.js'

ListingsCtrl.$inject = ['CONSTANTS', 'logger', '$q','TcAuthService', 'UserService',
'UserStatsService', 'ProfileService', 'ChallengeService',
'ExternalAccountService', 'ngDialog', '$anchorScroll', '$scope'
'ExternalAccountService', 'ngDialog', '$anchorScroll', '$scope',
]

function ListingsCtrl(CONSTANTS, logger, $q, TcAuthService, UserService, UserStatsService, ProfileService,
ChallengeService, ExternalAccountService, ngDialog, $anchorScroll, $scope) {
var vm = this
var handle
vm.neverParticipated = false
vm.loading = true
vm.userHasChallenges = true
vm.challengeView = 'tile'

activate()

function activate() {
$scope.myChallenges = []
$scope.userProps = { isAuth: false }
$scope.userProps = { isAuth: false, myChallenges: [] }
logger.debug('Calling ListingsController activate()')

vm.myChallenges = []
loadUser().then(function(token) {
handle = UserService.getUserIdentity().handle
// mock current user have this challenges
vm.myChallenges.push({'id':30056409})
vm.myChallenges.push({'id':30056067})
vm.myChallenges.push({'id':16870})

// update auth flag
if(TcAuthService.isAuthenticated()) {
$scope.userProps = { isAuth: true }
getChallenges(handle)
$scope.userProps = { isAuth: true, myChallenges: vm.myChallenges }
}
}, function(error) {
// do nothing, just show non logged in state of navigation bar
})
}

function getChallenges(handle) {
var marathonMatchParams = {
limit: 8,
filter: 'status=active'
}

var challengeParams = {
limit: 8,
orderBy: 'submissionEndDate',
filter: 'status=active'
}

$q.all([
ChallengeService.getUserMarathonMatches(handle, marathonMatchParams),
ChallengeService.getUserChallenges(handle, challengeParams)
]).then(function(challenges){
var marathonMatches = challenges[0]
var devDesignChallenges = challenges[1]

if (!marathonMatches.length && !devDesignChallenges.length) {
vm.userHasChallenges = false
_checkForParticipation().then(function() {
vm.loading = false
})
} else {
ChallengeService.processActiveDevDesignChallenges(devDesignChallenges)
ChallengeService.processActiveMarathonMatches(marathonMatches)
var userChallenges = marathonMatches.concat(devDesignChallenges)

userChallenges = _.sortBy(userChallenges, function(n) {
return n.registrationEndDate
})
vm.myChallenges = userChallenges.reverse().slice(0, 8)

// update myChallenges
$scope.userProps = { isAuth: true, myChallenges: vm.myChallenges }

vm.userHasChallenges = true
vm.loading = false
}
})
.catch(function(err) {
logger.error('Error getting challenges and marathon matches', err)

vm.userHasChallenges = true
vm.loading = false
})
}

function _checkForParticipation() {
return ChallengeService.checkChallengeParticipation(handle, function(participated) {
vm.neverParticipated = !participated
})
}
}

})()