<commit_before>"use strict";

define([
  "backbone",
  "underscore",
  "handlebars",
  "text!templates/file-list-view.html",
  "select2"
], function(Backbone, _, Handlebars, filelistTemplate,
  Select2) {

  var Filelist = Backbone.View.extend({

    el: "#file-list",

    template: Handlebars.compile(filelistTemplate),

    initialize: function() {
      this.listenTo(this.collection, 'reset', this.render);
      this.collection.fetch({reset: true});
    },

    postInit: function() {
      var data=[{id:0,tag:'enhancement'},
        {id:1,tag:'<NAME>'},
        {id:2,tag:'<NAME>'},
        {id:3,tag:'<NAME>'},
        {id:4,tag:'wontfix'}];
      function format(item) { return item.tag; }
      this.$("#file-search").select2({
          width: "copy",
          data:{ results: data, text: 'tag' },
          formatSelection: format,
          formatResult: format
      });
    },

    render: function() {
      var models = this.collection.models;
      this.$el.html(this.template({
        files: _.map(models, function(model) {
          return model.attributes;
        })
      }));
      this.postInit();
      return this;
    }<commit_msg>file search in dashboard enabled<commit_after>"use strict";

define([
  "backbone",
  "underscore",
  "handlebars",
  "text!templates/file-list-view.html",
  "select2"
], function(Backbone, _, Handlebars, filelistTemplate,
  Select2) {

  var Filelist = Backbone.View.extend({

    el: "#file-list",

    template: Handlebars.compile(filelistTemplate),

    initialize: function() {
      this.listenTo(this.collection, 'reset', this.render);
      this.collection.fetch({reset: true});
    },

    postInit: function() {
      var format = function(item) {
        return item.title;
      };
      // Should search by the label
      // TODO: modularize select field setup
      this.$("#file-search").select2({
        id: function(obj) {
          return "http://localhost:3000/#file/" + obj.id + "/view";
        },
        ajax: {
          url: "api/files/search",
          dataType: "json",
          data: function(term, page) {
            return {q: term}
          },
          results: function(term, page) {
            return {results: term, text: "title"};
          }
        },
        formatSelection: format,
        formatResult: format
      });
      // Attach selection change handler
      this.$("#file-search").on("change", _.bind(this.openFile, this));
    },

    openFile: function(ev) {
      alert(ev.val);
    },

    render: function() {
      var models = this.collection.models;
      this.$el.html(this.template({
        files: _.map(models, function(model) {
          return model.attributes;
        })
      }));
      this.postInit();
      return this;
    }
{'fraction_non_alphanumeric': 0.16021699819168173, 'fraction_numerical': 0.0054249547920434, 'mean_word_length': 2.3086124401913874, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, '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': '1659732', 'n_tokens_mistral': 851, 'n_tokens_neox': 828, 'n_words': 165}