diff options
Diffstat (limited to 'sdnr/wt/devicemanager/provider/src/test/resources/elasticsearch/plugins/head/src/app/services/cluster/cluster.js')
-rw-r--r-- | sdnr/wt/devicemanager/provider/src/test/resources/elasticsearch/plugins/head/src/app/services/cluster/cluster.js | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/sdnr/wt/devicemanager/provider/src/test/resources/elasticsearch/plugins/head/src/app/services/cluster/cluster.js b/sdnr/wt/devicemanager/provider/src/test/resources/elasticsearch/plugins/head/src/app/services/cluster/cluster.js new file mode 100644 index 000000000..c4ddf6552 --- /dev/null +++ b/sdnr/wt/devicemanager/provider/src/test/resources/elasticsearch/plugins/head/src/app/services/cluster/cluster.js @@ -0,0 +1,47 @@ +(function( $, app ) { + + var services = app.ns("services"); + var ux = app.ns("ux"); + + function parse_version( v ) { + return v.match(/^(\d+)\.(\d+)\.(\d+)/).slice(1,4).map( function(d) { return parseInt(d || 0, 10); } ); + } + + services.Cluster = ux.Class.extend({ + defaults: { + base_uri: null + }, + init: function() { + this.base_uri = this.config.base_uri; + }, + setVersion: function( v ) { + this.version = v; + this._version_parts = parse_version( v ); + }, + versionAtLeast: function( v ) { + var testVersion = parse_version( v ); + for( var i = 0; i < 3; i++ ) { + if( testVersion[i] !== this._version_parts[i] ) { + return testVersion[i] < this._version_parts[i]; + } + } + return true; + }, + request: function( params ) { + return $.ajax( $.extend({ + url: this.base_uri + params.path, + dataType: "json", + error: function(xhr, type, message) { + if("console" in window) { + console.log({ "XHR Error": type, "message": message }); + } + } + }, params) ); + }, + "get": function(path, success) { return this.request( { type: "GET", path: path, success: success } ); }, + "post": function(path, data, success) { return this.request( { type: "POST", path: path, data: data, success: success } ); }, + "put": function(path, data, success) { return this.request( { type: "PUT", path: path, data: data, success: success } ); }, + "delete": function(path, data, success) { return this.request( { type: "DELETE", path: path, data: data, success: success } ); } + }); + +})( this.jQuery, this.app ); |