{"size": 2745, "ext": "js", "max_stars_repo_path": "app/assets/javascripts/angular/controllers/main_controller.js", "max_stars_repo_name": "digitaltom/photobooth", "max_stars_repo_stars_event_min_datetime": "2015-11-22T22:15:07.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-24T13:55:45.000Z", "max_issues_repo_path": "app/assets/javascripts/angular/controllers/main_controller.js", "max_issues_repo_name": "digitaltom/photobooth", "max_issues_repo_issues_event_min_datetime": "2016-06-28T09:17:45.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T21:58:02.000Z", "max_forks_repo_path": "app/assets/javascripts/angular/controllers/main_controller.js", "max_forks_repo_name": "digitaltom/photobooth", "max_forks_repo_forks_event_min_datetime": "2016-06-29T12:03:26.000Z", "max_forks_repo_forks_event_max_datetime": "2019-02-03T20:01:12.000Z"}
{"max_stars_count": 23, "max_issues_count": 178, "max_forks_count": 5, "avg_line_length": 29.2021276596, "max_line_length": 79, "alphanum_fraction": 0.5883424408}
photoBoothApp.controller('MainCtrl', [
  '$scope',
  '$http',
  '$uibModal',
  '$log',
  '$rootScope',
  '$timeout',
  '$interval',
  function ($scope, $http, $uibModal, $log, $rootScope, $timeout, $interval) {

    $scope.shoot_step = function (counter, delay) {
      $timeout(function() {
        $rootScope.current_shoot = counter;
        $rootScope.shoot_progress = 25*counter;
        $rootScope.shoot_progress_txt = counter + ' / 4';
      }, delay);
    }

    $scope.takePicture = function () {

      $rootScope.current_shoot = 0;
      $rootScope.shoot_txt = 'Take pose!';
      $rootScope.shoot_progress_txt = '';
      $scope.openShootModal();

      // ms before shooting
      var countdown_delay = 2000;
      // ms for each camera picture
      var picture_delay = 4000;

      $rootScope.shoot_progress = 100;
      countdown = $interval(function() {
        $rootScope.shoot_progress = $rootScope.shoot_progress - 5;
        if ($rootScope.shoot_progress <= 0) { $interval.cancel(countdown); }
      }, countdown_delay/20);

      $timeout(function() {
        $rootScope.shoot_txt = 'Action, taking 4 pictures';
        $http({
          method: 'POST',
          url: '/picture_sets.json'
        }).then(
          function successCallback(response) {
            $scope.closeShootModal();
            $scope.picture_sets.unshift(response.data);
          },
          function errorCallback(response) {
            $scope.closeShootModal();
            $rootScope.alerts.push({type: 'danger', msg: response.data.error});
          }
        );
      }, countdown_delay);

      $scope.shoot_step(1, picture_delay * 1 + countdown_delay);
      $scope.shoot_step(2, picture_delay * 2 + countdown_delay);
      $scope.shoot_step(3, picture_delay * 3 + countdown_delay);
      $scope.shoot_step(4, picture_delay * 4 + countdown_delay);

      $timeout(function() {
        $rootScope.current_shoot = 5;
        $rootScope.shoot_txt = 'Processing animation';
      }, picture_delay * 5 + countdown_delay);

    };

    $scope.update = function () {
      $http({
        method: 'GET',
        url: '/picture_sets.json'
      }).then(function successCallback(response) {
        $scope.picture_sets = response.data;
      }, function errorCallback(response) {
        $rootScope.alerts.push({type: 'error', msg: response.data.error});
      });
    };

    $scope.openShootModal = function () {
      $scope.shootModalInstance = $uibModal.open({
        animation: true,
        size: 'lg',
        templateUrl: 'picture_shoot.html'
      });
    };

    $scope.closeShootModal = function () {
      $scope.shootModalInstance.dismiss('cancel')
    }

    $scope.update();

    $scope.rw = (location.search != '?rw/');

  }]);
