<commit_before>var app = angular.module('heypi', ['ngMaterial','ui.router','md.data.table']);

app.config(function($stateProvider,$mdThemingProvider) {

  $mdThemingProvider.theme('default')
    .primaryPalette('blue')
    .accentPalette('light-blue');

  $stateProvider
  .state('collections', {
      url:'/collections',
      templateUrl: '/templates/collections',
      controller: 'AppController'
    })
  .state('collections.collectionTable', {
      url:'/:name',
      templateUrl: '/templates/collectionTable',
      controller: 'AppController'
    })
  .state('docs', {
      url:'/docs',
      templateUrl: '/templates/docs',
      controller: 'AppController'
    })
})

app.controller('AppController', function($mdSidenav, $http, $scope, $stateParams, $filter) {
  var vm = this;

  $scope.collectionName = $stateParams.name
  $scope.selected = [];
  $scope.docsToAdd = [];
  $scope.modelObject = {};
  $scope.blankObj = {};

  function getData(query) {
    var http = $http({
      method: 'GET',
      url: '/api/' + $stateParams.name + query,
      headers: {'x-access-token':'<KEY>'}
    })
    return http;
  }

  $scope.query = {
    filter: '',
    order: 'rid',
    limit: 10,
    page: 1,
    string: ''
  };

  function createModelObject() {
    console.log($scope.selected);
    //clean clone of object so we can reference it to add new objects
    var clone = _.clone($scope.docs.documents[$scope.docs.documents - 1]);
    $scope.blankObj = _.omit(clone, _.keys(clone));
    $scope.modelObject = _.mapObject($scope.modelObject, function(val, key) {
      return val = text;
    });
  }

  $scope.saveItems = function() {
    batch($scope.docsToAdd,'insert').then(function(resp) {
      $scope.editMode = false;
      location.reload();
    })
  }

  $scope.deleteItems = function() {
    batch($scope.selected, 'delete').then(function(resp){
      console.log();
      $scope.docs.documents = _.difference($scope.docs.documents,$scope.selected);
    })
  }

  $scope.toggleEdit = function() {
    $scope.editMode = !$scope.editMode;
    $scope.addMode = false;
  }

  $scope.addItem = function() {
    $scope.docs.documents.splice(0,$scope.blankObj);
    $scope.docsToAdd.push(angular.copy($scope.blankObj));
    $scope.editMode = true;
    $scope.addMode = true;
  }

  var batch = function(data,method) {
    //remove hashkeys
    var docs = JSON.parse(angular.toJson(data)),
        batchArray = [];

    _.each(docs, function(doc){
      batchArray.push({"method":method,"document":doc})
    });

    var http = $http({
      method: "POST",
      url: '/api/batch/' + $stateParams.name,
      headers: { "x-access-token":"<KEY>"},
      data: { "operations": batchArray }
    })

    return http;
  }

  var buildQueryString = function() {
    //order
    var direction = '',
        order = $scope.query.order;

    if (order[0] === '-') {
      direction = '_down';
      order = order.substr(1);
    } else {
      direction = '_up';
    }

    var limit = 'limit=' + $scope.query.limit,
        orderStr = '?sort=' + order + direction + '&';
        skip  = '&skip=' + ($scope.query.page - 1) * $scope.query.limit

    $scope.query.string =  orderStr  + limit + skip;
  }

  //load initial data
  buildQueryString()

  getData($scope.query.string).then(function(resp) {
    $scope.docs = resp.data;
    $scope.headers = _.keys(resp.data.documents[0]);
    $scope.query.order = _.keys($scope.docs.documents[0])[1];
    createModelObject();
  })

  $scope.search = function (predicate) {
    $scope.filter = predicate;
    $scope.deferred = $nutrition.desserts.get($scope.query, success).$promise;
  };

  $scope.onOrderChange = function (order) {
    $scope.query.order = order;
  };

  $scope.onPaginationChange = function (page, limit) {
    buildQueryString();
    getData($scope.query.string).then(function(docs) {
      console.log($scope.query.string);
      $scope.docs = docs.data;
    })
  };

  vm.toggleSidenav = function(menuId) {
    $mdSidenav(menuId).toggle();
  };<commit_msg>switched to server side ordering<commit_after>var app = angular.module('heypi', ['ngMaterial','ui.router','md.data.table']);

app.config(function($stateProvider,$mdThemingProvider) {

  $mdThemingProvider.theme('default')
    .primaryPalette('blue')
    .accentPalette('light-blue');

  $stateProvider
  .state('collections', {
      url:'/collections',
      templateUrl: '/templates/collections',
      controller: 'AppController'
    })
  .state('collections.collectionTable', {
      url:'/:name',
      templateUrl: '/templates/collectionTable',
      controller: 'AppController'
    })
  .state('docs', {
      url:'/docs',
      templateUrl: '/templates/docs',
      controller: 'AppController'
    })
})

app.controller('AppController', function($mdSidenav, $http, $scope, $stateParams, $filter) {
  var vm = this;

  $scope.collectionName = $stateParams.name
  $scope.selected = [];
  $scope.docsToAdd = [];
  $scope.modelObject = {};
  $scope.blankObj = {};

  function getData(query) {
    var http = $http({
      method: 'GET',
      url: '/api/' + $stateParams.name + query,
      headers: {'x-access-token':'<PASSWORD> <KEY>'}
    })
    return http;
  }

  $scope.query = {
    filter: '',
    order: 'rid',
    limit: 10,
    page: 1,
    string: ''
  };

  function createModelObject() {
    console.log($scope.selected);
    //clean clone of object so we can reference it to add new objects
    var clone = _.clone($scope.docs.documents[$scope.docs.documents - 1]);
    $scope.blankObj = _.omit(clone, _.keys(clone));
    $scope.modelObject = _.mapObject($scope.modelObject, function(val, key) {
      return val = text;
    });
  }

  $scope.saveItems = function() {
    batch($scope.docsToAdd,'insert').then(function(resp) {
      $scope.editMode = false;
      location.reload();
    })
  }

  $scope.deleteItems = function() {
    batch($scope.selected, 'delete').then(function(resp){
      console.log();
      $scope.docs.documents = _.difference($scope.docs.documents,$scope.selected);
    })
  }

  $scope.toggleEdit = function() {
    $scope.editMode = !$scope.editMode;
    $scope.addMode = false;
  }

  $scope.addItem = function() {
    $scope.docs.documents.splice(0,$scope.blankObj);
    $scope.docsToAdd.push(angular.copy($scope.blankObj));
    $scope.editMode = true;
    $scope.addMode = true;
  }

  var batch = function(data,method) {
    //remove hashkeys
    var docs = JSON.parse(angular.toJson(data)),
        batchArray = [];

    _.each(docs, function(doc){
      batchArray.push({"method":method,"document":doc})
    });

    var http = $http({
      method: "POST",
      url: '/api/batch/' + $stateParams.name,
      headers: { "x-access-token":"<KEY>"},
      data: { "operations": batchArray }
    })

    return http;
  }

  var buildQueryString = function() {
    //order
    var direction = '',
        order = $scope.query.order;

    if (order[0] === '-') {
      direction = '_down';
      order = order.substr(1);
    } else {
      direction = '_up';
    }

    var limit = 'limit=' + $scope.query.limit,
        orderStr = '?sort=' + order + direction + '&';
        skip  = '&skip=' + ($scope.query.page - 1) * $scope.query.limit

    $scope.query.string =  orderStr  + limit + skip;
  }

  //load initial data
  buildQueryString()

  getData($scope.query.string).then(function(resp) {
    $scope.docs = resp.data;
    $scope.headers = _.keys(resp.data.documents[0]);
    $scope.query.order = _.keys($scope.docs.documents[0])[1];
    createModelObject();
  })

  $scope.search = function (predicate) {
    $scope.filter = predicate;
    $scope.deferred = $nutrition.desserts.get($scope.query, success).$promise;
  };

  $scope.onOrderChange = function (order) {
    buildQueryString();
    getData($scope.query.string).then(function(docs) {
      console.log($scope.query.string);
      $scope.docs = docs.data;
    })
  };

  $scope.onPaginationChange = function (page, limit) {
    buildQueryString();
    getData($scope.query.string).then(function(docs) {
      console.log($scope.query.string);
      $scope.docs = docs.data;
    })
  };

  vm.toggleSidenav = function(menuId) {
    $mdSidenav(menuId).toggle();
  };
{'fraction_non_alphanumeric': 0.176033158600512, 'fraction_numerical': 0.0026819456296476897, 'mean_word_length': 2.980591945657448, 'pattern_counts': {'":': 8, '<': 8, '<?xml version=': 0, '>': 8, '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': '7416691', 'n_tokens_mistral': 2736, 'n_tokens_neox': 2650, 'n_words': 450}