Skip to content

Commit

Permalink
Add "Score Board" menu button once it has been found
Browse files Browse the repository at this point in the history
(resolves #431)
  • Loading branch information
bkimminich committed Jan 7, 2018
1 parent 97ceaba commit f4dc3e1
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 6 deletions.
6 changes: 2 additions & 4 deletions app/index.template.html
Expand Up @@ -138,11 +138,9 @@
<li class="dropdown" ng-show="isLoggedIn()">
<a href="#/complain"><i class="fas fa-bomb fa-lg"></i> <span translate="NAV_COMPLAIN"></span></a>
</li>
<!--
<li class="dropdown">
<a href="#/score-board">Score Board</a>
<li class="dropdown" ng-show="scoreBoardMenuVisible">
<a href="#/score-board"><i class="fas fa-trophy fa-lg"></i> <span translate="TITLE_SCORE_BOARD"></span></a>
</li>
-->
<li class="dropdown ribbon-spacer">
<a href="#/about"><i class="fas fa-info-circle fa-lg"></i> <span translate="TITLE_ABOUT"></span></a>
</li>
Expand Down
6 changes: 5 additions & 1 deletion app/js/controllers/ChallengeSolvedNotificationController.js
@@ -1,11 +1,12 @@
angular.module('juiceShop').controller('ChallengeSolvedNotificationController', [
'$scope',
'$rootScope',
'$translate',
'$cookies',
'socket',
'ConfigurationService',
'ChallengeService',
function ($scope, $translate, $cookies, socket, configurationService, challengeService) {
function ($scope, $rootScope, $translate, $cookies, socket, configurationService, challengeService) {
'use strict'

$scope.notifications = []
Expand Down Expand Up @@ -51,6 +52,9 @@ angular.module('juiceShop').controller('ChallengeSolvedNotificationController',
if (!data.isRestore) {
$scope.saveProgress()
}
if (data.name === 'Score Board') {
$rootScope.$emit('score_board_challenge_solved')
}
socket.emit('notification received', data.flag)
}
})
Expand Down
17 changes: 16 additions & 1 deletion app/js/controllers/NavbarController.js
Expand Up @@ -5,7 +5,8 @@ angular.module('juiceShop').controller('NavbarController', [
'AdministrationService',
'ConfigurationService',
'UserService',
function ($scope, $rootScope, $location, administrationService, configurationService, userService) {
'ChallengeService',
function ($scope, $rootScope, $location, administrationService, configurationService, userService, challengeService) {
'use strict'

$scope.version = ''
Expand Down Expand Up @@ -48,11 +49,25 @@ angular.module('juiceShop').controller('NavbarController', [
$rootScope.userEmail = ''
})

$rootScope.scoreBoardMenuVisible = false
setScoreBoardMenuVisibility()
$rootScope.$on('score_board_challenge_solved', function () {
$rootScope.scoreBoardMenuVisible = true
})

function updateUserEmail () {
userService.whoAmI().then(function (user) {
$rootScope.userEmail = user.email
}).catch(function (err) {
console.log(err)
})
}

function setScoreBoardMenuVisibility () {
challengeService.find({ name: 'Score Board' }).then(function (challenges) {
$rootScope.scoreBoardMenuVisible = challenges[0].solved
}).catch(function (err) {
console.log(err)
})
}
}])
17 changes: 17 additions & 0 deletions test/client/controllers/navbarControllerSpec.js
Expand Up @@ -8,6 +8,7 @@ describe('controllers', function () {
$httpBackend.whenGET('/rest/user/whoami').respond(200, {user: {}})
$httpBackend.whenGET('/rest/admin/application-configuration').respond(200, {config: {}})
$httpBackend.whenGET('/rest/admin/application-version').respond(200, {})
$httpBackend.whenGET('/api/Challenges/?name=Score+Board').respond(200, {data: [{solved: false}]})
}))

afterEach(function () {
Expand Down Expand Up @@ -129,5 +130,21 @@ describe('controllers', function () {

expect(console.log).toHaveBeenCalledWith('error')
}))

it('should hide Score Board menu item when corresponding challenge was not solved yet', inject(function () {
$httpBackend.expectGET('/api/Challenges/?name=Score+Board').respond(200, {data: [{solved: false}]})

$httpBackend.flush()

expect(scope.scoreBoardMenuVisible).toBe(false)
}))

it('should show Score Board menu item when corresponding challenge was solved', inject(function () {
$httpBackend.expectGET('/api/Challenges/?name=Score+Board').respond(200, {data: [{solved: true}]})

$httpBackend.flush()

expect(scope.scoreBoardMenuVisible).toBe(true)
}))
})
})

0 comments on commit f4dc3e1

Please sign in to comment.