<commit_before>'use strict';

/* Controllers */

function CreateRoomCtrl($scope, $location, socket) {
  $scope.createRoom = function() {
    socket.emit('create room', {}, function(roomUrl){
      $scope.$apply(function() {
        $location.path(roomUrl);
      });
    });
  }
}

CreateRoomCtrl.$inject = ['$scope', '$location', 'socket'];


function RoomCtrl($scope, $routeParams, socket) {

  var processMessage = function(response, process) {
    $scope.$apply(function() {
      if (response.error) {
        $scope.errorMessage = response.error;
        setTimeout(function() {
          $scope.$apply(function() {
            $scope.errorMessage = null;    
          });
        }, 3000);
      } else {
        $scope.errorMessage = null;
        process(response);
      }
    });
  }

  var refreshRoomInfo = function(roomObj) {
    if (roomObj.createAdmin) {
      $.cookie("admin-" + $scope.roomId, true);  
    }
    if($.cookie("admin-" + $scope.roomId)) {
      $scope.showAdmin = true;
    }
    
    $scope.playerCount = roomObj.clientcount;
    $scope.cardPack = roomObj.cardPack;

    if ($scope.cardPack == 'fib') {
      $scope.cards = ['0', '1', '2', '3', '5', '8', '13', '20', '40', '?'];
    } else if ($scope.cardPack == 'seq') {
      $scope.cards = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '?'];
    }
    console.log("received votes: " + roomObj.votes);
    $scope.votes = roomObj.votes;
  }

  $scope.configureRoom = function() {
    socket.on('room joined', function () {
      this.emit('room info', $scope.roomId, function(response){
        processMessage(response, refreshRoomInfo);
      });
    });
    socket.on('room left', function () {
      this.emit('room info', $scope.roomId, function(response){
        processMessage(response, refreshRoomInfo);
      });
    });
    socket.on('card pack set', function () {
      this.emit('room info', $scope.roomId, function(response){
        processMessage(response, refreshRoomInfo);
      });
    });
    socket.on('voted', function () {
      this.emit('room info', $scope.roomId, function(response){
        processMessage(response, refreshRoomInfo);
      });
    });
    socket.on('vote reset', function () {
      this.emit('room info', $scope.roomId, function(response){
        processMessage(response, refreshRoomInfo);
      });
    });
    socket.emit('join room', $scope.roomId, function(response){
      processMessage(response, refreshRoomInfo);
    });
  }

  $scope.setCardPack = function(cardPack) {
    $scope.cardPack = cardPack;
    $scope.resetVote();
    socket.emit('set card pack', $scope.roomId, cardPack);
  }

  $scope.vote = function(vote) {
    console.log("vote " + vote);
    $scope.myVote = vote;
    socket.emit('vote', $scope.roomId, vote);
  }

  $scope.resetVote = function() {
    socket.emit('reset vote', $scope.roomId);
  }

  $scope.roomId = $routeParams.roomId;
  $scope.playerCount = 0;
  $scope.showAdmin = false;
  $scope.errorMessage = null;
  $scope.votes = [];
  $scope.cardPack = '';
}

RoomCtrl.$inject = ['$scope', '$routeParams', 'socket'];<commit_msg>When resetting a vote - reset the vote for everybody.<commit_after>'use strict';

/* Controllers */

function CreateRoomCtrl($scope, $location, socket) {
  $scope.createRoom = function() {
    socket.emit('create room', {}, function(roomUrl){
      $scope.$apply(function() {
        $location.path(roomUrl);
      });
    });
  }
}

CreateRoomCtrl.$inject = ['$scope', '$location', 'socket'];


function RoomCtrl($scope, $routeParams, socket) {

  var processMessage = function(response, process) {
    $scope.$apply(function() {
      if (response.error) {
        $scope.errorMessage = response.error;
        setTimeout(function() {
          $scope.$apply(function() {
            $scope.errorMessage = null;    
          });
        }, 3000);
      } else {
        $scope.errorMessage = null;
        process(response);
      }
    });
  }

  var refreshRoomInfo = function(roomObj) {
    if (roomObj.createAdmin) {
      $.cookie("admin-" + $scope.roomId, true);  
    }
    if($.cookie("admin-" + $scope.roomId)) {
      $scope.showAdmin = true;
    }
    
    $scope.playerCount = roomObj.clientcount;
    $scope.cardPack = roomObj.cardPack;

    if ($scope.cardPack == 'fib') {
      $scope.cards = ['0', '1', '2', '3', '5', '8', '13', '20', '40', '?'];
    } else if ($scope.cardPack == 'seq') {
      $scope.cards = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '?'];
    }
    console.log("received votes: " + roomObj.votes);
    $scope.votes = roomObj.votes;
  }

  $scope.configureRoom = function() {
    socket.on('room joined', function () {
      this.emit('room info', $scope.roomId, function(response){
        processMessage(response, refreshRoomInfo);
      });
    });
    socket.on('room left', function () {
      this.emit('room info', $scope.roomId, function(response){
        processMessage(response, refreshRoomInfo);
      });
    });
    socket.on('card pack set', function () {
      this.emit('room info', $scope.roomId, function(response){
        processMessage(response, refreshRoomInfo);
      });
    });
    socket.on('voted', function () {
      this.emit('room info', $scope.roomId, function(response){
        processMessage(response, refreshRoomInfo);
      });
    });
    socket.on('vote reset', function () {
      $scope.myVote = null;
      this.emit('room info', $scope.roomId, function(response){
        processMessage(response, refreshRoomInfo);
      });
    });
    socket.emit('join room', $scope.roomId, function(response){
      processMessage(response, refreshRoomInfo);
    });
  }

  $scope.setCardPack = function(cardPack) {
    $scope.cardPack = cardPack;
    $scope.resetVote();
    socket.emit('set card pack', $scope.roomId, cardPack);
  }

  $scope.vote = function(vote) {
    console.log("vote " + vote);
    $scope.myVote = vote;
    socket.emit('vote', $scope.roomId, vote);
  }

  $scope.resetVote = function() {
    socket.emit('reset vote', $scope.roomId);
  }

  $scope.roomId = $routeParams.roomId;
  $scope.playerCount = 0;
  $scope.showAdmin = false;
  $scope.errorMessage = null;
  $scope.votes = [];
  $scope.cardPack = '';
  $scope.myVote = null;
}

RoomCtrl.$inject = ['$scope', '$routeParams', 'socket'];
{'fraction_non_alphanumeric': 0.18648905803996194, 'fraction_numerical': 0.009197589597209007, 'mean_word_length': 2.8980222496909764, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7351754', 'n_tokens_mistral': 2061, 'n_tokens_neox': 2020, 'n_words': 373}