<commit_before>class DNDUploader extends KDView

  constructor: (options={}, data)->

    options.cssClass      = "file-droparea"
    options.bind          = "dragenter dragover dragleave dragend drop"
    options.hoverDetect  ?= yes
    options.uploadToVM   ?= yes
    options.defaultPath or= "/home/#{KD.nick()}/Uploads"

    super options, data

    @reset()

    @setPath options.path  if options.path

    if options.hoverDetect
      @on "dragenter", => @setClass   "hover"
      @on "dragover",  => @setClass   "hover"
      @on "dragleave", => @unsetClass "hover"
      @on "drop",      => @unsetClass "hover"

    @on "uploadFile", (fsFile, percent)=>
      filePath  = "[#{fsFile.vmName}]#{fsFile.path}"
      @finder.treeController.nodes[filePath]?.showProgressView percent

    @on "uploadStart", (fsFile)=>
      filePath   = "[#{fsFile.vmName}]#{fsFile.path}"
      parentPath = "[#{fsFile.vmName}]#{fsFile.parentPath}"

      bindAbort = (nodeView)->
        nodeView.once "abortProgress", => fsFile.abort yes

      nodeView = @finder.treeController.nodes[filePath]
      if nodeView
      then bindAbort nodeView
      else
        @finder.treeController.on "NodeWasAdded", (nodeView)->
          if nodeView.getData().path is filePath
            bindAbort nodeView

        fsFile.save "", =>
          @finder.expandFolders FSHelper.getPathHierarchy parentPath

  viewAppended: ->
    super
    # @finder = KD.getSingleton "finderController"
    # tc      = @finder.treeController
    @notify = (msg) ->
      new KDNotificationView
        title : msg


  reset: ->
    {uploadToVM, defaultPath, title} = @getOptions()
    @setPath()
    @updatePartial """
      <div class="file-drop">
        #{title or "Drop files here!"}
        <small>#{if uploadToVM then defaultPath else ''}</small>
      </div>
    """
    @_uploaded = {}

  drop: (event)->
    super
    {files, items}  = event.originalEvent.dataTransfer

    if files.length >= 20
      @notify """
      Too many files to transfer!<br>
      Archive your files and try again.
      """, "error", """
      Max 20 files allowed to upload at once.
      You can archive your files and try again.
      """

    if items?.item?(0)?.webkitGetAsEntry
      for item in items
        entry = item.webkitGetAsEntry()
        if entry.isDirectory
          @walkDirectory entry.filesystem.root, (file)=>
            # upload walked file
            @uploadFiles [file], event
          , =>
            # fallback for file upload, upload the other files stack
            @uploadFiles files, event
        else if entry.isFile
          entry.file (file)=>
            # upload file entry
            @uploadFiles [file], event
    else
      # fallback to upload files for folder upload browsers
      @uploadFiles files, event

  uploadFiles: (files, event)->
    @_uploaded or= {}
    if files?.length

      lastFile = files.last

      for file, index in files
        sizeInMb = file.size/1024/1024
        if sizeInMb > 100 && @getOptions().uploadToVM
          @notify "Too big file to upload.", "error", "Max 100MB allowed per file."
          continue
        reader = new FileReader
        reader.onloadend = do (file=files[index])=> (readEvent)=>

          fileName = file.fileName or file.name

          if file.relativePath<commit_msg>Use KD.notify_ instead new KDnotif....<commit_after>class DNDUploader extends KDView

  constructor: (options={}, data)->

    options.cssClass      = "file-droparea"
    options.bind          = "dragenter dragover dragleave dragend drop"
    options.hoverDetect  ?= yes
    options.uploadToVM   ?= yes
    options.defaultPath or= "/home/#{KD.nick()}/Uploads"

    super options, data

    @reset()

    @setPath options.path  if options.path

    if options.hoverDetect
      @on "dragenter", => @setClass   "hover"
      @on "dragover",  => @setClass   "hover"
      @on "dragleave", => @unsetClass "hover"
      @on "drop",      => @unsetClass "hover"

    @on "uploadFile", (fsFile, percent)=>
      filePath  = "[#{fsFile.vmName}]#{fsFile.path}"
      @finder.treeController.nodes[filePath]?.showProgressView percent

    @on "uploadStart", (fsFile)=>
      filePath   = "[#{fsFile.vmName}]#{fsFile.path}"
      parentPath = "[#{fsFile.vmName}]#{fsFile.parentPath}"

      bindAbort = (nodeView)->
        nodeView.once "abortProgress", => fsFile.abort yes

      nodeView = @finder.treeController.nodes[filePath]
      if nodeView
      then bindAbort nodeView
      else
        @finder.treeController.on "NodeWasAdded", (nodeView)->
          if nodeView.getData().path is filePath
            bindAbort nodeView

        fsFile.save "", =>
          @finder.expandFolders FSHelper.getPathHierarchy parentPath

  viewAppended: ->
    super

  reset: ->
    {uploadToVM, defaultPath, title} = @getOptions()
    @setPath()
    @updatePartial """
      <div class="file-drop">
        #{title or "Drop files here!"}
        <small>#{if uploadToVM then defaultPath else ''}</small>
      </div>
    """
    @_uploaded = {}

  drop: (event)->
    super
    {files, items}  = event.originalEvent.dataTransfer

    if files.length >= 20
      KD.notify_ """
      Too many files to transfer!<br>
      Archive your files and try again.
      """, "error", """
      Max 20 files allowed to upload at once.
      You can archive your files and try again.
      """

    if items?.item?(0)?.webkitGetAsEntry
      for item in items
        entry = item.webkitGetAsEntry()
        if entry.isDirectory
          @walkDirectory entry.filesystem.root, (file)=>
            # upload walked file
            @uploadFiles [file], event
          , =>
            # fallback for file upload, upload the other files stack
            @uploadFiles files, event
        else if entry.isFile
          entry.file (file)=>
            # upload file entry
            @uploadFiles [file], event
    else
      # fallback to upload files for folder upload browsers
      @uploadFiles files, event

  uploadFiles: (files, event)->
    @_uploaded or= {}
    if files?.length

      lastFile = files.last

      for file, index in files
        sizeInMb = file.size/1024/1024
        if sizeInMb > 100 && @getOptions().uploadToVM
          KD.notify_ "Too big file to upload.", "error", "Max 100MB allowed per file."
          continue
        reader = new FileReader
        reader.onloadend = do (file=files[index])=> (readEvent)=>

          fileName = file.fileName or file.name

          if file.relativePath
{'fraction_non_alphanumeric': 0.11955855303494789, 'fraction_numerical': 0.005824647455548743, 'mean_word_length': 2.3037974683544302, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 58, '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': '4545004', 'n_tokens_mistral': 1978, 'n_tokens_neox': 1909, 'n_words': 518}