<commit_before>var app = angular.module("app");

app.service("ResMgr", ['$q', '$http', function ($q, $http) {
  return {
    models: {},
    getName: function(model) {
      model = model.replace('-', '_');
      model = model.underscore().split('_');
      model = model.slice(0, model.length - 1).join('_').camelize() + model[model.length - 1].classify();
      return model;
    },
    getUrl: function(model) {
      model = model.underscore().split('_');
      model = model.slice(0, model.length - 1).join('_').camelize() + model[model.length - 1].pluralize().camelize();
      return model.underscore();
    },
    getModel: function (model, config) {
      config = config || {};
      config.name = model = this.getName(model);
      if(!config.url) config.url           = this.getUrl(model);
      if(!config.key) config.key           = model.underscore();
      if(!config.display)  config.display  = model.underscore().titleize();
      if(!config.displays) config.displays = config.url.titleize();
      return config;
    },
    register: function (model, api_url, params, config) {
      model = this.getName(model);
      params = params || {id: '@id'};
      config = config || {};
      if(!this.models[model]) {
        app.factory(model, ['$resource', function ($resource) {
          return $resource(api_url, params, {
            query:  { method: 'GET', isArray: true },
            update: { method: 'PUT' }
          });
        }]);
        this.models[model] = this.getModel(model, config);
        this.models[model]["api_url"] = api_url;
        this.models[model]["klass"] = angular.injector(['ng', 'app']).get(model);
      }
      return this.models[model];
    },
    query: function (model, data, callback) {
      var d = $q.defer(); model = this.getName(model);
      this.models[model]["klass"].query(data, function (response, headers) {
        response.error? d.reject(response) : d.resolve(response);
        callback && callback(response, headers('_meta_total'));
      }, function (response) { console.log(response) });
      return d.promise;
    },
    get: function (model, data, callback) {
      var d = $q.defer(); model = this.getName(model);
      this.models[model]["klass"].get(data, function (response, headers) {
        response.error? d.reject(response) : d.resolve(response);
        callback && callback(response);
      }, function (response) { console.log(response) });
      return d.promise;
    },
    create: function (model, data, callback) {
      var d = $q.defer(); model = this.getName(model);
      new this.models[model]["klass"](data).$save(function (response) {
        response.error? d.reject(response) : d.resolve(response);
        callback && callback(response);
      }, function (response) { console.log(response) });
      return d.promise;
    },
    update: function (model, data, callback) {
      var d = $q.defer(); model = this.getName(model);
      new this.models[model]["klass"](data).$update(function (response) {
        console.log(response);
        response.error? d.reject(response) : d.resolve(response);
        callback && callback(response);
      }, function (response) { console.log(response) });
      return d.promise;
    },
    delete: function (model, data, callback) {
      var d = $q.defer(); model = this.getName(model);
      new this.models[model]["klass"](data).$delete(function (response) {
        response.error? d.reject(response) : d.resolve(response);
        callback && callback(response);
      }, function (response) { console.log(response) });
      return d.promise;
    }
  };
}]);<commit_msg>Cleanup in resource_manager.js<commit_after>var app = angular.module("app");

app.service("ResMgr", ['$q', '$http', function ($q, $http) {
  return {
    models: {},
    getName: function(model) {
      model = model.replace('-', '_');
      model = model.underscore().split('_');
      model = model.slice(0, model.length - 1).join('_').camelize() + model[model.length - 1].classify();
      return model;
    },
    getUrl: function(model) {
      model = model.underscore().split('_');
      model = model.slice(0, model.length - 1).join('_').camelize() + model[model.length - 1].pluralize().camelize();
      return model.underscore();
    },
    getModel: function (model, config) {
      config = config || {};
      config.name = model = this.getName(model);
      if(!config.url) config.url           = this.getUrl(model);
      if(!config.key) config.key           = model.underscore();
      if(!config.display)  config.display  = model.underscore().titleize();
      if(!config.displays) config.displays = config.url.titleize();
      return config;
    },
    register: function (model, api_url, params, config) {
      model = this.getName(model);
      params = params || {id: '@id'};
      config = config || {};
      if(!this.models[model]) {
        app.factory(model, ['$resource', function ($resource) {
          return $resource(api_url, params, {
            query:  { method: 'GET', isArray: true },
            update: { method: 'PUT' }
          });
        }]);
        this.models[model] = this.getModel(model, config);
        this.models[model]["api_url"] = api_url;
        this.models[model]["klass"] = angular.injector(['ng', 'app']).get(model);
      }
      return this.models[model];
    },
    query: function (model, data, callback) {
      var d = $q.defer(); model = this.getName(model);
      this.models[model]["klass"].query(data, function (response, headers) {
        response.error? d.reject(response) : d.resolve(response);
        callback && callback(response, headers('_meta_total'));
      }, function (response) { console.log(response) });
      return d.promise;
    },
    get: function (model, data, callback) {
      var d = $q.defer(); model = this.getName(model);
      this.models[model]["klass"].get(data, function (response, headers) {
        response.error? d.reject(response) : d.resolve(response);
        callback && callback(response);
      }, function (response) { console.log(response) });
      return d.promise;
    },
    create: function (model, data, callback) {
      var d = $q.defer(); model = this.getName(model);
      new this.models[model]["klass"](data).$save(function (response) {
        response.error? d.reject(response) : d.resolve(response);
        callback && callback(response);
      }, function (response) { console.log(response) });
      return d.promise;
    },
    update: function (model, data, callback) {
      var d = $q.defer(); model = this.getName(model);
      new this.models[model]["klass"](data).$update(function (response) {
        response.error? d.reject(response) : d.resolve(response);
        callback && callback(response);
      }, function (response) { console.log(response) });
      return d.promise;
    },
    delete: function (model, data, callback) {
      var d = $q.defer(); model = this.getName(model);
      new this.models[model]["klass"](data).$delete(function (response) {
        response.error? d.reject(response) : d.resolve(response);
        callback && callback(response);
      }, function (response) { console.log(response) });
      return d.promise;
    }
  };
}]);
{'fraction_non_alphanumeric': 0.17722744881018263, 'fraction_numerical': 0.0016602102933038186, 'mean_word_length': 2.8740621650589495, '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': '3308680', 'n_tokens_mistral': 2182, 'n_tokens_neox': 2165, 'n_words': 439}