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.
|
|
|
|
*/
|
|
|
|
|
2013-01-10 19:13:33 -05:00
|
|
|
var dataimport_timeout = 2000;
|
|
|
|
var cookie_dataimport_autorefresh = 'dataimport_autorefresh';
|
2012-03-21 05:36:59 -04:00
|
|
|
|
2012-02-23 14:23:10 -05:00
|
|
|
sammy.bind
|
|
|
|
(
|
2012-03-21 05:36:59 -04:00
|
|
|
'dataimport_queryhandler_load',
|
|
|
|
function( event, params )
|
|
|
|
{
|
|
|
|
var core_basepath = params.active_core.attr( 'data-basepath' );
|
|
|
|
|
|
|
|
$.ajax
|
|
|
|
(
|
|
|
|
{
|
|
|
|
url : core_basepath + '/admin/mbeans?cat=QUERYHANDLER&wt=json',
|
|
|
|
dataType : 'json',
|
|
|
|
beforeSend : function( xhr, settings )
|
|
|
|
{
|
|
|
|
},
|
|
|
|
success : function( response, text_status, xhr )
|
|
|
|
{
|
|
|
|
var handlers = response['solr-mbeans'][1];
|
|
|
|
var dataimport_handlers = [];
|
|
|
|
for( var key in handlers )
|
|
|
|
{
|
|
|
|
if( handlers[key]['class'] !== key &&
|
|
|
|
handlers[key]['class'] === 'org.apache.solr.handler.dataimport.DataImportHandler' )
|
2012-02-23 14:23:10 -05:00
|
|
|
{
|
2012-03-21 05:36:59 -04:00
|
|
|
dataimport_handlers.push( key );
|
2012-02-23 14:23:10 -05:00
|
|
|
}
|
2012-03-21 05:36:59 -04:00
|
|
|
}
|
|
|
|
params.callback( dataimport_handlers );
|
|
|
|
},
|
|
|
|
error : function( xhr, text_status, error_thrown)
|
|
|
|
{
|
|
|
|
},
|
|
|
|
complete : function( xhr, text_status )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
2012-02-23 14:23:10 -05:00
|
|
|
);
|
|
|
|
|
|
|
|
// #/:core/dataimport
|
|
|
|
sammy.get
|
|
|
|
(
|
2013-01-05 05:57:21 -05:00
|
|
|
new RegExp( app.core_regex_base + '\\/(dataimport)$' ),
|
2012-03-21 05:36:59 -04:00
|
|
|
function( context )
|
|
|
|
{
|
|
|
|
sammy.trigger
|
|
|
|
(
|
|
|
|
'dataimport_queryhandler_load',
|
|
|
|
{
|
|
|
|
active_core : this.active_core,
|
|
|
|
callback : function( dataimport_handlers )
|
|
|
|
{
|
|
|
|
if( 0 === dataimport_handlers.length )
|
|
|
|
{
|
|
|
|
$( '#content' )
|
|
|
|
.html( 'sorry, no dataimport-handler defined!' );
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
context.redirect( context.path + '/' + dataimport_handlers[0] );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
2012-02-23 14:23:10 -05:00
|
|
|
);
|
|
|
|
|
|
|
|
// #/:core/dataimport
|
|
|
|
sammy.get
|
|
|
|
(
|
2013-01-05 05:57:21 -05:00
|
|
|
new RegExp( app.core_regex_base + '\\/(dataimport)\\/' ),
|
2012-03-21 05:36:59 -04:00
|
|
|
function( context )
|
|
|
|
{
|
|
|
|
var core_basepath = this.active_core.attr( 'data-basepath' );
|
|
|
|
var content_element = $( '#content' );
|
|
|
|
|
|
|
|
var path_parts = this.path.match( /^(.+\/dataimport\/)(.*)$/ );
|
|
|
|
var handler_url = core_basepath + path_parts[2];
|
2012-02-23 14:23:10 -05:00
|
|
|
|
2012-03-21 05:36:59 -04:00
|
|
|
$( 'li.dataimport', this.active_core )
|
|
|
|
.addClass( 'active' );
|
2012-02-23 14:23:10 -05:00
|
|
|
|
2012-03-21 05:36:59 -04:00
|
|
|
$.get
|
|
|
|
(
|
|
|
|
'tpl/dataimport.html',
|
|
|
|
function( template )
|
|
|
|
{
|
|
|
|
content_element
|
|
|
|
.html( template );
|
2012-02-23 14:23:10 -05:00
|
|
|
|
2012-03-21 05:36:59 -04:00
|
|
|
var dataimport_element = $( '#dataimport', content_element );
|
|
|
|
var form_element = $( '#form', dataimport_element );
|
|
|
|
var config_element = $( '#config', dataimport_element );
|
2013-01-10 19:13:33 -05:00
|
|
|
var error_element = $( '#error', dataimport_element );
|
|
|
|
var debug_response_element = $( '#debug_response', dataimport_element );
|
|
|
|
|
|
|
|
var autorefresh_status = false;
|
|
|
|
var debug_mode = false;
|
2012-02-23 14:23:10 -05:00
|
|
|
|
2012-03-21 05:36:59 -04:00
|
|
|
// handler
|
2012-02-23 14:23:10 -05:00
|
|
|
|
2012-03-21 05:36:59 -04:00
|
|
|
sammy.trigger
|
|
|
|
(
|
|
|
|
'dataimport_queryhandler_load',
|
|
|
|
{
|
|
|
|
active_core : context.active_core,
|
|
|
|
callback : function( dataimport_handlers )
|
|
|
|
{
|
|
|
|
var handlers_element = $( '#navigation ul', form_element );
|
|
|
|
var handlers = [];
|
|
|
|
|
|
|
|
for( var i = 0; i < dataimport_handlers.length; i++ )
|
|
|
|
{
|
|
|
|
handlers.push
|
2012-02-23 14:23:10 -05:00
|
|
|
(
|
2012-03-21 05:36:59 -04:00
|
|
|
'<li><a href="' + path_parts[1] + dataimport_handlers[i] + '">' +
|
|
|
|
dataimport_handlers[i] +
|
|
|
|
'</a></li>'
|
2012-02-23 14:23:10 -05:00
|
|
|
);
|
2012-03-21 05:36:59 -04:00
|
|
|
}
|
2012-02-23 14:23:10 -05:00
|
|
|
|
2012-03-21 05:36:59 -04:00
|
|
|
$( handlers_element )
|
|
|
|
.html( handlers.join( "\n") ) ;
|
|
|
|
|
|
|
|
$( 'a[href="' + context.path + '"]', handlers_element ).closest( 'li' )
|
|
|
|
.addClass( 'current' );
|
2012-02-23 14:23:10 -05:00
|
|
|
|
2012-03-21 05:36:59 -04:00
|
|
|
$( 'form', form_element )
|
|
|
|
.show();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
// config
|
|
|
|
|
|
|
|
function dataimport_fetch_config()
|
|
|
|
{
|
|
|
|
$.ajax
|
|
|
|
(
|
|
|
|
{
|
2013-01-10 19:13:33 -05:00
|
|
|
url : handler_url + '?command=show-config&indent=true',
|
2012-03-21 05:36:59 -04:00
|
|
|
dataType : 'xml',
|
|
|
|
context : $( '#dataimport_config', config_element ),
|
|
|
|
beforeSend : function( xhr, settings )
|
|
|
|
{
|
2013-01-10 19:13:33 -05:00
|
|
|
error_element
|
|
|
|
.empty()
|
|
|
|
.hide();
|
2012-03-21 05:36:59 -04:00
|
|
|
},
|
|
|
|
success : function( config, text_status, xhr )
|
|
|
|
{
|
|
|
|
dataimport_element
|
|
|
|
.removeClass( 'error' );
|
2012-02-23 14:23:10 -05:00
|
|
|
|
2012-03-21 05:36:59 -04:00
|
|
|
config_element
|
|
|
|
.addClass( 'hidden' );
|
2012-02-23 14:23:10 -05:00
|
|
|
|
2012-03-21 05:36:59 -04:00
|
|
|
var entities = [ '<option value=""></option>' ];
|
2012-02-23 14:23:10 -05:00
|
|
|
|
2012-03-21 05:36:59 -04:00
|
|
|
$( 'document > entity', config )
|
|
|
|
.each
|
|
|
|
(
|
|
|
|
function( i, element )
|
|
|
|
{
|
|
|
|
entities.push( '<option>' + $( element ).attr( 'name' ).esc() + '</option>' );
|
|
|
|
}
|
|
|
|
);
|
2012-02-23 14:23:10 -05:00
|
|
|
|
2012-03-21 05:36:59 -04:00
|
|
|
$( '#entity', form_element )
|
|
|
|
.html( entities.join( "\n" ) );
|
2013-01-10 19:13:33 -05:00
|
|
|
|
|
|
|
$( '.editable textarea', this )
|
|
|
|
.val( xhr.responseText.replace( /\n+$/, '' ) );
|
2012-03-21 05:36:59 -04:00
|
|
|
},
|
|
|
|
error : function( xhr, text_status, error_thrown )
|
|
|
|
{
|
|
|
|
if( 'parsererror' === error_thrown )
|
|
|
|
{
|
|
|
|
dataimport_element
|
|
|
|
.addClass( 'error' );
|
2012-02-23 14:23:10 -05:00
|
|
|
|
2013-01-10 19:13:33 -05:00
|
|
|
error_element
|
|
|
|
.text( 'Dataimport XML-Configuration is not valid' )
|
2012-03-21 05:36:59 -04:00
|
|
|
.show();
|
|
|
|
|
|
|
|
config_element
|
|
|
|
.removeClass( 'hidden' );
|
2012-02-23 14:23:10 -05:00
|
|
|
}
|
2012-03-21 05:36:59 -04:00
|
|
|
},
|
|
|
|
complete : function( xhr, text_status )
|
|
|
|
{
|
|
|
|
var code = $(
|
|
|
|
'<pre class="syntax language-xml"><code>' +
|
|
|
|
xhr.responseText.esc() +
|
|
|
|
'</code></pre>'
|
|
|
|
);
|
2013-01-10 19:13:33 -05:00
|
|
|
$( '.formatted', this ).html( code );
|
2012-02-23 14:23:10 -05:00
|
|
|
|
2012-03-21 05:36:59 -04:00
|
|
|
if( 'success' === text_status )
|
|
|
|
{
|
|
|
|
hljs.highlightBlock( code.get(0) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
dataimport_fetch_config();
|
|
|
|
|
2013-01-10 19:13:33 -05:00
|
|
|
$( '.block .toggle', dataimport_element )
|
2012-03-21 05:36:59 -04:00
|
|
|
.die( 'click' )
|
|
|
|
.live
|
|
|
|
(
|
|
|
|
'click',
|
|
|
|
function( event )
|
|
|
|
{
|
|
|
|
$( this ).parents( '.block' )
|
|
|
|
.toggleClass( 'hidden' );
|
2012-02-23 14:23:10 -05:00
|
|
|
|
2012-03-21 05:36:59 -04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
var reload_config_element = $( '.reload_config', config_element );
|
|
|
|
reload_config_element
|
|
|
|
.die( 'click' )
|
|
|
|
.live
|
|
|
|
(
|
|
|
|
'click',
|
|
|
|
function( event )
|
|
|
|
{
|
|
|
|
$.ajax
|
|
|
|
(
|
|
|
|
{
|
|
|
|
url : handler_url + '?command=reload-config',
|
|
|
|
dataType : 'xml',
|
|
|
|
context: $( this ),
|
|
|
|
beforeSend : function( xhr, settings )
|
|
|
|
{
|
|
|
|
this
|
|
|
|
.removeClass( 'error' )
|
|
|
|
.addClass( 'loader' );
|
|
|
|
},
|
|
|
|
success : function( response, text_status, xhr )
|
|
|
|
{
|
|
|
|
this
|
|
|
|
.addClass( 'success' );
|
|
|
|
|
|
|
|
window.setTimeout
|
2012-02-23 14:23:10 -05:00
|
|
|
(
|
2012-03-21 05:36:59 -04:00
|
|
|
function()
|
|
|
|
{
|
|
|
|
reload_config_element
|
|
|
|
.removeClass( 'success' );
|
|
|
|
},
|
|
|
|
5000
|
|
|
|
);
|
|
|
|
},
|
|
|
|
error : function( xhr, text_status, error_thrown )
|
|
|
|
{
|
|
|
|
this
|
|
|
|
.addClass( 'error' );
|
|
|
|
},
|
|
|
|
complete : function( xhr, text_status )
|
|
|
|
{
|
|
|
|
this
|
|
|
|
.removeClass( 'loader' );
|
2012-02-23 14:23:10 -05:00
|
|
|
|
2012-03-21 05:36:59 -04:00
|
|
|
dataimport_fetch_config();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
return false;
|
|
|
|
}
|
2013-01-10 19:13:33 -05:00
|
|
|
);
|
|
|
|
|
|
|
|
var debug_mode_element = $( '.debug_mode', config_element );
|
|
|
|
debug_mode_element
|
|
|
|
.die( 'click' )
|
|
|
|
.live
|
|
|
|
(
|
|
|
|
'click',
|
|
|
|
function( event )
|
|
|
|
{
|
|
|
|
var self = $( this );
|
|
|
|
var block = self.closest( '.block' )
|
|
|
|
|
|
|
|
var debug_checkbox = $( 'input[name="debug"]', form_element );
|
|
|
|
var submit_span = $( 'button[type="submit"] span', form_element );
|
|
|
|
|
|
|
|
debug_mode = !debug_mode;
|
|
|
|
|
|
|
|
block.toggleClass( 'debug_mode', debug_mode );
|
|
|
|
|
|
|
|
if( debug_mode )
|
|
|
|
{
|
|
|
|
block.removeClass( 'hidden' );
|
|
|
|
|
|
|
|
debug_checkbox
|
|
|
|
.attr( 'checked', 'checked' )
|
|
|
|
.trigger( 'change' );
|
|
|
|
|
|
|
|
submit_span
|
|
|
|
.data( 'original', submit_span.text() )
|
|
|
|
.text( submit_span.data( 'debugmode' ) );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
submit_span
|
|
|
|
.text( submit_span.data( 'original' ) )
|
|
|
|
.removeData( 'original' );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
// abort
|
|
|
|
|
|
|
|
var abort_import_element = $( '.abort-import', dataimport_element );
|
|
|
|
abort_import_element
|
|
|
|
.off( 'click' )
|
|
|
|
.on
|
|
|
|
(
|
|
|
|
'click',
|
|
|
|
function( event )
|
|
|
|
{
|
|
|
|
var span_element = $( 'span', this );
|
|
|
|
|
|
|
|
$.ajax
|
|
|
|
(
|
|
|
|
{
|
|
|
|
url : handler_url + '?command=abort&wt=json',
|
|
|
|
dataType : 'json',
|
|
|
|
type: 'POST',
|
|
|
|
context: $( this ),
|
|
|
|
beforeSend : function( xhr, settings )
|
|
|
|
{
|
|
|
|
span_element
|
|
|
|
.addClass( 'loader' );
|
|
|
|
},
|
|
|
|
success : function( response, text_status, xhr )
|
|
|
|
{
|
|
|
|
span_element
|
|
|
|
.data( 'original', span_element.text() )
|
|
|
|
.text( span_element.data( 'aborting' ) );
|
|
|
|
|
|
|
|
this
|
|
|
|
.removeClass( 'warn' )
|
|
|
|
.addClass( 'success' );
|
|
|
|
|
|
|
|
window.setTimeout
|
|
|
|
(
|
|
|
|
function()
|
|
|
|
{
|
|
|
|
$( 'span', abort_import_element )
|
|
|
|
.removeClass( 'loader' )
|
|
|
|
.text( span_element.data( 'original' ) )
|
|
|
|
.removeData( 'original' );
|
|
|
|
|
|
|
|
abort_import_element
|
|
|
|
.removeClass( 'success' )
|
|
|
|
.addClass( 'warn' );
|
|
|
|
},
|
|
|
|
dataimport_timeout * 2
|
|
|
|
);
|
|
|
|
|
|
|
|
dataimport_fetch_status();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
);
|
2012-03-21 05:36:59 -04:00
|
|
|
|
|
|
|
// state
|
2013-01-10 19:13:33 -05:00
|
|
|
|
|
|
|
var status_button = $( 'form button.refresh-status', form_element );
|
|
|
|
|
|
|
|
status_button
|
|
|
|
.off( 'click' )
|
|
|
|
.on
|
|
|
|
(
|
|
|
|
'click',
|
|
|
|
function( event )
|
|
|
|
{
|
|
|
|
dataimport_fetch_status();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
)
|
|
|
|
.trigger( 'click' );
|
2012-02-23 14:23:10 -05:00
|
|
|
|
2013-01-10 19:13:33 -05:00
|
|
|
function dataimport_fetch_status( clear_timeout )
|
2012-03-21 05:36:59 -04:00
|
|
|
{
|
2013-01-10 19:13:33 -05:00
|
|
|
if( clear_timeout )
|
|
|
|
{
|
|
|
|
app.clear_timeout();
|
|
|
|
}
|
|
|
|
|
2012-03-21 05:36:59 -04:00
|
|
|
$.ajax
|
|
|
|
(
|
|
|
|
{
|
2013-01-10 19:13:33 -05:00
|
|
|
url : handler_url + '?command=status&indent=true&wt=json',
|
|
|
|
dataType : 'json',
|
2012-03-21 05:36:59 -04:00
|
|
|
beforeSend : function( xhr, settings )
|
|
|
|
{
|
2013-01-10 19:13:33 -05:00
|
|
|
$( 'span', status_button )
|
|
|
|
.addClass( 'loader' );
|
2012-03-21 05:36:59 -04:00
|
|
|
},
|
|
|
|
success : function( response, text_status, xhr )
|
|
|
|
{
|
|
|
|
var state_element = $( '#current_state', content_element );
|
|
|
|
|
2013-01-10 19:13:33 -05:00
|
|
|
var status = response.status;
|
|
|
|
var rollback_time = response.statusMessages.Rolledback || null;
|
|
|
|
var abort_time = response.statusMessages.Aborted || null;
|
|
|
|
|
|
|
|
var messages = response.statusMessages;
|
|
|
|
var messages_count = 0;
|
|
|
|
for( var key in messages ) { messages_count++; }
|
2012-03-21 05:36:59 -04:00
|
|
|
|
2013-01-10 19:13:33 -05:00
|
|
|
function dataimport_compute_details( response, details_element, elapsed_seconds )
|
2012-03-21 05:36:59 -04:00
|
|
|
{
|
2013-01-11 20:08:11 -05:00
|
|
|
details_element
|
|
|
|
.show();
|
|
|
|
|
|
|
|
// --
|
|
|
|
|
|
|
|
var document_config = {
|
2013-01-10 19:13:33 -05:00
|
|
|
'Requests' : 'Total Requests made to DataSource',
|
|
|
|
'Fetched' : 'Total Rows Fetched',
|
|
|
|
'Skipped' : 'Total Documents Skipped',
|
|
|
|
'Processed' : 'Total Documents Processed'
|
|
|
|
};
|
|
|
|
|
2013-01-11 20:08:11 -05:00
|
|
|
var document_details = [];
|
|
|
|
for( var key in document_config )
|
2012-03-21 05:36:59 -04:00
|
|
|
{
|
2013-01-11 20:08:11 -05:00
|
|
|
var value = parseInt( response.statusMessages[document_config[key]], 10 );
|
2012-03-21 05:36:59 -04:00
|
|
|
|
2013-01-26 10:00:28 -05:00
|
|
|
var detail = '<abbr title="' + document_config[key].esc() + '">' + key.esc() + '</abbr>: ' + app.format_number( value ).esc();
|
2013-01-10 19:13:33 -05:00
|
|
|
if( elapsed_seconds && 'skipped' !== key.toLowerCase() )
|
|
|
|
{
|
2013-01-26 10:00:28 -05:00
|
|
|
detail += ' <span>(' + app.format_number( Math.round( value / elapsed_seconds ) ).esc() + '/s)</span>'
|
2013-01-10 19:13:33 -05:00
|
|
|
}
|
2012-03-21 05:36:59 -04:00
|
|
|
|
2013-01-11 20:08:11 -05:00
|
|
|
document_details.push( detail );
|
2013-01-10 19:13:33 -05:00
|
|
|
};
|
|
|
|
|
2013-01-11 20:08:11 -05:00
|
|
|
$( '.docs', details_element )
|
|
|
|
.html( document_details.join( ', ' ) );
|
|
|
|
|
|
|
|
// --
|
|
|
|
|
|
|
|
var dates_config = {
|
|
|
|
'Started' : 'Full Dump Started',
|
|
|
|
'Aborted' : 'Aborted',
|
|
|
|
'Rolledback' : 'Rolledback'
|
|
|
|
};
|
|
|
|
|
|
|
|
var dates_details = [];
|
|
|
|
for( var key in dates_config )
|
|
|
|
{
|
|
|
|
var value = response.statusMessages[dates_config[key]];
|
|
|
|
|
|
|
|
if( value )
|
|
|
|
{
|
|
|
|
var detail = '<abbr title="' + dates_config[key].esc() + '">' + key.esc() + '</abbr>: '
|
|
|
|
+ '<abbr class="time">' + value.esc() + '</abbr>';
|
|
|
|
dates_details.push( detail );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
var dates_element = $( '.dates', details_element );
|
|
|
|
|
|
|
|
dates_element
|
|
|
|
.html( dates_details.join( ', ' ) );
|
|
|
|
|
|
|
|
$( '.time', dates_element )
|
|
|
|
.removeData( 'timeago' )
|
|
|
|
.timeago();
|
2013-01-10 19:13:33 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
var get_time_taken = function get_default_time_taken()
|
|
|
|
{
|
|
|
|
var time_taken_text = response.statusMessages['Time taken'];
|
|
|
|
return app.convert_duration_to_seconds( time_taken_text );
|
|
|
|
};
|
|
|
|
|
|
|
|
var get_default_info_text = function default_info_text()
|
|
|
|
{
|
|
|
|
var info_text = response.statusMessages[''] || '';
|
|
|
|
|
|
|
|
// format numbers included in status nicely
|
|
|
|
info_text = info_text.replace
|
|
|
|
(
|
|
|
|
/\d{4,}/g,
|
|
|
|
function( match, position, string )
|
|
|
|
{
|
2013-01-26 10:00:28 -05:00
|
|
|
return app.format_number( parseInt( match, 10 ) );
|
2013-01-10 19:13:33 -05:00
|
|
|
}
|
|
|
|
);
|
2012-03-21 05:36:59 -04:00
|
|
|
|
2013-01-10 19:13:33 -05:00
|
|
|
var time_taken_text = app.convert_seconds_to_readable_time( get_time_taken() );
|
|
|
|
if( time_taken_text )
|
2012-03-21 05:36:59 -04:00
|
|
|
{
|
2013-01-10 19:13:33 -05:00
|
|
|
info_text += ' (Duration: ' + time_taken_text.esc() + ')';
|
2012-03-21 05:36:59 -04:00
|
|
|
}
|
|
|
|
|
2013-01-10 19:13:33 -05:00
|
|
|
return info_text;
|
|
|
|
};
|
|
|
|
|
|
|
|
var show_info = function show_info( info_text, elapsed_seconds )
|
|
|
|
{
|
|
|
|
$( '.info strong', state_element )
|
|
|
|
.text( info_text || get_default_info_text() );
|
|
|
|
|
|
|
|
$( '.info .details', state_element )
|
|
|
|
.hide();
|
|
|
|
};
|
|
|
|
|
|
|
|
var show_full_info = function show_full_info( info_text, elapsed_seconds )
|
|
|
|
{
|
|
|
|
show_info( info_text, elapsed_seconds );
|
|
|
|
|
|
|
|
dataimport_compute_details
|
|
|
|
(
|
|
|
|
response,
|
|
|
|
$( '.info .details', state_element ),
|
|
|
|
elapsed_seconds || get_time_taken()
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2012-03-21 05:36:59 -04:00
|
|
|
state_element
|
2013-01-10 19:13:33 -05:00
|
|
|
.removeAttr( 'class' );
|
|
|
|
|
2013-01-11 20:08:11 -05:00
|
|
|
var current_time = new Date();
|
|
|
|
$( '.last_update abbr', state_element )
|
|
|
|
.text( current_time.toTimeString().split( ' ' ).shift() )
|
|
|
|
.attr( 'title', current_time.toUTCString() );
|
|
|
|
|
2012-03-21 05:36:59 -04:00
|
|
|
$( '.info', state_element )
|
|
|
|
.removeClass( 'loader' );
|
2012-02-23 14:23:10 -05:00
|
|
|
|
2013-01-10 19:13:33 -05:00
|
|
|
if( 'busy' === status )
|
2012-03-21 05:36:59 -04:00
|
|
|
{
|
|
|
|
state_element
|
2013-01-10 19:13:33 -05:00
|
|
|
.addClass( 'indexing' );
|
2012-03-21 05:36:59 -04:00
|
|
|
|
2013-01-10 19:13:33 -05:00
|
|
|
if( autorefresh_status )
|
|
|
|
{
|
|
|
|
$( '.info', state_element )
|
|
|
|
.addClass( 'loader' );
|
|
|
|
}
|
2012-02-23 14:23:10 -05:00
|
|
|
|
2013-01-10 19:13:33 -05:00
|
|
|
var time_elapsed_text = response.statusMessages['Time Elapsed'];
|
|
|
|
var elapsed_seconds = app.convert_duration_to_seconds( time_elapsed_text );
|
|
|
|
time_elapsed_text = app.convert_seconds_to_readable_time( elapsed_seconds );
|
2012-03-21 05:36:59 -04:00
|
|
|
|
2013-01-10 19:13:33 -05:00
|
|
|
var info_text = time_elapsed_text
|
|
|
|
? 'Indexing since ' + time_elapsed_text
|
|
|
|
: 'Indexing ...';
|
|
|
|
|
|
|
|
show_full_info( info_text, elapsed_seconds );
|
2012-03-21 05:36:59 -04:00
|
|
|
}
|
2013-01-10 19:13:33 -05:00
|
|
|
else if( rollback_time )
|
2012-03-21 05:36:59 -04:00
|
|
|
{
|
|
|
|
state_element
|
2013-01-10 19:13:33 -05:00
|
|
|
.addClass( 'failure' );
|
2012-03-21 05:36:59 -04:00
|
|
|
|
2013-01-10 19:13:33 -05:00
|
|
|
show_full_info();
|
2012-03-21 05:36:59 -04:00
|
|
|
}
|
2013-01-10 19:13:33 -05:00
|
|
|
else if( abort_time )
|
2012-03-21 05:36:59 -04:00
|
|
|
{
|
|
|
|
state_element
|
2013-01-10 19:13:33 -05:00
|
|
|
.addClass( 'aborted' );
|
2012-03-21 05:36:59 -04:00
|
|
|
|
2013-01-10 19:13:33 -05:00
|
|
|
show_full_info( 'Aborting current Import ...' );
|
|
|
|
}
|
|
|
|
else if( 'idle' === status && 0 !== messages_count )
|
|
|
|
{
|
|
|
|
state_element
|
|
|
|
.addClass( 'success' );
|
2012-03-21 05:36:59 -04:00
|
|
|
|
2013-01-10 19:13:33 -05:00
|
|
|
show_full_info();
|
2012-02-23 14:23:10 -05:00
|
|
|
}
|
2013-01-10 19:13:33 -05:00
|
|
|
else
|
2012-03-21 05:36:59 -04:00
|
|
|
{
|
2013-01-10 19:13:33 -05:00
|
|
|
state_element
|
|
|
|
.addClass( 'idle' );
|
|
|
|
|
|
|
|
show_info( 'No information available (idle)' );
|
2012-03-21 05:36:59 -04:00
|
|
|
}
|
2013-01-10 19:13:33 -05:00
|
|
|
|
|
|
|
// show raw status
|
|
|
|
|
|
|
|
var code = $(
|
|
|
|
'<pre class="syntax language-json"><code>' +
|
|
|
|
app.format_json( xhr.responseText ).esc() +
|
|
|
|
'</code></pre>'
|
|
|
|
);
|
|
|
|
|
|
|
|
$( '#raw_output_container', content_element ).html( code );
|
|
|
|
hljs.highlightBlock( code.get(0) );
|
2013-01-11 20:08:11 -05:00
|
|
|
|
|
|
|
if( !app.timeout && autorefresh_status )
|
|
|
|
{
|
|
|
|
app.timeout = window.setTimeout
|
|
|
|
(
|
|
|
|
function()
|
|
|
|
{
|
|
|
|
dataimport_fetch_status( true )
|
|
|
|
},
|
|
|
|
dataimport_timeout
|
|
|
|
);
|
|
|
|
}
|
2012-03-21 05:36:59 -04:00
|
|
|
},
|
|
|
|
error : function( xhr, text_status, error_thrown )
|
|
|
|
{
|
|
|
|
console.debug( arguments );
|
2012-02-23 14:23:10 -05:00
|
|
|
|
2012-03-21 05:36:59 -04:00
|
|
|
reload_config_element
|
|
|
|
.addClass( 'error' );
|
|
|
|
},
|
|
|
|
complete : function( xhr, text_status )
|
|
|
|
{
|
2013-01-10 19:13:33 -05:00
|
|
|
$( 'span', status_button )
|
|
|
|
.removeClass( 'loader' )
|
|
|
|
.addClass( 'success' );
|
|
|
|
|
|
|
|
window.setTimeout
|
|
|
|
(
|
|
|
|
function()
|
|
|
|
{
|
|
|
|
$( 'span', status_button )
|
|
|
|
.removeClass( 'success' );
|
|
|
|
},
|
|
|
|
dataimport_timeout / 2
|
|
|
|
);
|
2012-03-21 05:36:59 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
2012-02-23 14:23:10 -05:00
|
|
|
|
2012-03-21 05:36:59 -04:00
|
|
|
// form
|
|
|
|
|
2013-01-10 19:13:33 -05:00
|
|
|
var form = $( 'form', form_element );
|
|
|
|
|
|
|
|
form
|
2012-03-21 05:36:59 -04:00
|
|
|
.ajaxForm
|
|
|
|
(
|
|
|
|
{
|
|
|
|
url : handler_url,
|
2013-01-10 19:13:33 -05:00
|
|
|
data : {
|
|
|
|
wt : 'json',
|
|
|
|
indent : 'true'
|
|
|
|
},
|
|
|
|
dataType : 'json',
|
|
|
|
type: 'POST',
|
2012-03-21 05:36:59 -04:00
|
|
|
beforeSend : function( xhr, settings )
|
|
|
|
{
|
2013-01-10 19:13:33 -05:00
|
|
|
$( 'button[type="submit"] span', form_element )
|
2012-03-21 05:36:59 -04:00
|
|
|
.addClass( 'loader' );
|
2013-01-10 19:13:33 -05:00
|
|
|
|
|
|
|
error_element
|
|
|
|
.empty()
|
|
|
|
.hide();
|
2012-03-21 05:36:59 -04:00
|
|
|
},
|
|
|
|
beforeSubmit : function( array, form, options )
|
|
|
|
{
|
|
|
|
var entity = $( '#entity', form ).val();
|
|
|
|
if( entity.length )
|
|
|
|
{
|
|
|
|
array.push( { name : 'entity', value: entity } );
|
|
|
|
}
|
|
|
|
|
|
|
|
var start = parseInt( $( '#start', form ).val(), 10 );
|
|
|
|
if( start )
|
|
|
|
{
|
|
|
|
array.push( { name : 'start', value: start } );
|
|
|
|
}
|
|
|
|
|
|
|
|
var rows = parseInt( $( '#rows', form ).val(), 10 );
|
|
|
|
if( rows )
|
|
|
|
{
|
|
|
|
array.push( { name : 'rows', value: rows } );
|
|
|
|
}
|
|
|
|
|
2012-09-19 03:04:52 -04:00
|
|
|
$( 'input:checkbox', form ).not( ':checked' )
|
|
|
|
.each( function( i, input )
|
|
|
|
{
|
|
|
|
array.push( { name: input.name, value: 'false' } );
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2012-03-21 05:36:59 -04:00
|
|
|
var custom_parameters = $( '#custom_parameters', form ).val();
|
|
|
|
if( custom_parameters.length )
|
|
|
|
{
|
2012-09-06 04:24:46 -04:00
|
|
|
var params = custom_parameters.split( '&' );
|
|
|
|
for( var i in params )
|
|
|
|
{
|
|
|
|
var tmp = params[i].split( '=' );
|
|
|
|
array.push( { name : tmp[0], value: tmp[1] } );
|
|
|
|
}
|
2012-03-21 05:36:59 -04:00
|
|
|
}
|
2013-01-10 19:13:33 -05:00
|
|
|
|
|
|
|
if( debug_mode )
|
|
|
|
{
|
|
|
|
array.push( { name: 'dataConfig', value: $( '#dataimport_config .editable textarea' ).val() } );
|
|
|
|
}
|
2012-03-21 05:36:59 -04:00
|
|
|
},
|
|
|
|
success : function( response, text_status, xhr )
|
|
|
|
{
|
|
|
|
},
|
|
|
|
error : function( xhr, text_status, error_thrown )
|
|
|
|
{
|
2013-01-10 19:13:33 -05:00
|
|
|
var response = null;
|
|
|
|
try
|
|
|
|
{
|
|
|
|
eval( 'response = ' + xhr.responseText + ';' );
|
|
|
|
}
|
|
|
|
catch( e ){}
|
|
|
|
|
|
|
|
error_element
|
|
|
|
.text( response.error.msg || 'Unknown Error (Exception w/o Message)' )
|
|
|
|
.show();
|
2012-03-21 05:36:59 -04:00
|
|
|
},
|
|
|
|
complete : function( xhr, text_status )
|
|
|
|
{
|
2013-01-10 19:13:33 -05:00
|
|
|
$( 'button[type="submit"] span', form_element )
|
2012-03-21 05:36:59 -04:00
|
|
|
.removeClass( 'loader' );
|
2013-01-10 19:13:33 -05:00
|
|
|
|
|
|
|
var debug = $( 'input[name="debug"]:checked', form );
|
|
|
|
if( 0 !== debug.size() )
|
|
|
|
{
|
|
|
|
var code = $(
|
|
|
|
'<pre class="syntax language-json"><code>' +
|
|
|
|
app.format_json( xhr.responseText ).esc() +
|
|
|
|
'</code></pre>'
|
|
|
|
);
|
|
|
|
|
|
|
|
$( '.content', debug_response_element ).html( code );
|
|
|
|
hljs.highlightBlock( code.get(0) );
|
|
|
|
}
|
|
|
|
|
|
|
|
dataimport_fetch_status();
|
2012-03-21 05:36:59 -04:00
|
|
|
}
|
2012-02-23 14:23:10 -05:00
|
|
|
}
|
2012-03-21 05:36:59 -04:00
|
|
|
);
|
2013-01-10 19:13:33 -05:00
|
|
|
|
|
|
|
$( 'input[name="debug"]', form )
|
|
|
|
.off( 'change' )
|
|
|
|
.on
|
|
|
|
(
|
|
|
|
'change',
|
|
|
|
function( event )
|
|
|
|
{
|
|
|
|
debug_response_element.toggle( this.checked );
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
$( '#auto-refresh-status a', form_element )
|
|
|
|
.off( 'click' )
|
|
|
|
.on
|
|
|
|
(
|
|
|
|
'click',
|
|
|
|
function( event )
|
|
|
|
{
|
|
|
|
$.cookie( cookie_dataimport_autorefresh, $.cookie( cookie_dataimport_autorefresh ) ? null : true );
|
|
|
|
$( this ).trigger( 'state' );
|
|
|
|
|
|
|
|
dataimport_fetch_status();
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
)
|
|
|
|
.off( 'state' )
|
|
|
|
.on
|
|
|
|
(
|
|
|
|
'state',
|
|
|
|
function( event )
|
|
|
|
{
|
|
|
|
autorefresh_status = !!$.cookie( cookie_dataimport_autorefresh );
|
|
|
|
|
|
|
|
$.cookie( cookie_dataimport_autorefresh )
|
|
|
|
? $( this ).addClass( 'on' )
|
|
|
|
: $( this ).removeClass( 'on' );
|
|
|
|
}
|
|
|
|
)
|
|
|
|
.trigger( 'state' );
|
2012-03-21 05:36:59 -04:00
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
2013-06-27 07:40:44 -04:00
|
|
|
);
|