Propchange: ofbiz/trunk/specialpurpose/solr/webapp/solr/js/require.js
------------------------------------------------------------------------------ svn:eol-style = native Propchange: ofbiz/trunk/specialpurpose/solr/webapp/solr/js/require.js ------------------------------------------------------------------------------ svn:keywords = Date Rev Author URL Id Propchange: ofbiz/trunk/specialpurpose/solr/webapp/solr/js/require.js ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: ofbiz/trunk/specialpurpose/solr/webapp/solr/js/scripts/analysis.js URL: http://svn.apache.org/viewvc/ofbiz/trunk/specialpurpose/solr/webapp/solr/js/scripts/analysis.js?rev=1700119&view=auto ============================================================================== --- ofbiz/trunk/specialpurpose/solr/webapp/solr/js/scripts/analysis.js (added) +++ ofbiz/trunk/specialpurpose/solr/webapp/solr/js/scripts/analysis.js Sun Aug 30 13:27:07 2015 @@ -0,0 +1,545 @@ +/* + 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/analysis +sammy.get +( + new RegExp( app.core_regex_base + '\\/(analysis)$' ), + function( context ) + { + var active_core = this.active_core; + var core_basepath = active_core.attr( 'data-basepath' ); + var content_element = $( '#content' ); + + $.get + ( + 'tpl/analysis.html', + function( template ) + { + content_element + .html( template ); + + var analysis_element = $( '#analysis', content_element ); + var analysis_form = $( 'form', analysis_element ); + var analysis_result = $( '#analysis-result', analysis_element ); + analysis_result.hide(); + + var verbose_link = $( '.verbose_output a', analysis_element ); + + var type_or_name = $( '#type_or_name', analysis_form ); + var schema_browser_element = $( '#tor_schema' ); + var schema_browser_path = app.core_menu.find( '.schema-browser a' ).attr( 'href' ); + var schema_browser_map = { 'fieldname' : 'field', 'fieldtype' : 'type' }; + + type_or_name + .die( 'change' ) + .live + ( + 'change', + function( event ) + { + var info = $( this ).val().split( '=' ); + + schema_browser_element + .attr( 'href', schema_browser_path + '?' + schema_browser_map[info[0]] + '=' + info[1] ); + } + ); + + $.ajax + ( + { + url : core_basepath + '/admin/luke?wt=json&show=schema', + dataType : 'json', + context : type_or_name, + beforeSend : function( xhr, settings ) + { + this + .html( '<option value="">Loading ... </option>' ) + .addClass( 'loader' ); + }, + success : function( response, text_status, xhr ) + { + var content = ''; + + var fields = []; + for( var field_name in response.schema.fields ) + { + fields.push + ( + '<option value="fieldname=' + field_name + '">' + field_name + '</option>' + ); + } + if( 0 !== fields.length ) + { + content += '<optgroup label="Fields">' + "\n"; + content += fields.sort().join( "\n" ) + "\n"; + content += '</optgroup>' + "\n"; + } + + var types = []; + for( var type_name in response.schema.types ) + { + types.push + ( + '<option value="fieldtype=' + type_name + '">' + type_name + '</option>' + ); + } + if( 0 !== types.length ) + { + content += '<optgroup label="Types">' + "\n"; + content += types.sort().join( "\n" ) + "\n"; + content += '</optgroup>' + "\n"; + } + + this + .html( content ); + + var defaultSearchField = 'fieldname\=' + ( context.params['analysis.fieldname'] || response.schema.defaultSearchField ); + + if( context.params['analysis.fieldtype'] ) + { + defaultSearchField = 'fieldtype\=' + context.params['analysis.fieldtype']; + } + + $( 'option[value="' + defaultSearchField + '"]', this ) + .attr( 'selected', 'selected' ); + + this + .chosen() + .trigger( 'change' ); + + var fields = 0; + for( var key in context.params ) + { + if( 'string' === typeof context.params[key] && 0 !== context.params[key].length ) + { + fields++; + $( '[name="' + key + '"]', analysis_form ) + .val( context.params[key] ); + } + } + + if( 'undefined' !== typeof context.params.verbose_output ) + { + verbose_link.trigger( 'toggle', !!context.params.verbose_output.match( /^(1|true)$/ ) ); + } + + if( 0 !== fields ) + { + analysis_form + .trigger( 'execute' ); + } + }, + error : function( xhr, text_status, error_thrown) + { + }, + complete : function( xhr, text_status ) + { + this + .removeClass( 'loader' ); + } + } + ); + + $( '.analysis-error .head a', analysis_element ) + .die( 'click' ) + .live + ( + 'click', + function( event ) + { + $( this ).parents( '.analysis-error' ) + .toggleClass( 'expanded' ); + } + ); + + var check_empty_spacer = function() + { + var spacer_holder = $( 'td.part.data.spacer .holder', analysis_result ); + + if( 0 === spacer_holder.size() ) + { + return false; + } + + var verbose_output = analysis_result.hasClass( 'verbose_output' ); + + spacer_holder + .each + ( + function( index, element ) + { + element = $( element ); + + if( verbose_output ) + { + var cell = element.parent(); + element.height( cell.height() ); + } + else + { + element.removeAttr( 'style' ); + } + } + ); + } + + verbose_link + .die( 'toggle' ) + .live + ( + 'toggle', + function( event, state ) + { + $( this ).parent() + .toggleClass( 'active', state ); + + analysis_result + .toggleClass( 'verbose_output', state ); + + check_empty_spacer(); + } + ) + .die( 'click' ) + .live + ( + 'click', + function( event ) + { + $( this ).parent() + .toggleClass( 'active' ); + + analysis_form.trigger( 'submit' ); + } + ); + + var button = $( 'button', analysis_form ) + + var compute_analysis_params = function() + { + var params = analysis_form.formToArray(); + + var type_or_name = $( '#type_or_name', analysis_form ).val().split( '=' ); + params.push( { name: 'analysis.' + type_or_name[0], value: type_or_name[1] } ); + params.push( { name: 'verbose_output', value: $( '.verbose_output', analysis_element ).hasClass( 'active' ) ? 1 : 0 } ); + + return params; + } + + analysis_form + .die( 'submit' ) + .live + ( + 'submit', + function( event ) + { + var params = $.param( compute_analysis_params() ) + .replace( /[\w\.]+=\+*(&)/g, '$1' ) // remove empty parameters + .replace( /(&)+/, '$1' ) // reduce multiple ampersands + .replace( /^&/, '' ) // remove leading ampersand + .replace( /\+/g, '%20' ); // replace plus-signs with encoded whitespaces + + context.redirect( context.path.split( '?' ).shift() + '?' + params ); + return false; + } + ) + .die( 'execute' ) + .live + ( + 'execute', + function( event ) + { + var url = core_basepath + '/analysis/field?wt=json&analysis.showmatch=true&' + context.path.split( '?' ).pop(); + url = url.replace( /&verbose_output=\d/, '' ); + + $.ajax + ( + { + url : url, + dataType : 'json', + beforeSend : function( xhr, settings ) + { + loader.show( $( 'span', button ) ); + button.attr( 'disabled', true ); + }, + success : function( response, status_text, xhr, form ) + { + $( '.analysis-error', analysis_element ) + .hide(); + + analysis_result + .empty() + .show(); + + for( var name in response.analysis.field_names ) + { + build_analysis_table( 'name', name, response.analysis.field_names[name] ); + } + + for( var name in response.analysis.field_types ) + { + build_analysis_table( 'type', name, response.analysis.field_types[name] ); + } + + check_empty_spacer(); + }, + error : function( xhr, text_status, error_thrown ) + { + analysis_result + .empty() + .hide(); + + if( 404 === xhr.status ) + { + $( '#analysis-handler-missing', analysis_element ) + .show(); + } + else + { + $( '#analysis-error', analysis_element ) + .show(); + + var response = null; + try + { + eval( 'response = ' + xhr.responseText + ';' ); + } + catch( e ) + { + console.error( e ); + } + + $( '#analysis-error .body', analysis_element ) + .text( response ? response.error.msg : xhr.responseText ); + } + }, + complete : function() + { + loader.hide( $( 'span', button ) ); + button.removeAttr( 'disabled' ); + } + } + ); + } + ); + + var generate_class_name = function( type ) + { + var classes = [type]; + if( 'text' !== type ) + { + classes.push( 'verbose_output' ); + } + return classes.join( ' ' ); + } + + var build_analysis_table = function( field_or_name, name, analysis_data ) + { + for( var type in analysis_data ) + { + var type_length = analysis_data[type].length; + if( 0 !== type_length ) + { + var global_elements_count = 0; + if( 'string' === typeof analysis_data[type][1] ) + { + analysis_data[type][1] = [{ 'text': analysis_data[type][1] }] + } + + for( var i = 1; i < type_length; i += 2 ) + { + var tmp_type_length = analysis_data[type][i].length; + for( var j = 0; j < tmp_type_length; j++ ) + { + global_elements_count = Math.max + ( + ( analysis_data[type][i][j].positionHistory || [] )[0] || 1, + global_elements_count + ); + } + } + + var content = '<div class="' + type + '">' + "\n"; + content += '<table border="0" cellspacing="0" cellpadding="0">' + "\n"; + + for( var i = 0; i < analysis_data[type].length; i += 2 ) + { + var colspan = 1; + var elements = analysis_data[type][i+1]; + var elements_count = global_elements_count; + + if( !elements[0] || !elements[0].positionHistory ) + { + colspan = elements_count; + elements_count = 1; + } + + var legend = []; + for( var key in elements[0] ) + { + var key_parts = key.split( '#' ); + var used_key = key_parts.pop(); + var short_key = used_key; + + if( 1 === key_parts.length ) + { + used_key = '<abbr title="' + key + '">' + used_key + '</abbr>'; + } + + if( 'positionHistory' === short_key || 'match' === short_key ) + { + continue; + } + + legend.push + ( + '<tr class="' + generate_class_name( short_key ) + '">' + + '<td>' + used_key + '</td>' + + '</tr>' + ); + } + + content += '<tbody>' + "\n"; + content += '<tr class="step">' + "\n"; + + // analyzer + var analyzer_name = analysis_data[type][i].replace( /(\$1)+$/g, '' ); + + var analyzer_short = -1 !== analyzer_name.indexOf( '$' ) + ? analyzer_name.split( '$' )[1] + : analyzer_name.split( '.' ).pop(); + analyzer_short = analyzer_short.match( /[A-Z]/g ).join( '' ); + + content += '<td class="part analyzer"><div>' + "\n"; + content += '<abbr title="' + analysis_data[type][i].esc() + '">' + "\n"; + content += analyzer_short.esc() + '</abbr></div></td>' + "\n"; + + // legend + content += '<td class="part legend"><div class="holder">' + "\n"; + content += '<table border="0" cellspacing="0" cellpadding="0">' + "\n"; + content += '<tr><td>' + "\n"; + content += '<table border="0" cellspacing="0" cellpadding="0">' + "\n"; + content += legend.join( "\n" ) + "\n"; + content += '</table></td></tr></table></td>' + "\n"; + + // data + var cell_content = '<td class="part data spacer" colspan="' + colspan + '"><div class="holder"> </div></td>'; + var cells = new Array( elements_count + 1 ).join( cell_content ); + content += cells + "\n"; + + content += '</tr>' + "\n"; + content += '</tbody>' + "\n"; + } + content += '</table>' + "\n"; + content += '</div>' + "\n"; + + $( '.' + type, analysis_result ) + .remove(); + + analysis_result + .append( content ); + + var analysis_result_type = $( '.' + type, analysis_result ); + + for( var i = 0; i < analysis_data[type].length; i += 2 ) + { + for( var j = 0; j < analysis_data[type][i+1].length; j += 1 ) + { + var pos = analysis_data[type][i+1][j].positionHistory + ? analysis_data[type][i+1][j].positionHistory[0] + : 1; + var selector = 'tr.step:eq(' + ( i / 2 ) +') ' + + 'td.data:eq(' + ( pos - 1 ) + ') ' + + '.holder'; + var cell = $( selector, analysis_result_type ); + + cell.parent() + .removeClass( 'spacer' ); + + var table = $( 'table tr.details', cell ); + if( 0 === table.size() ) + { + cell + .html + ( + '<table border="0" cellspacing="0" cellpadding="0">' + + '<tr class="details"></tr></table>' + ); + var table = $( 'table tr.details', cell ); + } + + var tokens = []; + for( var key in analysis_data[type][i+1][j] ) + { + var short_key = key.split( '#' ).pop(); + + if( 'positionHistory' === short_key || 'match' === short_key ) + { + continue; + } + + var classes = []; + classes.push( generate_class_name( short_key ) ); + + var data = analysis_data[type][i+1][j][key]; + if( 'object' === typeof data && data instanceof Array ) + { + data = data.join( ' ' ); + } + if( 'string' === typeof data ) + { + data = data.esc(); + } + + if( null === data || 0 === data.length ) + { + classes.push( 'empty' ); + data = '∅'; + } + + if( analysis_data[type][i+1][j].match && + ( 'text' === short_key || 'raw_bytes' === short_key ) ) + { + classes.push( 'match' ); + } + + tokens.push + ( + '<tr class="' + classes.join( ' ' ) + '">' + + '<td>' + data + '</td>' + + '</tr>' + ); + } + table + .append + ( + '<td class="details">' + + '<table border="0" cellspacing="0" cellpadding="0">' + + tokens.join( "\n" ) + + '</table></td>' + ); + } + } + + } + } + } + + } + ); + } +); Propchange: ofbiz/trunk/specialpurpose/solr/webapp/solr/js/scripts/analysis.js ------------------------------------------------------------------------------ svn:eol-style = native Propchange: ofbiz/trunk/specialpurpose/solr/webapp/solr/js/scripts/analysis.js ------------------------------------------------------------------------------ svn:keywords = Date Rev Author URL Id Propchange: ofbiz/trunk/specialpurpose/solr/webapp/solr/js/scripts/analysis.js ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: ofbiz/trunk/specialpurpose/solr/webapp/solr/js/scripts/app.js URL: http://svn.apache.org/viewvc/ofbiz/trunk/specialpurpose/solr/webapp/solr/js/scripts/app.js?rev=1700119&view=auto ============================================================================== --- ofbiz/trunk/specialpurpose/solr/webapp/solr/js/scripts/app.js (added) +++ ofbiz/trunk/specialpurpose/solr/webapp/solr/js/scripts/app.js Sun Aug 30 13:27:07 2015 @@ -0,0 +1,669 @@ +/* + 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 loader = { + + show : function( element ) + { + $( element ) + .addClass( 'loader' ); + }, + + hide : function( element ) + { + $( element ) + .removeClass( 'loader' ); + } + +}; + +Number.prototype.esc = function() +{ + return new String( this ).esc(); +} + +String.prototype.esc = function() +{ + return this.replace( /</g, '<' ).replace( />/g, '>' ); +} + +SolrDate = function( date ) +{ + // ["Sat Mar 03 11:00:00 CET 2012", "Sat", "Mar", "03", "11:00:00", "CET", "2012"] + var parts = date.match( /^(\w+)\s+(\w+)\s+(\d+)\s+(\d+\:\d+\:\d+)\s+(\w+)\s+(\d+)$/ ); + + // "Sat Mar 03 2012 10:37:33" + return new Date( parts[1] + ' ' + parts[2] + ' ' + parts[3] + ' ' + parts[6] + ' ' + parts[4] ); +} + +var sammy = $.sammy +( + function() + { + this.bind + ( + 'run', + function( event, config ) + { + if( 0 === config.start_url.length ) + { + location.href = '#/'; + return false; + } + } + ); + + this.bind + ( + 'error', + function( message, original_error ) + { + alert( original_error.message ); + } + ); + + // activate_core + this.before + ( + {}, + function( context ) + { + app.clear_timeout(); + + var menu_wrapper = $( '#menu-wrapper' ); + + $( 'li[id].active', menu_wrapper ) + .removeClass( 'active' ); + + $( 'li.active', menu_wrapper ) + .removeClass( 'active' ); + + // global dashboard doesn't have params.splat + if( !this.params.splat ) + { + this.params.splat = [ '~index' ]; + } + + var selector = '~' === this.params.splat[0][0] + ? '#' + this.params.splat[0].replace( /^~/, '' ) + '.global' + : '#core-selector #' + this.params.splat[0].replace( /\./g, '__' ); + + var active_element = $( selector, menu_wrapper ); + + if( 0 === active_element.size() ) + { + this.app.error( 'There exists no core with name "' + this.params.splat[0] + '"' ); + return false; + } + + if( active_element.hasClass( 'global' ) ) + { + active_element + .addClass( 'active' ); + + if( this.params.splat[1] ) + { + $( '.' + this.params.splat[1], active_element ) + .addClass( 'active' ); + } + + $( '#core-selector option[selected]' ) + .removeAttr( 'selected' ) + .trigger( 'liszt:updated' ); + + $( '#core-selector .chzn-container > a' ) + .addClass( 'chzn-default' ); + } + else + { + active_element + .attr( 'selected', 'selected' ) + .trigger( 'liszt:updated' ); + + if( !this.params.splat[1] ) + { + this.params.splat[1] = 'overview'; + } + + $( '#core-menu .' + this.params.splat[1] ) + .addClass( 'active' ); + + this.active_core = active_element; + } + } + ); + } +); + +var solr_admin = function( app_config ) +{ + that = this, + + menu_element = null, + + is_multicore = null, + cores_data = null, + active_core = null, + + config = app_config, + params = null, + dashboard_values = null, + schema_browser_data = null, + + plugin_data = null, + + this.menu_element = $( '#core-selector select' ); + this.core_menu = $( '#core-menu ul' ); + + this.config = config; + this.timeout = null; + + this.core_regex_base = '^#\\/([\\w\\d-\\.]+)'; + + browser = { + locale : null, + language : null, + country : null + }; + + show_global_error = function( error ) + { + var main = $( '#main' ); + + $( 'div[id$="-wrapper"]', main ) + .remove(); + + main + .addClass( 'error' ) + .append( error ); + + var pre_tags = $( 'pre', main ); + if( 0 !== pre_tags.size() ) + { + hljs.highlightBlock( pre_tags.get(0) ); + } + }; + + sort_cores_data = function sort_cores_data( cores_status ) + { + // build array of core-names for sorting + var core_names = []; + for( var core_name in cores_status ) + { + core_names.push( core_name ); + } + core_names.sort(); + + var core_count = core_names.length; + var cores = {}; + + for( var i = 0; i < core_count; i++ ) + { + var core_name = core_names[i]; + cores[core_name] = cores_status[core_name]; + } + + return cores; + }; + + this.set_cores_data = function set_cores_data( cores ) + { + that.cores_data = sort_cores_data( cores.status ); + + that.menu_element + .empty(); + + var core_list = []; + core_list.push( '<option></option>' ); + + var core_count = 0; + for( var core_name in that.cores_data ) + { + core_count++; + var core_path = config.solr_path + '/' + core_name; + var classes = []; + + if( cores.status[core_name]['isDefaultCore'] ) + { + classes.push( 'default' ); + } + + var core_tpl = '<option ' + + ' id="' + core_name.replace( /\./g, '__' ) + '" ' + + ' class="' + classes.join( ' ' ) + '"' + + ' data-basepath="' + core_path + '"' + + ' schema="' + cores.status[core_name]['schema'] + '"' + + ' config="' + cores.status[core_name]['config'] + '"' + + ' value="#/' + core_name + '"' + + ' title="' + core_name + '"' + + '>' + + core_name + + '</option>'; + + core_list.push( core_tpl ); + } + + var has_cores = 0 !== core_count; + if( has_cores ) + { + that.menu_element + .append( core_list.join( "\n" ) ) + .trigger( 'liszt:updated' ); + } + + var core_selector = $( '#core-selector' ); + core_selector.find( '#has-cores' ).toggle( has_cores ); + core_selector.find( '#has-no-cores' ).toggle( !has_cores ); + + if( has_cores ) + { + var cores_element = core_selector.find( '#has-cores' ); + var selector_width = cores_element.width(); + + cores_element.find( '.chzn-container' ) + .css( 'width', selector_width + 'px' ); + + cores_element.find( '.chzn-drop' ) + .css( 'width', ( selector_width - 2 ) + 'px' ); + } + + this.check_for_init_failures( cores ); + }; + + this.remove_init_failures = function remove_init_failures() + { + $( '#init-failures' ) + .hide() + .find( 'ul' ) + .empty(); + } + + this.check_for_init_failures = function check_for_init_failures( cores ) + { + if( !cores.initFailures ) + { + this.remove_init_failures(); + return false; + } + + var failures = []; + for( var core_name in cores.initFailures ) + { + failures.push + ( + '<li>' + + '<strong>' + core_name.esc() + ':</strong>' + "\n" + + cores.initFailures[core_name].esc() + "\n" + + '</li>' + ); + } + + if( 0 === failures.length ) + { + this.remove_init_failures(); + return false; + } + + $( '#init-failures' ) + .show() + .find( 'ul' ) + .html( failures.join( "\n" ) ); + } + + this.run = function() + { + var navigator_language = navigator.userLanguage || navigator.language; + var language_match = navigator_language.match( /^(\w{2})([-_](\w{2}))?$/ ); + if( language_match ) + { + if( language_match[1] ) + { + browser.language = language_match[1].toLowerCase(); + } + if( language_match[3] ) + { + browser.country = language_match[3].toUpperCase(); + } + if( language_match[1] && language_match[3] ) + { + browser.locale = browser.language + '_' + browser.country + } + } + + $.ajax + ( + { + url : config.solr_path + config.core_admin_path + '?wt=json&indexInfo=false', + dataType : 'json', + beforeSend : function( arr, form, options ) + { + $( '#content' ) + .html( '<div id="index"><div class="loader">Loading ...</div></div>' ); + }, + success : function( response ) + { + that.set_cores_data( response ); + + that.menu_element + .chosen() + .off( 'change' ) + .on + ( + 'change', + function( event ) + { + location.href = $( 'option:selected', this ).val(); + return false; + } + ) + .on + ( + 'liszt:updated', + function( event ) + { + var core_name = $( 'option:selected', this ).text(); + + that.core_menu + .html + ( + //Keep this in alphabetical order after the overview + '<li class="overview"><a href="#/' + core_name + '"><span>Overview</span></a></li>' + "\n" + + '<li class="analysis"><a href="#/' + core_name + '/analysis"><span>Analysis</span></a></li>' + "\n" + + '<li class="dataimport"><a href="#/' + core_name + '/dataimport"><span>Dataimport</span></a></li>' + "\n" + + '<li class="documents"><a href="#/' + core_name + '/documents"><span>Documents</span></a></li>' + "\n" + + '<li class="files"><a href="#/' + core_name + '/files"><span>Files</span></a></li>' + "\n" + + '<li class="ping"><a rel="' + that.config.solr_path + '/' + core_name + '/admin/ping"><span>Ping</span></a></li>' + "\n" + + '<li class="plugins"><a href="#/' + core_name + '/plugins"><span>Plugins / Stats</span></a></li>' + "\n" + + '<li class="query"><a href="#/' + core_name + '/query"><span>Query</span></a></li>' + "\n" + + '<li class="replication"><a href="#/' + core_name + '/replication"><span>Replication</span></a></li>' + "\n" + + '<li class="schema-browser"><a href="#/' + core_name + '/schema-browser"><span>Schema Browser</span></a></li>' + ) + .show(); + + if( !core_name ) + { + that.core_menu + .hide() + .empty(); + } + } + ); + + var system_url = config.solr_path + '/admin/info/system?wt=json'; + $.ajax + ( + { + url : system_url, + dataType : 'json', + beforeSend : function( arr, form, options ) + { + }, + success : function( response ) + { + that.dashboard_values = response; + + var environment_args = null; + var cloud_args = null; + + if( response.jvm && response.jvm.jmx && response.jvm.jmx.commandLineArgs ) + { + var command_line_args = response.jvm.jmx.commandLineArgs.join( ' | ' ); + + environment_args = command_line_args.match( /-Dsolr.environment=((dev|test|prod)?[\w\d]*)/i ); + } + + if( response.mode ) + { + cloud_args = response.mode.match( /solrcloud/i ); + } + + // environment + + var wrapper = $( '#wrapper' ); + var environment_element = $( '#environment' ); + if( environment_args ) + { + wrapper + .addClass( 'has-environment' ); + + if( environment_args[1] ) + { + environment_element + .html( environment_args[1] ); + } + + if( environment_args[2] ) + { + environment_element + .addClass( environment_args[2] ); + } + } + else + { + wrapper + .removeClass( 'has-environment' ); + } + + // cloud + + var cloud_nav_element = $( '#menu #cloud' ); + if( cloud_args ) + { + cloud_nav_element + .show(); + } + + // sammy + + sammy.run( location.hash ); + }, + error : function() + { + show_global_error + ( + '<div class="message"><p>Unable to load environment info from <code>' + system_url.esc() + '</code>.</p>' + + '<p>This interface requires that you activate the admin request handlers in all SolrCores by adding the ' + + 'following configuration to your <code>solrconfig.xml</code>:</p></div>' + "\n" + + + '<div class="code"><pre class="syntax language-xml"><code>' + + '<!-- Admin Handlers - This will register all the standard admin RequestHandlers. -->'.esc() + "\n" + + '<requestHandler name="/admin/" class="solr.admin.AdminHandlers" />'.esc() + + '</code></pre></div>' + ); + }, + complete : function() + { + loader.hide( this ); + } + } + ); + }, + error : function() + { + }, + complete : function() + { + } + } + ); + }; + + this.convert_duration_to_seconds = function convert_duration_to_seconds( str ) + { + var seconds = 0; + var arr = new String( str || '' ).split( '.' ); + var parts = arr[0].split( ':' ).reverse(); + var parts_count = parts.length; + + for( var i = 0; i < parts_count; i++ ) + { + seconds += ( parseInt( parts[i], 10 ) || 0 ) * Math.pow( 60, i ); + } + + // treat more or equal than .5 as additional second + if( arr[1] && 5 <= parseInt( arr[1][0], 10 ) ) + { + seconds++; + } + + return seconds; + }; + + this.convert_seconds_to_readable_time = function convert_seconds_to_readable_time( seconds ) + { + seconds = parseInt( seconds || 0, 10 ); + var minutes = Math.floor( seconds / 60 ); + var hours = Math.floor( minutes / 60 ); + + var text = []; + if( 0 !== hours ) + { + text.push( hours + 'h' ); + seconds -= hours * 60 * 60; + minutes -= hours * 60; + } + + if( 0 !== minutes ) + { + text.push( minutes + 'm' ); + seconds -= minutes * 60; + } + + if( 0 !== seconds ) + { + text.push( ( '0' + seconds ).substr( -2 ) + 's' ); + } + + return text.join( ' ' ); + }; + + this.clear_timeout = function clear_timeout() + { + if( !app.timeout ) + { + return false; + } + + console.debug( 'Clearing Timeout #' + this.timeout ); + clearTimeout( this.timeout ); + this.timeout = null; + }; + + this.format_json = function format_json( json_str ) + { + if( JSON.stringify && JSON.parse ) + { + json_str = JSON.stringify( JSON.parse( json_str ), undefined, 2 ); + } + + return json_str.esc(); + }; + + this.format_number = function format_number( number ) + { + var sep = { + 'de_CH' : '\'', + 'de' : '.', + 'en' : ',', + 'es' : '.', + 'it' : '.', + 'ja' : ',', + 'sv' : ' ', + 'tr' : '.', + '_' : '' // fallback + }; + + return ( number || 0 ).toString().replace + ( + /\B(?=(\d{3})+(?!\d))/g, + sep[ browser.locale ] || sep[ browser.language ] || sep['_'] + ); + }; + +}; + +var connection_check_delay = 1000; +var connection_working = true; + +var connection_check = function connection_check() +{ + $.ajax + ( + { + url : config.solr_path + config.core_admin_path + '?wt=json&indexInfo=false', + dataType : 'json', + context : $( '.blockUI #connection_status span' ), + beforeSend : function( arr, form, options ) + { + this + .addClass( 'loader' ); + }, + success : function( response ) + { + connection_working = true; + + this + .html( 'Instance is available - <a href="javascript:location.reload();">Reload the page</a>' ); + + this.parents( '#connection_status' ) + .addClass( 'online' ); + + this.parents( '.blockUI' ) + .css( 'borderColor', '#080' ); + }, + error : function() + { + connection_check_delay += connection_check_delay; + window.setTimeout( connection_check, connection_check_delay ); + }, + complete : function() + { + this + .removeClass( 'loader' ); + } + } + ); +}; + +var connection_error = function connection_error() +{ + connection_working = false; + + $.blockUI + ( + { + message: $( '#connection_status' ), + css: { width: '450px', borderColor: '#f00' } + } + ); + + window.setTimeout( connection_check, connection_check_delay ); +} + +$( document ).ajaxError +( + function( event, xhr, settings, thrownError ) + { + if( connection_working && 0 === xhr.status ) + { + connection_error(); + } + } +); + +$.ajaxSetup( { cache: false } ); +var app = new solr_admin( app_config ); Propchange: ofbiz/trunk/specialpurpose/solr/webapp/solr/js/scripts/app.js ------------------------------------------------------------------------------ svn:eol-style = native Propchange: ofbiz/trunk/specialpurpose/solr/webapp/solr/js/scripts/app.js ------------------------------------------------------------------------------ svn:keywords = Date Rev Author URL Id Propchange: ofbiz/trunk/specialpurpose/solr/webapp/solr/js/scripts/app.js ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: ofbiz/trunk/specialpurpose/solr/webapp/solr/js/scripts/cloud.js URL: http://svn.apache.org/viewvc/ofbiz/trunk/specialpurpose/solr/webapp/solr/js/scripts/cloud.js?rev=1700119&view=auto ============================================================================== --- ofbiz/trunk/specialpurpose/solr/webapp/solr/js/scripts/cloud.js (added) +++ ofbiz/trunk/specialpurpose/solr/webapp/solr/js/scripts/cloud.js Sun Aug 30 13:27:07 2015 @@ -0,0 +1,740 @@ +/* + 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 zk_error = function zk_error( xhr, text_status, error_thrown ) +{ + var zk = null; + try + { + eval( 'zk = ' + xhr.responseText + ';' ); + } + catch( e ) {} + + var message = '<p class="txt">Loading of "<code>' + xhr.url + '</code>" ' + + 'failed (HTTP-Status <code>' + xhr.status + '</code>)</p>' + "\n"; + + if( zk.error ) + { + message += '<p class="msg">"' + zk.error.esc() + '"</p>' + "\n"; + } + + this.closest( '#cloud' ) + .html( '<div class="block" id="error">' + message + '</div>' ); +}; + +var init_debug = function( cloud_element ) +{ + var debug_element = $( '#debug', cloud_element ); + var debug_button = $( '#menu #cloud .dump a' ); + + var clipboard_element = $( '.clipboard', debug_element ); + var clipboard_button = $( 'a', clipboard_element ); + + debug_button + .die( 'click' ) + .live + ( + 'click', + function( event ) + { + debug_element.trigger( 'show' ); + return false; + } + ); + + $( '.close', debug_element ) + .die( 'click' ) + .live + ( + 'click', + function( event ) + { + debug_element.trigger( 'hide' ); + return false; + } + ); + + $( '.clipboard', debug_element ) + .die( 'click' ) + .live + ( + 'click', + function( event ) + { + return false; + } + ); + + debug_element + .die( 'show' ) + .live + ( + 'show', + function( event ) + { + debug_element.show(); + + $.ajax + ( + { + url : app.config.solr_path + '/zookeeper?wt=json&dump=true', + dataType : 'text', + context : debug_element, + beforeSend : function( xhr, settings ) + { + $( '.debug', debug_element ) + .html( '<span class="loader">Loading Dump ...</span>' ); + + ZeroClipboard.setMoviePath( 'img/ZeroClipboard.swf' ); + + clipboard_client = new ZeroClipboard.Client(); + + clipboard_client.addEventListener + ( + 'load', + function( client ) + { + } + ); + + clipboard_client.addEventListener + ( + 'complete', + function( client, text ) + { + clipboard_element + .addClass( 'copied' ); + + clipboard_button + .data( 'text', clipboard_button.text() ) + .text( clipboard_button.data( 'copied' ) ); + } + ); + }, + success : function( response, text_status, xhr ) + { + clipboard_client.glue + ( + clipboard_element.get(0), + clipboard_button.get(0) + ); + + clipboard_client.setText( response.replace( /\\/g, '\\\\' ) ); + + $( '.debug', debug_element ) + .removeClass( 'loader' ) + .text( response ); + }, + error : function( xhr, text_status, error_thrown ) + { + }, + complete : function( xhr, text_status ) + { + } + } + ); + } + ) + .die( 'hide' ) + .live + ( + 'hide', + function( event ) + { + $( '.debug', debug_element ) + .empty(); + + clipboard_element + .removeClass( 'copied' ); + + clipboard_button + .data( 'copied', clipboard_button.text() ) + .text( clipboard_button.data( 'text' ) ); + + clipboard_client.destroy(); + + debug_element.hide(); + } + ); +}; + +var helper_path_class = function( p ) +{ + var classes = [ 'link' ]; + classes.push( 'lvl-' + p.target.depth ); + + if( p.target.data && p.target.data.leader ) + { + classes.push( 'leader' ); + } + + if( p.target.data && p.target.data.state ) + { + classes.push( p.target.data.state ); + } + + return classes.join( ' ' ); +}; + +var helper_node_class = function( d ) +{ + var classes = [ 'node' ]; + classes.push( 'lvl-' + d.depth ); + + if( d.data && d.data.leader ) + { + classes.push( 'leader' ); + } + + if( d.data && d.data.state ) + { + classes.push( d.data.state ); + } + + return classes.join( ' ' ); +}; + +var helper_data = { + protocol: [], + host: [], + hostname: [], + port: [], + pathname: [] +}; + +var helper_node_text = function( d ) +{ + if( !d.data || !d.data.uri ) + { + return d.name; + } + + var name = d.data.uri.hostname; + + if( 1 !== helper_data.protocol.length ) + { + name = d.data.uri.protocol + '//' + name; + } + + if( 1 !== helper_data.port.length ) + { + name += ':' + d.data.uri.port; + } + + if( 1 !== helper_data.pathname.length ) + { + name += d.data.uri.pathname; + } + + return name; +}; + +var generate_graph = function( graph_element, graph_data, leaf_count ) +{ + var w = graph_element.width(), + h = leaf_count * 20; + + var tree = d3.layout.tree() + .size([h, w - 400]); + + var diagonal = d3.svg.diagonal() + .projection(function(d) { return [d.y, d.x]; }); + + var vis = d3.select( '#canvas' ).append( 'svg' ) + .attr( 'width', w ) + .attr( 'height', h) + .append( 'g' ) + .attr( 'transform', 'translate(100, 0)' ); + + var nodes = tree.nodes( graph_data ); + + var link = vis.selectAll( 'path.link' ) + .data( tree.links( nodes ) ) + .enter().append( 'path' ) + .attr( 'class', helper_path_class ) + .attr( 'd', diagonal ); + + var node = vis.selectAll( 'g.node' ) + .data( nodes ) + .enter().append( 'g' ) + .attr( 'class', helper_node_class ) + .attr( 'transform', function(d) { return 'translate(' + d.y + ',' + d.x + ')'; } ) + + node.append( 'circle' ) + .attr( 'r', 4.5 ); + + node.append( 'text' ) + .attr( 'dx', function( d ) { return 0 === d.depth ? -8 : 8; } ) + .attr( 'dy', function( d ) { return 5; } ) + .attr( 'text-anchor', function( d ) { return 0 === d.depth ? 'end' : 'start'; } ) + .attr( 'data-href', function( d ) { return d.name; } ) + .text( helper_node_text ); + + $( 'text[data-href*="//"]', graph_element ) + .die( 'click' ) + .live + ( + 'click', + function() + { + location.href = $( this ).data( 'href' ); + } + ); +}; + +var generate_rgraph = function( graph_element, graph_data, leaf_count ) +{ + var max_val = Math.min( graph_element.width(), $( 'body' ).height() ) + var r = max_val / 2; + + var cluster = d3.layout.cluster() + .size([360, r - 160]); + + var diagonal = d3.svg.diagonal.radial() + .projection(function(d) { return [d.y, d.x / 180 * Math.PI]; }); + + var vis = d3.select( '#canvas' ).append( 'svg' ) + .attr( 'width', r * 2 ) + .attr( 'height', r * 2 ) + .append( 'g' ) + .attr( 'transform', 'translate(' + r + ',' + r + ')' ); + + var nodes = cluster.nodes( graph_data ); + + var link = vis.selectAll( 'path.link' ) + .data( cluster.links( nodes ) ) + .enter().append( 'path' ) + .attr( 'class', helper_path_class ) + .attr( 'd', diagonal ); + + var node = vis.selectAll( 'g.node' ) + .data( nodes ) + .enter().append( 'g' ) + .attr( 'class', helper_node_class ) + .attr( 'transform', function(d) { return 'rotate(' + (d.x - 90) + ')translate(' + d.y + ')'; } ) + + node.append( 'circle' ) + .attr( 'r', 4.5 ); + + node.append( 'text' ) + .attr( 'dx', function(d) { return d.x < 180 ? 8 : -8; } ) + .attr( 'dy', '.31em' ) + .attr( 'text-anchor', function(d) { return d.x < 180 ? 'start' : 'end'; } ) + .attr( 'transform', function(d) { return d.x < 180 ? null : 'rotate(180)'; } ) + .attr( 'data-href', function( d ) { return d.name; } ) + .text( helper_node_text ); + + $( 'text[data-href*="//"]', graph_element ) + .die( 'click' ) + .live + ( + 'click', + function() + { + location.href = $( this ).data( 'href' ); + } + ); +}; + +var prepare_graph = function( graph_element, callback ) +{ + $.ajax + ( + { + url : app.config.solr_path + '/zookeeper?wt=json&path=%2Flive_nodes', + dataType : 'json', + success : function( response, text_status, xhr ) + { + var live_nodes = {}; + for( var c in response.tree[0].children ) + { + live_nodes[response.tree[0].children[c].data.title] = true; + } + + $.ajax + ( + { + url : app.config.solr_path + '/zookeeper?wt=json&detail=true&path=%2Fclusterstate.json', + dataType : 'json', + context : graph_element, + beforeSend : function( xhr, settings ) + { + this + .show(); + }, + success : function( response, text_status, xhr ) + { + var state = null; + eval( 'state = ' + response.znode.data + ';' ); + + var leaf_count = 0; + var graph_data = { + name: null, + children : [] + }; + + for( var c in state ) + { + var shards = []; + for( var s in state[c].shards ) + { + var nodes = []; + for( var n in state[c].shards[s].replicas ) + { + leaf_count++; + var replica = state[c].shards[s].replicas[n] + + var uri = replica.base_url; + var parts = uri.match( /^(\w+:)\/\/(([\w\d\.-]+)(:(\d+))?)(.+)$/ ); + var uri_parts = { + protocol: parts[1], + host: parts[2], + hostname: parts[3], + port: parseInt( parts[5] || 80, 10 ), + pathname: parts[6] + }; + + helper_data.protocol.push( uri_parts.protocol ); + helper_data.host.push( uri_parts.host ); + helper_data.hostname.push( uri_parts.hostname ); + helper_data.port.push( uri_parts.port ); + helper_data.pathname.push( uri_parts.pathname ); + + var status = replica.state; + + if( !live_nodes[replica.node_name] ) + { + status = 'gone'; + } + + var node = { + name: uri, + data: { + type : 'node', + state : status, + leader : 'true' === replica.leader, + uri : uri_parts + } + }; + nodes.push( node ); + } + + var shard = { + name: s, + data: { + type : 'shard' + }, + children: nodes + }; + shards.push( shard ); + } + + var collection = { + name: c, + data: { + type : 'collection' + }, + children: shards + }; + graph_data.children.push( collection ); + } + + helper_data.protocol = $.unique( helper_data.protocol ); + helper_data.host = $.unique( helper_data.host ); + helper_data.hostname = $.unique( helper_data.hostname ); + helper_data.port = $.unique( helper_data.port ); + helper_data.pathname = $.unique( helper_data.pathname ); + + callback( graph_element, graph_data, leaf_count ); + }, + error : function( xhr, text_status, error_thrown) + { + }, + complete : function( xhr, text_status ) + { + } + } + ); + }, + error : function( xhr, text_status, error_thrown) + { + }, + complete : function( xhr, text_status ) + { + } + } + ); + +}; + +var init_graph = function( graph_element ) +{ + prepare_graph + ( + graph_element, + function( graph_element, graph_data, leaf_count ) + { + generate_graph( graph_element, graph_data, leaf_count ); + } + ); +} + +var init_rgraph = function( graph_element ) +{ + prepare_graph + ( + graph_element, + function( graph_element, graph_data, leaf_count ) + { + generate_rgraph( graph_element, graph_data, leaf_count ); + } + ); +} + +var init_tree = function( tree_element ) +{ + $.ajax + ( + { + url : app.config.solr_path + '/zookeeper?wt=json', + dataType : 'json', + context : tree_element, + beforeSend : function( xhr, settings ) + { + this + .show(); + }, + success : function( response, text_status, xhr ) + { + var self = this; + + $( '#tree', this ) + .jstree + ( + { + "plugins" : [ "json_data" ], + "json_data" : { + "data" : response.tree, + "progressive_render" : true + }, + "core" : { + "animation" : 0 + } + } + ) + .jstree + ( + 'open_node', + 'li:first' + ); + + var tree_links = $( '#tree a', this ); + + tree_links + .die( 'click' ) + .live + ( + 'click', + function( event ) + { + $( 'a.active', $( this ).parents( '#tree' ) ) + .removeClass( 'active' ); + + $( this ) + .addClass( 'active' ); + + tree_element + .addClass( 'show' ); + + var file_content = $( '#file-content' ); + + $( 'a.close', file_content ) + .die( 'click' ) + .live + ( + 'click', + function( event ) + { + $( '#tree a.active' ) + .removeClass( 'active' ); + + tree_element + .removeClass( 'show' ); + + return false; + } + ); + + $.ajax + ( + { + url : this.href, + dataType : 'json', + context : file_content, + beforeSend : function( xhr, settings ) + { + }, + success : function( response, text_status, xhr ) + { + var props = []; + for( var key in response.znode.prop ) + { + props.push + ( + '<li><dl class="clearfix">' + "\n" + + '<dt>' + key.esc() + '</dt>' + "\n" + + '<dd>' + response.znode.prop[key].esc() + '</dd>' + "\n" + + '</dl></li>' + ); + } + + $( '#prop ul', this ) + .empty() + .html( props.join( "\n" ) ); + + $( '#prop ul li:odd', this ) + .addClass( 'odd' ); + + var data_element = $( '#data', this ); + + var highlight = false; + var data = '<em>Node "' + response.znode.path + '" has no utf8 Content</em>'; + + if( response.znode.data ) + { + var classes = ''; + var path = response.znode.path.split( '.' ); + + if( 1 < path.length ) + { + highlight = true; + classes = 'syntax language-' + path.pop().esc(); + } + + data = '<pre class="' + classes + '">' + + response.znode.data.esc() + + '</pre>'; + } + + + data_element + .show() + .html( data ); + + if( highlight ) + { + hljs.highlightBlock( data_element.get(0) ); + } + + }, + error : function( xhr, text_status, error_thrown) + { + }, + complete : function( xhr, text_status ) + { + } + } + ); + + return false; + } + ); + }, + error : zk_error, + complete : function( xhr, text_status ) + { + } + } + ); +}; + +// #/~cloud +sammy.get +( + /^#\/(~cloud)$/, + function( context ) + { + var content_element = $( '#content' ); + + $.get + ( + 'tpl/cloud.html', + function( template ) + { + content_element + .html( template ); + + var cloud_element = $( '#cloud', content_element ); + var navigation_element = $( '#menu #cloud' ); + + init_debug( cloud_element ); + + $( '.tree', navigation_element ) + .die( 'activate' ) + .live + ( + 'activate', + function( event ) + { + $( this ).addClass( 'active' ); + init_tree( $( '#tree-content', cloud_element ) ); + } + ); + + $( '.graph', navigation_element ) + .die( 'activate' ) + .live + ( + 'activate', + function( event ) + { + $( this ).addClass( 'active' ); + init_graph( $( '#graph-content', cloud_element ) ); + } + ); + + $( '.rgraph', navigation_element ) + .die( 'activate' ) + .live + ( + 'activate', + function( event ) + { + $( this ).addClass( 'active' ); + init_rgraph( $( '#graph-content', cloud_element ) ); + } + ); + + $.ajax + ( + { + url : app.config.solr_path + '/zookeeper?wt=json', + dataType : 'json', + context : cloud_element, + success : function( response, text_status, xhr ) + { + $( 'a[href="' + context.path + '"]', navigation_element ) + .trigger( 'activate' ); + }, + error : zk_error + } + ); + + } + ); + } +); Propchange: ofbiz/trunk/specialpurpose/solr/webapp/solr/js/scripts/cloud.js ------------------------------------------------------------------------------ svn:eol-style = native Propchange: ofbiz/trunk/specialpurpose/solr/webapp/solr/js/scripts/cloud.js ------------------------------------------------------------------------------ svn:keywords = Date Rev Author URL Id Propchange: ofbiz/trunk/specialpurpose/solr/webapp/solr/js/scripts/cloud.js ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: ofbiz/trunk/specialpurpose/solr/webapp/solr/js/scripts/cores.js URL: http://svn.apache.org/viewvc/ofbiz/trunk/specialpurpose/solr/webapp/solr/js/scripts/cores.js?rev=1700119&view=auto ============================================================================== --- ofbiz/trunk/specialpurpose/solr/webapp/solr/js/scripts/cores.js (added) +++ ofbiz/trunk/specialpurpose/solr/webapp/solr/js/scripts/cores.js Sun Aug 30 13:27:07 2015 @@ -0,0 +1,734 @@ +/* + 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. +*/ + +sammy.bind +( + 'cores_load_data', + function( event, params ) + { + $.ajax + ( + { + url : app.config.solr_path + app.config.core_admin_path + '?wt=json', + dataType : 'json', + beforeSend : function( xhr, settings ) + { + }, + success : function( response, text_status, xhr ) + { + if( params.only_failures ) + { + app.check_for_init_failures( response ); + return true; + } + + var has_cores = false; + for( core in response.status ) + { + has_cores = true; break; + } + + app.set_cores_data( response ); + + if( has_cores ) + { + params.success( app.cores_data ); + } + /** OFBiz customization **/ + else if( response.ofbizLogin ) + { + params.ofbizLogin(); + } + else + { + params.error(); + } + }, + error : function( xhr, text_status, error_thrown) + { + }, + complete : function( xhr, text_status ) + { + } + } + ); + } +); + +sammy.bind +( + 'cores_build_navigation', + function( event, params ) + { + var navigation_content = ['<ul>']; + + for( var core in params.cores ) + { + var core_name = core; + if( !core_name ) + { + core_name = '<em>(empty)</em>'; + } + navigation_content.push( '<li><a href="' + params.basepath + core + '">' + core_name + '</a></li>' ); + } + + params.navigation_element + .html( navigation_content.join( "\n" ) ); + + $( 'a[href="' + params.basepath + params.current_core + '"]', params.navigation_element ).parent() + .addClass( 'current' ); + } +); + +sammy.bind +( + 'cores_load_template', + function( event, params ) + { + if( app.cores_template ) + { + params.callback(); + return true; + } + + $.get + ( + 'tpl/cores.html', + function( template ) + { + params.content_element + .html( template ); + + app.cores_template = template; + params.callback(); + } + ); + } +); + +// #/~cores +sammy.get +( + /^#\/(~cores)$/, + function( context ) + { + delete app.cores_template; + var content_element = $( '#content' ); + + sammy.trigger + ( + 'cores_load_data', + { + /** OFBiz customization **/ + ofbizLogin : function() + { + context.redirect( 'control/checkLogin' ); + }, + success : function( cores ) + { + var first_core = null; + for( var key in cores ) + { + if( !first_core ) + { + first_core = key; + } + continue; + } + context.redirect( context.path + '/' + first_core ); + }, + error : function() + { + sammy.trigger + ( + 'cores_load_template', + { + content_element : content_element, + callback : function() + { + var cores_element = $( '#cores', content_element ); + var navigation_element = $( '#navigation', cores_element ); + var data_element = $( '#data', cores_element ); + var core_data_element = $( '#core-data', data_element ); + var index_data_element = $( '#index-data', data_element ); + + // layout + + var ui_block = $( '#ui-block' ); + var actions_element = $( '.actions', cores_element ); + var div_action = $( 'div.action', actions_element ); + + ui_block + .css( 'opacity', 0.7 ) + .width( cores_element.width() + 10 ) + .height( cores_element.height() ); + + if( $( '#cloud.global' ).is( ':visible' ) ) + { + $( '.cloud', div_action ) + .show(); + } + + $( 'button.action', actions_element ) + .die( 'click' ) + .live + ( + 'click', + function( event ) + { + var self = $( this ); + + self + .toggleClass( 'open' ); + + $( '.action.' + self.attr( 'id' ), actions_element ) + .trigger( 'open' ); + + return false; + } + ); + + div_action + .die( 'close' ) + .live + ( + 'close', + function( event ) + { + div_action.hide(); + ui_block.hide(); + } + ) + .die( 'open' ) + .live + ( + 'open', + function( event ) + { + var self = $( this ); + var rel = $( '#' + self.data( 'rel' ) ); + + self + .trigger( 'close' ) + .show() + .css( 'left', rel.position().left ); + + ui_block + .show(); + } + ); + + $( 'form button.reset', actions_element ) + .die( 'click' ) + .live + ( + 'click', + function( event ) + { + $( this ).closest( 'div.action' ) + .trigger( 'close' ); + } + ); + + $( 'form', div_action ) + .ajaxForm + ( + { + url : app.config.solr_path + app.config.core_admin_path + '?wt=json&indexInfo=false', + dataType : 'json', + beforeSubmit : function( array, form, options ) + { + $( 'button[type="submit"] span', form ) + .addClass( 'loader' ); + }, + success : function( response, status_text, xhr, form ) + { + delete app.cores_data; + sammy.refresh(); + + $( 'button.reset', form ) + .trigger( 'click' ); + }, + error : function( xhr, text_status, error_thrown ) + { + var response = null; + eval( 'response = ' + xhr.responseText + ';' ); + + var error_elem = $( '.error', div_action.filter( ':visible' ) ); + error_elem.show(); + $( 'span', error_elem ).text( response.error.msg ); + }, + complete : function() + { + $( 'button span.loader', actions_element ) + .removeClass( 'loader' ); + } + } + ); + + // -- + + $( '#add', content_element ) + .trigger( 'click' ); + + $( '[data-rel="add"] input[type="text"]:first', content_element ) + .focus(); + } + } + ); + } + } + ); + } +); + +// #/~cores +sammy.get +( + /^#\/(~cores)\//, + function( context ) + { + var content_element = $( '#content' ); + + var path_parts = this.path.match( /^(.+\/~cores\/)(.*)$/ ); + var current_core = path_parts[2]; + + sammy.trigger + ( + 'cores_load_data', + { + /** OFBiz customization **/ + ofbizLogin : function() + { + context.redirect( 'control/checkLogin' ); + }, + error : function() + { + context.redirect( '#/' + context.params.splat[0] ); + }, + success : function( cores ) + { + sammy.trigger + ( + 'cores_load_template', + { + content_element : content_element, + callback : function() + { + var cores_element = $( '#cores', content_element ); + var navigation_element = $( '#navigation', cores_element ); + var data_element = $( '#data', cores_element ); + var core_data_element = $( '#core-data', data_element ); + var index_data_element = $( '#index-data', data_element ); + + cores_element + .removeClass( 'empty' ); + + sammy.trigger + ( + 'cores_build_navigation', + { + cores : cores, + basepath : path_parts[1], + current_core : current_core, + navigation_element : navigation_element + } + ); + + var core_data = cores[current_core]; + var core_basepath = $( '#' + current_core, app.menu_element ).attr( 'data-basepath' ); + + // core-data + + $( '.startTime dd', core_data_element ) + .html( core_data.startTime ); + + $( '.instanceDir dd', core_data_element ) + .html( core_data.instanceDir ); + + $( '.dataDir dd', core_data_element ) + .html( core_data.dataDir ); + + // index-data + + $( '.lastModified dd', index_data_element ) + .html( core_data.index.lastModified || '-' ); + + $( '.version dd', index_data_element ) + .html( core_data.index.version ); + + $( '.numDocs dd', index_data_element ) + .html( core_data.index.numDocs ); + + $( '.maxDoc dd', index_data_element ) + .html( core_data.index.maxDoc ); + + $( '.deletedDocs dd', index_data_element ) + .html( core_data.index.deletedDocs || '-' ); + + $( '.optimized dd', index_data_element ) + .addClass( !core_data.index.hasDeletions ? 'ico-1' : 'ico-0' ); + + $( '#actions #optimize', cores_element ) + .show(); + + $( '.optimized dd span', index_data_element ) + .html( !core_data.index.hasDeletions ? 'yes' : 'no' ); + + $( '.current dd', index_data_element ) + .addClass( core_data.index.current ? 'ico-1' : 'ico-0' ); + + $( '.current dd span', index_data_element ) + .html( core_data.index.current ? 'yes' : 'no' ); + + $( '.directory dd', index_data_element ) + .html + ( + core_data.index.directory + .replace( /:/g, ':​' ) + .replace( /@/g, '@​' ) + ); + + var core_names = []; + var core_selects = $( '#actions select', cores_element ); + + for( var key in cores ) + { + core_names.push( '<option value="' + key + '">' + key + '</option>' ) + } + + core_selects + .html( core_names.join( "\n") ); + + $( 'option[value="' + current_core + '"]', core_selects.filter( '.other' ) ) + .remove(); + + $( 'input[data-core="current"]', cores_element ) + .val( current_core ); + + // layout + + var ui_block = $( '#ui-block' ); + var actions_element = $( '.actions', cores_element ); + var div_action = $( 'div.action', actions_element ); + + ui_block + .css( 'opacity', 0.7 ) + .width( cores_element.width() + 10 ) + .height( cores_element.height() ); + + if( $( '#cloud.global' ).is( ':visible' ) ) + { + $( '.cloud', div_action ) + .show(); + } + + $( 'button.action', actions_element ) + .die( 'click' ) + .live + ( + 'click', + function( event ) + { + var self = $( this ); + + self + .toggleClass( 'open' ); + + $( '.action.' + self.attr( 'id' ), actions_element ) + .trigger( 'open' ); + + return false; + } + ); + + div_action + .die( 'close' ) + .live + ( + 'close', + function( event ) + { + div_action.hide(); + ui_block.hide(); + } + ) + .die( 'open' ) + .live + ( + 'open', + function( event ) + { + var self = $( this ); + var rel = $( '#' + self.data( 'rel' ) ); + + self + .trigger( 'close' ) + .show() + .css( 'left', rel.position().left ); + + ui_block + .show(); + } + ); + + $( 'form button.reset', actions_element ) + .die( 'click' ) + .live + ( + 'click', + function( event ) + { + $( this ).closest( 'div.action' ) + .trigger( 'close' ); + } + ); + + var form_callback = { + + rename : function( form, response ) + { + var url = path_parts[1] + $( 'input[name="other"]', form ).val(); + context.redirect( url ); + } + + }; + + $( 'form', div_action ) + .ajaxForm + ( + { + url : app.config.solr_path + app.config.core_admin_path + '?wt=json&indexInfo=false', + dataType : 'json', + beforeSubmit : function( array, form, options ) + { + $( 'button[type="submit"] span', form ) + .addClass( 'loader' ); + }, + success : function( response, status_text, xhr, form ) + { + var action = $( 'input[name="action"]', form ).val().toLowerCase(); + + delete app.cores_data; + + if( form_callback[action] ) + { + form_callback[action]( form, response ); + } + else + { + sammy.refresh(); + } + + $( 'button.reset', form ) + .trigger( 'click' ); + }, + error : function( xhr, text_status, error_thrown ) + { + var response = null; + eval( 'response = ' + xhr.responseText + ';' ); + + var error_elem = $( '.error', div_action.filter( ':visible' ) ); + error_elem.show(); + $( 'span', error_elem ).text( response.error.msg ); + }, + complete : function() + { + $( 'button span.loader', actions_element ) + .removeClass( 'loader' ); + } + } + ); + + var reload_button = $( '#actions #reload', cores_element ); + reload_button + .die( 'click' ) + .live + ( + 'click', + function( event ) + { + $.ajax + ( + { + url : app.config.solr_path + app.config.core_admin_path + '?wt=json&action=RELOAD&core=' + current_core, + dataType : 'json', + context : $( this ), + beforeSend : function( xhr, settings ) + { + $( 'span', this ) + .addClass( 'loader' ); + }, + success : function( response, text_status, xhr ) + { + this + .addClass( 'success' ); + + delete app.cores_data; + sammy.refresh(); + + window.setTimeout + ( + function() + { + reload_button + .removeClass( 'success' ); + }, + 1000 + ); + }, + error : function( xhr, text_status, error_thrown ) + { + this + .addClass( 'warn' ); + + sammy.trigger( 'cores_load_data', { only_failures : true } ); + + window.setTimeout + ( + function() + { + reload_button + .removeClass( 'warn' ); + }, + 1000 + ); + }, + complete : function( xhr, text_status ) + { + $( 'span', this ) + .removeClass( 'loader' ); + } + } + ); + } + ); + + $( '#actions #unload', cores_element ) + .die( 'click' ) + .live + ( + 'click', + function( event ) + { + var ret = confirm( 'Do you really want to unload Core "' + current_core + '"?' ); + if( !ret ) + { + return false; + } + + $.ajax + ( + { + url : app.config.solr_path + app.config.core_admin_path + '?wt=json&action=UNLOAD&core=' + current_core, + dataType : 'json', + context : $( this ), + beforeSend : function( xhr, settings ) + { + $( 'span', this ) + .addClass( 'loader' ); + }, + success : function( response, text_status, xhr ) + { + delete app.cores_data; + context.redirect( path_parts[1].substr( 0, path_parts[1].length - 1 ) ); + }, + error : function( xhr, text_status, error_thrown ) + { + }, + complete : function( xhr, text_status ) + { + $( 'span', this ) + .removeClass( 'loader' ); + } + } + ); + } + ); + + var optimize_button = $( '#actions #optimize', cores_element ); + optimize_button + .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 ) + { + $( 'span', this ) + .addClass( 'loader' ); + }, + success : function( response, text_status, xhr ) + { + this + .addClass( 'success' ); + + window.setTimeout + ( + function() + { + optimize_button + .removeClass( 'success' ); + }, + 1000 + ); + + $( '.optimized dd.ico-0', index_data_element ) + .removeClass( 'ico-0' ) + .addClass( 'ico-1' ); + }, + error : function( xhr, text_status, error_thrown) + { + console.warn( 'd0h, optimize broken!' ); + }, + complete : function( xhr, text_status ) + { + $( 'span', this ) + .removeClass( 'loader' ); + } + } + ); + } + ); + + $( '.timeago', data_element ) + .timeago(); + + $( 'ul', data_element ) + .each + ( + function( i, element ) + { + $( 'li:odd', element ) + .addClass( 'odd' ); + } + ) + } + } + ); + } + } + ); + } +); \ No newline at end of file Propchange: ofbiz/trunk/specialpurpose/solr/webapp/solr/js/scripts/cores.js ------------------------------------------------------------------------------ svn:eol-style = native Propchange: ofbiz/trunk/specialpurpose/solr/webapp/solr/js/scripts/cores.js ------------------------------------------------------------------------------ svn:keywords = Date Rev Author URL Id Propchange: ofbiz/trunk/specialpurpose/solr/webapp/solr/js/scripts/cores.js ------------------------------------------------------------------------------ svn:mime-type = text/plain |
Free forum by Nabble | Edit this page |