<commit_before>"use strict";
/*
 * cchecker_web/static/js/app/index.js
 */

_.extend(App.prototype, {
  views: {
    navbar: null,
    testSelection: null,
    netCDFUpload: null
  },
  collections: {
    testCollection: new TestCollection()
  },
  models:{
    upload: new UploadModel(),
    configModel: new ConfigModel()
  },
  form: new FormData(),
  initializeViews: function() {
    var self = this;
    // Initialize the Navbar with a Logout button
    this.views.navbar = new IOOSNavbarView({
      el: $('#navbar-view')
    });
    this.views.navbar.render();

    this.views.testSelection = new TestSelectionView({
      el: $('.testselection'),
      collection: this.collections.testCollection
    });

    this.views.netCDFUpload = new NetCDFUploadView({
      el: $('#fileupload'),
      model: this.models.upload
    });
  },
  initializeCollections: function() {
    var self = this;

    // Get the checkers
    var testFetch = this.collections.testCollection.fetch({
      beforeSend: this.beforeSend.bind(this)
    });
    $.when.apply($, [testFetch]).done(function() {
      self.views.testSelection.render();
    });
  },
  initializeModels: function() {
    var self = this;
  },
  fetchCollections: function() {
    var self = this;
    var configFetch = this.models.configModel.fetch({
      beforeSend: this.beforeSend.bind(this),
      success: function(model) {
        var size = model.get('size_limit') / 1048576;
        $('#max-size').html("(Max Size: " + size.toFixed(1).toString() + "MB)");
      }
    });
  },
  start: function() {
    var self = this;
    this.drop = $('#dropbox');
    this.submit = $('#submit-btn');

    // Listen for someone selecting a file witht he browse button
    $('.btn-file :file').change(function(e) {
      if($(this).get(0).files.length > 0) {
        var file = $(this).get(0).files[0];
        self.models.upload.set({filename: file.name, file:file});
        self.drop.addClass('uploading');
        self.views.netCDFUpload.render();
      }
    });

    // Someone dragged a file
    this.drop.on('dragover', function(e) {
      e.preventDefault();
      e.stopPropagation();
      $(this).removeClass();
      self.views.netCDFUpload.$el.html("");
    });

    this.drop.on('dragenter', function(e) {
      $(this).addClass('hovered');
    });

    this.drop.on('dragleave', function(e) {
      $(this).removeClass('hovered');
    });

    // Someone dropped a file
    this.drop.on('drop', function(e) {
      e.preventDefault();
      e.stopPropagation();

      _.each(e.originalEvent.dataTransfer.files, function(file, i) {
        if(i > 0) {
          return;
        }
        self.models.upload.set({filename: file.name, file: file});
      });

      $(this).addClass('uploading');
      self.views.netCDFUpload.render();
    });


    this.submit.on('click', function() {
      var checkID = self.views.testSelection.getSelected();
      self.form.append('checker', checkID);
      self.form.append('file-0', self.models.upload.get('file'));
      var urlInput = $('#url-input').val();
      if(urlInput.length > 0) {
        self.form.append('url', urlInput);
      }
      var req = $.ajax({
        url: self.urlRoot + 'upload',
        xhr: function() {
          var x = $.ajaxSettings.xhr();
          x.upload.addEventListener('progress', function(e) {
            if(e.lengthComputable) {
              var pct = e.loaded / e.total * 100;
            }<commit_msg>Use form.set instead of form.append<commit_after>"use strict";
/*
 * cchecker_web/static/js/app/index.js
 */

_.extend(App.prototype, {
  views: {
    navbar: null,
    testSelection: null,
    netCDFUpload: null
  },
  collections: {
    testCollection: new TestCollection()
  },
  models:{
    upload: new UploadModel(),
    configModel: new ConfigModel()
  },
  form: new FormData(),
  initializeViews: function() {
    var self = this;
    // Initialize the Navbar with a Logout button
    this.views.navbar = new IOOSNavbarView({
      el: $('#navbar-view')
    });
    this.views.navbar.render();

    this.views.testSelection = new TestSelectionView({
      el: $('.testselection'),
      collection: this.collections.testCollection
    });

    this.views.netCDFUpload = new NetCDFUploadView({
      el: $('#fileupload'),
      model: this.models.upload
    });
  },
  initializeCollections: function() {
    var self = this;

    // Get the checkers
    var testFetch = this.collections.testCollection.fetch({
      beforeSend: this.beforeSend.bind(this)
    });
    $.when.apply($, [testFetch]).done(function() {
      self.views.testSelection.render();
    });
  },
  initializeModels: function() {
    var self = this;
  },
  fetchCollections: function() {
    var self = this;
    var configFetch = this.models.configModel.fetch({
      beforeSend: this.beforeSend.bind(this),
      success: function(model) {
        var size = model.get('size_limit') / 1048576;
        $('#max-size').html("(Max Size: " + size.toFixed(1).toString() + "MB)");
      }
    });
  },
  start: function() {
    var self = this;
    this.drop = $('#dropbox');
    this.submit = $('#submit-btn');

    // Listen for someone selecting a file witht he browse button
    $('.btn-file :file').change(function(e) {
      if($(this).get(0).files.length > 0) {
        var file = $(this).get(0).files[0];
        self.models.upload.set({filename: file.name, file:file});
        self.drop.addClass('uploading');
        self.views.netCDFUpload.render();
      }
    });

    // Someone dragged a file
    this.drop.on('dragover', function(e) {
      e.preventDefault();
      e.stopPropagation();
      $(this).removeClass();
      self.views.netCDFUpload.$el.html("");
    });

    this.drop.on('dragenter', function(e) {
      $(this).addClass('hovered');
    });

    this.drop.on('dragleave', function(e) {
      $(this).removeClass('hovered');
    });

    // Someone dropped a file
    this.drop.on('drop', function(e) {
      e.preventDefault();
      e.stopPropagation();

      _.each(e.originalEvent.dataTransfer.files, function(file, i) {
        if(i > 0) {
          return;
        }
        self.models.upload.set({filename: file.name, file: file});
      });

      $(this).addClass('uploading');
      self.views.netCDFUpload.render();
    });


    this.submit.on('click', function() {
      var checkID = self.views.testSelection.getSelected();
      self.form.set('checker', checkID);
      self.form.set('file-0', self.models.upload.get('file'));
      var urlInput = $('#url-input').val();
      if(urlInput.length > 0) {
        self.form.set('url', urlInput);
      }
      var req = $.ajax({
        url: self.urlRoot + 'upload',
        xhr: function() {
          var x = $.ajaxSettings.xhr();
          x.upload.addEventListener('progress', function(e) {
            if(e.lengthComputable) {
              var pct = e.loaded / e.total * 100;
            }
{'fraction_non_alphanumeric': 0.1701574461938466, 'fraction_numerical': 0.00520005777841976, 'mean_word_length': 2.5093765838824127, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '1539409', 'n_tokens_mistral': 2191, 'n_tokens_neox': 2151, 'n_words': 404}