Added: ofbiz/trunk/specialpurpose/solr/webapp/solr/js/scripts/dashboard.js
URL: http://svn.apache.org/viewvc/ofbiz/trunk/specialpurpose/solr/webapp/solr/js/scripts/dashboard.js?rev=1700119&view=auto ============================================================================== --- ofbiz/trunk/specialpurpose/solr/webapp/solr/js/scripts/dashboard.js (added) +++ ofbiz/trunk/specialpurpose/solr/webapp/solr/js/scripts/dashboard.js Sun Aug 30 13:27:07 2015 @@ -0,0 +1,562 @@ +/* + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file 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. +*/ + +var set_healthcheck_status = function( status ) +{ + var hc_button = $( '.healthcheck-status' ) + if ( status == 'enable' ) + { + hc_button.parents( 'dd' ) + .removeClass( 'ico-0' ) + .addClass( 'ico-1' ); + hc_button + .addClass( 'enabled' ) + .html( 'disable ping' ); + } else { + hc_button.parents( 'dd' ) + .removeClass( 'ico-1') + .addClass( 'ico-0' ); + hc_button + .removeClass( 'enabled' ) + .html( 'enable ping' ); + } +}; + +// #/:core +sammy.get +( + new RegExp( app.core_regex_base + '$' ), + function( context ) + { + var core_basepath = this.active_core.attr( 'data-basepath' ); + var content_element = $( '#content' ); + + content_element + .removeClass( 'single' ); + + if( !app.core_menu.data( 'admin-extra-loaded' ) ) + { + app.core_menu.data( 'admin-extra-loaded', new Date() ); + + $.get + ( + core_basepath + '/admin/file/?file=admin-extra.menu-top.html&contentType=text/html;charset=utf-8', + function( menu_extra ) + { + app.core_menu + .prepend( menu_extra ); + } + ); + + $.get + ( + core_basepath + '/admin/file/?file=admin-extra.menu-bottom.html&contentType=text/html;charset=utf-8', + function( menu_extra ) + { + app.core_menu + .append( menu_extra ); + } + ); + } + + $.get + ( + 'tpl/dashboard.html', + function( template ) + { + content_element + .html( template ); + + var dashboard_element = $( '#dashboard' ); + + $.ajax + ( + { + url : core_basepath + '/admin/luke?wt=json&show=index&numTerms=0', + dataType : 'json', + context : $( '#statistics', dashboard_element ), + beforeSend : function( xhr, settings ) + { + $( 'h2', this ) + .addClass( 'loader' ); + + $( '.message', this ) + .show() + .html( 'Loading ...' ); + + $( '.content', this ) + .hide(); + }, + success : function( response, text_status, xhr ) + { + $( '.message', this ) + .empty() + .hide(); + + $( '.content', this ) + .show(); + + var data = { + 'index_num-docs' : response['index']['numDocs'], + 'index_heap-usage-bytes' : response['index']['indexHeapUsageBytes'], + 'index_max-doc' : response['index']['maxDoc'], + 'index_deleted-docs' : response['index']['deletedDocs'], + 'index_version' : response['index']['version'], + 'index_segmentCount' : response['index']['segmentCount'], + 'index_last-modified' : response['index']['lastModified'] + }; + + for( var key in data ) + { + $( '.' + key, this ) + .show(); + + $( '.value.' + key, this ) + .html( data[key] ); + } + + var optimized_element = $( '.value.index_optimized', this ); + if( !response['index']['hasDeletions'] ) + { + optimized_element + .addClass( 'ico-1' ); + + $( 'span', optimized_element ) + .html( 'yes' ); + } + else + { + optimized_element + .addClass( 'ico-0' ); + + $( 'span', optimized_element ) + .html( 'no' ); + } + + var current_element = $( '.value.index_current', this ); + if( response['index']['current'] ) + { + current_element + .addClass( 'ico-1' ); + + $( 'span', current_element ) + .html( 'yes' ); + } + else + { + current_element + .addClass( 'ico-0' ); + + $( 'span', current_element ) + .html( 'no' ); + } + + $( 'a', optimized_element ) + .die( 'click' ) + .live + ( + 'click', + function( event ) + { + $.ajax + ( + { + url : core_basepath + '/update?optimize=true&waitFlush=true&wt=json', + dataType : 'json', + context : $( this ), + beforeSend : function( xhr, settings ) + { + this + .addClass( 'loader' ); + }, + success : function( response, text_status, xhr ) + { + this.parents( 'dd' ) + .removeClass( 'ico-0' ) + .addClass( 'ico-1' ); + }, + error : function( xhr, text_status, error_thrown) + { + console.warn( 'd0h, optimize broken!' ); + }, + complete : function( xhr, text_status ) + { + this + .removeClass( 'loader' ); + } + } + ); + } + ); + + $( '.timeago', this ) + .timeago(); + }, + error : function( xhr, text_status, error_thrown ) + { + this + .addClass( 'disabled' ); + + $( '.message', this ) + .show() + .html( 'Luke is not configured' ); + }, + complete : function( xhr, text_status ) + { + $( 'h2', this ) + .removeClass( 'loader' ); + } + } + ); + + $.ajax + ( + { + url : core_basepath + '/replication?command=details&wt=json', + dataType : 'json', + context : $( '#replication', dashboard_element ), + beforeSend : function( xhr, settings ) + { + $( 'h2', this ) + .addClass( 'loader' ); + + $( '.message', this ) + .show() + .html( 'Loading' ); + + $( '.content', this ) + .hide(); + }, + success : function( response, text_status, xhr ) + { + $( '.message', this ) + .empty() + .hide(); + + $( '.content', this ) + .show(); + + $( '.replication', context.active_core ) + .show(); + + var data = response.details; + var is_slave = 'undefined' !== typeof( data.slave ); + var headline = $( 'h2 span', this ); + var details_element = $( '#details', this ); + var current_type_element = $( ( is_slave ? '.slave' : '.masterSearch' ), this ); + var master_data = is_slave ? data.slave.masterDetails : data; + + if( is_slave ) + { + this + .addClass( 'slave' ); + + headline + .html( headline.html() + ' (Slave)' ); + } + else + { + this + .addClass( 'master' ); + + headline + .html( headline.html() + ' (Master)' ); + } + + // the currently searchable commit regardless of type + $( '.version div', current_type_element ) + .html( data.indexVersion ); + $( '.generation div', current_type_element ) + .html( data.generation ); + $( '.size div', current_type_element ) + .html( data.indexSize ); + + // what's replicable on the master + var master_element = $( '.master', details_element ); + $( '.version div', master_element ) + .html( master_data.master.replicableVersion || '-' ); + $( '.generation div', master_element ) + .html( master_data.master.replicableGeneration || '-' ); + $( '.size div', master_element ) + .html( "-" ); + + if( is_slave ) + { + var master_element = $( '.masterSearch', details_element ); + $( '.version div', master_element ) + .html( data.slave.masterDetails.indexVersion ); + $( '.generation div', master_element ) + .html( data.slave.masterDetails.generation ); + $( '.size div', master_element ) + .html( data.slave.masterDetails.indexSize ); + + // warnings if slave version|gen doesn't match what's replicable + if( data.indexVersion !== master_data.master.replicableVersion ) + { + $( '.version', details_element ) + .addClass( 'diff' ); + } + else + { + $( '.version', details_element ) + .removeClass( 'diff' ); + } + + if( data.generation !== master_data.master.replicableGeneration ) + { + $( '.generation', details_element ) + .addClass( 'diff' ); + } + else + { + $( '.generation', details_element ) + .removeClass( 'diff' ); + } + } + }, + error : function( xhr, text_status, error_thrown) + { + this + .addClass( 'disabled' ); + + $( '.message', this ) + .show() + .html( 'Replication is not configured' ); + }, + complete : function( xhr, text_status ) + { + $( 'h2', this ) + .removeClass( 'loader' ); + } + } + ); + + $.ajax + ( + { + url : core_basepath + '/admin/system?wt=json', + dataType : 'json', + context : $( '#instance', dashboard_element ), + beforeSend : function( xhr, settings ) + { + $( 'h2', this ) + .addClass( 'loader' ); + + $( '.message', this ) + .show() + .html( 'Loading' ); + + $( '.content', this ) + .hide(); + }, + success : function( response, text_status, xhr ) + { + $( '.message', this ) + .empty() + .hide(); + + $( '.content', this ) + .show(); + + $( 'dl', this ) + .show(); + + var data = { + 'dir_cwd' : response.core.directory.cwd, + 'dir_instance' : response.core.directory.instance, + 'dir_data' : response.core.directory.data, + 'dir_index' : response.core.directory.index, + 'dir_impl' : response.core.directory.dirimpl + }; + + for( var key in data ) + { + $( '.' + key, this ) + .show(); + + $( '.value.' + key, this ) + .html( data[key] ); + } + }, + error : function( xhr, text_status, error_thrown) + { + this + .addClass( 'disabled' ); + + $( '.message', this ) + .show() + .html( '/admin/system Handler is not configured' ); + }, + complete : function( xhr, text_status ) + { + $( 'h2', this ) + .removeClass( 'loader' ); + } + } + ); + + $.ajax + ( + { + url : core_basepath + '/admin/file/?file=admin-extra.html', + dataType : 'html', + context : $( '#admin-extra', dashboard_element ), + beforeSend : function( xhr, settings ) + { + $( 'h2', this ) + .addClass( 'loader' ); + + $( '.message', this ) + .show() + .html( 'Loading' ); + + $( '.content', this ) + .hide(); + }, + success : function( response, text_status, xhr ) + { + $( '.message', this ) + .hide() + .empty(); + + $( '.content', this ) + .show() + .html( response ); + }, + error : function( xhr, text_status, error_thrown) + { + this + .addClass( 'disabled' ); + + $( '.message', this ) + .show() + .html( 'We found no "admin-extra.html" file.' ); + }, + complete : function( xhr, text_status ) + { + $( 'h2', this ) + .removeClass( 'loader' ); + } + } + ); + + $.ajax + ( + { + url : core_basepath + '/admin/ping?action=status&wt=json', + dataType : 'json', + context : $( '#healthcheck', dashboard_element ), + beforeSend : function( xhr, settings ) + { + $( 'h2', this ) + .addClass( 'loader' ); + + $( '.message', this ) + .show() + .html( 'Loading' ); + + $( '.content', this ) + .hide(); + }, + success : function( response, text_status, xhr ) + { + $( '.message', this ) + .empty() + .hide(); + + $( '.content', this ) + .show(); + + var status_element = $( '.value.status', this ); + var toggle_button = $( '.healthcheck-status', this ); + var status = response['status']; + $( 'span', status_element ).html( status ); + + var action = ( response['status'] == 'enabled' ) ? 'enable' : 'disable'; + set_healthcheck_status(action); + + if( response['status'] == 'enabled' ) + { + status_element + .addClass( 'ico-1' ); + toggle_button + .addClass( 'enabled' ); + } + else + { + status_element + .addClass( 'ico-0' ); + } + + $( '.healthcheck-status', status_element ) + .die( 'click' ) + .live + ( + 'click', + function( event ) + { + var action = $(this).hasClass( 'enabled' ) ? 'disable' : 'enable'; + $.ajax + ( + { + url : core_basepath + '/admin/ping?action=' + action + '&wt=json', + dataType : 'json', + context : $( this ), + beforeSend : function( xhr, settings ) + { + this + .addClass( 'loader' ); + }, + success : function( response, text_status, xhr ) + { + set_healthcheck_status(action); + }, + error : function( xhr, text_status, error_thrown) + { + console.warn( 'd0h, enable broken!' ); + }, + complete : function( xhr, text_status ) + { + this + .removeClass( 'loader' ); + } + } + ); + } + ); + }, + error : function( xhr, text_status, error_thrown) + { + this + .addClass( 'disabled' ); + + $( '.message', this ) + .show() + .html( 'Ping request handler is not configured with a healthcheck file.' ); + }, + complete : function( xhr, text_status ) + { + $( 'h2', this ) + .removeClass( 'loader' ); + } + } + ); + + } + ); + } +); Propchange: ofbiz/trunk/specialpurpose/solr/webapp/solr/js/scripts/dashboard.js ------------------------------------------------------------------------------ svn:eol-style = native Propchange: ofbiz/trunk/specialpurpose/solr/webapp/solr/js/scripts/dashboard.js ------------------------------------------------------------------------------ svn:keywords = Date Rev Author URL Id Propchange: ofbiz/trunk/specialpurpose/solr/webapp/solr/js/scripts/dashboard.js ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: ofbiz/trunk/specialpurpose/solr/webapp/solr/js/scripts/dataimport.js URL: http://svn.apache.org/viewvc/ofbiz/trunk/specialpurpose/solr/webapp/solr/js/scripts/dataimport.js?rev=1700119&view=auto ============================================================================== --- ofbiz/trunk/specialpurpose/solr/webapp/solr/js/scripts/dataimport.js (added) +++ ofbiz/trunk/specialpurpose/solr/webapp/solr/js/scripts/dataimport.js Sun Aug 30 13:27:07 2015 @@ -0,0 +1,812 @@ +/* + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file 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. +*/ + +var dataimport_timeout = 2000; +var cookie_dataimport_autorefresh = 'dataimport_autorefresh'; + +sammy.bind +( + 'dataimport_queryhandler_load', + function( event, params ) + { + var core_basepath = params.active_core.attr( 'data-basepath' ); + + $.ajax + ( + { + url : core_basepath + '/admin/mbeans?cat=QUERYHANDLER&wt=json', + dataType : 'json', + beforeSend : function( xhr, settings ) + { + }, + success : function( response, text_status, xhr ) + { + var handlers = response['solr-mbeans'][1]; + var dataimport_handlers = []; + for( var key in handlers ) + { + if( handlers[key]['class'] !== key && + handlers[key]['class'] === 'org.apache.solr.handler.dataimport.DataImportHandler' ) + { + dataimport_handlers.push( key ); + } + } + params.callback( dataimport_handlers ); + }, + error : function( xhr, text_status, error_thrown) + { + }, + complete : function( xhr, text_status ) + { + } + } + ); + } +); + +// #/:core/dataimport +sammy.get +( + new RegExp( app.core_regex_base + '\\/(dataimport)$' ), + function( context ) + { + sammy.trigger + ( + 'dataimport_queryhandler_load', + { + active_core : this.active_core, + callback : function( dataimport_handlers ) + { + if( 0 === dataimport_handlers.length ) + { + $( '#content' ) + .html( 'sorry, no dataimport-handler defined!' ); + + return false; + } + + context.redirect( context.path + '/' + dataimport_handlers[0] ); + } + } + ); + } +); + +// #/:core/dataimport +sammy.get +( + new RegExp( app.core_regex_base + '\\/(dataimport)\\/' ), + function( context ) + { + var core_basepath = this.active_core.attr( 'data-basepath' ); + var content_element = $( '#content' ); + + var path_parts = this.path.match( /^(.+\/dataimport\/)(.*)$/ ); + var handler_url = core_basepath + path_parts[2]; + + $( 'li.dataimport', this.active_core ) + .addClass( 'active' ); + + $.get + ( + 'tpl/dataimport.html', + function( template ) + { + content_element + .html( template ); + + var dataimport_element = $( '#dataimport', content_element ); + var form_element = $( '#form', dataimport_element ); + var config_element = $( '#config', dataimport_element ); + var error_element = $( '#error', dataimport_element ); + var debug_response_element = $( '#debug_response', dataimport_element ); + + var autorefresh_status = false; + var debug_mode = false; + + // handler + + sammy.trigger + ( + 'dataimport_queryhandler_load', + { + active_core : context.active_core, + callback : function( dataimport_handlers ) + { + var handlers_element = $( '#navigation ul', form_element ); + var handlers = []; + + for( var i = 0; i < dataimport_handlers.length; i++ ) + { + handlers.push + ( + '<li><a href="' + path_parts[1] + dataimport_handlers[i] + '">' + + dataimport_handlers[i] + + '</a></li>' + ); + } + + $( handlers_element ) + .html( handlers.join( "\n") ) ; + + $( 'a[href="' + context.path + '"]', handlers_element ).closest( 'li' ) + .addClass( 'current' ); + + $( 'form', form_element ) + .show(); + } + } + ); + + // config + + function dataimport_fetch_config() + { + $.ajax + ( + { + url : handler_url + '?command=show-config&indent=true', + dataType : 'xml', + context : $( '#dataimport_config', config_element ), + beforeSend : function( xhr, settings ) + { + error_element + .empty() + .hide(); + }, + success : function( config, text_status, xhr ) + { + dataimport_element + .removeClass( 'error' ); + + config_element + .addClass( 'hidden' ); + + var entities = [ '<option value=""></option>' ]; + + $( 'document > entity', config ) + .each + ( + function( i, element ) + { + entities.push( '<option>' + $( element ).attr( 'name' ).esc() + '</option>' ); + } + ); + + $( '#entity', form_element ) + .html( entities.join( "\n" ) ); + + $( '.editable textarea', this ) + .val( xhr.responseText.replace( /\n+$/, '' ) ); + }, + error : function( xhr, text_status, error_thrown ) + { + if( 'parsererror' === error_thrown ) + { + dataimport_element + .addClass( 'error' ); + + error_element + .text( 'Dataimport XML-Configuration is not valid' ) + .show(); + + config_element + .removeClass( 'hidden' ); + } + }, + complete : function( xhr, text_status ) + { + var code = $( + '<pre class="syntax language-xml"><code>' + + xhr.responseText.esc() + + '</code></pre>' + ); + $( '.formatted', this ).html( code ); + + if( 'success' === text_status ) + { + hljs.highlightBlock( code.get(0) ); + } + } + } + ); + } + dataimport_fetch_config(); + + $( '.block .toggle', dataimport_element ) + .die( 'click' ) + .live + ( + 'click', + function( event ) + { + $( this ).parents( '.block' ) + .toggleClass( 'hidden' ); + + return false; + } + ) + + var reload_config_element = $( '.reload_config', config_element ); + reload_config_element + .die( 'click' ) + .live + ( + 'click', + function( event ) + { + $.ajax + ( + { + url : handler_url + '?command=reload-config', + dataType : 'xml', + context: $( this ), + beforeSend : function( xhr, settings ) + { + this + .removeClass( 'error' ) + .addClass( 'loader' ); + }, + success : function( response, text_status, xhr ) + { + this + .addClass( 'success' ); + + window.setTimeout + ( + function() + { + reload_config_element + .removeClass( 'success' ); + }, + 5000 + ); + }, + error : function( xhr, text_status, error_thrown ) + { + this + .addClass( 'error' ); + }, + complete : function( xhr, text_status ) + { + this + .removeClass( 'loader' ); + + dataimport_fetch_config(); + } + } + ); + return false; + } + ); + + var debug_mode_element = $( '.debug_mode', config_element ); + debug_mode_element + .die( 'click' ) + .live + ( + 'click', + function( event ) + { + var self = $( this ); + var block = self.closest( '.block' ) + + var debug_checkbox = $( 'input[name="debug"]', form_element ); + var submit_span = $( 'button[type="submit"] span', form_element ); + + debug_mode = !debug_mode; + + block.toggleClass( 'debug_mode', debug_mode ); + + if( debug_mode ) + { + block.removeClass( 'hidden' ); + + debug_checkbox + .attr( 'checked', 'checked' ) + .trigger( 'change' ); + + submit_span + .data( 'original', submit_span.text() ) + .text( submit_span.data( 'debugmode' ) ); + } + else + { + submit_span + .text( submit_span.data( 'original' ) ) + .removeData( 'original' ); + } + } + ); + + // abort + + var abort_import_element = $( '.abort-import', dataimport_element ); + abort_import_element + .off( 'click' ) + .on + ( + 'click', + function( event ) + { + var span_element = $( 'span', this ); + + $.ajax + ( + { + url : handler_url + '?command=abort&wt=json', + dataType : 'json', + type: 'POST', + context: $( this ), + beforeSend : function( xhr, settings ) + { + span_element + .addClass( 'loader' ); + }, + success : function( response, text_status, xhr ) + { + span_element + .data( 'original', span_element.text() ) + .text( span_element.data( 'aborting' ) ); + + this + .removeClass( 'warn' ) + .addClass( 'success' ); + + window.setTimeout + ( + function() + { + $( 'span', abort_import_element ) + .removeClass( 'loader' ) + .text( span_element.data( 'original' ) ) + .removeData( 'original' ); + + abort_import_element + .removeClass( 'success' ) + .addClass( 'warn' ); + }, + dataimport_timeout * 2 + ); + + dataimport_fetch_status(); + } + } + ); + return false; + } + ); + + // state + + var status_button = $( 'form button.refresh-status', form_element ); + + status_button + .off( 'click' ) + .on + ( + 'click', + function( event ) + { + dataimport_fetch_status(); + return false; + } + ) + .trigger( 'click' ); + + function dataimport_fetch_status( clear_timeout ) + { + if( clear_timeout ) + { + app.clear_timeout(); + } + + $.ajax + ( + { + url : handler_url + '?command=status&indent=true&wt=json', + dataType : 'json', + beforeSend : function( xhr, settings ) + { + $( 'span', status_button ) + .addClass( 'loader' ); + }, + success : function( response, text_status, xhr ) + { + var state_element = $( '#current_state', content_element ); + + var status = response.status; + var rollback_time = response.statusMessages.Rolledback || null; + var abort_time = response.statusMessages.Aborted || null; + + var messages = response.statusMessages; + var messages_count = 0; + for( var key in messages ) { messages_count++; } + + function dataimport_compute_details( response, details_element, elapsed_seconds ) + { + details_element + .show(); + + // -- + + var document_config = { + 'Requests' : 'Total Requests made to DataSource', + 'Fetched' : 'Total Rows Fetched', + 'Skipped' : 'Total Documents Skipped', + 'Processed' : 'Total Documents Processed' + }; + + var document_details = []; + for( var key in document_config ) + { + var value = parseInt( response.statusMessages[document_config[key]], 10 ); + + var detail = '<abbr title="' + document_config[key].esc() + '">' + key.esc() + '</abbr>: ' + app.format_number( value ).esc(); + if( elapsed_seconds && 'skipped' !== key.toLowerCase() ) + { + detail += ' <span>(' + app.format_number( Math.round( value / elapsed_seconds ) ).esc() + '/s)</span>' + } + + document_details.push( detail ); + }; + + $( '.docs', details_element ) + .html( document_details.join( ', ' ) ); + + // -- + + var dates_config = { + 'Started' : 'Full Dump Started', + 'Aborted' : 'Aborted', + 'Rolledback' : 'Rolledback' + }; + + var dates_details = []; + for( var key in dates_config ) + { + var value = response.statusMessages[dates_config[key]]; + + if( value ) + { + var detail = '<abbr title="' + dates_config[key].esc() + '">' + key.esc() + '</abbr>: ' + + '<abbr class="time">' + value.esc() + '</abbr>'; + dates_details.push( detail ); + } + }; + + var dates_element = $( '.dates', details_element ); + + dates_element + .html( dates_details.join( ', ' ) ); + + $( '.time', dates_element ) + .removeData( 'timeago' ) + .timeago(); + }; + + var get_time_taken = function get_default_time_taken() + { + var time_taken_text = response.statusMessages['Time taken']; + return app.convert_duration_to_seconds( time_taken_text ); + }; + + var get_default_info_text = function default_info_text() + { + var info_text = response.statusMessages[''] || ''; + + // format numbers included in status nicely + info_text = info_text.replace + ( + /\d{4,}/g, + function( match, position, string ) + { + return app.format_number( parseInt( match, 10 ) ); + } + ); + + var time_taken_text = app.convert_seconds_to_readable_time( get_time_taken() ); + if( time_taken_text ) + { + info_text += ' (Duration: ' + time_taken_text.esc() + ')'; + } + + return info_text; + }; + + var show_info = function show_info( info_text, elapsed_seconds ) + { + $( '.info strong', state_element ) + .text( info_text || get_default_info_text() ); + + $( '.info .details', state_element ) + .hide(); + }; + + var show_full_info = function show_full_info( info_text, elapsed_seconds ) + { + show_info( info_text, elapsed_seconds ); + + dataimport_compute_details + ( + response, + $( '.info .details', state_element ), + elapsed_seconds || get_time_taken() + ); + }; + + state_element + .removeAttr( 'class' ); + + var current_time = new Date(); + $( '.last_update abbr', state_element ) + .text( current_time.toTimeString().split( ' ' ).shift() ) + .attr( 'title', current_time.toUTCString() ); + + $( '.info', state_element ) + .removeClass( 'loader' ); + + if( 'busy' === status ) + { + state_element + .addClass( 'indexing' ); + + if( autorefresh_status ) + { + $( '.info', state_element ) + .addClass( 'loader' ); + } + + var time_elapsed_text = response.statusMessages['Time Elapsed']; + var elapsed_seconds = app.convert_duration_to_seconds( time_elapsed_text ); + time_elapsed_text = app.convert_seconds_to_readable_time( elapsed_seconds ); + + var info_text = time_elapsed_text + ? 'Indexing since ' + time_elapsed_text + : 'Indexing ...'; + + show_full_info( info_text, elapsed_seconds ); + } + else if( rollback_time ) + { + state_element + .addClass( 'failure' ); + + show_full_info(); + } + else if( abort_time ) + { + state_element + .addClass( 'aborted' ); + + show_full_info( 'Aborting current Import ...' ); + } + else if( 'idle' === status && 0 !== messages_count ) + { + state_element + .addClass( 'success' ); + + show_full_info(); + } + else + { + state_element + .addClass( 'idle' ); + + show_info( 'No information available (idle)' ); + } + + // show raw status + + var code = $( + '<pre class="syntax language-json"><code>' + + app.format_json( xhr.responseText ).esc() + + '</code></pre>' + ); + + $( '#raw_output_container', content_element ).html( code ); + hljs.highlightBlock( code.get(0) ); + + if( !app.timeout && autorefresh_status ) + { + app.timeout = window.setTimeout + ( + function() + { + dataimport_fetch_status( true ) + }, + dataimport_timeout + ); + } + }, + error : function( xhr, text_status, error_thrown ) + { + console.debug( arguments ); + + reload_config_element + .addClass( 'error' ); + }, + complete : function( xhr, text_status ) + { + $( 'span', status_button ) + .removeClass( 'loader' ) + .addClass( 'success' ); + + window.setTimeout + ( + function() + { + $( 'span', status_button ) + .removeClass( 'success' ); + }, + dataimport_timeout / 2 + ); + } + } + ); + } + + // form + + var form = $( 'form', form_element ); + + form + .ajaxForm + ( + { + url : handler_url, + data : { + wt : 'json', + indent : 'true' + }, + dataType : 'json', + type: 'POST', + beforeSend : function( xhr, settings ) + { + $( 'button[type="submit"] span', form_element ) + .addClass( 'loader' ); + + error_element + .empty() + .hide(); + }, + beforeSubmit : function( array, form, options ) + { + var entity = $( '#entity', form ).val(); + if( entity.length ) + { + array.push( { name : 'entity', value: entity } ); + } + + var start = parseInt( $( '#start', form ).val(), 10 ); + if( start ) + { + array.push( { name : 'start', value: start } ); + } + + var rows = parseInt( $( '#rows', form ).val(), 10 ); + if( rows ) + { + array.push( { name : 'rows', value: rows } ); + } + + $( 'input:checkbox', form ).not( ':checked' ) + .each( function( i, input ) + { + array.push( { name: input.name, value: 'false' } ); + } + ); + + var custom_parameters = $( '#custom_parameters', form ).val(); + if( custom_parameters.length ) + { + var params = custom_parameters.split( '&' ); + for( var i in params ) + { + var tmp = params[i].split( '=' ); + array.push( { name : tmp[0], value: tmp[1] } ); + } + } + + if( debug_mode ) + { + array.push( { name: 'dataConfig', value: $( '#dataimport_config .editable textarea' ).val() } ); + } + }, + success : function( response, text_status, xhr ) + { + }, + error : function( xhr, text_status, error_thrown ) + { + var response = null; + try + { + eval( 'response = ' + xhr.responseText + ';' ); + } + catch( e ){} + + error_element + .text( response.error.msg || 'Unknown Error (Exception w/o Message)' ) + .show(); + }, + complete : function( xhr, text_status ) + { + $( 'button[type="submit"] span', form_element ) + .removeClass( 'loader' ); + + var debug = $( 'input[name="debug"]:checked', form ); + if( 0 !== debug.size() ) + { + var code = $( + '<pre class="syntax language-json"><code>' + + app.format_json( xhr.responseText ).esc() + + '</code></pre>' + ); + + $( '.content', debug_response_element ).html( code ); + hljs.highlightBlock( code.get(0) ); + } + + dataimport_fetch_status(); + } + } + ); + + $( 'input[name="debug"]', form ) + .off( 'change' ) + .on + ( + 'change', + function( event ) + { + debug_response_element.toggle( this.checked ); + } + ); + + $( '#auto-refresh-status a', form_element ) + .off( 'click' ) + .on + ( + 'click', + function( event ) + { + $.cookie( cookie_dataimport_autorefresh, $.cookie( cookie_dataimport_autorefresh ) ? null : true ); + $( this ).trigger( 'state' ); + + dataimport_fetch_status(); + + return false; + } + ) + .off( 'state' ) + .on + ( + 'state', + function( event ) + { + autorefresh_status = !!$.cookie( cookie_dataimport_autorefresh ); + + $.cookie( cookie_dataimport_autorefresh ) + ? $( this ).addClass( 'on' ) + : $( this ).removeClass( 'on' ); + } + ) + .trigger( 'state' ); + } + ); + } +); Propchange: ofbiz/trunk/specialpurpose/solr/webapp/solr/js/scripts/dataimport.js ------------------------------------------------------------------------------ svn:eol-style = native Propchange: ofbiz/trunk/specialpurpose/solr/webapp/solr/js/scripts/dataimport.js ------------------------------------------------------------------------------ svn:keywords = Date Rev Author URL Id Propchange: ofbiz/trunk/specialpurpose/solr/webapp/solr/js/scripts/dataimport.js ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: ofbiz/trunk/specialpurpose/solr/webapp/solr/js/scripts/documents.js URL: http://svn.apache.org/viewvc/ofbiz/trunk/specialpurpose/solr/webapp/solr/js/scripts/documents.js?rev=1700119&view=auto ============================================================================== --- ofbiz/trunk/specialpurpose/solr/webapp/solr/js/scripts/documents.js (added) +++ ofbiz/trunk/specialpurpose/solr/webapp/solr/js/scripts/documents.js Sun Aug 30 13:27:07 2015 @@ -0,0 +1,370 @@ +/* + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file 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. + */ +//helper for formatting JSON and others +var content_generator = { + + _default: function (toEsc) { + return toEsc.esc(); + }, + + json: function (toEsc) { + return app.format_json(toEsc); + } + +}; + +//Utiltity function for turning on/off various elements +function toggles(documents_form, show_json, show_file, show_doc, doc_text, show_wizard) { + var json_only = $('#json-only'); + var the_document = $('#document', documents_form); + if (show_doc) { + //console.log("doc: " + doc_text); + the_document.val(doc_text); + the_document.show(); + } else { + the_document.hide(); + } + if (show_json) { + json_only.show(); + } else { + json_only.hide(); + } + var file_upload = $('#file-upload', documents_form); + var upload_only = $('#upload-only', documents_form); + if (show_file) { + file_upload.show(); + upload_only.show(); + } else { + file_upload.hide(); + upload_only.hide(); + } + var wizard = $('#wizard', documents_form); + if (show_wizard) { + wizard.show(); + } else { + wizard.hide(); + } +} +// #/:core/documents + +//Utiltity function for setting up the wizard fields +function addWizardFields(active_core, wizard) { + var core_basepath = active_core.attr('data-basepath'); + var select_options = ""; + //Populate the select options based off the Fields REST API + $.getJSON(window.location.protocol + '//' + window.location.host + + core_basepath + "/schema/fields").done( + //TODO: handle dynamic fields + //TODO: get the unique key, too + function (data) { + var field_select = $("#wiz-field-select", wizard); + field_select.empty(); + $.each(data.fields, + function (i, item) { + //console.log("i[" + i + "]=" + item.name); + if (item.name != "_version_"){ + select_options += '<option name="' + item.name + '">' + + item.name + '</option>'; + } + }); + //console.log("select_options: " + select_options); + //fill in the select options + field_select.append(select_options); + }); + var wizard_doc = $("#wizard-doc", wizard); + wizard_doc.die('focusin') + .live('focusin', function (event) { + $("#wizard-doc", wizard).text(""); + } + ); + //Add the click handler for the "Add Field" target, which + //takes the field content and moves it into the document target + var add_field = $("#add-field-href", wizard); + add_field.die("click") + .live("click", + function (event) { + //take the field and the contents and append it to the document + var wiz_select = $("#wiz-field-select", wizard); + var selected = $("option:selected", wiz_select); + console.log("selected field: " + selected); + var wiz_doc = $("#wizard-doc", wizard); + var the_document = $("#document"); + var current_doc = the_document.val(); + console.log("current_text: " + current_doc + " wiz_doc: " + wiz_doc.val()); + var index = current_doc.lastIndexOf("}"); + var new_entry = '"' + selected.val() + '":"' + wiz_doc.val() + '"'; + if (index >= 0) { + current_doc = current_doc.substring(0, index) + ', ' + new_entry + "}"; + } else { + //we don't have a doc at all + current_doc = "{" + new_entry + "}"; + } + current_doc = content_generator['json'](current_doc); + the_document.val(current_doc); + //clear the wiz doc window + wiz_doc.val(""); + return false; + } + ); + + //console.log("adding " + i + " child: " + child); + +} + +//The main program for adding the docs +sammy.get +( + new RegExp(app.core_regex_base + '\\/(documents)$'), + function (context) { + var active_core = this.active_core; + var core_basepath = active_core.attr('data-basepath'); + var content_element = $('#content'); + + + $.post + ( + 'tpl/documents.html', + function (template) { + + content_element + .html(template); + var documents_element = $('#documents', content_element); + var documents_form = $('#form form', documents_element); + var url_element = $('#url', documents_element); + var result_element = $('#result', documents_element); + var response_element = $('#response', documents_element); + var doc_type_select = $('#document-type', documents_form); + //Since we are showing "example" docs, when the area receives the focus + // remove the example content. + $('#document', documents_form).die('focusin') + .live('focusin', + function (event) { + var document_type = $('#document-type', documents_form).val(); + if (document_type != "wizard"){ + //Don't clear the document when in wizard mode. + var the_document = $('#document', documents_form); + the_document.text(""); + } + } + ); + + /*response_element.html("");*/ + //Setup the handlers for toggling the various display options for the "Document Type" select + doc_type_select + .die('change') + .live + ( + 'change', + function (event) { + var document_type = $('#document-type', documents_form).val(); + var file_upload = $('#file-upload', documents_form); + + //need to clear out any old file upload by forcing a redraw so that + //we don't try to upload an old file + file_upload.html(file_upload.html()); + if (document_type == "json") { + toggles(documents_form, true, false, true, '{"id":"change.me","title":"change.me"}', false); + $("#attribs").show(); + } else if (document_type == "upload") { + toggles(documents_form, false, true, false, "", false); + $("#attribs").show(); + } else if (document_type == "csv") { + toggles(documents_form, false, false, true, "id,title\nchange.me,change.me", false); + $("#attribs").show(); + } else if (document_type == "solr") { + toggles(documents_form, false, false, true, '<add>\n' + + '<doc>\n' + + '<field name="id">change.me</field>\n' + + '<field name="title" >chang.me</field>\n' + + '</doc>\n' + + '</add>\n', false); + $("#attribs").hide(); + } else if (document_type == "wizard") { + var wizard = $('#wizard', documents_form); + addWizardFields(active_core, wizard); + //$("#wizard-doc", wizard).text('Enter your field text here and then click "Add Field" to add the field to the document.'); + toggles(documents_form, false, false, true, "", true); + $("#attribs").show(); + } else if (document_type == "xml") { + toggles(documents_form, false, false, true, '<doc>\n' + + '<field name="id">change.me</field>' + + '<field name="title">change.me</field>' + + '</doc>', false); + $("#attribs").show(); + } + return false; + } + ); + doc_type_select.chosen().trigger('change'); + //Setup the submit option handling. + documents_form + .die('submit') + .live + ( + 'submit', + function (event) { + var form_values = []; + var handler_path = $('#qt', documents_form).val(); + if ('/' !== handler_path[0]) { + form_values.push({ name: 'qt', value: handler_path.esc() }); + handler_path = '/update'; + } + + var document_url = window.location.protocol + '//' + window.location.host + + core_basepath + handler_path + '?wt=json'; + + url_element + .attr('href', document_url) + .text(document_url) + .trigger('change'); + var the_document = $('#document', documents_form).val(); + var commit_within = $('#commitWithin', documents_form).val(); + var boost = $('#boost', documents_form).val(); + var overwrite = $('#overwrite', documents_form).val(); + var the_command = ""; + var content_type = ""; + var document_type = $('#document-type', documents_form).val(); + var doingFileUpload = false; + //Both JSON and Wizard use the same pathway for submission + //New entries primarily need to fill the_command and set the content_type + if (document_type == "json" || document_type == "wizard") { + //create a JSON command + the_command = "{" + + '"add":{ "doc":' + the_document + "," + + '"boost":' + boost + "," + + '"overwrite":' + overwrite + "," + + '"commitWithin":' + commit_within + + "}}"; + content_type = "application/json"; + } else if (document_type == "csv") { + the_command = the_document; + document_url += "&commitWithin=" + commit_within + "&overwrite=" + overwrite; + content_type = "application/csv"; + } else if (document_type == "xml") { + the_command = '<add commitWithin="' + commit_within + + '" overwrite="' + overwrite + '"' + + ">" + + the_document + "</add>"; + content_type = "text/xml"; + } else if (document_type == "upload") { + doingFileUpload = true; + } else if (document_type == "solr") { + //guess content_type + the_command = the_document; + if (the_document.indexOf("<") >= 0) { + //XML + content_type = "text/xml"; + } else if (the_document.indexOf("{") >= 0) { + //JSON + content_type = "application/json"; + } //TODO: do we need to handle others? + } else { + //How to handle other? + } + + //Handle the submission of the form in the case where we are not uploading a file + if (doingFileUpload == false) { + $.ajax( + { + url: document_url, + //dataType : 'json', + processData: false, + type: 'POST', + contentType: content_type, + data: the_command, + context: response_element, + beforeSend: function (xhr, settings) { + console.log("beforeSend: Vals: " + document_url + " content-type: " + document_type + " the cmd: " + the_command); + + }, + success: function (response, text_status, xhr) { + console.log("success: " + response + " status: " + text_status + " xhr: " + xhr.responseText); + this.html('<div><span class="description">Status</span>: ' + text_status + '</div>' + + '<div><span class="description">Response:</span>' + '<pre class="syntax language-json"><code>' + content_generator['json'](xhr.responseText) + "</code></pre></div>"); + result_element.show(); + }, + error: function (xhr, text_status, error_thrown) { + console.log("error: " + text_status + " thrown: " + error_thrown); + this.html('<div><span class="description">Status</span>: ' + text_status + '</div><div><span class="description">Error:</span> ' + + '' + error_thrown + + '</div>' + + '<div><span class="description">Error</span>:' + '<pre class="syntax language-json"><code>' + + content_generator['json'](xhr.responseText) + + '</code></pre></div>'); + result_element.show(); + }, + complete: function (xhr, text_status) { + //console.log("complete: " + text_status + " xhr: " + xhr.responseText + " doc type: " + document_type); + + //alert(text_status + ": " + xhr.responseText); + /*this + .removeClass( 'loader' );*/ + } + } + ); + } else { + //upload the file + var the_file = $('#the-file', documents_form); + var erh_params = $('#erh-params', documents_form).val(); + if (erh_params != "") { + if (erh_params.substring(0,1) != "&"){ + erh_params = "&" + erh_params; + } + document_url = document_url + erh_params; + } + console.log("uploading file to: " + document_url); + the_file.ajaxfileupload({ + 'action': document_url, + 'validate_extensions': false, + 'upload_now': true, + 'params': { + 'extra': 'info' + }, + 'onComplete': function (response) { + response = response.replace('<pre style="word-wrap: break-word; white-space: pre-wrap;">', ""); + response = response.replace("</pre>", ""); + console.log('completed upload: ' + response); + response_element.html('<div><span class="description">Response:</span>' + '<pre class="syntax language-json"><code>' + content_generator['json'](response) + "</code></pre></div>"); + result_element.show(); + + }, + 'onStart': function () { + console.log("starting file upload"); + //if (weWantedTo) return false; // cancels upload + }, + 'onCancel': function () { + console.log('no file selected'); + } + }); + } + return false; + } + ); + } + ) + } +) +/* + Sample docs: + <doc boost="2.5"> + <field name="id">05991</field> + <field name="title" boost="2.0">Bridgewater</field> + </doc> + + {"id":"foo","title":"blah"} + + */ \ No newline at end of file Propchange: ofbiz/trunk/specialpurpose/solr/webapp/solr/js/scripts/documents.js ------------------------------------------------------------------------------ svn:eol-style = native Propchange: ofbiz/trunk/specialpurpose/solr/webapp/solr/js/scripts/documents.js ------------------------------------------------------------------------------ svn:keywords = Date Rev Author URL Id Propchange: ofbiz/trunk/specialpurpose/solr/webapp/solr/js/scripts/documents.js ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: ofbiz/trunk/specialpurpose/solr/webapp/solr/js/scripts/files.js URL: http://svn.apache.org/viewvc/ofbiz/trunk/specialpurpose/solr/webapp/solr/js/scripts/files.js?rev=1700119&view=auto ============================================================================== --- ofbiz/trunk/specialpurpose/solr/webapp/solr/js/scripts/files.js (added) +++ ofbiz/trunk/specialpurpose/solr/webapp/solr/js/scripts/files.js Sun Aug 30 13:27:07 2015 @@ -0,0 +1,256 @@ +/* + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file 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. +*/ + +// #/:core/files +sammy.get +( + new RegExp( app.core_regex_base + '\\/(files)$' ), + function( context ) + { + core_basepath = this.active_core.attr( 'data-basepath' ); + current_core = context.params.splat[0]; + + var content_element = $( '#content' ); + + var file_endpoint = core_basepath + '/admin/file'; + + var path = context.path.split( '?' ); + var selected_file = null; + if( path && path[1] ) + { + selected_file = path[1].split( '=' ).pop(); + } + + $.get + ( + 'tpl/files.html', + function( template ) + { + content_element + .html( template ); + + var frame_element = $( '#frame', content_element ); + + var tree_callback = function( event, data ) + { + $( 'li[data-file].jstree-closed', event.currentTarget ) + .filter + ( + function( index, element ) + { + return selected_file && 0 === selected_file.indexOf( $( element ).data( 'file' ) ); + } + ) + .each + ( + function( index, element ) + { + data.inst.open_node( element ); + } + ); + + if( selected_file ) + { + $( 'li[data-file="' + selected_file.replace( /\/$/, '' ) + '"] > a', event.currentTarget ) + .addClass( 'active' ); + } + }; + + var load_tree = function() + { + $( '#tree', frame_element ) + .empty() + .jstree + ( + { + plugins : [ 'json_data', 'sort' ], + json_data : { + ajax: { + url : file_endpoint + '?wt=json', + data : function( n ) + { + if( -1 === n ) + return null; + + return { + file : n.attr( 'data-file' ) + }; + }, + success : function( response, status, xhr ) + { + var files = []; + + for( var file in response.files ) + { + var is_directory = response.files[file].directory; + var prefix = xhr.data ? xhr.data.file + '/' : '' + + var item = { + data: { + title : file, + attr : { + href : '#/' + current_core + '/files?file=' + prefix + file + } + }, + attr : { + 'data-file' : prefix + file + } + }; + + if( is_directory ) + { + item.state = 'closed'; + item.data.attr.href += '/'; + } + + files.push( item ); + } + + return files; + } + }, + progressive_render : true + }, + core : { + animation : 0 + } + } + ) + .on + ( + 'loaded.jstree', + tree_callback + ) + .on + ( + 'open_node.jstree', + tree_callback + ); + }; + load_tree(); + + if( selected_file ) + { + $( '#new-file-holder input' ) + .val + ( + '/' !== selected_file.substr( -1 ) + ? selected_file.replace( /[^\/]+$/, '' ) + : selected_file + ); + } + + if( selected_file && '/' !== selected_file.substr( -1 ) ) + { + frame_element + .addClass( 'show' ); + + var endpoint = file_endpoint + '?file=' + selected_file; + + var content_type_map = { xml : 'text/xml', html : 'text/html', js : 'text/javascript' }; + var file_ext = selected_file.match( /\.(\w+)$/ ); + endpoint += '&contentType=' + ( content_type_map[ file_ext[1] || '' ] || 'text/plain' ) + ';charset=utf-8'; + + var public_url = window.location.protocol + '//' + window.location.host + endpoint; + + $( '#url', frame_element ) + .text( public_url ) + .attr( 'href', public_url ); + + var load_file = function( load_tree ) + { + if( load_tree ) + { + load_tree(); + } + + $.ajax + ( + { + url : endpoint, + context : frame_element, + beforeSend : function( xhr, settings ) + { + var block = $( '.view-file .response', this ); + + if( !block.data( 'placeholder' ) ) + { + block.data( 'placeholder', block.text() ); + } + + block + .text( block.data( 'placeholder' ) ); + }, + success : function( response, text_status, xhr ) + { + var content_type = xhr.getResponseHeader( 'Content-Type' ) || ''; + var highlight = null; + + if( 0 === content_type.indexOf( 'text/xml' ) || 0 === xhr.responseText.indexOf( '<?xml' ) || + 0 === content_type.indexOf( 'text/html' ) || 0 === xhr.responseText.indexOf( '<!--' ) ) + { + highlight = 'xml'; + } + else if( 0 === content_type.indexOf( 'text/javascript' ) ) + { + highlight = 'javascript'; + } + + var code = $( + '<pre class="syntax' + ( highlight ? ' language-' + highlight : '' )+ '"><code>' + + xhr.responseText.esc() + + '</code></pre>' + ); + $( '.view-file .response', this ) + .html( code ); + + if( highlight ) + { + hljs.highlightBlock( code.get( 0 ) ); + } + + $( 'form textarea', this ) + .val( xhr.responseText ); + }, + error : function( xhr, text_status, error_thrown) + { + $( '.view-file .response', this ) + .text( 'No such file exists.' ); + }, + complete : function( xhr, text_status ) + { + } + } + ); + } + load_file(); + } + } + ); + } +); + +// legacy redirect for 'config' & 'schema' pages +// #/:core/schema, #/:core/config +sammy.get +( + new RegExp( app.core_regex_base + '\\/(schema|config)$' ), + function( context ) + { + context.redirect( '#/' + context.params.splat[0] + '/files?file=' + this.active_core.attr( context.params.splat[1] ) ); + } +); \ No newline at end of file Propchange: ofbiz/trunk/specialpurpose/solr/webapp/solr/js/scripts/files.js ------------------------------------------------------------------------------ svn:eol-style = native Propchange: ofbiz/trunk/specialpurpose/solr/webapp/solr/js/scripts/files.js ------------------------------------------------------------------------------ svn:keywords = Date Rev Author URL Id Propchange: ofbiz/trunk/specialpurpose/solr/webapp/solr/js/scripts/files.js ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: ofbiz/trunk/specialpurpose/solr/webapp/solr/js/scripts/index.js URL: http://svn.apache.org/viewvc/ofbiz/trunk/specialpurpose/solr/webapp/solr/js/scripts/index.js?rev=1700119&view=auto ============================================================================== --- ofbiz/trunk/specialpurpose/solr/webapp/solr/js/scripts/index.js (added) +++ ofbiz/trunk/specialpurpose/solr/webapp/solr/js/scripts/index.js Sun Aug 30 13:27:07 2015 @@ -0,0 +1,340 @@ +/* + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file 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. +*/ + +var parse_memory_value = function( value ) +{ + if( value !== Number( value ) ) + { + var units = 'BKMGTPEZY'; + var match = value.match( /^(\d+([,\.]\d+)?) (\w)\w?$/ ); + var value = parseFloat( match[1] ) * Math.pow( 1024, units.indexOf( match[3].toUpperCase() ) ); + } + + return value; +}; + +var generate_bar = function( bar_container, bar_data, convert_label_values ) +{ + bar_holder = $( '.bar-holder', bar_container ); + + var bar_level = 1; + var max_width = Math.round( $( '.bar-max', bar_holder ).width() ); + $( '.bar-max.val', bar_holder ).text( bar_data['max'] ); + + bar_level++; + $( '.bar-total.bar', bar_holder ).width( new String( (bar_data['total']/bar_data['max'])*100 ) + '%' ); + $( '.bar-total.val', bar_holder ).text( bar_data['total'] ); + + if( bar_data['used'] ) + { + bar_level++; + $( '.bar-used.bar', bar_holder ).width( new String( (bar_data['used']/bar_data['total'])*100 ) + '%' ); + $( '.bar-used.val', bar_holder ).text( bar_data['used'] ); + } + + bar_holder + .addClass( 'bar-lvl-' + bar_level ); + + var percentage = ( ( ( bar_data['used'] || bar_data['total'] ) / bar_data['max'] ) * 100 ).toFixed(1); + + var hl = $( '[data-desc="' + bar_container.attr( 'id' ) + '"]' ); + + $( '.bar-desc', hl ) + .remove(); + + hl + .append( ' <small class="bar-desc">' + percentage + '%</small>' ); + + if( !!convert_label_values ) + { + $( '.val', bar_holder ) + .each + ( + function() + { + var self = $( this ); + + var unit = null; + var byte_value = parseInt( self.html() ); + + self + .attr( 'title', 'raw: ' + byte_value + ' B' ); + + byte_value /= 1024; + byte_value /= 1024; + unit = 'MB'; + + if( 1024 <= byte_value ) + { + byte_value /= 1024; + unit = 'GB'; + } + + byte_value = byte_value.toFixed( 2 ) + ' ' + unit; + + self + .text( byte_value ); + } + ); + } +}; + +var system_info = function( element, system_data ) +{ + // -- usage + + var load_average = ( system_data['system']['uptime'] || '' ).match( /load averages?: (\d+[.,]\d\d),? (\d+[.,]\d\d),? (\d+[.,]\d\d)/ ); + if( load_average ) + { + var hl = $( '#system h2', element ); + + $( '.bar-desc', hl ) + .remove(); + + hl + .append( ' <small class="bar-desc">' + load_average.slice( 1 ).join( ' ' ).replace( /,/g, '.' ).esc() + '</small>' ); + } + + // -- physical-memory-bar + + var bar_holder = $( '#physical-memory-bar', element ); + if( system_data['system']['totalPhysicalMemorySize'] === undefined || system_data['system']['freePhysicalMemorySize'] === undefined ) + { + bar_holder.hide(); + } + else + { + bar_holder.show(); + + var bar_data = { + 'max' : parse_memory_value( system_data['system']['totalPhysicalMemorySize'] ), + 'total' : parse_memory_value( system_data['system']['totalPhysicalMemorySize'] - system_data['system']['freePhysicalMemorySize'] ) + }; + + generate_bar( bar_holder, bar_data, true ); + } + + // -- swap-space-bar + + var bar_holder = $( '#swap-space-bar', element ); + if( system_data['system']['totalSwapSpaceSize'] === undefined || system_data['system']['freeSwapSpaceSize'] === undefined ) + { + bar_holder.hide(); + } + else + { + bar_holder.show(); + + var bar_data = { + 'max' : parse_memory_value( system_data['system']['totalSwapSpaceSize'] ), + 'total' : parse_memory_value( system_data['system']['totalSwapSpaceSize'] - system_data['system']['freeSwapSpaceSize'] ) + }; + + generate_bar( bar_holder, bar_data, true ); + } + + // -- file-descriptor-bar + + var bar_holder = $( '#file-descriptor-bar', element ); + if( system_data['system']['maxFileDescriptorCount'] === undefined || system_data['system']['openFileDescriptorCount'] === undefined ) + { + bar_holder.hide(); + } + else + { + bar_holder.show(); + + var bar_data = { + 'max' : parse_memory_value( system_data['system']['maxFileDescriptorCount'] ), + 'total' : parse_memory_value( system_data['system']['openFileDescriptorCount'] ) + }; + + generate_bar( bar_holder, bar_data ); + } + + 0 === $( '#system div[id$="-bar"]:visible', element ).size() + ? $( '#system .no-info', element ).show() + : $( '#system .no-info', element ).hide(); + + // -- memory-bar + + var bar_holder = $( '#jvm-memory-bar', element ); + if( system_data['jvm']['memory'] === undefined ) + { + bar_holder.hide(); + } + else + { + bar_holder.show(); + + var jvm_memory = $.extend + ( + { + 'free' : null, + 'total' : null, + 'max' : null, + 'used' : null, + 'raw' : { + 'free' : null, + 'total' : null, + 'max' : null, + 'used' : null, + 'used%' : null + } + }, + system_data['jvm']['memory'] + ); + + var bar_data = { + 'max' : parse_memory_value( jvm_memory['raw']['max'] || jvm_memory['max'] ), + 'total' : parse_memory_value( jvm_memory['raw']['total'] || jvm_memory['total'] ), + 'used' : parse_memory_value( jvm_memory['raw']['used'] || jvm_memory['used'] ) + }; + + generate_bar( bar_holder, bar_data, true ); + } + +} + +// #/ +sammy.get +( + /^#\/$/, + function( context ) + { + var content_element = $( '#content' ); + + content_element + .html( '<div id="index"></div>' ); + + $.ajax + ( + { + url : 'tpl/index.html', + context : $( '#index', content_element ), + beforeSend : function( arr, form, options ) + { + }, + success : function( template ) + { + var self = this; + + this + .html( template ); + + var data = { + 'start_time' : app.dashboard_values['jvm']['jmx']['startTime'], + 'jvm_version' : app.dashboard_values['jvm']['name'] + ' (' + app.dashboard_values['jvm']['version'] + ')', + 'processors' : app.dashboard_values['jvm']['processors'], + 'solr_spec_version' : app.dashboard_values['lucene']['solr-spec-version'] || '-', + 'solr_impl_version' : app.dashboard_values['lucene']['solr-impl-version'] || '-', + 'lucene_spec_version' : app.dashboard_values['lucene']['lucene-spec-version'] || '-', + 'lucene_impl_version' : app.dashboard_values['lucene']['lucene-impl-version'] || '-' + }; + + for( var key in data ) + { + var value_element = $( '.' + key + ' dd', this ); + + value_element + .text( data[key].esc() ); + + value_element.closest( 'li' ) + .show(); + } + + var commandLineArgs = app.dashboard_values['jvm']['jmx']['commandLineArgs']; + if( 0 !== commandLineArgs.length ) + { + var cmd_arg_element = $( '.command_line_args dt', this ); + var cmd_arg_key_element = $( '.command_line_args dt', this ); + var cmd_arg_element = $( '.command_line_args dd', this ); + + for( var key in commandLineArgs ) + { + cmd_arg_element = cmd_arg_element.clone(); + cmd_arg_element.text( commandLineArgs[key] ); + + cmd_arg_key_element + .after( cmd_arg_element ); + } + + cmd_arg_key_element.closest( 'li' ) + .show(); + + $( '.command_line_args dd:last', this ) + .remove(); + + $( '.command_line_args dd:odd', this ) + .addClass( 'odd' ); + } + + $( '.timeago', this ) + .timeago(); + + $( '.index-left .block li:visible:odd', this ) + .addClass( 'odd' ); + + // -- system_info + + system_info( this, app.dashboard_values ); + + $( '#system a.reload', this ) + .die( 'click' ) + .live + ( + 'click', + function( event ) + { + $.ajax + ( + { + url : config.solr_path + '/admin/info/system?wt=json', + dataType : 'json', + context : this, + beforeSend : function( arr, form, options ) + { + loader.show( this ); + }, + success : function( response ) + { + system_info( self, response ); + }, + error : function() + { + }, + complete : function() + { + loader.hide( this ); + } + } + ); + + return false; + } + ); + }, + error : function( xhr, text_status, error_thrown ) + { + }, + complete : function( xhr, text_status ) + { + } + } + ); + } +); Propchange: ofbiz/trunk/specialpurpose/solr/webapp/solr/js/scripts/index.js ------------------------------------------------------------------------------ svn:eol-style = native Propchange: ofbiz/trunk/specialpurpose/solr/webapp/solr/js/scripts/index.js ------------------------------------------------------------------------------ svn:keywords = Date Rev Author URL Id Propchange: ofbiz/trunk/specialpurpose/solr/webapp/solr/js/scripts/index.js ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: ofbiz/trunk/specialpurpose/solr/webapp/solr/js/scripts/java-properties.js URL: http://svn.apache.org/viewvc/ofbiz/trunk/specialpurpose/solr/webapp/solr/js/scripts/java-properties.js?rev=1700119&view=auto ============================================================================== --- ofbiz/trunk/specialpurpose/solr/webapp/solr/js/scripts/java-properties.js (added) +++ ofbiz/trunk/specialpurpose/solr/webapp/solr/js/scripts/java-properties.js Sun Aug 30 13:27:07 2015 @@ -0,0 +1,106 @@ +/* + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file 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. +*/ + +// #/~java-properties +sammy.get +( + /^#\/(~java-properties)$/, + function( context ) + { + var content_element = $( '#content' ); + + content_element + .html( '<div id="java-properties"></div>' ); + + $.ajax + ( + { + url : app.config.solr_path + '/admin/info/properties?wt=json', + dataType : 'json', + context : $( '#java-properties', content_element ), + beforeSend : function( xhr, settings ) + { + this + .html( '<div class="loader">Loading ...</div>' ); + }, + success : function( response, text_status, xhr ) + { + var system_properties = response['system.properties']; + var properties_data = {}; + var properties_content = []; + var properties_order = []; + + var workaround = xhr.responseText.match( /"(line\.separator)"\s*:\s*"(.+?)"/ ); + if( workaround && workaround[2] ) + { + system_properties[workaround[1]] = workaround[2]; + } + + for( var key in system_properties ) + { + var displayed_key = key.replace( /\./g, '.​' ); + var displayed_value = [ system_properties[key] ]; + var item_class = 'clearfix'; + + if( -1 !== key.indexOf( '.path' ) || -1 !== key.indexOf( '.dirs' ) ) + { + displayed_value = system_properties[key].split( system_properties['path.separator'] ); + if( 1 < displayed_value.length ) + { + item_class += ' multi'; + } + } + + var item_content = '<li><dl class="' + item_class + '">' + "\n" + + '<dt>' + displayed_key.esc() + '</dt>' + "\n"; + + for( var i in displayed_value ) + { + item_content += '<dd>' + displayed_value[i].esc() + '</dd>' + "\n"; + } + + item_content += '</dl></li>'; + + properties_data[key] = item_content; + properties_order.push( key ); + } + + properties_order.sort(); + for( var i in properties_order ) + { + properties_content.push( properties_data[properties_order[i]] ); + } + + this + .html( '<ul>' + properties_content.join( "\n" ) + '</ul>' ); + + $( 'li:odd', this ) + .addClass( 'odd' ); + + $( '.multi dd:odd', this ) + .addClass( 'odd' ); + }, + error : function( xhr, text_status, error_thrown) + { + }, + complete : function( xhr, text_status ) + { + } + } + ); + } +); \ No newline at end of file Propchange: ofbiz/trunk/specialpurpose/solr/webapp/solr/js/scripts/java-properties.js ------------------------------------------------------------------------------ svn:eol-style = native Propchange: ofbiz/trunk/specialpurpose/solr/webapp/solr/js/scripts/java-properties.js ------------------------------------------------------------------------------ svn:keywords = Date Rev Author URL Id Propchange: ofbiz/trunk/specialpurpose/solr/webapp/solr/js/scripts/java-properties.js ------------------------------------------------------------------------------ svn:mime-type = text/plain |
Free forum by Nabble | Edit this page |