2012-03-07 11:30:20 -05:00
|
|
|
/*
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
|
2012-02-23 14:23:10 -05:00
|
|
|
var loader = {
|
|
|
|
|
2012-03-07 11:30:20 -05:00
|
|
|
show : function( element )
|
|
|
|
{
|
|
|
|
$( element )
|
|
|
|
.addClass( 'loader' );
|
|
|
|
},
|
2012-02-23 14:23:10 -05:00
|
|
|
|
2012-03-07 11:30:20 -05:00
|
|
|
hide : function( element )
|
|
|
|
{
|
|
|
|
$( element )
|
|
|
|
.removeClass( 'loader' );
|
|
|
|
}
|
2012-02-23 14:23:10 -05:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
Number.prototype.esc = function()
|
|
|
|
{
|
2012-03-07 11:30:20 -05:00
|
|
|
return new String( this ).esc();
|
2012-02-23 14:23:10 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
String.prototype.esc = function()
|
|
|
|
{
|
2012-03-07 11:30:20 -05:00
|
|
|
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] );
|
2012-02-23 14:23:10 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
var sammy = $.sammy
|
|
|
|
(
|
2012-03-07 11:30:20 -05:00
|
|
|
function()
|
|
|
|
{
|
|
|
|
this.bind
|
|
|
|
(
|
|
|
|
'run',
|
|
|
|
function( event, config )
|
|
|
|
{
|
|
|
|
if( 0 === config.start_url.length )
|
|
|
|
{
|
|
|
|
location.href = '#/';
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
2012-03-21 05:36:59 -04:00
|
|
|
|
|
|
|
this.bind
|
|
|
|
(
|
|
|
|
'error',
|
|
|
|
function( message, original_error )
|
|
|
|
{
|
|
|
|
alert( original_error.message );
|
|
|
|
}
|
|
|
|
);
|
2012-02-23 14:23:10 -05:00
|
|
|
|
2012-03-07 11:30:20 -05:00
|
|
|
// activate_core
|
|
|
|
this.before
|
|
|
|
(
|
|
|
|
{},
|
|
|
|
function( context )
|
|
|
|
{
|
2013-01-10 19:13:33 -05:00
|
|
|
app.clear_timeout();
|
2012-05-07 15:13:24 -04:00
|
|
|
|
2012-03-21 05:36:59 -04:00
|
|
|
var menu_wrapper = $( '#menu-wrapper' );
|
|
|
|
|
|
|
|
$( 'li[id].active', menu_wrapper )
|
2012-03-07 11:30:20 -05:00
|
|
|
.removeClass( 'active' );
|
2012-02-23 14:23:10 -05:00
|
|
|
|
2012-03-21 05:36:59 -04:00
|
|
|
$( 'li.active', menu_wrapper )
|
2012-03-07 11:30:20 -05:00
|
|
|
.removeClass( 'active' );
|
2012-02-23 14:23:10 -05:00
|
|
|
|
2013-01-28 14:56:10 -05:00
|
|
|
// global dashboard doesn't have params.splat
|
|
|
|
if( !this.params.splat )
|
2012-03-07 11:30:20 -05:00
|
|
|
{
|
2013-01-28 14:56:10 -05:00
|
|
|
this.params.splat = [ '~index' ];
|
|
|
|
}
|
2012-05-07 15:39:22 -04:00
|
|
|
|
2013-01-28 14:56:10 -05:00
|
|
|
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;
|
|
|
|
}
|
2012-03-07 11:30:20 -05:00
|
|
|
|
2013-01-28 14:56:10 -05:00
|
|
|
if( active_element.hasClass( 'global' ) )
|
|
|
|
{
|
2012-03-07 11:30:20 -05:00
|
|
|
active_element
|
|
|
|
.addClass( 'active' );
|
|
|
|
|
|
|
|
if( this.params.splat[1] )
|
|
|
|
{
|
|
|
|
$( '.' + this.params.splat[1], active_element )
|
|
|
|
.addClass( 'active' );
|
|
|
|
}
|
|
|
|
|
2013-01-28 14:56:10 -05:00
|
|
|
$( '#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] )
|
2012-03-07 11:30:20 -05:00
|
|
|
{
|
2013-01-28 14:56:10 -05:00
|
|
|
this.params.splat[1] = 'overview';
|
2012-03-07 11:30:20 -05:00
|
|
|
}
|
2013-01-28 14:56:10 -05:00
|
|
|
|
|
|
|
$( '#core-menu .' + this.params.splat[1] )
|
|
|
|
.addClass( 'active' );
|
|
|
|
|
|
|
|
this.active_core = active_element;
|
2012-03-07 11:30:20 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
2012-02-23 14:23:10 -05:00
|
|
|
);
|
|
|
|
|
|
|
|
var solr_admin = function( app_config )
|
|
|
|
{
|
2013-01-08 17:39:10 -05:00
|
|
|
that = this,
|
2012-02-23 14:23:10 -05:00
|
|
|
|
2012-03-07 11:30:20 -05:00
|
|
|
menu_element = null,
|
2012-02-23 14:23:10 -05:00
|
|
|
|
2012-03-07 11:30:20 -05:00
|
|
|
is_multicore = null,
|
|
|
|
cores_data = null,
|
|
|
|
active_core = null,
|
2012-02-23 14:23:10 -05:00
|
|
|
|
2012-03-07 11:30:20 -05:00
|
|
|
config = app_config,
|
|
|
|
params = null,
|
|
|
|
dashboard_values = null,
|
|
|
|
schema_browser_data = null,
|
2012-02-23 14:23:10 -05:00
|
|
|
|
2012-03-07 11:30:20 -05:00
|
|
|
plugin_data = null,
|
2012-02-23 14:23:10 -05:00
|
|
|
|
2013-01-28 14:56:10 -05:00
|
|
|
this.menu_element = $( '#core-selector select' );
|
|
|
|
this.core_menu = $( '#core-menu ul' );
|
2012-03-07 11:30:20 -05:00
|
|
|
|
2013-01-28 14:56:10 -05:00
|
|
|
this.config = config;
|
2012-05-07 15:13:24 -04:00
|
|
|
this.timeout = null;
|
|
|
|
|
2013-01-05 05:57:21 -05:00
|
|
|
this.core_regex_base = '^#\\/([\\w\\d-\\.]+)';
|
|
|
|
|
2013-01-29 12:34:10 -05:00
|
|
|
browser = {
|
|
|
|
locale : null,
|
|
|
|
language : null,
|
|
|
|
country : null
|
|
|
|
};
|
|
|
|
|
2012-07-30 19:11:35 -04:00
|
|
|
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) );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-01-05 09:21:28 -05:00
|
|
|
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 )
|
|
|
|
{
|
2013-01-08 17:39:10 -05:00
|
|
|
that.cores_data = sort_cores_data( cores.status );
|
2013-01-05 09:21:28 -05:00
|
|
|
|
2013-01-08 17:39:10 -05:00
|
|
|
that.menu_element
|
2013-01-05 09:21:28 -05:00
|
|
|
.empty();
|
|
|
|
|
2013-01-28 14:56:10 -05:00
|
|
|
var core_list = [];
|
|
|
|
core_list.push( '<option></option>' );
|
|
|
|
|
2013-01-05 09:21:28 -05:00
|
|
|
var core_count = 0;
|
2013-01-08 17:39:10 -05:00
|
|
|
for( var core_name in that.cores_data )
|
2013-01-05 09:21:28 -05:00
|
|
|
{
|
|
|
|
core_count++;
|
|
|
|
var core_path = config.solr_path + '/' + core_name;
|
|
|
|
var classes = [];
|
|
|
|
|
|
|
|
if( cores.status[core_name]['isDefaultCore'] )
|
|
|
|
{
|
|
|
|
classes.push( 'default' );
|
|
|
|
}
|
|
|
|
|
2013-01-28 14:56:10 -05:00
|
|
|
var core_tpl = '<option '
|
|
|
|
+ ' id="' + core_name.replace( /\./g, '__' ) + '" '
|
2013-01-05 09:21:28 -05:00
|
|
|
+ ' class="' + classes.join( ' ' ) + '"'
|
|
|
|
+ ' data-basepath="' + core_path + '"'
|
|
|
|
+ ' schema="' + cores.status[core_name]['schema'] + '"'
|
|
|
|
+ ' config="' + cores.status[core_name]['config'] + '"'
|
2013-01-28 14:56:10 -05:00
|
|
|
+ ' value="#/' + core_name + '"'
|
|
|
|
+ ' title="' + core_name + '"'
|
|
|
|
+ '>'
|
|
|
|
+ core_name
|
|
|
|
+ '</option>';
|
|
|
|
|
|
|
|
core_list.push( core_tpl );
|
2013-01-05 09:21:28 -05:00
|
|
|
}
|
|
|
|
|
2013-07-16 15:54:52 -04:00
|
|
|
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' );
|
|
|
|
}
|
2013-01-28 14:56:10 -05:00
|
|
|
|
2013-01-05 09:21:28 -05:00
|
|
|
if( cores.initFailures )
|
|
|
|
{
|
|
|
|
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 )
|
|
|
|
{
|
|
|
|
var init_failures = $( '#init-failures' );
|
|
|
|
|
|
|
|
init_failures.show();
|
|
|
|
$( 'ul', init_failures ).html( failures.join( "\n" ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-03-07 11:30:20 -05:00
|
|
|
this.run = function()
|
|
|
|
{
|
2013-01-29 12:34:10 -05:00
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-07 11:30:20 -05:00
|
|
|
$.ajax
|
|
|
|
(
|
|
|
|
{
|
2013-01-28 12:38:47 -05:00
|
|
|
url : config.solr_path + config.core_admin_path + '?wt=json&indexInfo=false',
|
2012-03-07 11:30:20 -05:00
|
|
|
dataType : 'json',
|
|
|
|
beforeSend : function( arr, form, options )
|
|
|
|
{
|
|
|
|
$( '#content' )
|
|
|
|
.html( '<div id="index"><div class="loader">Loading ...</div></div>' );
|
|
|
|
},
|
|
|
|
success : function( response )
|
|
|
|
{
|
2013-01-08 17:39:10 -05:00
|
|
|
that.set_cores_data( response );
|
2012-03-21 05:36:59 -04:00
|
|
|
|
2013-01-28 14:56:10 -05:00
|
|
|
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();
|
|
|
|
|
2013-06-26 12:27:43 -04:00
|
|
|
that.core_menu
|
2013-07-16 15:54:52 -04:00
|
|
|
.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" +
|
2013-11-17 08:23:23 -05:00
|
|
|
'<li class="files"><a href="#/' + core_name + '/files"><span>Files</span></a></li>' + "\n" +
|
2013-07-16 15:54:52 -04:00
|
|
|
'<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 )
|
2013-01-28 14:56:10 -05:00
|
|
|
{
|
|
|
|
that.core_menu
|
|
|
|
.hide()
|
|
|
|
.empty();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2013-07-16 15:54:52 -04:00
|
|
|
var system_url = config.solr_path + '/admin/info/system?wt=json';
|
2012-03-07 11:30:20 -05:00
|
|
|
$.ajax
|
|
|
|
(
|
|
|
|
{
|
2012-07-30 19:11:35 -04:00
|
|
|
url : system_url,
|
2012-03-07 11:30:20 -05:00
|
|
|
dataType : 'json',
|
|
|
|
beforeSend : function( arr, form, options )
|
|
|
|
{
|
|
|
|
},
|
|
|
|
success : function( response )
|
|
|
|
{
|
2013-01-08 17:39:10 -05:00
|
|
|
that.dashboard_values = response;
|
2012-03-07 11:30:20 -05:00
|
|
|
|
|
|
|
var environment_args = null;
|
|
|
|
var cloud_args = null;
|
|
|
|
|
|
|
|
if( response.jvm && response.jvm.jmx && response.jvm.jmx.commandLineArgs )
|
2012-02-23 14:23:10 -05:00
|
|
|
{
|
2012-03-07 11:30:20 -05:00
|
|
|
var command_line_args = response.jvm.jmx.commandLineArgs.join( ' | ' );
|
|
|
|
|
|
|
|
environment_args = command_line_args.match( /-Dsolr.environment=((dev|test|prod)?[\w\d]*)/i );
|
|
|
|
}
|
|
|
|
|
2013-02-27 10:15:03 -05:00
|
|
|
if( response.mode )
|
|
|
|
{
|
|
|
|
cloud_args = response.mode.match( /solrcloud/i );
|
|
|
|
}
|
2012-03-07 11:30:20 -05:00
|
|
|
|
|
|
|
// environment
|
|
|
|
|
2012-09-06 03:42:24 -04:00
|
|
|
var wrapper = $( '#wrapper' );
|
2012-03-07 11:30:20 -05:00
|
|
|
var environment_element = $( '#environment' );
|
|
|
|
if( environment_args )
|
2012-02-23 14:23:10 -05:00
|
|
|
{
|
2012-09-06 03:42:24 -04:00
|
|
|
wrapper
|
|
|
|
.addClass( 'has-environment' );
|
2012-03-07 11:30:20 -05:00
|
|
|
|
|
|
|
if( environment_args[1] )
|
|
|
|
{
|
|
|
|
environment_element
|
|
|
|
.html( environment_args[1] );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( environment_args[2] )
|
|
|
|
{
|
|
|
|
environment_element
|
|
|
|
.addClass( environment_args[2] );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2012-02-23 14:23:10 -05:00
|
|
|
{
|
2012-09-06 03:42:24 -04:00
|
|
|
wrapper
|
|
|
|
.removeClass( 'has-environment' );
|
2012-02-23 14:23:10 -05:00
|
|
|
}
|
2012-03-07 11:30:20 -05:00
|
|
|
|
|
|
|
// cloud
|
|
|
|
|
|
|
|
var cloud_nav_element = $( '#menu #cloud' );
|
|
|
|
if( cloud_args )
|
|
|
|
{
|
|
|
|
cloud_nav_element
|
|
|
|
.show();
|
|
|
|
}
|
|
|
|
|
|
|
|
// sammy
|
|
|
|
|
|
|
|
sammy.run( location.hash );
|
|
|
|
},
|
|
|
|
error : function()
|
|
|
|
{
|
2012-07-30 19:11:35 -04:00
|
|
|
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>'
|
|
|
|
);
|
2012-03-07 11:30:20 -05:00
|
|
|
},
|
|
|
|
complete : function()
|
|
|
|
{
|
|
|
|
loader.hide( this );
|
|
|
|
}
|
2012-02-23 14:23:10 -05:00
|
|
|
}
|
2012-03-07 11:30:20 -05:00
|
|
|
);
|
|
|
|
},
|
|
|
|
error : function()
|
|
|
|
{
|
|
|
|
},
|
|
|
|
complete : function()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
2013-01-10 19:13:33 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
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 );
|
|
|
|
}
|
|
|
|
|
2013-08-19 13:36:20 -04:00
|
|
|
return json_str.esc();
|
2013-01-10 19:13:33 -05:00
|
|
|
};
|
2012-02-23 14:23:10 -05:00
|
|
|
|
2013-01-26 10:00:28 -05:00
|
|
|
this.format_number = function format_number( number )
|
|
|
|
{
|
2013-01-29 12:34:10 -05:00
|
|
|
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['_']
|
|
|
|
);
|
2013-01-26 10:00:28 -05:00
|
|
|
};
|
|
|
|
|
2012-02-23 14:23:10 -05:00
|
|
|
};
|
|
|
|
|
2013-06-19 16:34:16 -04:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2013-03-15 16:36:01 -04:00
|
|
|
$.ajaxSetup( { cache: false } );
|
2012-07-30 19:11:35 -04:00
|
|
|
var app = new solr_admin( app_config );
|