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 )
{
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
2012-03-07 11:30:20 -05:00
if ( this . params . splat )
{
2012-03-21 05:36:59 -04:00
var active _element = $ ( '#' + this . params . splat [ 0 ] , menu _wrapper ) ;
2012-02-23 14:23:10 -05:00
2012-03-07 11:30:20 -05:00
if ( 0 === active _element . size ( ) )
{
2012-03-21 05:36:59 -04:00
this . app . error ( 'There exists no core with name "' + this . params . splat [ 0 ] + '"' ) ;
2012-03-07 11:30:20 -05:00
return false ;
}
active _element
. addClass ( 'active' ) ;
if ( this . params . splat [ 1 ] )
{
$ ( '.' + this . params . splat [ 1 ] , active _element )
. addClass ( 'active' ) ;
}
if ( ! active _element . hasClass ( 'global' ) )
{
this . active _core = active _element ;
}
}
}
) ;
}
2012-02-23 14:23:10 -05:00
) ;
var solr _admin = function ( app _config )
{
self = this ,
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 ,
environment _basepath = 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
2012-03-21 05:36:59 -04:00
this . menu _element = $ ( '#menu-selector' ) ;
2012-03-07 11:30:20 -05:00
this . config = config ;
this . run = function ( )
{
$ . ajax
(
{
url : config . solr _path + config . core _admin _path + '?wt=json' ,
dataType : 'json' ,
beforeSend : function ( arr , form , options )
{
$ ( '#content' )
. html ( '<div id="index"><div class="loader">Loading ...</div></div>' ) ;
} ,
success : function ( response )
{
self . cores _data = response . status ;
2012-03-21 05:36:59 -04:00
var core _count = 0 ; for ( var i in response . status ) { core _count ++ ; }
is _multicore = core _count > 1 ;
2012-03-07 11:30:20 -05:00
if ( is _multicore )
{
self . menu _element
. addClass ( 'multicore' ) ;
$ ( '#cores' , menu _element )
. show ( ) ;
}
else
{
self . menu _element
. addClass ( 'singlecore' ) ;
}
for ( var core _name in response . status )
{
var core _path = config . solr _path + '/' + core _name ;
if ( ! core _name )
{
core _name = 'singlecore' ;
core _path = config . solr _path
}
2012-02-23 14:23:10 -05:00
2012-03-07 11:30:20 -05:00
if ( ! environment _basepath )
2012-02-23 14:23:10 -05:00
{
2012-03-07 11:30:20 -05:00
environment _basepath = core _path ;
}
var core _tpl = '<li id="' + core _name + '" data-basepath="' + core _path + '">' + "\n"
+ ' <p><a href="#/' + core _name + '">' + core _name + '</a></p>' + "\n"
+ ' <ul>' + "\n"
+ ' <li class="ping"><a rel="' + core _path + '/admin/ping"><span>Ping</span></a></li>' + "\n"
+ ' <li class="query"><a href="#/' + core _name + '/query"><span>Query</span></a></li>' + "\n"
+ ' <li class="schema"><a href="#/' + core _name + '/schema"><span>Schema</span></a></li>' + "\n"
+ ' <li class="config"><a href="#/' + core _name + '/config"><span>Config</span></a></li>' + "\n"
+ ' <li class="replication"><a href="#/' + core _name + '/replication"><span>Replication</span></a></li>' + "\n"
+ ' <li class="analysis"><a href="#/' + core _name + '/analysis"><span>Analysis</span></a></li>' + "\n"
+ ' <li class="schema-browser"><a href="#/' + core _name + '/schema-browser"><span>Schema Browser</span></a></li>' + "\n"
+ ' <li class="plugins"><a href="#/' + core _name + '/plugins"><span>Plugins</span></a></li>' + "\n"
+ ' <li class="dataimport"><a href="#/' + core _name + '/dataimport"><span>Dataimport</span></a></li>' + "\n"
+ ' </ul>' + "\n"
+ '</li>' ;
self . menu _element
. append ( core _tpl ) ;
}
$ . ajax
(
{
url : environment _basepath + '/admin/system?wt=json' ,
dataType : 'json' ,
beforeSend : function ( arr , form , options )
{
} ,
success : function ( response )
{
self . dashboard _values = response ;
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 ) ;
cloud _args = command _line _args . match ( /-Dzk/i ) ;
}
// title
$ ( 'title' , document )
. append ( ' (' + response . core . host + ')' ) ;
// environment
var environment _element = $ ( '#environment' ) ;
if ( environment _args )
2012-02-23 14:23:10 -05:00
{
2012-03-07 11:30:20 -05:00
environment _element
. show ( ) ;
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-03-07 11:30:20 -05:00
environment _element
. remove ( ) ;
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 ( )
{
var main = $ ( '#main' ) ;
$ ( 'div[id$="-wrapper"]' , main )
. remove ( ) ;
main
. addClass ( 'error' )
. append
(
'<div class="message">This interface requires that you activate the admin request handlers, add the following configuration to your <code>solrconfig.xml:</code></div>' +
'<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>'
) ;
hljs . highlightBlock ( $ ( 'pre' , main ) . get ( 0 ) ) ;
} ,
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 ( )
{
}
}
) ;
}
2012-02-23 14:23:10 -05:00
} ;
2012-03-21 05:36:59 -04:00
var app = new solr _admin ( app _config ) ;