/* 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 = '
  • ' + '' + types[i].esc(); if( changes.count[types[i]] ) { navigation_markup += ' ' + changes.count[types[i]].esc() + ''; } navigation_markup += '' + '
  • '; navigation_content.push( navigation_markup ); } navigation_content.push( '
  • Watch Changes
  • ' ); navigation_content.push( '
  • Refresh Values
  • ' ); 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 = '' + "\n"; frame_element .html( content ); $( 'a[href="' + decodeURIComponent( active_context.path ) + '"]', frame_element ) .parent().addClass( 'expanded' ); // 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 ( /^#\/([\w\d-]+)\/(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 ( /^#\/([\w\d-]+)\/(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() ); } } ); } );