Stryker

ChallengeController.js - Stryker report

Summary

File
Mutation score
# Killed
# Survived
# Timeout
# No coverage
# Errors
Total detected
Total undetected
Total mutants
ChallengeController.js
96%
56/58 42 2 14 0 0 56 2 58

Code

angular.module('juiceShop').controller('ChallengeController', 0[
  '$scope',
  '$sce',
  '$translate',
  '$cookies',
  '$uibModal',
  '$window',
  'ChallengeService',
  'ConfigurationService',
  'socket',
  function ($scope, $sce, $translate, $cookies, $uibModal, $window, challengeService, configurationService, socket) 1{
    'use strict'

    configurationService.getApplicationConfiguration().then(function (data) 2{
      $scope.allowRepeatNotifications = 3data.application.showChallengeSolvedNotifications && data.application.showCtfFlagsInNotifications
      $scope.showChallengeHints = data.application.showChallengeHints
    })

    $scope.repeatNotification = function (challenge) 4{
      if (56$scope.allowRepeatNotifications) 7{
        challengeService.repeatNotification(encodeURIComponent(challenge.name)).success(function () 8{
          $window.scrollTo(0, 0)
        })
      }
    }

    $scope.openHint = function (challenge) 9{
      if (101112$scope.showChallengeHints && challenge.hintUrl) 13{
        $window.open(challenge.hintUrl, '_blank')
      }
    }

    $scope.trustDescriptionHtml = function () 14{
      for (var i = 0; 151617i < $scope.challenges.length; 18i++) 19{
        $scope.challenges[i].description = $sce.trustAsHtml($scope.challenges[i].description)
      }
    }

    $scope.calculateProgressPercentage = function () 20{
      var solvedChallenges = 0
      for (var i = 0; 212223i < $scope.challenges.length; 24i++) 25{
        solvedChallenges += (2627$scope.challenges[i].solved) ? 1 : 0
      }
      $scope.percentChallengesSolved = (2829100 * solvedChallenges / $scope.challenges.length).toFixed(0)
      if (30313233$scope.percentChallengesSolved > 75) 34{
        $scope.completionColor = 'success'
      } else if (35363738$scope.percentChallengesSolved > 25) 39{
        $scope.completionColor = 'warning'
      } else 40{
        $scope.completionColor = 'danger'
      }
    }

    challengeService.find().then(function (challenges) 41{
      $scope.challenges = challenges
      $scope.trustDescriptionHtml()
      $scope.calculateProgressPercentage()
    }).catch(function (err) 42{
      console.log(err)
    })

    socket.on('challenge solved', function (data) 43{
      if (444546data && data.challenge) 47{
        for (var i = 0; 484950i < $scope.challenges.length; 51i++) 52{
          if (535455$scope.challenges[i].name === data.name) 56{
            $scope.challenges[i].solved = 57true
            break
          }
        }
        $scope.calculateProgressPercentage()
      }
    })
  }])