From: Errietta Kostala Date: Wed, 27 May 2015 15:34:12 +0000 (+0000) Subject: Error handling when compressing readings X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=scpubgit%2Fstemmaweb.git;a=commitdiff_plain;h=2d34519e7ea7d01377d355f858030a9faa5d014b Error handling when compressing readings --- diff --git a/lib/stemmaweb/Controller/Relation.pm b/lib/stemmaweb/Controller/Relation.pm index c40b8cb..fd5a452 100644 --- a/lib/stemmaweb/Controller/Relation.pm +++ b/lib/stemmaweb/Controller/Relation.pm @@ -10,6 +10,14 @@ use TryCatch; BEGIN { extends 'Catalyst::Controller' } +sub throw { + Text::Tradition::Error->throw( + 'ident' => 'Collation error', + 'message' => $_[0], + ); +} + + =head1 NAME stemmaweb::Controller::Relation - Controller for the relationship mapper @@ -475,36 +483,60 @@ sub compress :Chained('text') :PathPart :Args(0) { } } + my @nodes; + push @nodes, "$readings[$first]"; + for (my $i = $first+1; $i < $len; $i++) { my $rdg = $readings[$first]; my $next = $readings[$i]; last unless $next->is_combinable; + push @nodes, "$next"; - warn "Joining readings $rdg and $next\n"; + try { + $collation->merge_readings( "$rdg", "$next", 1 ); + } catch ($e) { + $c->stash->{result} = { + error_msg => $e->message, + }; - $collation->merge_readings( "$rdg", "$next", 1 ); + $c->detach('View::JSON'); + } } - # Finally, make sure we haven't screwed anything up. - foreach my $wit ( $tradition->witnesses ) { - my $pathtext = $collation->path_text( $wit->sigil ); - throw( "Text differs for witness " . $wit->sigil ) - unless $pathtext eq $origtext{$wit->sigil}; - if( $wit->is_layered ) { - my $acsig = $wit->sigil . $collation->ac_label; - $pathtext = $collation->path_text( $acsig ); - throw( "Layered text differs for witness " . $wit->sigil ) - unless $pathtext eq $origtext{$acsig}; + try { + # Finally, make sure we haven't screwed anything up. + foreach my $wit ( $tradition->witnesses ) { + my $pathtext = $collation->path_text( $wit->sigil ); + throw( "Text differs for witness " . $wit->sigil ) + unless $pathtext eq $origtext{$wit->sigil}; + if( $wit->is_layered ) { + my $acsig = $wit->sigil . $collation->ac_label; + $pathtext = $collation->path_text( $acsig ); + throw( "Layered text differs for witness " . $wit->sigil ) + unless $pathtext eq $origtext{$acsig}; + } } + } catch ($e) { + $c->stash->{result} = { + error_msg => $e->message, + }; + + $c->detach('View::JSON'); } + $collation->relations->rebuild_equivalence(); $collation->calculate_ranks(); $m->save($collation); - $c->stash->{'result'} = {}; + + $c->stash->{'result'} = { + success => 1, + nodes => \@nodes, + }; + $c->forward('View::JSON'); } } diff --git a/root/css/relationship.css b/root/css/relationship.css index 98f03b7..fbe46ce 100644 --- a/root/css/relationship.css +++ b/root/css/relationship.css @@ -233,3 +233,7 @@ user-select: none; background-color: #FFFFCC; z-index: 51; /* Cf. #update_workspace_button */ } + +.error { + color: red; +} diff --git a/root/js/relationship.js b/root/js/relationship.js index d079b5b..bf62e6b 100644 --- a/root/js/relationship.js +++ b/root/js/relationship.js @@ -5,7 +5,6 @@ var start_element_height = 0; var reltypes = {}; var readingdata = {}; var text_direction = 'LR'; -var current_selected = []; jQuery.removeFromArray = function(value, arr) { return jQuery.grep(arr, function(elem, index) { @@ -858,11 +857,12 @@ function merge_node( source_node_id, target_node_id ) { function compress_nodes(readings) { //add text of other readings to 1st reading - for (var i = 1; i < readings.length; i++) { - var first = get_ellipse(readings[0]); - var cur = get_ellipse(readings[i]); - var first_title = first.parent().find('text')[0]; + var first = get_ellipse(readings[0]); + var first_title = first.parent().find('text')[0]; + + for (var i = 1; i < readings.length; i++) { + var cur = get_ellipse(readings[i]); var cur_title = cur.parent().find('text')[0]; first_title.textContent += " " + cur_title.textContent; @@ -977,8 +977,6 @@ function Marquee() { } }); if( $('ellipse[fill="#9999ff"]').size() > 0 ) { - current_selected = readings; - //add intersection of witnesses sets to the multi select form and open it $('#detach_collated_form').empty(); @@ -1011,6 +1009,7 @@ function Marquee() { $('#action-detach').change(function() { if ($('#action-detach')[0].checked) { $('#detach_collated_form').show(); + $('#multipleselect-form-text').show(); $('#detach_btn').show(); $('#merge_btn').hide(); @@ -1020,6 +1019,7 @@ function Marquee() { $('#action-merge').change(function() { if ($('#action-merge')[0].checked) { $('#detach_collated_form').hide(); + $('#multipleselect-form-text').hide(); $('#detach_btn').hide(); $('#merge_btn').show(); @@ -1337,11 +1337,18 @@ $(document).ready(function () { var form_values = $('#detach_collated_form').serialize(); var jqjson = $.post(ncpath, form_values, function(data) { - compress_nodes(current_selected); - current_selected = []; + if (data.success) { + if (data.nodes) { + compress_nodes(data.nodes); + } + + mybuttons.button('enable'); + self.dialog('close'); + } else if (data.error_msg) { + document.getElementById('duplicate-merge-error').innerHTML = data.error_msg; + mybuttons.button('enable'); - mybuttons.button('enable'); - self.dialog('close'); + } }); } }, diff --git a/root/src/relate.tt b/root/src/relate.tt index a8e4d89..016ae38 100644 --- a/root/src/relate.tt +++ b/root/src/relate.tt @@ -109,8 +109,11 @@ $(document).ready(function () {
+ +
+
- Detach or merge?


+ Detach or merge?