summaryrefslogtreecommitdiffstats
path: root/sdnr/wt/devicemanager/provider/src/main/resources/elasticsearch/plugins/head/src/app/ui/csvTable/csvTable.js
diff options
context:
space:
mode:
Diffstat (limited to 'sdnr/wt/devicemanager/provider/src/main/resources/elasticsearch/plugins/head/src/app/ui/csvTable/csvTable.js')
-rw-r--r--sdnr/wt/devicemanager/provider/src/main/resources/elasticsearch/plugins/head/src/app/ui/csvTable/csvTable.js99
1 files changed, 0 insertions, 99 deletions
diff --git a/sdnr/wt/devicemanager/provider/src/main/resources/elasticsearch/plugins/head/src/app/ui/csvTable/csvTable.js b/sdnr/wt/devicemanager/provider/src/main/resources/elasticsearch/plugins/head/src/app/ui/csvTable/csvTable.js
deleted file mode 100644
index 5482b9629..000000000
--- a/sdnr/wt/devicemanager/provider/src/main/resources/elasticsearch/plugins/head/src/app/ui/csvTable/csvTable.js
+++ /dev/null
@@ -1,99 +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, joey ) {
-
- var ui = app.ns("ui");
-
- var CELL_SEPARATOR = ",";
- var CELL_QUOTE = '"';
- var LINE_SEPARATOR = "\r\n";
-
- ui.CSVTable = ui.AbstractWidget.extend({
- defaults: {
- results: null
- },
- _baseCls: "uiCSVTable",
- init: function( parent ) {
- this._super();
- var results = this.config.results.hits.hits;
- var columns = this._parseResults( results );
- this._downloadButton = new ui.Button({
- label: "Generate Download Link",
- onclick: this._downloadLinkGenerator_handler
- });
- this._downloadLink = $.joey( { tag: "A", text: "download", });
- this._downloadLink.hide();
- this._csvText = this._csv_template( columns, results );
- this.el = $.joey( this._main_template() );
- this.attach( parent );
- },
- _downloadLinkGenerator_handler: function() {
- var csvData = new Blob( [ this._csvText ], { type: 'text/csv' });
- var csvURL = URL.createObjectURL( csvData );
- this._downloadLink.attr( "href", csvURL );
- this._downloadLink.show();
- },
- _parseResults: function( results ) {
- var columnPaths = {};
- (function parse( path, obj ) {
- if( obj instanceof Array ) {
- for( var i = 0; i < obj.length; i++ ) {
- parse( path, obj[i] );
- }
- } else if( typeof obj === "object" ) {
- for( var prop in obj ) {
- parse( path + "." + prop, obj[ prop ] );
- }
- } else {
- columnPaths[ path ] = true;
- }
- })( "root", results );
- var columns = [];
- for( var column in columnPaths ) {
- columns.push( column.split(".").slice(1) );
- }
- return columns;
- },
- _main_template: function() { return (
- { tag: "DIV", cls: this._baseCls, id: this.id(), children: [
- this._downloadButton,
- this._downloadLink,
- { tag: "PRE", text: this._csvText }
- ] }
- ); },
- _csv_template: function( columns, results ) {
- return this._header_template( columns ) + LINE_SEPARATOR + this._results_template( columns, results );
- },
- _header_template: function( columns ) {
- return columns.map( function( column ) {
- return column.join(".");
- }).join( CELL_SEPARATOR );
- },
- _results_template: function( columns, results ) {
- return results.map( function( result ) {
- return columns.map( function( column ) {
- var l = 0,
- ptr = result;
- while( l !== column.length && ptr != null ) {
- ptr = ptr[ column[ l++ ] ];
- }
- return ( ptr == null ) ? "" : ( CELL_QUOTE + ptr.toString().replace(/"/g, '""') + CELL_QUOTE );
- }).join( CELL_SEPARATOR );
- }).join( LINE_SEPARATOR );
- }
- });
-
-})( this.jQuery, this.app, this.joey );