<commit_before>"use strict"

Dropzone.autoDiscover = false

class @WelcomeCtrl

  constructor: ($scope) ->

    $scope.state        = 'ready'
    $scope.dragged_over = false
    dom                 = $('#dropzone')

    options = {
      previewsContainer:  "#previews"
      autoProcessQueue:   false
      maxFiles:           5000
      url:                "/shares"
      clickable:          "#dropzone"
    }

    myDropzone = new Dropzone( document.body, options )

    _.extend myDropzone,

      failures: []

      processDrop: () ->
        @multiple = @multiple || @getQueuedFiles().length > 1
        @startTime          = new Date
        $scope.files_count  = @files.length
        $scope.dragged_over = false
        $scope.$apply -> $scope.state = 'processing'

        if @multiple
          @uploadMultipleFiles()
        else
          @processQueue()

      isSingleFileDropped: ()->
        items = @getQueuedFiles()
        console.log items
        items.length == 1 && items[0].webkitGetAsEntry().isFile

      uploadMultipleFiles: ()->
        $.ajax
          url:      'shares'
          dataType: 'json'
          type:     'POST'

        .success (data) =>
          if data.success
            @failures    = []
            @key         = data.id
            @options.url = "/shares/#{@key}/append"
            @processQueue()
          else
            console.log 'Fail creating share!'
        .fail () ->
          console.log 'Fail creating share!'

      onSuccess: ()->
        $scope.$apply =>
          $scope.state      = 'success'
          $scope.elapsed    = ((new Date) - @startTime)/1000.0
          $scope.view_url   = "#{location.origin}/shares/#{@key}.html"
          $scope.count_down = 5
          #@countDown()

      allSuccessful: () ->
        _.isEmpty( @getQueuedFiles() ) &&
        _.isEmpty( @getUploadingFiles() ) &&
        _.isEmpty( @failures )

      countDown: ->
        $scope.$apply ->
          $scope.count_down -= 1

        if $scope.count_down <= 0
          @redirect()
        else
          setTimeout @countDown.bind(@), 1000

      redirect: ->
        location.href = $scope.view_url


    (()->

      @on "complete", (file) ->
        @failures.push( file ) unless file.status == "success"
        @processQueue()

      @on "success", (file) ->
        id = JSON.parse( file.xhr.response ).id
        @key = id if id
        @onSuccess() if @allSuccessful()

      @on "dragover", () ->
        $scope.$apply () ->
          $scope.dragged_over = true

      @on "dragleave", () ->
        $scope.$apply () ->
          $scope.dragged_over = false

      @on "totaluploadprogress", (per) ->
        $scope.progress = per

      @on "sending", (file, xhr, formData) ->
        formData.append "path", file.fullPath || file.name

      @on "drop", (evt) ->

      @on "queuecomplete", (evt) ->

      @on "addedfile", (evt) ->
        clearTimeout @process_lock
        @process_lock = setTimeout =>
          @processDrop()
        , 1000

      ).call myDropzone


@WelcomeCtrl['$inject'] = ['$scope']
<commit_msg>fix missing count down<commit_after>"use strict"

Dropzone.autoDiscover = false

class @WelcomeCtrl

  constructor: ($scope) ->

    $scope.state        = 'ready'
    $scope.dragged_over = false
    dom                 = $('#dropzone')

    options = {
      previewsContainer:  "#previews"
      autoProcessQueue:   false
      maxFiles:           5000
      url:                "/shares"
      clickable:          "#dropzone"
    }

    myDropzone = new Dropzone( document.body, options )

    _.extend myDropzone,

      failures: []

      processDrop: () ->
        @multiple = @multiple || @getQueuedFiles().length > 1
        @startTime          = new Date
        $scope.files_count  = @files.length
        $scope.dragged_over = false
        $scope.$apply -> $scope.state = 'processing'

        if @multiple
          @uploadMultipleFiles()
        else
          @processQueue()

      isSingleFileDropped: ()->
        items = @getQueuedFiles()
        console.log items
        items.length == 1 && items[0].webkitGetAsEntry().isFile

      uploadMultipleFiles: ()->
        $.ajax
          url:      'shares'
          dataType: 'json'
          type:     'POST'

        .success (data) =>
          if data.success
            @failures    = []
            @key         = data.id
            @options.url = "/shares/#{@key}/append"
            @processQueue()
          else
            console.log 'Fail creating share!'
        .fail () ->
          console.log 'Fail creating share!'

      onSuccess: ()->
        $scope.$apply =>
          $scope.state      = 'success'
          $scope.elapsed    = ((new Date) - @startTime)/1000.0
          $scope.view_url   = "#{location.origin}/shares/#{@key}.html"
          $scope.count_down = 5
          @countDown()

      allSuccessful: () ->
        _.isEmpty( @getQueuedFiles() ) &&
        _.isEmpty( @getUploadingFiles() ) &&
        _.isEmpty( @failures )

      countDown: ->
        $scope.$apply ->
          $scope.count_down -= 1

        if $scope.count_down <= 0
          @redirect()
        else
          setTimeout @countDown.bind(@), 1000

      redirect: ->
        location.href = $scope.view_url


    (()->

      @on "complete", (file) ->
        @failures.push( file ) unless file.status == "success"
        @processQueue()

      @on "success", (file) ->
        id = JSON.parse( file.xhr.response ).id
        @key = id if id
        @onSuccess() if @allSuccessful()

      @on "dragover", () ->
        $scope.$apply () ->
          $scope.dragged_over = true

      @on "dragleave", () ->
        $scope.$apply () ->
          $scope.dragged_over = false

      @on "totaluploadprogress", (per) ->
        $scope.progress = per

      @on "sending", (file, xhr, formData) ->
        formData.append "path", file.fullPath || file.name

      @on "drop", (evt) ->

      @on "queuecomplete", (evt) ->

      @on "addedfile", (evt) ->
        clearTimeout @process_lock
        @process_lock = setTimeout =>
          @processDrop()
        , 1000

      ).call myDropzone


@WelcomeCtrl['$inject'] = ['$scope']

{'fraction_non_alphanumeric': 0.14241935483870968, 'fraction_numerical': 0.007419354838709678, 'mean_word_length': 1.6320033955857385, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 57, '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': '3940216', 'n_tokens_mistral': 1897, 'n_tokens_neox': 1806, 'n_words': 383}