mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 01:13:23 -04:00
[BaseObject] move to utils
This commit is contained in:
parent
9d6633d337
commit
4258f49d7b
3 changed files with 42 additions and 44 deletions
|
@ -1,43 +0,0 @@
|
|||
define(function (require) {
|
||||
return function BaseObjectProvider() {
|
||||
var _ = require('lodash');
|
||||
var rison = require('utils/rison');
|
||||
var angular = require('angular');
|
||||
|
||||
function BaseObject(attributes) {
|
||||
// Set the attributes or default to an empty object
|
||||
_.assign(this, attributes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the attirbutes for the objct
|
||||
* @returns {object}
|
||||
*/
|
||||
BaseObject.prototype.toObject = function () {
|
||||
// return just the data.
|
||||
return _.omit(this, function (value, key) {
|
||||
return key.charAt(0) === '$' || key.charAt(0) === '_' || _.isFunction(value);
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Serialize the model to RISON
|
||||
* @returns {string}
|
||||
*/
|
||||
BaseObject.prototype.toRISON = function () {
|
||||
var obj = this.toObject();
|
||||
// Use Angular to remove the private vars
|
||||
return rison.encode(JSON.parse(angular.toJson(obj)));
|
||||
};
|
||||
|
||||
/**
|
||||
* Serialize the model to JSON
|
||||
* @returns {object}
|
||||
*/
|
||||
BaseObject.prototype.toJSON = function () {
|
||||
return this.toObject();
|
||||
};
|
||||
|
||||
return BaseObject;
|
||||
};
|
||||
});
|
41
src/kibana/utils/BaseObject.js
Normal file
41
src/kibana/utils/BaseObject.js
Normal file
|
@ -0,0 +1,41 @@
|
|||
define(function (require) {
|
||||
var _ = require('lodash');
|
||||
var rison = require('utils/rison');
|
||||
var angular = require('angular');
|
||||
|
||||
function BaseObject(attributes) {
|
||||
// Set the attributes or default to an empty object
|
||||
_.assign(this, attributes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the attirbutes for the objct
|
||||
* @returns {object}
|
||||
*/
|
||||
BaseObject.prototype.toObject = function () {
|
||||
// return just the data.
|
||||
return _.omit(this, function (value, key) {
|
||||
return key.charAt(0) === '$' || key.charAt(0) === '_' || _.isFunction(value);
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Serialize the model to RISON
|
||||
* @returns {string}
|
||||
*/
|
||||
BaseObject.prototype.toRISON = function () {
|
||||
var obj = this.toObject();
|
||||
// Use Angular to remove the private vars
|
||||
return rison.encode(JSON.parse(angular.toJson(obj)));
|
||||
};
|
||||
|
||||
/**
|
||||
* Serialize the model to JSON
|
||||
* @returns {object}
|
||||
*/
|
||||
BaseObject.prototype.toJSON = function () {
|
||||
return this.toObject();
|
||||
};
|
||||
|
||||
return BaseObject;
|
||||
});
|
|
@ -13,7 +13,7 @@ define(function (require) {
|
|||
|
||||
inject(function (_$rootScope_, Private) {
|
||||
$rootScope = _$rootScope_;
|
||||
BaseObject = Private(require('factories/base_object'));
|
||||
BaseObject = require('utils/BaseObject');
|
||||
});
|
||||
});
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue