X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2Fstemmaweb%2FController%2FRoot.pm;h=0315867f83aadaa57dfcfb1f534db92d8c435927;hb=664580033ad210926cafbb4940b20078f61b7cc0;hp=e62c924a3e74f25868187b282e77a7b9a3262e8e;hpb=ec2f89ffc68331cd280429698e318f9a07e940cb;p=scpubgit%2Fstemmaweb.git diff --git a/lib/stemmaweb/Controller/Root.pm b/lib/stemmaweb/Controller/Root.pm index e62c924..0315867 100644 --- a/lib/stemmaweb/Controller/Root.pm +++ b/lib/stemmaweb/Controller/Root.pm @@ -1,7 +1,7 @@ package stemmaweb::Controller::Root; use Moose; use namespace::autoclean; -use Text::Tradition::Analysis qw/ run_analysis /; +use JSON qw (); use TryCatch; use XML::LibXML; use XML::LibXML::XPathContext; @@ -314,7 +314,6 @@ sub textinfo :Local :Args(1) { my $textinfo = { textid => $textid, name => $tradition->name, - #language => $tradition->language, public => $tradition->public || 0, owner => $tradition->user ? $tradition->user->email : undef, witnesses => [ map { $_->sigil } $tradition->witnesses ], @@ -322,7 +321,13 @@ sub textinfo :Local :Args(1) { if( $tradition->can('language') ) { $textinfo->{'language'} = $tradition->language; } - my @stemmasvg = map { { name => $_->identifier, svg => $_->as_svg() } } + if( $tradition->can('stemweb_jobid') ) { + $textinfo->{'stemweb_jobid'} = $tradition->stemweb_jobid || 0; + } + my @stemmasvg = map { { + name => $_->identifier, + directed => _json_bool( !$_->is_undirected ), + svg => $_->as_svg() } } $tradition->stemmata; map { $_ =~ s/\n/ /mg } @stemmasvg; $textinfo->{stemmata} = \@stemmasvg; @@ -381,9 +386,19 @@ sub stemma :Local :Args(2) { my $dot = $c->request->body_params->{'dot'}; # Graph::Reader::Dot does not handle bare unicode. We get around this # by wrapping all words in double quotes, as long as they aren't already - # wrapped, and as long as they aren't the initial 'digraph stemma'. + # wrapped, and as long as they aren't the initial '(di)?graph .*'. # Horrible HACK. - $dot =~ s/(?forward('View::SVG'); } else { # JSON $stemma_xml =~ s/\n/ /mg; - $c->stash->{'result'} = { 'stemmaid' => $stemmaid, 'stemmasvg' => $stemma_xml }; + $c->stash->{'result'} = { + 'stemmaid' => $stemmaid, + 'name' => $stemma->identifier, + 'directed' => _json_bool( !$stemma->is_undirected ), + 'svg' => $stemma_xml }; $c->forward('View::JSON'); } } @@ -519,6 +538,10 @@ sub _json_error { return 0; } +sub _json_bool { + return $_[0] ? JSON::true : JSON::false; +} + =head2 default Standard 404 error page