fix bug in help URL formation. Fixes #48
[scpubgit/stemmaweb.git] / lib / stemmaweb / Controller / Relation.pm
index c5f3281..24d1de3 100644 (file)
@@ -1,8 +1,10 @@
 package stemmaweb::Controller::Relation;
 use JSON qw/ to_json from_json /;
 use Moose;
+use Moose::Util::TypeConstraints qw/ find_type_constraint /;
 use Module::Load;
 use namespace::autoclean;
+use Text::Tradition::Datatypes;
 use TryCatch;
 
 BEGIN { extends 'Catalyst::Controller' }
@@ -70,7 +72,10 @@ sub main :Chained('text') :PathPart('') :Args(0) {
        my $collation = $tradition->collation;
        
        # Stash the relationship definitions
-       $c->stash->{'relationship_scopes'} = to_json( [ qw/ local global / ] );
+       $c->stash->{'relationship_scopes'} = 
+               to_json( find_type_constraint( 'RelationshipScope' )->values );
+       $c->stash->{'ternary_values'} = 
+               to_json( find_type_constraint( 'Ternary' )->values );
        my @reltypeinfo;
        foreach my $type ( sort { _typesort( $a, $b ) } $collation->relations->types ) {
                next if $type->is_weak;
@@ -128,7 +133,7 @@ sub main :Chained('text') :PathPart('') :Args(0) {
        $c->stash->{'startseg'} = $startseg if defined $startseg;
        $c->stash->{'svg_string'} = $svg_str;
        $c->stash->{'text_title'} = $tradition->name;
-       if( $tradition->can('language') ) {
+       if( $tradition->can('language') && $tradition->language ) {
                $c->stash->{'text_lang'} = $tradition->language;
                $c->stash->{'can_morphologize'} = 1;
        } else {
@@ -208,6 +213,7 @@ sub relationships :Chained('text') :PathPart :Args(0) {
                                  a_derivable_from_b => $relobj->a_derivable_from_b,
                                  b_derivable_from_a => $relobj->b_derivable_from_a,
                                  non_independent => $relobj->non_independent,
+                                 is_significant => $relobj->is_significant
                                  };
                        $relhash->{'note'} = $relobj->annotation if $relobj->has_annotation;
                        push( @all_relations, $relhash );
@@ -247,6 +253,7 @@ sub relationships :Chained('text') :PathPart :Args(0) {
                
                        delete $opts->{scope} unless $opts->{scope};
                        delete $opts->{annotation} unless $opts->{annotation};
+                       delete $opts->{is_significant} unless $opts->{is_significant};
                        $opts->{propagate} = 1;
                        
                        try {
@@ -255,7 +262,10 @@ sub relationships :Chained('text') :PathPart :Args(0) {
                                $m->save( $tradition );
                        } catch( Text::Tradition::Error $e ) {
                                $c->response->status( '403' );
-                               $c->stash->{'result'} = { 'error' => $e->message };
+                               $c->stash->{'result'} = { error => $e->message };
+                       } catch {
+                               $c->response->status( '500' );
+                               $c->stash->{'result'} = { error => "Something went wrong with the request" };
                        }
                } elsif( $c->request->method eq 'DELETE' ) {
                        my $node = $c->request->param('source_id');
@@ -269,7 +279,10 @@ sub relationships :Chained('text') :PathPart :Args(0) {
                        } catch( Text::Tradition::Error $e ) {
                                $c->response->status( '403' );
                                $c->stash->{'result'} = { 'error' => $e->message };
-                       }       
+                       } catch {
+                               $c->response->status( '500' );
+                               $c->stash->{'result'} = { error => "Something went wrong with the request" };
+                       }
                }
        }
        $c->forward('View::JSON');
@@ -389,7 +402,7 @@ sub reading :Chained('text') :PathPart :Args(1) {
                                                                $errmsg = $e->message;
                                                        } catch {
                                                                # Something else went wrong, probably a Moose error
-                                                               $c->response->status( '403' );
+                                                               $c->response->status( '500' );
                                                                $errmsg = 'Something went wrong with the request';      
                                                        }
                                                }
@@ -573,7 +586,7 @@ sub duplicate :Chained('text') :PathPart :Args(0) {
                                $errmsg = $e->message;
                        } catch {
                                # Something else went wrong, probably a Moose error
-                               $c->response->status( '403' );
+                               $c->response->status( '500' );
                                $errmsg = 'Something went wrong with the request';      
                        }
                        if( $newrdg ) {