SOLR-7851 Angular analysis tab tweaks

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1693486 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Upayavira 2015-07-30 19:36:22 +00:00
parent 9cb8523c59
commit ba50839c99
2 changed files with 40 additions and 343 deletions

View File

@ -34,10 +34,10 @@ solrAdminApp.controller('AnalysisController',
value: "fieldtype=" + type,
label: type});
}
$scope.core = $routeParams.core;
});
$scope.parseQueryString();
// @todo - if URL param, set $scope.verbose;
// @todo - set defaultSearchField either to context["analysis.fieldname"] or context["analysis.fieldtype"]
};
@ -131,6 +131,7 @@ solrAdminApp.controller('AnalysisController',
$location.search("analysis.fieldtype", name);
$location.search("analysis.fieldname", null);
}
$location.search("verbose_output", $scope.verbose ? "1" : "0");
};
$scope.parseQueryString = function () {
@ -147,10 +148,16 @@ solrAdminApp.controller('AnalysisController',
$scope.queryText = search["analysis.query"];
if (search["analysis.fieldname"]) {
$scope.fieldOrType = "fieldname=" + search["analysis.fieldname"];
$scope.schemaBrowserUrl = "field=" + search["analysis.fieldname"];
} else {
$scope.fieldOrType = "fieldtype=" + search["analysis.fieldtype"];
$scope.schemaBrowserUrl = "type=" + search["analysis.fieldtype"];
}
if (search["verbose_output"] == undefined) {
$scope.verbose = true;
} else {
$scope.verbose = search["verbose_output"] == "1";
}
$scope.verbose = search["verbose_output"] == "1";
if ($scope.fieldOrType || $scope.indexText || $scope.queryText) {
params.core = $routeParams.core;
@ -163,348 +170,30 @@ solrAdminApp.controller('AnalysisController',
}
};
$scope.changeFieldOrType = function() {
var parts = $scope.fieldOrType.split("=");
if (parts[0]=='fieldname') {
$scope.schemaBrowserUrl = "field=" + parts[1];
} else {
$scope.schemaBrowserUrl = "type=" + parts[1];
}
};
$scope.toggleVerbose = function() {$scope.verbose = !$scope.verbose};
$scope.toggleVerbose = function() {
$scope.verbose = !$scope.verbose;
$location.search("verbose_output", $scope.verbose ? "1" : "0");
};
$scope.refresh();
}
);
/***************
// #/:core/analysis
sammy.get
(
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] );
}
);
========================
$( '.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' );
}
);
========================
analysis_form
.die( 'submit' )
.live
(
'submit',
function( event )
{
var params = analysis_form.formToArray();
/****
var params = {
"analysis.fieldvalue": $scope.indexText,
"analysis.query": $scope.queryText,
"analysis.fieldname": $scope.field,
"verbose_output": $scope.verbose ? 1:0};
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
$location.path($params);
Analysis.fields({}, function(data) {
var url = core_basepath + '/analysis/field?wt=json&analysis.showmatch=true&' + context.path.split( '?' ).pop();
url = url.replace( /&verbose_output=\d/, '' );
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();
},
}, function(error) {
function(error) {
if (error.status == 404) {
$scope.analysisHandlerMissing = true;
// @todo #analysis-handler-missing.show();
$scope.isHandlerMissing = true;
} else {
$scope.analysisError = error.error.msg;
// @todo #analysis-error.show();
}
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 ) // index or query
{
var type_length = analysis_data[type].length; // number of stages in pipeline
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
);
}
}
for( component in components(analysis_data[type])) // why 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
(
);
}
// 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( '' );
// data
var cell_content = '<td class="part data spacer" colspan="' + colspan + '"><div class="holder">&nbsp;</div></td>';
var cells = new Array( elements_count + 1 ).join( cell_content );
content += cells + "\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 = '&empty;';
}
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>'
);
}
}
}
}
}
************/
****/

View File

@ -16,6 +16,14 @@ limitations under the License.
-->
<div id="analysis">
<div class="block analysis-error" id="analysis-handler-missing" ng-show="isHandlerMissing">
<div class="head">This Functionality requires the <code>/analysis/field</code> Handler to be registered and active!</div>
</div>
<div class="block analysis-error" id="analysis-error" ng-show="analysisError">
<div class="body">{{analysisError}}</div>
</div>
<div id="analysis-holder">
<div id="field-analysis">
@ -41,9 +49,9 @@ limitations under the License.
<li class="settings-holder clearfix">
<div class="settings clearfix">
<label for="type_or_name">Analyse Fieldname / FieldType:</label>
<select style="width:130px" chosen id="type_or_name" ng-model="fieldOrType" ng-options="f.value as f.label group by f.group for f in fieldsAndTypes"></select>
<select style="width:130px" chosen ng-change="changeFieldOrType()" id="type_or_name" ng-model="fieldOrType" ng-options="f.value as f.label group by f.group for f in fieldsAndTypes"></select>
<a id="tor_schema" href="#"><span>Schema Browser</span>&nbsp;</a>
<a id="tor_schema" ng-href="#/{{core}}/schema-browser?{{schemaBrowserUrl}}"><span>Schema Browser</span>&nbsp;</a>
<div class="buttons clearfix">
@ -66,7 +74,6 @@ limitations under the License.
<div id="analysis-result" class="clearfix verbose_output">
<div ng-class="key" ng-repeat="(key, type) in result">
<h1>{{key}}</h1>
<table border="0" cellspacing="0" cellpadding="0">
<tbody ng-repeat="component in type">
<tr class="step">
@ -76,7 +83,7 @@ limitations under the License.
</div>
</td>
<td class="part legend">
<td class="part legend" ng-show="verbose">
<div class="holder">
<table border="0" cellspacing="0" cellpadding="0">
<tr>
@ -91,15 +98,15 @@ limitations under the License.
</table>
</div>
</td>
<td class="part data" colspan="1" ng-repeat="token in component.tokens track by token.index">
<div class="holder">
<table border="0" cellspacing="0" cellpadding="0" ng-show="!token.blank">
<td class="part data" ng-class="{spacer:token.blank}" colspan="1" ng-repeat="token in component.tokens track by token.index">
<div class="holder" ng-hide="token.blank">
<table border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr class="details">
<td class="details">
<table border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr class="{{value.key}}" ng-repeat="value in token.keys">
<tr class="{{value.name}}" ng-repeat="value in token.keys" ng-show="verbose || value.name=='text'">
<td>{{value.value}}</td>
</tr>
</tbody>
@ -109,6 +116,7 @@ limitations under the License.
</tbody>
</table>
</div>
<div class="holder" ng-show="token.blank">&nbsp;</div>
</td>
</tr>
</tbody>