<commit_before>'use strict';

/**
 * @ngdoc function
 * @name ratemycoopApp.controller:ReviewformCtrl
 * @description
 * # ReviewformCtrl
 * Controller of the ratemycoopApp
 */
angular.module('ratemycoopApp')
  .controller('ReviewformCtrl', function ($scope, Company, Major, City, Perk, PayType, User, $routeParams) {
    $scope.loading = {
      main: true, // Promise, must be turned to false somewhere
      perks: true // Promise, must be turned to false somewhere
    };


    /**
     * Initialize Session
     */
    if (User.isAuthenticated()) {
      $scope.user = User.getCurrent(
        function (success) {
          $scope.formData.userId = success.id;
        }
      );
    } else {
      // TODO: Must handle unauthenticated and redirect to login screen.
      console.log('ERROR: User must be authenticated');
      $scope.user = null;
    }

    /**
     * Used if we want to fetch for pay types, as opposed to using just
     * $scope.payTypes
     */
    $scope.fetchedPayTypes = PayType.find({},
      function (success) {
      });

    $scope.payTypes = [{id: 1, name: "Hourly"}, {id: 2, name: "Salary"}, {id: 3, name: "Stipend"}];

    /**
     * Get company info on-load
     */
    $scope.company = Company.findOne({
        filter: {
          where: {name: $routeParams.companyname},
          include: ['perks', 'majors', 'reviews', {'locations': 'region'}]
        }
      },
      function (successData) {
        $scope.loading.main = false;
      }
    );

    /**
     * Get major info on-load
     */
    $scope.majors = Major.find({},
      function (successData) {
        angular.forEach(successData, function (result) {
          result.title = result.name;
          result.description = result.code;
        });

        $('#majorSearch').search({
          source: $scope.majors,
          maxResults: 4,
          searchFields: ['code', 'name']
        })
      }
    );


    $scope.allPerks = Perk.find({},
      function (successData) {
        angular.forEach(successData, function (value) {
          value['isSelected'] = false;
        });
        $scope.loading.perks = false;
        // Success allperks
      }
    );

    $scope.addPerk = function (perk) {
      perk.isSelected = true; //This toggles ui change
      $scope.formData.perks.push(perk.id); // This adds only id, to formData.perks
    };

    $scope.unselectPerk = function (perk) {
      perk.isSelected = false; // this toggles ui change
      var i = $scope.formData.perks.indexOf(perk.id); // this finds and removes perk id from perks
      if (i > -1) {
        $scope.formData.perks.splice(i, 1);
      }


    };

    $scope.printFormData = function () {
      console.log($scope.formData);
    };


    $scope.formData = {
      overallRating: 0,
      cultureRating: 0,
      difficultyRating: 0,

      description: "",

      pay: "",
      payTypeId: $scope.payTypes[0].id,

      //userId: $scope.user.id == set when async call to USER returns

      perks: [],

      returnOffer: false,
      recommend: false,
      anonymous: false

    };

    /**
     *
     */
    $scope.submitReview = function () {
      //$scope.loading.main = true;
      //$scope.loading.false = true;
      console.log("Review is being submitted :) ");
      var pushObject = prepForPush($scope.formData);

      //Company.reviews.create(
      //  {id: $scope.company.id},
      //  pushObject,
      //  function(success){
      //    // TODO handle review creation success
      //    $scope.loading.main = false;
      //    $scope.loading.false = false;
      //  },
      //  function(error){
      //    // TODO handle review creation error
      //    $scope.loading.main = false;
      //    $scope.loading.false = false;
      //  }
      //);

      //var companyId = $scope.company.id;
      //angular.forEach($scope.formData.perks, function (perk) {<commit_msg>- final loading set to true<commit_after>'use strict';

/**
 * @ngdoc function
 * @name ratemycoopApp.controller:ReviewformCtrl
 * @description
 * # ReviewformCtrl
 * Controller of the ratemycoopApp
 */
angular.module('ratemycoopApp')
  .controller('ReviewformCtrl', function ($scope, Company, Major, City, Perk, PayType, User, $routeParams) {
    $scope.loading = {
      main: true, // Promise, must be turned to false somewhere
      perks: true // Promise, must be turned to false somewhere
    };


    /**
     * Initialize Session
     */
    if (User.isAuthenticated()) {
      $scope.user = User.getCurrent(
        function (success) {
          $scope.formData.userId = success.id;
        }
      );
    } else {
      // TODO: Must handle unauthenticated and redirect to login screen.
      console.log('ERROR: User must be authenticated');
      $scope.user = null;
    }

    /**
     * Used if we want to fetch for pay types, as opposed to using just
     * $scope.payTypes
     */
    $scope.fetchedPayTypes = PayType.find({},
      function (success) {
      });

    $scope.payTypes = [{id: 1, name: "Hourly"}, {id: 2, name: "Salary"}, {id: 3, name: "Stipend"}];

    /**
     * Get company info on-load
     */
    $scope.company = Company.findOne({
        filter: {
          where: {name: $routeParams.companyname},
          include: ['perks', 'majors', 'reviews', {'locations': 'region'}]
        }
      },
      function (successData) {
        $scope.loading.main = false;
      }
    );

    /**
     * Get major info on-load
     */
    $scope.majors = Major.find({},
      function (successData) {
        angular.forEach(successData, function (result) {
          result.title = result.name;
          result.description = result.code;
        });

        $('#majorSearch').search({
          source: $scope.majors,
          maxResults: 4,
          searchFields: ['code', 'name']
        })
      }
    );


    $scope.allPerks = Perk.find({},
      function (successData) {
        angular.forEach(successData, function (value) {
          value['isSelected'] = false;
        });
        $scope.loading.perks = false;
        // Success allperks
      }
    );

    $scope.addPerk = function (perk) {
      perk.isSelected = true; //This toggles ui change
      $scope.formData.perks.push(perk.id); // This adds only id, to formData.perks
    };

    $scope.unselectPerk = function (perk) {
      perk.isSelected = false; // this toggles ui change
      var i = $scope.formData.perks.indexOf(perk.id); // this finds and removes perk id from perks
      if (i > -1) {
        $scope.formData.perks.splice(i, 1);
      }


    };

    $scope.printFormData = function () {
      console.log($scope.formData);
    };


    $scope.formData = {
      overallRating: 0,
      cultureRating: 0,
      difficultyRating: 0,

      description: "",

      pay: "",
      payTypeId: $scope.payTypes[0].id,

      //userId: $scope.user.id == set when async call to USER returns

      perks: [],

      returnOffer: false,
      recommend: false,
      anonymous: false

    };

    /**
     *
     */
    $scope.submitReview = function () {
      $scope.loading.main = true;
      $scope.loading.false = true;
      console.log("Review is being submitted :) ");
      var pushObject = prepForPush($scope.formData);

      //Company.reviews.create(
      //  {id: $scope.company.id},
      //  pushObject,
      //  function(success){
      //    // TODO handle review creation success
      //    $scope.loading.main = false;
      //    $scope.loading.false = false;
      //  },
      //  function(error){
      //    // TODO handle review creation error
      //    $scope.loading.main = false;
      //    $scope.loading.false = false;
      //  }
      //);

      //var companyId = $scope.company.id;
      //angular.forEach($scope.formData.perks, function (perk) {
{'fraction_non_alphanumeric': 0.14507838601901824, 'fraction_numerical': 0.0025700334104343356, 'mean_word_length': 1.9854238588415805, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6805526', 'n_tokens_mistral': 2442, 'n_tokens_neox': 2378, 'n_words': 547}