X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2Fstemmaweb%2FController%2FRoot.pm;h=9a0d3f4dbbc6582d78381745c19a71f8df64ccae;hb=80c4b652c73cd313bc3cffd9d6e36c58e41e9833;hp=eebf21adeee80b2eee6c1e41be9b5272460ff54b;hpb=6aabefa3b8ad3b5746b5e8d857e3992b9abdf3da;p=scpubgit%2Fstemmaweb.git diff --git a/lib/stemmaweb/Controller/Root.pm b/lib/stemmaweb/Controller/Root.pm index eebf21a..9a0d3f4 100644 --- a/lib/stemmaweb/Controller/Root.pm +++ b/lib/stemmaweb/Controller/Root.pm @@ -123,12 +123,15 @@ sub newtradition :Local :Args(0) { my $name = $c->request->param('name') || 'Uploaded tradition'; my $lang = $c->request->param( 'language' ) || 'Default'; my $public = $c->request->param( 'public' ) ? 1 : undef; + my $direction = $c->request->param('direction') || 'LR'; + my( $ext ) = $upload->filename =~ /\.(\w+)$/; my %newopts = ( 'name' => $name, 'language' => $lang, 'public' => $public, - 'file' => $upload->tempname + 'file' => $upload->tempname, + 'direction' => $direction, ); my $tradition; @@ -144,7 +147,7 @@ sub newtradition :Local :Args(0) { $errmsg = "XML file parsing error: $err"; } if( $doc ) { - if( $doc->documentElement->nodeName eq 'GraphML' ) { + if( $doc->documentElement->nodeName eq 'graphml' ) { $type = 'CollateX'; } elsif( $doc->documentElement->nodeName ne 'TEI' ) { $errmsg = 'Unrecognized XML type ' . $doc->documentElement->nodeName; @@ -275,6 +278,20 @@ sub textinfo :Local :Args(1) { $changed = 1 if $ispublic; } + # Handle text direction + my $tdval = delete $params->{direction} || 'LR'; + + unless( $tradition->collation->direction + && $tradition->collation->direction eq $tdval ) { + try { + $tradition->collation->change_direction( $tdval ); + $changed = 1; + } catch { + return _json_error( $c, 500, "Error setting direction to $tdval: $@" ); + } + } + + # Handle ownership change if( exists $params->{'owner'} ) { # Only admins can update user / owner @@ -314,9 +331,14 @@ sub textinfo :Local :Args(1) { my $textinfo = { textid => $textid, name => $tradition->name, + direction => $tradition->collation->direction || 'LR', public => $tradition->public || 0, owner => $tradition->user ? $tradition->user->email : undef, witnesses => [ map { $_->sigil } $tradition->witnesses ], + # TODO Send them all with appropriate parameters so that the + # client side can choose what to display. + reltypes => [ map { $_->name } grep { !$_->is_weak && $_->is_colocation } + $tradition->collation->relationship_types ] }; ## TODO Make these into callbacks in the other controllers maybe? if( $tradition->can('language') ) { @@ -396,21 +418,6 @@ sub stemma :Local :Args(2) { if( $c->req->method eq 'POST' ) { if( $ok eq 'full' ) { 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 '(di)?graph .*'. - # Horrible HACK. - my @dlines = split( "\n", $dot ); - my $wdot = ''; - foreach( @dlines ) { - unless( /^(di)?graph/ ) { # Skip the first line - s/(?stash->{'result'} = $stemma->as_svg(); $c->forward('View::SVG'); } else { # JSON - $c->stash->{'result'} = { _stemma_info( $stemma, $stemmaid ) }; + $c->stash->{'result'} = _stemma_info( $stemma, $stemmaid ); $c->forward('View::JSON'); } } @@ -528,26 +535,39 @@ sub stemmaroot :Local :Args(2) { =head2 download - GET /download/$textid + GET /download/$textid/$format -Returns the full XML definition of the tradition and its stemmata, if any. +Returns a file for download of the tradition in the requested format. =cut -sub download :Local :Args(1) { - my( $self, $c, $textid ) = @_; +sub download :Local :Args(2) { + my( $self, $c, $textid, $format ) = @_; my $tradition = $c->model('Directory')->tradition( $textid ); unless( $tradition ) { return _json_error( $c, 404, "No tradition with ID $textid" ); } my $ok = _check_permission( $c, $tradition ); return unless $ok; + + my $outmethod = "as_" . lc( $format ); + my $view = "View::$format"; + $c->stash->{'name'} = $tradition->name(); + $c->stash->{'download'} = 1; + my @outputargs; + if( $format eq 'SVG' ) { + # Send the list of colors through to the backend. + # TODO Think of some way not to hard-code this. + push( @outputargs, { 'show_relations' => 'all', + 'graphcolors' => [ "#5CCCCC", "#67E667", "#F9FE72", "#6B90D4", + "#FF7673", "#E467B3", "#AA67D5", "#8370D8", "#FFC173" ] } ); + } try { - $c->stash->{'result'} = $tradition->collation->as_graphml(); + $c->stash->{'result'} = $tradition->collation->$outmethod( @outputargs ); } catch( Text::Tradition::Error $e ) { return _json_error( $c, 500, $e->message ); } - $c->forward('View::GraphML'); + $c->forward( $view ); } ####################