<commit_before>(function() {
  'use strict';

  angular
    .app
    .factory('SettingsServ', SettingsServ);

  SettingsServ.$inject = ['DB', 'Utils'];

  function SettingsServ(DB, Utils) {
    var settingsDb = DB.getDb('settings'),
      defaults = {
        language: 'en',
        showTags: true,
        trackers: {
          selected: 0,
          list: [
            { url: 'http://kat.cr/usearch/' },
            { url: 'http://filelist.ro/browse.php?search=' }
          ]
        }
      },
      settings = {},
      // insert default settings into DB
      seed = function() {
        return DB.insert(settingsDb, { settings: defaults }).then(function(res) {
          console.log('SettingsServ inserted', res.settings);
          apply(res.settings);
        }, Utils.onError);
      },
      // apply loaded settings
      apply = function(res) {
        for(var i in res) {
          settings[i] = res[i];
        }
      },
      // reset settings to default
      reset = function() {
        purge().then(seed, Utils.onError);
      },
      // delete all settings
      purge = function() {
        return DB.delete(settingsDb, {}, { multiple: true }).then(function(res) {
          console.log('SettingsServ deleted', res);
        }, Utils.onError);
      };

    // purge();

    var promise = DB.find(settingsDb, {}).then(function(res) {
      console.log('SettingsServ settings', res);
      res.length ? apply(res[0].settings) : seed();
    }, Utils.onError);

    return {
      promise: promise,
      get: function() {
        return settings;
      },
      reset: reset
    };
  }
}());<commit_msg>save to db method for settings serv<commit_after>(function() {
  'use strict';

  angular
    .app
    .factory('SettingsServ', SettingsServ);

  SettingsServ.$inject = ['DB', 'Utils'];

  function SettingsServ(DB, Utils) {
    var settingsDb = DB.getDb('settings'),
      defaults = {
        language: 'en',
        showTags: true,
        trackers: {
          selected: 0,
          list: [
            { url: 'http://kat.cr/usearch/' },
            { url: 'http://filelist.ro/browse.php?search=' }
          ]
        }
      },
      settings = {},
      // insert default settings into DB
      seed = function() {
        return DB.insert(settingsDb, { settings: defaults }).then(function(res) {
          console.log('SettingsServ inserted', res.settings);
          apply(res.settings);
        }, Utils.onError);
      },
      // apply loaded settings
      apply = function(res) {
        for(var i in res) {
          settings[i] = res[i];
        }
      },
      // reset settings to default
      reset = function() {
        purge().then(seed, Utils.onError);
      },
      // save current settings to DB
      save = function() {
        // TODO: fix this to gain access to settings._id
        return DB.update(settingsDb, { _id: settings._id }, {
          settings: angular.copy(settings)
        }, function(res) {
          console.log('SettingsServ update success', res);
        }, Utils.onError);
      },
      // delete all settings
      purge = function() {
        return DB.delete(settingsDb, {}, { multiple: true }).then(function(res) {
          console.log('SettingsServ deleted', res);
        }, Utils.onError);
      };

    // purge();

    var promise = DB.find(settingsDb, {}).then(function(res) {
      console.log('SettingsServ settings', res);
      res.length ? apply(res[0].settings) : seed();
    }, Utils.onError);

    return {
      promise: promise,
      get: function() {
        return settings;
      },
      save: save,
      reset: reset
    };
  }
}());
{'fraction_non_alphanumeric': 0.1505081021697336, 'fraction_numerical': 0.0010985992859104642, 'mean_word_length': 1.9019920318725099, 'pattern_counts': {'":': 0, '<': 3, '<?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': '7356911', 'n_tokens_mistral': 1060, 'n_tokens_neox': 1043, 'n_words': 237}