diff options
Diffstat (limited to 'sdnr/wt/devicemanager/provider/src/main/resources/elasticsearch/plugins/head/src/app/data')
9 files changed, 0 insertions, 864 deletions
diff --git a/sdnr/wt/devicemanager/provider/src/main/resources/elasticsearch/plugins/head/src/app/data/boolQuery.js b/sdnr/wt/devicemanager/provider/src/main/resources/elasticsearch/plugins/head/src/app/data/boolQuery.js deleted file mode 100644 index a43c51cf9..000000000 --- a/sdnr/wt/devicemanager/provider/src/main/resources/elasticsearch/plugins/head/src/app/data/boolQuery.js +++ /dev/null @@ -1,90 +0,0 @@ -/** - * Copyright 2010-2013 Ben Birch - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this software except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -(function( app ) { - - var data = app.ns("data"); - var ux = app.ns("ux"); - - data.BoolQuery = ux.Observable.extend({ - defaults: { - size: 50 // size of pages to return - }, - init: function() { - this._super(); - this.refuid = 0; - this.refmap = {}; - this.search = { - query: { bool: { must: [], must_not: [], should: [] } }, - from: 0, - size: this.config.size, - sort: [], - aggs: {} - }; - this.defaultClause = this.addClause(); - }, - setSize: function(size) { - this.search.size = parseInt( size, 10 ); - }, - setPage: function(page) { - this.search.from = this.config.size * (page - 1) + 1; - }, - addClause: function(value, field, op, bool) { - bool = bool || "should"; - op = op || "match_all"; - field = field || "_all"; - var clause = this._setClause(value, field, op, bool); - var uqid = "q-" + this.refuid++; - this.refmap[uqid] = { clause: clause, value: value, field: field, op: op, bool: bool }; - if(this.search.query.bool.must.length + this.search.query.bool.should.length > 1) { - this.removeClause(this.defaultClause); - } - this.fire("queryChanged", this, { uqid: uqid, search: this.search} ); - return uqid; // returns reference to inner query object to allow fast updating - }, - removeClause: function(uqid) { - var ref = this.refmap[uqid], - bool = this.search.query.bool[ref.bool]; - var clauseIdx = bool.indexOf(ref.clause); - // Check that this clause hasn't already been removed - if (clauseIdx >=0) { - bool.splice(clauseIdx, 1); - } - }, - _setClause: function(value, field, op, bool) { - var clause = {}, query = {}; - if(op === "match_all") { - } else if(op === "query_string") { - query["default_field"] = field; - query["query"] = value; - } else if(op === "missing") { - op = "constant_score" - var missing = {}, filter = {}; - missing["field"] = field; - filter["missing"] = missing - query["filter"] = filter; - } else { - query[field.substring(field.indexOf(".")+1)] = value; - } - clause[op] = query; - this.search.query.bool[bool].push(clause); - return clause; - }, - getData: function() { - return JSON.stringify(this.search); - } - }); - -})( this.app );
\ No newline at end of file diff --git a/sdnr/wt/devicemanager/provider/src/main/resources/elasticsearch/plugins/head/src/app/data/dataSourceInterface.js b/sdnr/wt/devicemanager/provider/src/main/resources/elasticsearch/plugins/head/src/app/data/dataSourceInterface.js deleted file mode 100644 index dc82e3075..000000000 --- a/sdnr/wt/devicemanager/provider/src/main/resources/elasticsearch/plugins/head/src/app/data/dataSourceInterface.js +++ /dev/null @@ -1,39 +0,0 @@ -/** - * Copyright 2010-2013 Ben Birch - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this software except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -(function( app ) { - - var data = app.ns("data"); - var ux = app.ns("ux"); - - data.DataSourceInterface = ux.Observable.extend({ - /* - properties - meta = { total: 0 }, - headers = [ { name: "" } ], - data = [ { column: value, column: value } ], - sort = { column: "name", dir: "desc" } - events - data: function( DataSourceInterface ) - */ - _getSummary: function(res) { - this.summary = i18n.text("TableResults.Summary", res._shards.successful, res._shards.total, res.hits.total, (res.took / 1000).toFixed(3)); - }, - _getMeta: function(res) { - this.meta = { total: res.hits.total, shards: res._shards, tool: res.took }; - } - }); - -})( this.app );
\ No newline at end of file diff --git a/sdnr/wt/devicemanager/provider/src/main/resources/elasticsearch/plugins/head/src/app/data/metaData.js b/sdnr/wt/devicemanager/provider/src/main/resources/elasticsearch/plugins/head/src/app/data/metaData.js deleted file mode 100644 index 03bc7f0d1..000000000 --- a/sdnr/wt/devicemanager/provider/src/main/resources/elasticsearch/plugins/head/src/app/data/metaData.js +++ /dev/null @@ -1,187 +0,0 @@ -/** - * Copyright 2010-2013 Ben Birch - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this software except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -(function( app ) { - - /* - notes on elasticsearch terminology used in this project - - indices[index] contains one or more - types[type] contains one or more - documents contain one or more - paths[path] - each path contains one element of data - each path maps to one field - - eg PUT, "/twitter/tweet/1" - { - user: "mobz", - date: "2011-01-01", - message: "You know, for browsing elasticsearch", - name: { - first: "Ben", - last: "Birch" - } - } - - creates - 1 index: twitter - this is the collection of index data - 1 type: tweet - this is the type of document (kind of like a table in sql) - 1 document: /twitter/tweet/1 - this is an actual document in the index ( kind of like a row in sql) - 5 paths: [ ["user"], ["date"], ["message"], ["name","first"], ["name","last"] ] - since documents can be heirarchical this maps a path from a document root to a piece of data - 5 fields: [ "user", "date", "message", "first", "last" ] - this is an indexed 'column' of data. fields are not heirarchical - - the relationship between a path and a field is called a mapping. mappings also contain a wealth of information about how es indexes the field - - notes - 1) a path is stored as an array, the dpath is <index> . <type> . path.join("."), - which can be considered the canonical reference for a mapping - 2) confusingly, es uses the term index for both the collection of indexed data, and the individually indexed fields - so the term index_name is the same as field_name in this sense. - - */ - - var data = app.ns("data"); - var ux = app.ns("ux"); - - var coretype_map = { - "string" : "string", - "keyword" : "string", - "text" : "string", - "byte" : "number", - "short" : "number", - "long" : "number", - "integer" : "number", - "float" : "number", - "double" : "number", - "ip" : "number", - "date" : "date", - "boolean" : "boolean", - "binary" : "binary", - "multi_field" : "multi_field" - }; - - var default_property_map = { - "string" : { "store" : "no", "index" : "analysed" }, - "number" : { "store" : "no", "precision_steps" : 4 }, - "date" : { "store" : "no", "format" : "dateOptionalTime", "index": "yes", "precision_steps": 4 }, - "boolean" : { "store" : "no", "index": "yes" }, - "binary" : { }, - "multi_field" : { } - }; - - // parses metatdata from a cluster, into a bunch of useful data structures - data.MetaData = ux.Observable.extend({ - defaults: { - state: null // (required) response from a /_cluster/state request - }, - init: function() { - this._super(); - this.refresh(this.config.state); - }, - getIndices: function(alias) { - return alias ? this.aliases[alias] : this.indicesList; - }, - // returns an array of strings containing all types that are in all of the indices passed in, or all types - getTypes: function(indices) { - var indices = indices || [], types = []; - this.typesList.forEach(function(type) { - for(var i = 0; i < indices.length; i++) { - if(! this.indices[indices[i]].types.contains(type)) - return; - } - types.push(type); - }, this); - return types; - }, - refresh: function(state) { - // currently metadata expects all like named fields to have the same type, even when from different types and indices - var aliases = this.aliases = {}; - var indices = this.indices = {}; - var types = this.types = {}; - var fields = this.fields = {}; - var paths = this.paths = {}; - - function createField( mapping, index, type, path, name ) { - var dpath = [ index, type ].concat( path ).join( "." ); - var field_name = mapping.index_name || path.join( "." ); - var field = paths[ dpath ] = fields[ field_name ] || $.extend({ - field_name : field_name, - core_type : coretype_map[ mapping.type ], - dpaths : [] - }, default_property_map[ coretype_map[ mapping.type ] ], mapping ); - - if (field.type === "multi_field" && typeof field.fields !== "undefined") { - for (var subField in field.fields) { - field.fields[ subField ] = createField( field.fields[ subField ], index, type, path.concat( subField ), name + "." + subField ); - } - } - if (fields.dpaths) { - field.dpaths.push(dpath); - } - return field; - } - function getFields(properties, type, index, listeners) { - (function procPath(prop, path) { - for (var n in prop) { - if ("properties" in prop[n]) { - procPath( prop[ n ].properties, path.concat( n ) ); - } else { - var field = createField(prop[n], index, type, path.concat(n), n); - listeners.forEach( function( listener ) { - listener[ field.field_name ] = field; - } ); - } - } - })(properties, []); - } - for (var index in state.metadata.indices) { - indices[index] = { - types : [], fields : {}, paths : {}, parents : {} - }; - indices[index].aliases = state.metadata.indices[index].aliases; - indices[index].aliases.forEach(function(alias) { - (aliases[alias] || (aliases[alias] = [])).push(index); - }); - var mapping = state.metadata.indices[index].mappings; - for (var type in mapping) { - indices[index].types.push(type); - if ( type in types) { - types[type].indices.push(index); - } else { - types[type] = { - indices : [index], fields : {} - }; - } - getFields(mapping[type].properties, type, index, [fields, types[type].fields, indices[index].fields]); - if ( typeof mapping[type]._parent !== "undefined") { - indices[index].parents[type] = mapping[type]._parent.type; - } - } - } - - this.aliasesList = Object.keys(aliases); - this.indicesList = Object.keys(indices); - this.typesList = Object.keys(types); - this.fieldsList = Object.keys(fields); - } - }); - -})( this.app ); diff --git a/sdnr/wt/devicemanager/provider/src/main/resources/elasticsearch/plugins/head/src/app/data/metaDataFactory.js b/sdnr/wt/devicemanager/provider/src/main/resources/elasticsearch/plugins/head/src/app/data/metaDataFactory.js deleted file mode 100644 index e5d5cd8de..000000000 --- a/sdnr/wt/devicemanager/provider/src/main/resources/elasticsearch/plugins/head/src/app/data/metaDataFactory.js +++ /dev/null @@ -1,34 +0,0 @@ -/** - * Copyright 2010-2013 Ben Birch - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this software except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -(function( app ) { - - var data = app.ns("data"); - var ux = app.ns("ux"); - - data.MetaDataFactory = ux.Observable.extend({ - defaults: { - cluster: null // (required) an app.services.Cluster - }, - init: function() { - this._super(); - this.config.cluster.get("_cluster/state", function(data) { - this.metaData = new app.data.MetaData({state: data}); - this.fire("ready", this.metaData, { originalData: data }); // TODO originalData needed for legacy ui.FilterBrowser - }.bind(this)); - } - }); - -})( this.app ); diff --git a/sdnr/wt/devicemanager/provider/src/main/resources/elasticsearch/plugins/head/src/app/data/model/model.js b/sdnr/wt/devicemanager/provider/src/main/resources/elasticsearch/plugins/head/src/app/data/model/model.js deleted file mode 100644 index fa468177e..000000000 --- a/sdnr/wt/devicemanager/provider/src/main/resources/elasticsearch/plugins/head/src/app/data/model/model.js +++ /dev/null @@ -1,50 +0,0 @@ -/** - * Copyright 2010-2013 Ben Birch - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this software except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -(function( $, app ) { - - var data = app.ns("data"); - var ux = app.ns("ux"); - - data.Model = ux.Observable.extend({ - defaults: { - data: null - }, - init: function() { - this.set( this.config.data ); - }, - set: function( key, value ) { - if( arguments.length === 1 ) { - this._data = $.extend( {}, key ); - } else { - key.split(".").reduce(function( ptr, prop, i, props) { - if(i === (props.length - 1) ) { - ptr[prop] = value; - } else { - if( !(prop in ptr) ) { - ptr[ prop ] = {}; - } - return ptr[prop]; - } - }, this._data ); - } - }, - get: function( key ) { - return key.split(".").reduce( function( ptr, prop ) { - return ( ptr && ( prop in ptr ) ) ? ptr[ prop ] : undefined; - }, this._data ); - }, - }); -})( this.jQuery, this.app ); diff --git a/sdnr/wt/devicemanager/provider/src/main/resources/elasticsearch/plugins/head/src/app/data/model/modelSpec.js b/sdnr/wt/devicemanager/provider/src/main/resources/elasticsearch/plugins/head/src/app/data/model/modelSpec.js deleted file mode 100644 index 48e24fe3f..000000000 --- a/sdnr/wt/devicemanager/provider/src/main/resources/elasticsearch/plugins/head/src/app/data/model/modelSpec.js +++ /dev/null @@ -1,89 +0,0 @@ -/** - * Copyright 2010-2013 Ben Birch - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this software except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -describe("app.data.Model", function() { - - var Model = window.app.data.Model; - - it("test setting model does a shallow copy", function() { - var test = {}; - var array = [ 1, 2, 3 ]; - var m = new Model({ - data: { - "foo": "bar", - "test": test, - "array": array - } - }); - expect( m.get("foo") ).toBe("bar"); - expect( m.get("array").length ).toBe( 3 ); - expect( m.get("array")[1] ).toBe( 2 ); - expect( m.get("array") ).toBe( array ); - expect( m.get("test") ).toBe( test ); - }); - - it("should replace model with shallow copy when put with no path", function() { - var m = new Model({ foo: "bar" }); - m.set({ bar: "blat" }); - expect( m.get("foo")).toBe( undefined ); - expect( m.get("bar")).toBe("blat"); - }); - - it("test getting values from deep in a model", function() { - var m = new Model({ - data: { - "foo": { - "bar": { - "baz": { - "quix": "abcdefg" - } - } - } - } - }); - - expect( m.get("foo.bar.baz.quix") ).toBe( "abcdefg" ); - }); - - it("test setting non-existant values creates new values", function() { - var m = new Model({ - data: { - "foo": { - "bar": "abc" - } - } - }); - m.set("foo.bar", "123" ); - m.set("foo.baz", "456" ); - expect( m.get("foo.bar") ).toBe( "123" ); - expect( m.get("foo.baz") ).toBe( "456" ); - }); - - it("test setting values deep in a model", function() { - var m = new Model({ - data: { - "foo": { - "bar": "abc" - } - } - }); - m.set("foo.bar", "123" ); - m.set("foo.baz", "456" ); - m.set("foo.something.else.is.here", "xyz" ); - expect( m.get("foo.something.else.is").here ).toBe( "xyz" ); - expect( m.get("foo.something.else.is.here") ).toBe( "xyz" ); - }); - -}); diff --git a/sdnr/wt/devicemanager/provider/src/main/resources/elasticsearch/plugins/head/src/app/data/query.js b/sdnr/wt/devicemanager/provider/src/main/resources/elasticsearch/plugins/head/src/app/data/query.js deleted file mode 100644 index 6b9733c73..000000000 --- a/sdnr/wt/devicemanager/provider/src/main/resources/elasticsearch/plugins/head/src/app/data/query.js +++ /dev/null @@ -1,218 +0,0 @@ -/** - * Copyright 2010-2013 Ben Birch - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this software except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -(function( app ) { - - var data = app.ns("data"); - var ux = app.ns("ux"); - - data.Query = ux.Observable.extend({ - defaults: { - cluster: null, // (required) instanceof app.services.Cluster - size: 50 // size of pages to return - }, - init: function() { - this._super(); - this.cluster = this.config.cluster; - this.refuid = 0; - this.refmap = {}; - this.indices = []; - this.types = []; - this.search = { - query: { bool: { must: [], must_not: [], should: [] } }, - from: 0, - size: this.config.size, - sort: [], - aggs: {}, - version: true - }; - this.defaultClause = this.addClause(); - this.history = [ this.getState() ]; - }, - clone: function() { - var q = new data.Query({ cluster: this.cluster }); - q.restoreState(this.getState()); - for(var uqid in q.refmap) { - q.removeClause(uqid); - } - return q; - }, - getState: function() { - return $.extend(true, {}, { search: this.search, indices: this.indices, types: this.types }); - }, - restoreState: function(state) { - state = $.extend(true, {}, state || this.history[this.history.length - 1]); - this.indices = state.indices; - this.types = state.types; - this.search = state.search; - }, - getData: function() { - return JSON.stringify(this.search); - }, - query: function() { - var state = this.getState(); - this.cluster.post( - (this.indices.join(",") || "_all") + "/" + ( this.types.length ? this.types.join(",") + "/" : "") + "_search", - this.getData(), - function(results) { - if(results === null) { - alert(i18n.text("Query.FailAndUndo")); - this.restoreState(); - return; - } - this.history.push(state); - - this.fire("results", this, results); - }.bind(this)); - }, - loadParents: function(res,metadata){ - //create data for mget - var data = { docs :[] }; - var indexToTypeToParentIds = {}; - res.hits.hits.forEach(function(hit) { - if (typeof hit.fields != "undefined"){ - if (typeof hit.fields._parent != "undefined"){ - var parentType = metadata.indices[hit._index].parents[hit._type]; - if (typeof indexToTypeToParentIds[hit._index] == "undefined"){ - indexToTypeToParentIds[hit._index] = new Object(); - } - if (typeof indexToTypeToParentIds[hit._index][hit._type] == "undefined"){ - indexToTypeToParentIds[hit._index][hit._type] = new Object(); - } - if (typeof indexToTypeToParentIds[hit._index][hit._type][hit.fields._parent] == "undefined"){ - indexToTypeToParentIds[hit._index][hit._type][hit.fields._parent] = null; - data.docs.push({ _index:hit._index, _type:parentType, _id:hit.fields._parent}); - } - } - } - }); - - //load parents - var state = this.getState(); - this.cluster.post("_mget",JSON.stringify(data), - function(results) { - if(results === null) { - alert(i18n.text("Query.FailAndUndo")); - this.restoreState(); - return; - } - this.history.push(state); - var indexToTypeToParentIdToHit = new Object(); - results.docs.forEach(function(doc) { - if (typeof indexToTypeToParentIdToHit[doc._index] == "undefined"){ - indexToTypeToParentIdToHit[doc._index] = new Object(); - } - - if (typeof indexToTypeToParentIdToHit[doc._index][doc._type] == "undefined"){ - indexToTypeToParentIdToHit[doc._index][doc._type] = new Object(); - } - - indexToTypeToParentIdToHit[doc._index][doc._type][doc._id] = doc; - }); - - res.hits.hits.forEach(function(hit) { - if (typeof hit.fields != "undefined"){ - if (typeof hit.fields._parent != "undefined"){ - var parentType = metadata.indices[hit._index].parents[hit._type]; - hit._parent = indexToTypeToParentIdToHit[hit._index][parentType][hit.fields._parent]; - } - } - }); - - this.fire("resultsWithParents", this, res); - }.bind(this)); - }, - setPage: function(page) { - this.search.from = this.config.size * (page - 1); - }, - setSort: function(index, desc) { - var sortd = {}; sortd[index] = { reverse: !!desc }; - this.search.sort.unshift( sortd ); - for(var i = 1; i < this.search.sort.length; i++) { - if(Object.keys(this.search.sort[i])[0] === index) { - this.search.sort.splice(i, 1); - break; - } - } - }, - setIndex: function(index, add) { - if(add) { - if(! this.indices.contains(index)) this.indices.push(index); - } else { - this.indices.remove(index); - } - this.fire("setIndex", this, { index: index, add: !!add }); - }, - setType: function(type, add) { - if(add) { - if(! this.types.contains(type)) this.types.push(type); - } else { - this.types.remove(type); - } - this.fire("setType", this, { type: type, add: !!add }); - }, - addClause: function(value, field, op, bool) { - bool = bool || "should"; - op = op || "match_all"; - field = field || "_all"; - var clause = this._setClause(value, field, op, bool); - var uqid = "q-" + this.refuid++; - this.refmap[uqid] = { clause: clause, value: value, field: field, op: op, bool: bool }; - if(this.search.query.bool.must.length + this.search.query.bool.should.length > 1) { - this.removeClause(this.defaultClause); - } - this.fire("queryChanged", this, { uqid: uqid, search: this.search} ); - return uqid; // returns reference to inner query object to allow fast updating - }, - removeClause: function(uqid) { - var ref = this.refmap[uqid], - bool = this.search.query.bool[ref.bool]; - bool.remove(ref.clause); - if(this.search.query.bool.must.length + this.search.query.bool.should.length === 0) { - this.defaultClause = this.addClause(); - } - }, - addAggs: function(aggs) { - var aggsId = "f-" + this.refuid++; - this.search.aggs[aggsId] = aggs; - this.refmap[aggsId] = { aggsId: aggsId, aggs: aggs }; - return aggsId; - }, - removeAggs: function(aggsId) { - delete this.search.aggs[aggsId]; - delete this.refmap[aggsId]; - }, - _setClause: function(value, field, op, bool) { - var clause = {}, query = {}; - if(op === "match_all") { - } else if(op === "query_string") { - query["default_field"] = field; - query["query"] = value; - } else if(op === "missing") { - op = "constant_score" - var missing = {}, filter = {}; - missing["field"] = field; - filter["missing"] = missing - query["filter"] = filter; - } else { - query[field] = value; - } - clause[op] = query; - this.search.query.bool[bool].push(clause); - return clause; - } - }); - -})( this.app ); diff --git a/sdnr/wt/devicemanager/provider/src/main/resources/elasticsearch/plugins/head/src/app/data/queryDataSourceInterface.js b/sdnr/wt/devicemanager/provider/src/main/resources/elasticsearch/plugins/head/src/app/data/queryDataSourceInterface.js deleted file mode 100644 index 9daf4d0df..000000000 --- a/sdnr/wt/devicemanager/provider/src/main/resources/elasticsearch/plugins/head/src/app/data/queryDataSourceInterface.js +++ /dev/null @@ -1,102 +0,0 @@ -/** - * Copyright 2010-2013 Ben Birch - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this software except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -(function( app ) { - - var data = app.ns("data"); - - data.QueryDataSourceInterface = data.DataSourceInterface.extend({ - defaults: { - metadata: null, // (required) instanceof app.data.MetaData, the cluster metadata - query: null // (required) instanceof app.data.Query the data source - }, - init: function() { - this._super(); - this.config.query.on("results", this._results_handler.bind(this) ); - this.config.query.on("resultsWithParents", this._load_parents.bind(this) ); - }, - _results_handler: function(query, res) { - this._getSummary(res); - this._getMeta(res); - var sort = query.search.sort[0] || { "_score": { reverse: false }}; - var sortField = Object.keys(sort)[0]; - this.sort = { column: sortField, dir: (sort[sortField].reverse ? "asc" : "desc") }; - this._getData(res, this.config.metadata); - this.fire("data", this); - }, - _load_parents: function(query, res) { - query.loadParents(res, this.config.metadata); - }, - _getData: function(res, metadata) { - var metaColumns = ["_index", "_type", "_id", "_score"]; - var columns = this.columns = [].concat(metaColumns); - - this.data = res.hits.hits.map(function(hit) { - var row = (function(path, spec, row) { - for(var prop in spec) { - if(acx.isObject(spec[prop])) { - arguments.callee(path.concat(prop), spec[prop], row); - } else if(acx.isArray(spec[prop])) { - if(spec[prop].length) { - arguments.callee(path.concat(prop), spec[prop][0], row) - } - } else { - var dpath = path.concat(prop).join("."); - if(metadata.paths[dpath]) { - var field_name = metadata.paths[dpath].field_name; - if(! columns.contains(field_name)) { - columns.push(field_name); - } - row[field_name] = (spec[prop] === null ? "null" : spec[prop] ).toString(); - } else { - // TODO: field not in metadata index - } - } - } - return row; - })([ hit._index, hit._type ], hit._source, {}); - metaColumns.forEach(function(n) { row[n] = hit[n]; }); - row._source = hit; - if (typeof hit._parent!= "undefined") { - (function(prefix, path, spec, row) { - for(var prop in spec) { - if(acx.isObject(spec[prop])) { - arguments.callee(prefix, path.concat(prop), spec[prop], row); - } else if(acx.isArray(spec[prop])) { - if(spec[prop].length) { - arguments.callee(prefix, path.concat(prop), spec[prop][0], row) - } - } else { - var dpath = path.concat(prop).join("."); - if(metadata.paths[dpath]) { - var field_name = metadata.paths[dpath].field_name; - var column_name = prefix+"."+field_name; - if(! columns.contains(column_name)) { - columns.push(column_name); - } - row[column_name] = (spec[prop] === null ? "null" : spec[prop] ).toString(); - } else { - // TODO: field not in metadata index - } - } - } - })(hit._parent._type,[hit._parent._index, hit._parent._type], hit._parent._source, row); - } - return row; - }, this); - } - }); - -})( this.app ); diff --git a/sdnr/wt/devicemanager/provider/src/main/resources/elasticsearch/plugins/head/src/app/data/resultDataSourceInterface.js b/sdnr/wt/devicemanager/provider/src/main/resources/elasticsearch/plugins/head/src/app/data/resultDataSourceInterface.js deleted file mode 100644 index 69e585248..000000000 --- a/sdnr/wt/devicemanager/provider/src/main/resources/elasticsearch/plugins/head/src/app/data/resultDataSourceInterface.js +++ /dev/null @@ -1,55 +0,0 @@ -/** - * Copyright 2010-2013 Ben Birch - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this software except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -(function( app ) { - - var data = app.ns("data"); - - data.ResultDataSourceInterface = data.DataSourceInterface.extend({ - results: function(res) { - this._getSummary(res); - this._getMeta(res); - this._getData(res); - this.sort = {}; - this.fire("data", this); - }, - _getData: function(res) { - var columns = this.columns = []; - this.data = res.hits.hits.map(function(hit) { - var row = (function(path, spec, row) { - for(var prop in spec) { - if(acx.isObject(spec[prop])) { - arguments.callee(path.concat(prop), spec[prop], row); - } else if(acx.isArray(spec[prop])) { - if(spec[prop].length) { - arguments.callee(path.concat(prop), spec[prop][0], row) - } - } else { - var dpath = path.concat(prop).join("."); - if(! columns.contains(dpath)) { - columns.push(dpath); - } - row[dpath] = (spec[prop] || "null").toString(); - } - } - return row; - })([ hit._type ], hit, {}); - row._source = hit; - return row; - }, this); - } - }); - -})( this.app ); |