<commit_before>'use strict';

/**
 * @ngdoc function
 * @name Pear2Pear.controller:ProjectInfoCtrl
 * @description
 * # ProjectInfoCtrl
 * Controller of the Pear2Pear
 */

angular.module('Pear2Pear')
  .config(['$routeProvider', function ($routeProvider) {
    $routeProvider
      .when('/communities/:comId/projects/:id', {
        templateUrl: 'projects/info.html',
        controller: 'ProjectInfoCtrl'
      });
  }])
  .controller('ProjectInfoCtrl', [
              'SwellRTSession', 'pear', '$scope', '$location', '$route', '$timeout', 'common', 'CommunitiesSvc', 'ProjectsSvc',
              function (SwellRTSession, pear, $scope, $location, $route, $timeout, common, CommunitiesSvc, ProjectsSvc) {

    $scope.urlId= pear.urlId;

    $scope.communityId = $route.current.params.comId;

    $scope.comments = {
      new: []
    };

    SwellRTSession.onLoad(function(){

      CommunitiesSvc.find($route.current.params.comId).then(function(community){
        $scope.community = community;
      });

      ProjectsSvc.find($route.current.params.id)
        .then(function(proxy) {
          $scope.project = proxy;
          $scope.needs = $scope.project.needs;
        });
    });

    $scope.isSupporter = function(project) {
      if (!project) {
        return false;
      }

      if (!project.supporters) {
        return false;
      }
      // Migrate project.support
      return SwellRTSession.users.loggedIn() && project.supporters.indexOf(SwellRTSession.users.current()) > -1;
    };

    $scope.toggleSupport = function(project) {
      // Need a valid login to support
      // TODO, do not redirect without asking the user
      if (! SwellRTSession.users.loggedIn()) {
        $location.path('session/new');

        return;
      }
      project.toggleSupport();
    };

    $scope.toggleCommentsVisibility = function toggleCommentsVisibility(need) {
      $scope.comments.visible = need;
    };

    $scope.areCommentsVisible = function areCommentsVisible(need) {
      return $scope.comments.visible === need;
    };

    $scope.sendComment = function sendComment(needIndex) {
      var need = $scope.project.needs[needIndex];
      var comment = $scope.comments.new[needIndex];
      pear.addNeedComment(need, comment);
      pear.addChatNotification(
        $route.current.params.id, 'need.comment.notification', 
        {
          user: SwellRTSession.users.current().split('@')[0],
          need: need.text,<commit_msg>using project prototype to add chat notifications<commit_after>'use strict';

/**
 * @ngdoc function
 * @name Pear2Pear.controller:ProjectInfoCtrl
 * @description
 * # ProjectInfoCtrl
 * Controller of the Pear2Pear
 */

angular.module('Pear2Pear')
  .config(['$routeProvider', function ($routeProvider) {
    $routeProvider
      .when('/communities/:comId/projects/:id', {
        templateUrl: 'projects/info.html',
        controller: 'ProjectInfoCtrl'
      });
  }])
  .controller('ProjectInfoCtrl', [
              'SwellRTSession', 'pear', '$scope', '$location', '$route', '$timeout', 'common', 'CommunitiesSvc', 'ProjectsSvc',
              function (SwellRTSession, pear, $scope, $location, $route, $timeout, common, CommunitiesSvc, ProjectsSvc) {

    $scope.urlId= pear.urlId;

    $scope.communityId = $route.current.params.comId;

    $scope.comments = {
      new: []
    };

    SwellRTSession.onLoad(function(){

      CommunitiesSvc.find($route.current.params.comId).then(function(community){
        $scope.community = community;
      });

      ProjectsSvc.find($route.current.params.id)
        .then(function(proxy) {
          $scope.project = proxy;
          $scope.needs = $scope.project.needs;
        });
    });

    $scope.isSupporter = function(project) {
      if (!project) {
        return false;
      }

      if (!project.supporters) {
        return false;
      }
      // Migrate project.support
      return SwellRTSession.users.loggedIn() && project.supporters.indexOf(SwellRTSession.users.current()) > -1;
    };

    $scope.toggleSupport = function(project) {
      // Need a valid login to support
      // TODO, do not redirect without asking the user
      if (! SwellRTSession.users.loggedIn()) {
        $location.path('session/new');

        return;
      }
      project.toggleSupport();
    };

    $scope.toggleCommentsVisibility = function toggleCommentsVisibility(need) {
      $scope.comments.visible = need;
    };

    $scope.areCommentsVisible = function areCommentsVisible(need) {
      return $scope.comments.visible === need;
    };

    $scope.sendComment = function sendComment(needIndex) {
      var need = $scope.project.needs[needIndex];
      var comment = $scope.comments.new[needIndex];
      pear.addNeedComment(need, comment);
      $scope.project.addChatNotification(
        'need.comment.notification',
        {
          user: SwellRTSession.users.current().split('@')[0],
          need: need.text,
{'fraction_non_alphanumeric': 0.14210419622947495, 'fraction_numerical': 0.002027163997567403, 'mean_word_length': 2.81003861003861, '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': '5695944', 'n_tokens_mistral': 1485, 'n_tokens_neox': 1429, 'n_words': 252}