<commit_before>angular.module('loomioApp').directive 'previousProposalsCard', ->
  scope: {discussion: '='}
  restrict: 'E'
  templateUrl: 'generated/components/thread_page/previous_proposals_card/previous_proposals_card.html'
  replace: true
  controller: ($scope, $rootScope, $location, Records, ProposalFormService) ->

    Records.votes.fetchMyVotes($scope.discussion.closedProposals())
    Records.proposals.fetchByDiscussion($scope.discussion).then ->
      $scope.setSelectedProposal()
      $rootScope.$broadcast 'threadPageProposalsLoaded'

    $scope.setSelectedProposal = ->
      $scope.selectedProposalId = setProposalFromQueryParameter() or setLastClosedProposal()

    setProposalFromQueryParameter = ->
      proposal = Records.proposals.find($location.search().proposal)
      proposal.id if proposal

    setLastClosedProposal = ->
      return unless $scope.anyProposals() and !$scope.discussion.hasActiveProposal()
      proposal = $scope.discussion.closedProposals()[0]
      proposal if moment.add(-1, 'month') < proposal.closedAt

    $scope.$on 'setSelectedProposal', $scope.setSelectedProposal

    $scope.anyProposals = ->
      $scope.discussion.closedProposals().length > 0

    return<commit_msg>Fix moment.add javascript error<commit_after>angular.module('loomioApp').directive 'previousProposalsCard', ->
  scope: {discussion: '='}
  restrict: 'E'
  templateUrl: 'generated/components/thread_page/previous_proposals_card/previous_proposals_card.html'
  replace: true
  controller: ($scope, $rootScope, $location, Records, ProposalFormService) ->

    Records.votes.fetchMyVotes($scope.discussion.closedProposals())
    Records.proposals.fetchByDiscussion($scope.discussion).then ->
      $scope.setSelectedProposal()
      $rootScope.$broadcast 'threadPageProposalsLoaded'

    $scope.setSelectedProposal = ->
      $scope.selectedProposalId = setProposalFromQueryParameter() or setLastClosedProposal()

    setProposalFromQueryParameter = ->
      proposal = Records.proposals.find($location.search().proposal)
      proposal.id if proposal

    setLastClosedProposal = ->
      return unless $scope.anyProposals() and !$scope.discussion.hasActiveProposal()
      proposal = $scope.discussion.closedProposals()[0]
      proposal if moment().add(-1, 'month') < proposal.closedAt

    $scope.$on 'setSelectedProposal', $scope.setSelectedProposal

    $scope.anyProposals = ->
      $scope.discussion.closedProposals().length > 0

    return
{'fraction_non_alphanumeric': 0.12105263157894737, 'fraction_numerical': 0.0024291497975708503, 'mean_word_length': 4.654462242562929, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 19, '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': '987401', 'n_tokens_mistral': 750, 'n_tokens_neox': 723, 'n_words': 106}