<commit_before>'use strict'

angular.module('brokenPromisesApp')
    .controller 'MainCtrl', ($scope, $http, $filter, Restangular, $timeout) ->
        $scope.articles =
          day : []
          month : []
          year : []

        $scope.dates =
          day : do Date.today
          month : do Date.today
          year : do Date.today

        $scope.scrape_dates =
          day : undefined
          month : undefined
          year : undefined

        $scope.dates_format =
          day : 'MMMM dd yyyy'
          month : 'MMMM yyyy'
          year : 'yyyy'

        $scope.email =
          day :
            showform : no
            registered : no
            value : undefined
          month :
            showform : no
            registered : no
            value : undefined
          year :
            showform : no
            registered : no
            value : undefined

        $scope.calendars =
          day : no
          month : no
          year : no

        getDateArr = (scale) =>
          if scale is 'day'
            [($filter 'date') $scope.dates.day, "yyyy"
             ($filter 'date') $scope.dates.day, "MM"
             ($filter 'date') $scope.dates.day, "dd"]
          else if scale is 'month'
            [($filter 'date') $scope.dates.month, "yyyy"
             ($filter 'date') $scope.dates.month, "MM"]
          else if scale is 'year'
            [($filter 'date') $scope.dates.year, "yyyy"]
          else
            null

        $scope.subscribe = (scale) =>
          if $scope.email[scale].value
            dateArr = getDateArr scale
            url = "http://broken-promises.herokuapp.com/search_date/#{$scope.email[scale].value}/#{dateArr.join '/'}"
            ($http.post url, '').success (data) =>
              if data.status is 'ok'
                $scope.email[scale].registered = yes

        reset = (field) =>
          $scope.articles[field] = []
          $scope.email[field] =
            showform : no
            registered : no
            value : undefined
          $scope.scrape_dates[field] = undefined

        load = (field) =>
          dateArr = getDateArr field
          reset field
          $scope.articles[field] = undefined
          demanded = angular.copy $scope.dates[field]
          (do (Restangular.all "articles/#{dateArr.join '/'}").getList).then (data) =>
            if Date.compare demanded, $scope.dates[field]
              return
            reset field
            _.map data.articles, (article) =>
              article['reference_date'] = $scope.dates.day
              _.map article.ref_dates, (ref_date) =>
                if (_.difference dateArr, ref_date.date).length is 0
                  article['snippet'] = ref_date.extract if ref_date.extract?
              article.pub_date = new Date article.pub_date
              article.body = do article.body.trim
              $scope.articles[field].push angular.copy article
            ### Retrieve the 'last_scrape' date ###
            (do (Restangular.all "last_scrape/#{dateArr.join '/'}").getList).then (data) =>
              if Date.compare demanded, $scope.dates[field]
                return
              if data.status isnt 'no_result'
                $scope.scrape_dates[field] = new Date data.last_scrape_date<commit_msg>reference_date wasn't the right date<commit_after>'use strict'

angular.module('brokenPromisesApp')
    .controller 'MainCtrl', ($scope, $http, $filter, Restangular, $timeout) ->
        $scope.articles =
          day : []
          month : []
          year : []

        $scope.dates =
          day : do Date.today
          month : do Date.today
          year : do Date.today

        $scope.scrape_dates =
          day : undefined
          month : undefined
          year : undefined

        $scope.dates_format =
          day : 'MMMM dd yyyy'
          month : 'MMMM yyyy'
          year : 'yyyy'

        $scope.email =
          day :
            showform : no
            registered : no
            value : undefined
          month :
            showform : no
            registered : no
            value : undefined
          year :
            showform : no
            registered : no
            value : undefined

        $scope.calendars =
          day : no
          month : no
          year : no

        getDateArr = (scale) =>
          if scale is 'day'
            [($filter 'date') $scope.dates.day, "yyyy"
             ($filter 'date') $scope.dates.day, "MM"
             ($filter 'date') $scope.dates.day, "dd"]
          else if scale is 'month'
            [($filter 'date') $scope.dates.month, "yyyy"
             ($filter 'date') $scope.dates.month, "MM"]
          else if scale is 'year'
            [($filter 'date') $scope.dates.year, "yyyy"]
          else
            null

        $scope.subscribe = (scale) =>
          if $scope.email[scale].value
            dateArr = getDateArr scale
            url = "http://broken-promises.herokuapp.com/search_date/#{$scope.email[scale].value}/#{dateArr.join '/'}"
            ($http.post url, '').success (data) =>
              if data.status is 'ok'
                $scope.email[scale].registered = yes

        reset = (field) =>
          $scope.articles[field] = []
          $scope.email[field] =
            showform : no
            registered : no
            value : undefined
          $scope.scrape_dates[field] = undefined

        load = (field) =>
          dateArr = getDateArr field
          reset field
          $scope.articles[field] = undefined
          demanded = angular.copy $scope.dates[field]
          (do (Restangular.all "articles/#{dateArr.join '/'}").getList).then (data) =>
            if Date.compare demanded, $scope.dates[field]
              return
            reset field
            _.map data.articles, (article) =>
              article['reference_date'] = $scope.dates[field]
              _.map article.ref_dates, (ref_date) =>
                if (_.difference dateArr, ref_date.date).length is 0
                  article['snippet'] = ref_date.extract if ref_date.extract?
              article.pub_date = new Date article.pub_date
              article.body = do article.body.trim
              $scope.articles[field].push angular.copy article
            ### Retrieve the 'last_scrape' date ###
            (do (Restangular.all "last_scrape/#{dateArr.join '/'}").getList).then (data) =>
              if Date.compare demanded, $scope.dates[field]
                return
              if data.status isnt 'no_result'
                $scope.scrape_dates[field] = new Date data.last_scrape_date
{'fraction_non_alphanumeric': 0.11855203619909502, 'fraction_numerical': 0.00030165912518853697, 'mean_word_length': 1.5193768996960486, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 23, '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': '229468', 'n_tokens_mistral': 1852, 'n_tokens_neox': 1782, 'n_words': 437}