<commit_before>module.exports = {
  replace: true,
  template: require('./template.html'),
  data: function() {
    return {
      notebook: false,
      types: []
    };
  },
  computed: {
    apiUrl: function() {
      if (this.notebook) {
        return '_view/by_notebook?group_level=2&startkey=["' + this.notebook
          + '"]&endkey=["' + this.notebook + '", {}]';
      } else {
        return '_view/by_type?group_level=1';
      }
    }
  },
  created: function() {
    this.fetchData();
  },
  watch: {
    notebook: 'fetchData'
  },
  methods: {
    fetchData: function () {
      if (!this.apiUrl) return false;
      var xhr = new XMLHttpRequest(),
          self = this;
      xhr.open('GET', self.apiUrl);
      xhr.onload = function () {
        self.items = JSON.parse(xhr.responseText);
        self.types = [];
        if (self.notebook) {
          for (var i = 0; i < self.items.rows.length; i++) {
            // if there are 2 keys, we have a type entry
            if (self.items.rows[i].key.length === 2) {
              self.types.push({"type": self.items.rows[i].key[1],
                "count": self.items.rows[i].value});
            }
          }
        } else {
          for (var i = 0; i < self.items.rows.length; i++) {
            self.types.push({"type": self.items.rows[i].key[0],
              "count": self.items.rows[i].value});
          }
        }
      };
      xhr.send();
    }
  }
};<commit_msg>Switch type list to PouchDB<commit_after>var PouchDB = require('pouchdb');
// TODO: move this to a config lib
var db_name = location.pathname.split('/')[1];
var db_url = location.protocol + '//' + location.hostname
    + (location.port ? ':' + location.port : '') + '/' + db_name + '/';
var db = new PouchDB(db_url);

module.exports = {
  replace: true,
  template: require('./template.html'),
  data: function() {
    return {
      notebook: false,
      types: []
    };
  },
  computed: {
    apiUrl: function() {
      if (this.notebook) {
        return '_view/by_notebook?group_level=2&startkey=["' + this.notebook
          + '"]&endkey=["' + this.notebook + '", {}]';
      } else {
        return '_view/by_type?group_level=1';
      }
    }
  },
  created: function() {
    this.fetchData();
  },
  watch: {
    notebook: 'fetchData'
  },
  methods: {
    fetchData: function () {
      var self = this;
      var view = '';
      var params = {};
      if (this.notebook) {
        view = 'by_notebook';
        params = {
          group_level: 2,
          startkey: [this.notebook],
          endkey: [this.notebook, {}]
        };
      } else {
        view = 'by_type';
        params = {
          group_level: 1
        };
      }

      db.query('sprung/' + view, params)
        .then(function(resp) {
          self.items = resp;
          self.types = [];
          if (self.notebook) {
            for (var i = 0; i < self.items.rows.length; i++) {
              // if there are 2 keys, we have a type entry
              if (self.items.rows[i].key.length === 2) {
                self.types.push({"type": self.items.rows[i].key[1],
                  "count": self.items.rows[i].value});
              }
            }
          } else {
            for (var i = 0; i < self.items.rows.length; i++) {
              self.types.push({"type": self.items.rows[i].key[0],
                "count": self.items.rows[i].value});
            }
          }
        });
    }
  }
};
{'fraction_non_alphanumeric': 0.17267441860465116, 'fraction_numerical': 0.005523255813953488, 'mean_word_length': 1.7094488188976378, 'pattern_counts': {'":': 8, '<': 7, '<?xml version=': 0, '>': 3, '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': '2334740', 'n_tokens_mistral': 1144, 'n_tokens_neox': 1135, 'n_words': 219}