<commit_before>angular.module 'keranbeandco.common'
.controller 'news', ($scope, News) ->

  $scope.isAddNewsFormOpen = null
  $scope.newNews = new News

  News.find
    filter:
      include:
        'improvedUser'
      order: 'sentAt DESC'
  .$promise
  .then (res) ->
    $scope.allNews = res

  $scope.toggleAddNewsForm = (forceToggle) ->
    if typeof forceToggle is "undefined"
      $scope.isAddNewsFormOpen = !$scope.isAddNewsFormOpen
    else
      $scope.isAddNewsFormOpen = forceToggle
    if $scope.isAddNewsFormOpen
      $scope.addNewsIconStyle =
        "color": "rgb(244,67,54)"
    else
      $scope.addNewsIconStyle =
        "color": "rgb(63, 81, 181)"

  $scope.toggleAddNewsForm(false)

  $scope.addNews = () ->
    $scope.newNews.sentAt = new Date()
    News.create $scope.newNews
    .$promise
    .then (res) ->
      $scope.allNews.unshift res
      $scope.newNews = new News
      $scope.toggleAddNewsForm(false)<commit_msg>Use current user service for news adding<commit_after>angular.module 'keranbeandco.common'
.controller 'news', ($scope, News, currentUser) ->

  $scope.isAddNewsFormOpen = null
  $scope.newNews = new News

  News.find
    filter:
      include:
        'improvedUser'
      order: 'sentAt DESC'
  .$promise
  .then (res) ->
    $scope.allNews = res

  $scope.toggleAddNewsForm = (forceToggle) ->
    if typeof forceToggle is "undefined"
      $scope.isAddNewsFormOpen = !$scope.isAddNewsFormOpen
    else
      $scope.isAddNewsFormOpen = forceToggle
    if $scope.isAddNewsFormOpen
      $scope.addNewsIconStyle =
        "color": "rgb(244,67,54)"
    else
      $scope.addNewsIconStyle =
        "color": "rgb(63, 81, 181)"

  $scope.toggleAddNewsForm(false)

  $scope.addNews = () ->
    $scope.newNews.sentAt = new Date()
    currentUser.fetchCurrentUser (currentUser) ->
      $scope.newNews.improvedUser = currentUser
      News.create $scope.newNews
      .$promise
      .then (res) ->
        res.improvedUser = currentUser
        $scope.allNews.unshift res
        $scope.newNews = new News
        $scope.toggleAddNewsForm(false)
{'fraction_non_alphanumeric': 0.12242945958871354, 'fraction_numerical': 0.013390722142515544, 'mean_word_length': 2.789855072463768, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 14, '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': '1999566', 'n_tokens_mistral': 727, 'n_tokens_neox': 687, 'n_words': 136}