Added: ofbiz/trunk/specialpurpose/solr/webapp/solr/js/scripts/logging.js
URL: http://svn.apache.org/viewvc/ofbiz/trunk/specialpurpose/solr/webapp/solr/js/scripts/logging.js?rev=1700119&view=auto ============================================================================== --- ofbiz/trunk/specialpurpose/solr/webapp/solr/js/scripts/logging.js (added) +++ ofbiz/trunk/specialpurpose/solr/webapp/solr/js/scripts/logging.js Sun Aug 30 13:27:07 2015 @@ -0,0 +1,576 @@ +/* + 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 loglevel_path = app.config.solr_path + '/admin/info/logging'; +var cookie_logging_timezone = 'logging_timezone'; +var frame_element = null; + +var logging_handler = function( response, text_status, xhr ) +{ + var self = this; + var loggers = response.loggers; + + var levels = '<div class="selector-holder"><div class="selector">' + "\n" + + '<a class="trigger"><span><em>null</em></span></a>' + "\n" + + '<ul>' + "\n"; + + for( var key in response.levels ) + { + var level = response.levels[key].esc(); + levels += '<li><a href="#" data-level="' + level + '">' + level + '</a></li>' + "\n"; + } + + levels += '<li class="unset"><a href="#" data-level="unset">UNSET</a></li>' + "\n" + + '</ul>' + "\n" + + '<a class="close"><span>[x]</span></a>' + "\n" + + '</div></div>'; + + var logger_tree = function( filter ) + { + var logger_content = ''; + var filter_regex = new RegExp( '^' + filter + '\\.\\w+$' ); + + for( var i in loggers ) + { + var logger = loggers[i]; + var continue_matcher = false; + + if( !filter ) + { + continue_matcher = logger.name.indexOf( '.' ) !== -1; + } + else + { + continue_matcher = !logger.name.match( filter_regex ); + } + + if( continue_matcher ) + { + continue; + } + + var logger_class = ''; + + if( logger.set ) + { + logger_class = 'set'; + } + + if( !logger.level ) + { + logger_class = 'null'; + } + + var logger_name = logger.name.split( '.' ); + var display_name = logger_name.pop(); + + var leaf_class = 'jstree-leaf'; + if( logger.level ) + { + leaf_class += ' level-' + logger.level.esc().toLowerCase(); + } + + logger_content += '<li class="' + leaf_class + '" data-logger="' + logger.name.esc() + '">'; + logger_content += '<ins class="trigger jstree-icon"> </ins>' + "\n"; + logger_content += '<a href="#" class="trigger '+ logger_class + '"' ; + + if( logger.level ) + { + logger_content += 'rel="' + logger.level.esc() + '" '; + } + + logger_content += 'title="' + logger.name.esc() + '">' + "\n"; + + if( 0 !== logger_name.length ) + { + logger_content += '<span class="ns">' + logger_name.join( '.' ).esc() + '.</span>'; + } + + logger_content += '<span class="name">' + ( display_name ? display_name.esc() : '<em>empty</em>' ) + '</span>' + "\n"; + logger_content += '</a>'; + + logger_content += levels; + + if( !!logger.name ) + { + var child_logger_content = logger_tree( logger.name ); + if( child_logger_content ) + { + logger_content += '<ul>'; + logger_content += child_logger_content; + logger_content += '</ul>'; + } + } + + logger_content += '</li>'; + } + + return logger_content; + }; + + var logger_content = '<div class="block">' + "\n" + + '<h2><span>' + response.watcher.esc() + '</span></h2>' + "\n" + + '<ul class="tree jstree">' + logger_tree( null ) + '</ul>' + "\n" + + '</div>'; + + self + .html( logger_content ); + + self + .die( 'clear' ) + .live + ( + 'clear', + function( event ) + { + $( '.open', this ) + .removeClass( 'open' ); + } + ); + + $( 'li:last-child', this ) + .addClass( 'jstree-last' ); + + $( 'li.jstree-leaf > a', this ) + .each + ( + function( index, element ) + { + element = $( element ); + var level = element.attr( 'rel' ); + + if( level ) + { + var selector = $( '.selector-holder', element.closest( 'li' ) ); + + var trigger = $( 'a.trigger', selector ); + + trigger + .text( level.esc() ); + + if( element.hasClass( 'set' ) ) + { + trigger.first() + .addClass( 'set' ); + } + + $( 'ul a[data-level="' + level + '"]', selector ).first() + .addClass( 'level' ); + } + } + ) + + $( '.trigger', this ) + .die( 'click' ) + .live + ( + 'click', + function( event ) + { + self.trigger( 'clear' ); + + $( '.selector-holder', $( this ).parents( 'li' ).first() ).first() + .trigger( 'toggle' ); + + return false; + } + ); + + $( '.selector .close', this ) + .die( 'click' ) + .live + ( + 'click', + function( event ) + { + self.trigger( 'clear' ); + return false; + } + ); + + $( '.selector-holder', this ) + .die( 'toggle') + .live + ( + 'toggle', + function( event ) + { + var row = $( this ).closest( 'li' ); + + $( 'a:first', row ) + .toggleClass( 'open' ); + + $( '.selector-holder:first', row ) + .toggleClass( 'open' ); + } + ); + + $( '.selector ul a', this ) + .die( 'click' ) + .live + ( + 'click', + function( event ) + { + var element = $( this ); + + $.ajax + ( + { + url : loglevel_path, + dataType : 'json', + data : { + 'wt' : 'json', + 'set' : $( this ).parents( 'li[data-logger]' ).data( 'logger' ) + ':' + element.data( 'level' ) + }, + type : 'POST', + context : self, + beforeSend : function( xhr, settings ) + { + element + .addClass( 'loader' ); + }, + success : logging_handler + } + ); + + return false; + } + ); + +}; + +var format_time_options = {}; + +var format_time = function( time ) +{ + time = time ? new Date( time ) : new Date(); + return '<time datetime="' + time.toISOString().esc() + '">' + format_time_content( time ) + '</abbr>'; +} + +var format_time_content = function( time ) +{ + return time.toLocaleString( undefined, format_time_options ).esc(); +} + +var load_logging_viewer = function() +{ + var table = $( 'table', frame_element ); + var state = $( '#state', frame_element ); + var since = table.data( 'latest' ) || 0; + var sticky_mode = null; + + $.ajax + ( + { + url : loglevel_path + '?wt=json&since=' + since, + dataType : 'json', + beforeSend : function( xhr, settings ) + { + // initial request + if( 0 === since ) + { + sticky_mode = true; + } + + // state element is in viewport + else if( state.position().top <= $( window ).scrollTop() + $( window ).height() - ( $( 'body' ).height() - state.position().top ) ) + { + sticky_mode = true; + } + + else + { + sticky_mode = false; + } + }, + success : function( response, text_status, xhr ) + { + var docs = response.history.docs; + var docs_count = docs.length; + + var table = $( 'table', frame_element ); + + $( 'h2 span', frame_element ) + .text( response.watcher.esc() ); + + state + .html( 'Last Check: ' + format_time() ); + + app.timeout = setTimeout + ( + load_logging_viewer, + 10000 + ); + + if( 0 === docs_count ) + { + table.trigger( 'update' ); + return false; + } + + var content = '<tbody>'; + + for( var i = 0; i < docs_count; i++ ) + { + var doc = docs[i]; + + if( 1 === doc.time.length ) + { + for( var key in doc ) + { + doc[key] = doc[key][0]; + } + } + + if( !doc.trace ) + { + var lines = doc.message.split( "\n" ); + if( 1 < lines.length ) + { + doc.trace = doc.message; + doc.message = lines[0]; + delete lines; + } + } + + var has_trace = 'undefined' !== typeof( doc.trace ); + + doc.logger = '<abbr title="' + doc.logger.esc() + '">' + doc.logger.split( '.' ).pop().esc() + '</abbr>'; + + var classes = [ 'level-' + doc.level.toLowerCase().esc() ]; + if( has_trace ) + { + classes.push( 'has-trace' ); + } + + content += '<tr class="' + classes.join( ' ' ) + '">' + "\n"; + content += '<td class="span"><a><span>' + format_time( doc.time ) + '</span></a></td>' + "\n"; + content += '<td class="level span"><a><span>' + doc.level.esc() + '</span></span></a></td>' + "\n"; + content += '<td class="span"><a><span>' + doc.logger + '</span></a></td>' + "\n"; + content += '<td class="message span"><a><span>' + doc.message.replace( /,/g, ',​' ).esc() + '</span></a></td>' + "\n"; + content += '</tr>' + "\n"; + + if( has_trace ) + { + content += '<tr class="trace">' + "\n"; + content += '<td colspan="4"><pre>' + doc.trace.esc() + '</pre></td>' + "\n"; + content += '</tr>' + "\n"; + } + + } + + content += '</tbody>'; + + $( 'table', frame_element ) + .append( content ); + + table + .data( 'latest', response.info.last ) + .removeClass( 'has-data' ) + .trigger( 'update' ); + + if( sticky_mode ) + { + $( 'body' ) + .animate + ( + { scrollTop: state.position().top }, + 1000 + ); + } + }, + error : function( xhr, text_status, error_thrown) + { + }, + complete : function( xhr, text_status ) + { + } + } + ); +} + +// #/~logging +sammy.get +( + /^#\/(~logging)$/, + function( context ) + { + var content_element = $( '#content' ); + + $.get + ( + 'tpl/logging.html', + function( template ) + { + content_element + .html( template ); + + frame_element = $( '#frame', content_element ); + frame_element + .html + ( + '<div id="viewer">' + "\n" + + '<div class="block">' + "\n" + + '<h2><span> </span></h2>' + "\n" + + '</div>' + "\n" + + '<table border="0" cellpadding="0" cellspacing="0">' + "\n" + + '<thead>' + "\n" + + '<tr>' + "\n" + + '<th class="time">Time (<span>Local</span>)</th>' + "\n" + + '<th class="level">Level</th>' + "\n" + + '<th class="logger">Logger</th>' + "\n" + + '<th class="message">Message</th>' + "\n" + + '</tr>' + "\n" + + '</thead>' + "\n" + + '<tfoot>' + "\n" + + '<tr>' + "\n" + + '<td colspan="4">No Events available</td>' + "\n" + + '</tr>' + "\n" + + '</thead>' + "\n" + + '</table>' + "\n" + + '<div id="footer" class="clearfix">' + "\n" + + '<div id="state" class="loader"> </div>' + "\n" + + '<div id="date-format"><a>Show dates in UTC</a></div>' + "\n" + + '</div>' + "\n" + + '</div>' + ); + + var table = $( 'table', frame_element ); + + table + .die( 'update' ) + .live + ( + 'update', + function( event ) + { + var table = $( this ); + var tbody = $( 'tbody', table ); + + 0 !== tbody.size() + ? table.addClass( 'has-data' ) + : table.removeClass( 'has-data' ); + + return false; + } + ); + + load_logging_viewer(); + + $( '.has-trace a', table ) + .die( 'click' ) + .live + ( + 'click', + function( event ) + { + $( this ).closest( 'tr' ) + .toggleClass( 'open' ) + .next().toggle(); + + return false; + } + ); + + var date_format = $( '#date-format a', frame_element ); + + date_format + .off( 'click' ) + .on + ( + 'click', + function( event ) + { + var self = $( this ); + + if( !self.hasClass( 'on' ) ) + { + self.addClass( 'on' ); + $( 'table th.time span', frame_element ).text( 'UTC' ); + format_time_options.timeZone = 'UTC'; + $.cookie( cookie_logging_timezone, 'UTC' ); + } + else + { + self.removeClass( 'on' ); + $( 'table th.time span', frame_element ).text( 'Local' ); + delete format_time_options.timeZone; + $.cookie( cookie_logging_timezone, null ); + } + + $( 'time', frame_element ) + .each + ( + function( index, element ) + { + var self = $( element ); + self.text( format_time_content( new Date( self.attr( 'datetime' ) ) ) ); + } + ) + + return false; + } + ); + + if( 'UTC' === $.cookie( cookie_logging_timezone ) ) + { + date_format + .trigger( 'click' ); + } + } + ); + } +); + +// #/~logging/level +sammy.get +( + /^#\/(~logging)\/level$/, + function( context ) + { + var content_element = $( '#content' ); + + $.get + ( + 'tpl/logging.html', + function( template ) + { + content_element + .html( template ); + + $( '#menu a[href="' + context.path + '"]' ) + .parent().addClass( 'active' ); + + $.ajax + ( + { + url : loglevel_path + '?wt=json', + dataType : 'json', + context : $( '#frame', content_element ), + beforeSend : function( xhr, settings ) + { + this + .html( '<div class="loader">Loading ...</div>' ); + }, + success : logging_handler + } + ); + } + ); + } +); \ No newline at end of file Propchange: ofbiz/trunk/specialpurpose/solr/webapp/solr/js/scripts/logging.js ------------------------------------------------------------------------------ svn:eol-style = native Propchange: ofbiz/trunk/specialpurpose/solr/webapp/solr/js/scripts/logging.js ------------------------------------------------------------------------------ svn:keywords = Date Rev Author URL Id Propchange: ofbiz/trunk/specialpurpose/solr/webapp/solr/js/scripts/logging.js ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: ofbiz/trunk/specialpurpose/solr/webapp/solr/js/scripts/ping.js URL: http://svn.apache.org/viewvc/ofbiz/trunk/specialpurpose/solr/webapp/solr/js/scripts/ping.js?rev=1700119&view=auto ============================================================================== --- ofbiz/trunk/specialpurpose/solr/webapp/solr/js/scripts/ping.js (added) +++ ofbiz/trunk/specialpurpose/solr/webapp/solr/js/scripts/ping.js Sun Aug 30 13:27:07 2015 @@ -0,0 +1,72 @@ +/* + 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. +*/ + +$( '.ping a', app.core_menu ) + .live + ( + 'click', + function( event ) + { + $.ajax + ( + { + url : $( this ).attr( 'rel' ) + '?wt=json&ts=' + (new Date).getTime(), + dataType : 'json', + context: this, + beforeSend : function( arr, form, options ) + { + loader.show( this ); + }, + success : function( response, text_status, xhr ) + { + $( this ) + .removeAttr( 'title' ); + + $( this ).parents( 'li' ) + .removeClass( 'error' ); + + var qtime_element = $( '.qtime', this ); + + if( 0 === qtime_element.size() ) + { + qtime_element = $( '<small class="qtime"> (<span></span>)</small>' ); + + $( this ) + .append( qtime_element ); + } + + $( 'span', qtime_element ) + .html( response.responseHeader.QTime + 'ms' ); + }, + error : function( xhr, text_status, error_thrown ) + { + $( this ) + .attr( 'title', '/admin/ping is not configured (' + xhr.status + ': ' + error_thrown + ')' ); + + $( this ).parents( 'li' ) + .addClass( 'error' ); + }, + complete : function( xhr, text_status ) + { + loader.hide( this ); + } + } + ); + + return false; + } + ); \ No newline at end of file Propchange: ofbiz/trunk/specialpurpose/solr/webapp/solr/js/scripts/ping.js ------------------------------------------------------------------------------ svn:eol-style = native Propchange: ofbiz/trunk/specialpurpose/solr/webapp/solr/js/scripts/ping.js ------------------------------------------------------------------------------ svn:keywords = Date Rev Author URL Id Propchange: ofbiz/trunk/specialpurpose/solr/webapp/solr/js/scripts/ping.js ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: ofbiz/trunk/specialpurpose/solr/webapp/solr/js/scripts/plugins.js URL: http://svn.apache.org/viewvc/ofbiz/trunk/specialpurpose/solr/webapp/solr/js/scripts/plugins.js?rev=1700119&view=auto ============================================================================== --- ofbiz/trunk/specialpurpose/solr/webapp/solr/js/scripts/plugins.js (added) +++ ofbiz/trunk/specialpurpose/solr/webapp/solr/js/scripts/plugins.js Sun Aug 30 13:27:07 2015 @@ -0,0 +1,462 @@ +/* + 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 core_basepath = null; +var content_element = null; +var selected_type = null; +var context_path = null; +var active_context = null; +var changes = null; +var reference_xml = null; + +var compute_plugin_data = function( response, changeset ) +{ + var types = []; + var sort_table = {}; + var plugin_data = {}; + + var types_obj = {}; + var plugin_key = null; + + changes = { count : {}, list : {} } + + for( var i = 0; i < response['solr-mbeans'].length; i++ ) + { + if( !( i % 2 ) ) + { + plugin_key = response['solr-mbeans'][i]; + } + else + { + plugin_data[plugin_key] = response['solr-mbeans'][i]; + } + } + + for( var key in plugin_data ) + { + sort_table[key] = { + url : [], + component : [], + handler : [] + }; + for( var part_key in plugin_data[key] ) + { + if( plugin_data[key][part_key]['_changed_'] ) + { + delete plugin_data[key][part_key]['_changed_']; + + changes.count[key] = changes.count[key] || 0; + changes.count[key]++; + + changes.list[key] = changes.list[key] || {}; + changes.list[key][part_key] = true; + } + + if( 0 < part_key.indexOf( '.' ) ) + { + types_obj[key] = true; + sort_table[key]['handler'].push( part_key ); + } + else if( 0 === part_key.indexOf( '/' ) ) + { + types_obj[key] = true; + sort_table[key]['url'].push( part_key ); + } + else + { + types_obj[key] = true; + sort_table[key]['component'].push( part_key ); + } + } + } + + for( var type in types_obj ) + { + types.push( type ); + } + types.sort(); + + return { + 'plugin_data' : plugin_data, + 'sort_table' : sort_table, + 'types' : types + }; +}; + +var render_plugin_data = function( plugin_data, plugin_sort, types ) +{ + var frame_element = $( '#frame', content_element ); + var navigation_element = $( '#navigation ul', content_element ); + + var navigation_content = []; + for( var i = 0; i < types.length; i++ ) + { + var type_url = active_context.params.splat[0] + '/' + active_context.params.splat[1] + '/' + types[i].toLowerCase(); + + var navigation_markup = '<li class="' + types[i].toLowerCase().esc() + '">' + + '<a href="#/' + type_url + '" rel="' + types[i].esc() + '">' + types[i].esc(); + + if( changes.count[types[i]] ) + { + navigation_markup += ' <span>' + changes.count[types[i]].esc() + '</span>'; + } + + navigation_markup += '</a>' + + '</li>'; + + navigation_content.push( navigation_markup ); + } + + navigation_content.push( '<li class="PLUGINCHANGES"><a href="#">Watch Changes</a></li>' ); + navigation_content.push( '<li class="RELOAD"><a href="#" onClick="window.location.reload()">Refresh Values</a></li>' ); + + navigation_element + .html( navigation_content.join( "\n" ) ); + + $( '.PLUGINCHANGES a', navigation_element ) + .die( 'click' ) + .live + ( + 'click', + function( event ) + { + load_reference_xml(); + + changes = { count : {}, list : {} } + $( 'a > span', navigation_element ).remove(); + $( '.entry.changed', frame_element ).removeClass( 'changed' ); + + $.blockUI + ( + { + message: $('#recording'), + css: { width: '450px' } + } + ); + + return false; + } + ); + + $( '#recording button' ) + .die( 'click' ) + .live + ( + 'click', + function( event ) + { + $.ajax + ( + { + type: 'POST', + url: core_basepath + '/admin/mbeans', + dataType : 'json', + data: { + 'stats': 'true', + 'wt': 'json', + 'diff': 'true', + 'all': 'true', + 'stream.body': reference_xml + }, + success : function( response, text_status, xhr ) + { + load_reference_xml(); + + app.plugin_data = compute_plugin_data( response ); + render_plugin_data( app.plugin_data.plugin_data, app.plugin_data.sort_table, app.plugin_data.types ); + } + } + ); + $.unblockUI(); + return false; + } + ); + + $( 'a[href="' + context_path + '"]', navigation_element ) + .parent().addClass( 'current' ); + + var content = '<ul>'; + for( var sort_key in plugin_sort[selected_type] ) + { + plugin_sort[selected_type][sort_key].sort(); + var plugin_type_length = plugin_sort[selected_type][sort_key].length; + + for( var i = 0; i < plugin_type_length; i++ ) + { + var bean = plugin_sort[selected_type][sort_key][i]; + var classes = [ 'entry' ]; + + if( changes.list[selected_type] && changes.list[selected_type][bean] ) + { + classes.push( 'changed' ); + } + + content += '<li class="' + classes.join( ' ' ) + '">' + "\n"; + content += '<a href="' + context_path + '?entry=' + bean.esc() + '" data-bean="' + bean.esc() + '">'; + content += '<span>' + bean.esc() + '</span>'; + content += '</a>' + "\n"; + content += '<ul class="detail">' + "\n"; + + var details = plugin_data[selected_type][ plugin_sort[selected_type][sort_key][i] ]; + for( var detail_key in details ) + { + if( 'stats' !== detail_key ) + { + var detail_value = details[detail_key]; + + if( 'description' === detail_key ) + { + // Link component list to their MBeans page + if(detail_value.match(/^Search using components: /)) { + var idx = detail_value.indexOf(':'); + var url = '#/'+active_context.params.splat[0]+'/plugins/other?entry='; + var tmp = 'Search using components:<ul>'; + $.each(detail_value.substr(idx+1).split(","), function(index, value) { + value = $.trim(value); + tmp += '<li><a href="'+url+value+'" class="linker">'+value+"</a></li>"; + }); + tmp += "</ul>"; + detail_value = tmp; + } + } + + content += '<li><dl class="clearfix">' + "\n"; + content += '<dt>' + detail_key + ':</dt>' + "\n"; + if($.isArray(detail_value)) { + $.each(detail_value, function(index, value) { + content += '<dd>' + value + '</dd>' + "\n"; + }); + } + else { + content += '<dd>' + detail_value + '</dd>' + "\n"; + } + content += '</dl></li>' + "\n"; + } + else if( 'stats' === detail_key && details[detail_key] ) + { + content += '<li class="stats clearfix">' + "\n"; + content += '<span>' + detail_key + ':</span>' + "\n"; + content += '<ul>' + "\n"; + + for( var stats_key in details[detail_key] ) + { + var stats_value = new String( details[detail_key][stats_key] ); + stats_value = stats_value.replace( /([\(@])/g, '$1​' ); + + content += '<li><dl class="clearfix">' + "\n"; + content += '<dt>' + stats_key + ':</dt>' + "\n"; + content += '<dd>' + stats_value + '</dd>' + "\n"; + content += '</dl></li>' + "\n"; + } + + content += '</ul></li>' + "\n"; + } + } + + content += '</ul>' + "\n"; + } + } + content += '</ul>' + "\n"; + + frame_element + .html( content ); + + + var path = active_context.path.split( '?entry=' ); + var entries = ( path[1] || '' ).split( ',' ); + + var entry_count = entries.length; + for( var i = 0; i < entry_count; i++ ) + { + $( 'a[data-bean="' + entries[i] + '"]', frame_element ) + .parent().addClass( 'expanded' ); + } + + $( 'a', frame_element ) + .off( 'click' ) + .on + ( + 'click', + function( event ) + { + var self = $( this ); + var bean = self.data( 'bean' ); + + var split = '?entry='; + var path = active_context.path.split( split ); + var entry = ( path[1] || '' ); + + var regex = new RegExp( bean.replace( /\//g, '\\/' ) + '(,|$)' ); + var match = regex.test( entry ); + + var url = path[0] + split; + + url += match + ? entry.replace( regex, '' ) + : entry + ',' + bean; + + url = url.replace( /=,/, '=' ); + url = url.replace( /,$/, '' ); + url = url.replace( /\?entry=$/, '' ); + + active_context.redirect( url ); + return false; + } + ); + + // Try to make links for anything with http (but leave the rest alone) + $( '.detail dd' ).each(function(index) { + var txt = $(this).html(); + if(txt.indexOf("http") >= 0) { + $(this).linker({ + className : 'linker' + }); + } + }); + + // Add invisible whitespace after each slash + $( '.detail a.linker' ).each(function(index) { + $(this).html( $(this).html().replace( /\//g, '/​' ) ); + }); + + + $( '.entry', frame_element ) + .each + ( + function( i, entry ) + { + $( '.detail > li', entry ).not( '.stats' ).filter( ':even' ) + .addClass( 'odd' ); + + $( '.stats li:odd', entry ) + .addClass( 'odd' ); + } + ); +}; + +var load_reference_xml = function() +{ + $.ajax + ( + { + type: 'GET', + url: core_basepath + '/admin/mbeans?stats=true&wt=xml', + dataType : 'text', + success: function( data ) + { + reference_xml = data; + } + } + ); +} + +sammy.bind +( + 'plugins_load', + function( event, params ) + { + var callback = function() + { + params.callback( app.plugin_data.plugin_data, app.plugin_data.sort_table, app.plugin_data.types ); + } + + if( app.plugin_data ) + { + callback( app.plugin_data ); + return true; + } + + $.ajax + ( + { + url : core_basepath + '/admin/mbeans?stats=true&wt=json', + dataType : 'json', + beforeSend : function( xhr, settings ) + { + }, + success : function( response, text_status, xhr ) + { + app.plugin_data = compute_plugin_data( response ); + + $.get + ( + 'tpl/plugins.html', + function( template ) + { + $( '#content' ) + .html( template ); + + callback( app.plugin_data ); + } + ); + }, + error : function( xhr, text_status, error_thrown) + { + }, + complete : function( xhr, text_status ) + { + } + } + ); + } +); + +// #/:core/plugins/$type +sammy.get +( + new RegExp( app.core_regex_base + '\\/(plugins)\\/(\\w+)$' ), + function( context ) + { + core_basepath = this.active_core.attr( 'data-basepath' ); + content_element = $( '#content' ); + selected_type = context.params.splat[2].toUpperCase(); + context_path = context.path.split( '?' ).shift(); + active_context = context; + + sammy.trigger + ( + 'plugins_load', + { + active_core : this.active_core, + callback : render_plugin_data + } + ); + } +); + +// #/:core/plugins +sammy.get +( + new RegExp( app.core_regex_base + '\\/(plugins)$' ), + function( context ) + { + core_basepath = this.active_core.attr( 'data-basepath' ); + delete app.plugin_data; + + sammy.trigger + ( + 'plugins_load', + { + active_core : this.active_core, + callback : function( plugin_data, plugin_sort, types ) + { + context.redirect( context.path + '/' + types[0].toLowerCase() ); + } + } + ); + } +); Propchange: ofbiz/trunk/specialpurpose/solr/webapp/solr/js/scripts/plugins.js ------------------------------------------------------------------------------ svn:eol-style = native Propchange: ofbiz/trunk/specialpurpose/solr/webapp/solr/js/scripts/plugins.js ------------------------------------------------------------------------------ svn:keywords = Date Rev Author URL Id Propchange: ofbiz/trunk/specialpurpose/solr/webapp/solr/js/scripts/plugins.js ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: ofbiz/trunk/specialpurpose/solr/webapp/solr/js/scripts/query.js URL: http://svn.apache.org/viewvc/ofbiz/trunk/specialpurpose/solr/webapp/solr/js/scripts/query.js?rev=1700119&view=auto ============================================================================== --- ofbiz/trunk/specialpurpose/solr/webapp/solr/js/scripts/query.js (added) +++ ofbiz/trunk/specialpurpose/solr/webapp/solr/js/scripts/query.js Sun Aug 30 13:27:07 2015 @@ -0,0 +1,229 @@ +/* + 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/query +sammy.get +( + new RegExp( app.core_regex_base + '\\/(query)$' ), + function( context ) + { + var core_basepath = this.active_core.attr( 'data-basepath' ); + var content_element = $( '#content' ); + + $.get + ( + 'tpl/query.html', + function( template ) + { + content_element + .html( template ); + + var query_element = $( '#query', content_element ); + var query_form = $( '#form form', query_element ); + var url_element = $( '#url', query_element ); + var result_element = $( '#result', query_element ); + var response_element = $( '#response', result_element ); + + url_element + .die( 'change' ) + .live + ( + 'change', + function( event ) + { + var wt = $( '[name="wt"]', query_form ).val(); + + var content_generator = { + + _default : function( xhr ) + { + return xhr.responseText.esc(); + }, + + json : function( xhr ) + { + return app.format_json( xhr.responseText ); + } + + }; + + $.ajax + ( + { + url : this.href, + dataType : wt, + context : response_element, + beforeSend : function( xhr, settings ) + { + this + .html( '<div class="loader">Loading ...</div>' ); + }, + complete : function( xhr, text_status ) + { + var code = $( + '<pre class="syntax language-' + wt + '"><code>' + + ( content_generator[wt] || content_generator['_default'] )( xhr ) + + '</code></pre>' + ); + this.html( code ); + + if( 'success' === text_status ) + { + hljs.highlightBlock( code.get(0) ); + } + } + } + ); + } + ) + + $( '.optional legend input[type=checkbox]', query_form ) + .die( 'change' ) + .live + ( + 'change', + function( event ) + { + var fieldset = $( this ).parents( 'fieldset' ); + + this.checked + ? fieldset.addClass( 'expanded' ) + : fieldset.removeClass( 'expanded' ); + } + ); + + $( '.multiple a', query_form ) + .die( 'click' ) + .live + ( + 'click', + function( event ) + { + var self = $( this ); + var row = self.closest( '.row' ); + var container = self.closest( '.multiple' ); + + var add = parseInt( self.data( 'action' ), 10 ); + if( add ) + { + var new_row = row.clone(); + new_row.find( 'input' ).val( '' ); + row.after( new_row ); + row.next().find( 'input' ).focus(); + } + else if( 1 === $( '.row', container ).size() ) + { + row.find( 'input' ).val( '' ).focus(); + } + else + { + row.remove(); + container.find( 'input:last' ).focus(); + } + + return false; + } + ) + + query_form + .die( 'submit' ) + .live + ( + 'submit', + function( event ) + { + var form_values = []; + + var add_to_form_values = function add_to_form_values( fields ) + { + for( var i in fields ) + { + if( !fields[i].value || 0 === fields[i].value.length ) + { + continue; + } + + form_values.push( fields[i] ); + } + }; + + var fieldsets = $( '> fieldset', query_form ); + + var fields = fieldsets.first().formToArray( true ); + add_to_form_values( fields ); + + fieldsets.not( '.common' ) + .each + ( + function( i, set ) + { + if( $( 'legend input', set ).is( ':checked' ) ) + { + var fields = $( set ).formToArray( true ); + add_to_form_values( fields ); + } + } + ); + + var handler_path = $( '#qt', query_form ).val(); + if( '/' !== handler_path[0] ) + { + form_values.push( { name : 'qt', value : handler_path.esc() } ); + handler_path = '/select'; + } + + var query_url = window.location.protocol + '//' + window.location.host + + core_basepath + handler_path + '?' + $.param( form_values ); + + var custom_parameters = $( '#custom_parameters', query_form ).val(); + if( custom_parameters && 0 !== custom_parameters.length ) + { + query_url += '&' + custom_parameters.replace( /^&/, '' ); + } + + url_element + .attr( 'href', query_url ) + .text( query_url ) + .trigger( 'change' ); + + result_element + .show(); + + return false; + } + ); + + var fields = 0; + for( var key in context.params ) + { + if( 'string' === typeof context.params[key] ) + { + fields++; + $( '[name="' + key + '"]', query_form ) + .val( context.params[key] ); + } + } + + if( 0 !== fields ) + { + query_form + .trigger( 'submit' ); + } + } + ); + } +); \ No newline at end of file Propchange: ofbiz/trunk/specialpurpose/solr/webapp/solr/js/scripts/query.js ------------------------------------------------------------------------------ svn:eol-style = native Propchange: ofbiz/trunk/specialpurpose/solr/webapp/solr/js/scripts/query.js ------------------------------------------------------------------------------ svn:keywords = Date Rev Author URL Id Propchange: ofbiz/trunk/specialpurpose/solr/webapp/solr/js/scripts/query.js ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: ofbiz/trunk/specialpurpose/solr/webapp/solr/js/scripts/replication.js URL: http://svn.apache.org/viewvc/ofbiz/trunk/specialpurpose/solr/webapp/solr/js/scripts/replication.js?rev=1700119&view=auto ============================================================================== --- ofbiz/trunk/specialpurpose/solr/webapp/solr/js/scripts/replication.js (added) +++ ofbiz/trunk/specialpurpose/solr/webapp/solr/js/scripts/replication.js Sun Aug 30 13:27:07 2015 @@ -0,0 +1,527 @@ +/* + 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 timer_element = null; +var timer_timeout = null; + +var core_basepath = null; +var navigation_element = null; +var replication_element = null; + +var init_timer = function( next_tick ) +{ + if( timer_timeout ) + { + window.clearTimeout( timer_timeout ); + } + update_timer( next_tick ); +} + +var update_timer = function( next_tick ) +{ + if( 0 === next_tick ) + { + replication_fetch_status(); + return false; + } + + $( 'p .tick', timer_element ) + .text( app.convert_seconds_to_readable_time( next_tick ) ); + + timer_timeout = window.setTimeout + ( + 'update_timer( ' + --next_tick + ' )', + 1000 + ); +} + +var clear_timer = function() +{ + if( timer_timeout ) + { + window.clearTimeout( timer_timeout ); + timer_element.hide(); + } +} + +var replication_fetch_status = function() +{ + $.ajax + ( + { + url : core_basepath + '/replication?command=details&wt=json', + dataType : 'json', + beforeSend : function( xhr, settings ) + { + $( '.refresh-status span', navigation_element ) + .addClass( 'loader' ); + + clear_timer(); + }, + success : function( response, text_status, xhr ) + { + $( '.refresh-status span', navigation_element ) + .removeClass( 'loader' ); + + var data = response.details; + var is_slave = 'true' === data.isSlave; + + replication_element + .addClass( is_slave ? 'slave' : 'master' ); + + if( is_slave ) + { + var error_element = $( '#error', replication_element ); + + if( data.slave.ERROR ) + { + error_element + .html( data.slave.ERROR ) + .show(); + } + else + { + error_element + .hide() + .empty(); + } + + var progress_element = $( '#progress', replication_element ); + + var start_element = $( '#start', progress_element ); + $( 'span', start_element ) + .text( data.slave.replicationStartTime ); + + var eta_element = $( '#eta', progress_element ); + $( 'span', eta_element ) + .text( app.convert_seconds_to_readable_time( data.slave.timeRemaining ) ); + + var bar_element = $( '#bar', progress_element ); + $( '.files span', bar_element ) + .text( data.slave.numFilesToDownload ); + $( '.size span', bar_element ) + .text( data.slave.bytesToDownload ); + + var speed_element = $( '#speed', progress_element ); + $( 'span', speed_element ) + .text( data.slave.downloadSpeed ); + + var done_element = $( '#done', progress_element ); + $( '.files span', done_element ) + .text( data.slave.numFilesDownloaded ); + $( '.size span', done_element ) + .text( data.slave.bytesDownloaded ); + $( '.percent span', done_element ) + .text( parseInt(data.slave.totalPercent ) ); + + var percent = parseInt( data.slave.totalPercent ); + if( 0 === percent ) + { + done_element + .css( 'width', '1px' ); + } + else + { + done_element + .css( 'width', percent + '%' ); + } + + var current_file_element = $( '#current-file', replication_element ); + $( '.file', current_file_element ) + .text( data.slave.currentFile ); + $( '.done', current_file_element ) + .text( data.slave.currentFileSizeDownloaded ); + $( '.total', current_file_element ) + .text( data.slave.currentFileSize ); + $( '.percent', current_file_element ) + .text( parseInt( data.slave.currentFileSizePercent ) ); + + if( !data.slave.indexReplicatedAtList ) + { + data.slave.indexReplicatedAtList = []; + } + + if( !data.slave.replicationFailedAtList ) + { + data.slave.replicationFailedAtList = []; + } + + var iterations_element = $( '#iterations', replication_element ); + var iterations_list = $( '.iterations ul', iterations_element ); + + var iterations_data = []; + var iterations_obj = {}; + + for( var i in data.slave.indexReplicatedAtList ) + { + var date = data.slave.indexReplicatedAtList[i]; + if( !iterations_obj[date] ) + { + iterations_obj[date] = true; + iterations_data.push( date ); + } + } + + for( var i in data.slave.replicationFailedAtList ) + { + var date = data.slave.replicationFailedAtList[i]; + if( !iterations_obj[date] ) + { + iterations_obj[date] = true; + iterations_data.push( date ); + } + } + + iterations_data.sort().reverse(); + + if( 0 !== iterations_data.length ) + { + var iterations = []; + for( var i = 0; i < iterations_data.length; i++ ) + { + iterations.push( '<li data-date="' + iterations_data[i] + '">' + iterations_data[i] + '</li>' ); + } + + iterations_list + .html( iterations.join( "\n" ) ) + .show(); + + $( data.slave.indexReplicatedAtList ) + .each + ( + function( key, value ) + { + $( 'li[data-date="' + value + '"]', iterations_list ) + .addClass( 'replicated' ); + } + ); + + if( data.slave.indexReplicatedAt ) + { + $( 'li[data-date="' + data.slave.indexReplicatedAt + '"]', iterations_list ) + .addClass( 'latest' ); + } + + $( data.slave.replicationFailedAtList ) + .each + ( + function( key, value ) + { + $( 'li[data-date="' + value + '"]', iterations_list ) + .addClass( 'failed' ); + } + ); + + if( data.slave.replicationFailedAt ) + { + $( 'li[data-date="' + data.slave.replicationFailedAt + '"]', iterations_list ) + .addClass( 'latest' ); + } + + if( 0 !== $( 'li:hidden', iterations_list ).size() ) + { + $( 'a', iterations_element ) + .show(); + } + else + { + $( 'a', iterations_element ) + .hide(); + } + } + } + + var details_element = $( '#details', replication_element ); + var current_type_element = $( ( is_slave ? '.slave' : '.masterSearch' ), details_element ); + var master_data = is_slave ? data.slave.masterDetails : data; + + // 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 ) + { + // what's searchable on the master + var master_searchable = $( '.masterSearch', details_element ); + $( '.version div', master_searchable ) + .html( master_data.indexVersion ); + $( '.generation div', master_searchable ) + .html( master_data.generation ); + $( '.size div', master_searchable ) + .html( master_data.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' ); + } + } + + if( is_slave ) + { + var settings_element = $( '#settings', replication_element ); + + if( data.slave.masterUrl ) + { + $( '.masterUrl dd', settings_element ) + .html( response.details.slave.masterUrl ) + .parents( 'li' ).show(); + } + + var polling_content = ' '; + var polling_ico = 'ico-1'; + + if( 'true' === data.slave.isPollingDisabled ) + { + polling_ico = 'ico-0'; + + $( '.disable-polling', navigation_element ).hide(); + $( '.enable-polling', navigation_element ).show(); + } + else + { + $( '.disable-polling', navigation_element ).show(); + $( '.enable-polling', navigation_element ).hide(); + + if( data.slave.pollInterval ) + { + polling_content = '(interval: ' + data.slave.pollInterval + ')'; + } + } + + $( '.isPollingDisabled dd', settings_element ) + .removeClass( 'ico-0' ) + .removeClass( 'ico-1' ) + .addClass( polling_ico ) + .html( polling_content ) + .parents( 'li' ).show(); + + if( 'true' === data.slave.isReplicating ) + { + replication_element + .addClass( 'replicating' ); + + $( '.replicate-now', navigation_element ).hide(); + $( '.abort-replication', navigation_element ).show(); + + window.setTimeout( replication_fetch_status, 1000 ); + } + else + { + replication_element + .removeClass( 'replicating' ); + + $( '.replicate-now', navigation_element ).show(); + $( '.abort-replication', navigation_element ).hide(); + + + if( 'false' === data.slave.isPollingDisabled && data.slave.pollInterval ) + { + timer_element = $( '.timer', navigation_element ); + approx_element = $( '.approx', timer_element ); + + var next_tick = app.convert_duration_to_seconds( data.slave.pollInterval ); + approx_element.show(); + + if( data.slave.nextExecutionAt ) + { + var nextExecutionAt = new SolrDate( data.slave.nextExecutionAt ); + var currentDate = new SolrDate( data.slave.currentDate ); + + if( nextExecutionAt.getTime() > currentDate.getTime() ) + { + next_tick = ( nextExecutionAt.getTime() - currentDate.getTime() ) / 1000; + approx_element.hide(); + + $( 'small', timer_element ) + .text( data.slave.nextExecutionAt ) + .show(); + } + } + + init_timer( next_tick ); + + timer_element + .show(); + } + } + } + + var master_settings_element = $( '#master-settings', replication_element ); + var master_data = is_slave ? data.slave.masterDetails.master : data.master; + + var replication_icon = 'ico-0'; + if( 'true' === master_data.replicationEnabled ) + { + replication_icon = 'ico-1'; + + $( '.disable-replication', navigation_element ).show(); + $( '.enable-replication', navigation_element ).hide(); + } + else + { + $( '.disable-replication', navigation_element ).hide(); + $( '.enable-replication', navigation_element ).show(); + } + + $( '.replicationEnabled dd', master_settings_element ) + .removeClass( 'ico-0' ) + .removeClass( 'ico-1' ) + .addClass( replication_icon ) + .parents( 'li' ).show(); + + $( '.replicateAfter dd', master_settings_element ) + .html( master_data.replicateAfter.join( ', ' ) ) + .parents( 'li' ).show(); + + if( master_data.confFiles ) + { + var conf_files = []; + var conf_data = master_data.confFiles.split( ',' ); + + for( var i = 0; i < conf_data.length; i++ ) + { + var item = conf_data[i]; + + if( - 1 !== item.indexOf( ':' ) ) + { + info = item.split( ':' ); + item = '<abbr title="' + info[0] + ' » ' + info[1] + '">' + ( is_slave ? info[1] : info[0] ) + '</abbr>'; + } + + conf_files.push( item ); + } + + $( '.confFiles dd', master_settings_element ) + .html( conf_files.join( ', ' ) ) + .parents( 'li' ).show(); + } + + + $( '.block', replication_element ).last() + .addClass( 'last' ); + }, + error : function( xhr, text_status, error_thrown ) + { + $( '#content' ) + .html( 'sorry, no replication-handler defined!' ); + }, + complete : function( xhr, text_status ) + { + } + } + ); +} + +// #/:core/replication +sammy.get +( + new RegExp( app.core_regex_base + '\\/(replication)$' ), + function( context ) + { + core_basepath = this.active_core.attr( 'data-basepath' ); + var content_element = $( '#content' ); + + $.get + ( + 'tpl/replication.html', + function( template ) + { + content_element + .html( template ); + + replication_element = $( '#replication', content_element ); + navigation_element = $( '#navigation', replication_element ); + + replication_fetch_status(); + + $( '#iterations a', content_element ) + .die( 'click' ) + .live + ( + 'click', + function( event ) + { + $( this ).parents( '.iterations' ) + .toggleClass( 'expanded' ); + + return false; + } + ); + + $( 'button', navigation_element ) + .die( 'click' ) + .live + ( + 'click', + function( event ) + { + var button = $( this ); + var command = button.data( 'command' ); + + if( button.hasClass( 'refresh-status' ) && !button.hasClass( 'loader' ) ) + { + replication_fetch_status(); + } + else if( command ) + { + $.get + ( + core_basepath + '/replication?command=' + command + '&wt=json', + function() + { + replication_fetch_status(); + } + ); + } + return false; + } + ); + } + ); + } +); Propchange: ofbiz/trunk/specialpurpose/solr/webapp/solr/js/scripts/replication.js ------------------------------------------------------------------------------ svn:eol-style = native Propchange: ofbiz/trunk/specialpurpose/solr/webapp/solr/js/scripts/replication.js ------------------------------------------------------------------------------ svn:keywords = Date Rev Author URL Id Propchange: ofbiz/trunk/specialpurpose/solr/webapp/solr/js/scripts/replication.js ------------------------------------------------------------------------------ svn:mime-type = text/plain |
Free forum by Nabble | Edit this page |