From: Tara L Andrews Date: Fri, 29 Aug 2014 21:08:50 +0000 (+0200) Subject: quick and dirty parse validation form X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=scpubgit%2Fstemmaweb.git;a=commitdiff_plain;h=378668ee7b3cd52881e31f938eb592d7a1644c7f quick and dirty parse validation form --- diff --git a/lib/stemmaweb/Controller/Microservice.pm b/lib/stemmaweb/Controller/Microservice.pm index 3084367..0b5e9a6 100644 --- a/lib/stemmaweb/Controller/Microservice.pm +++ b/lib/stemmaweb/Controller/Microservice.pm @@ -27,7 +27,7 @@ following form parameters in the body: =over 4 -=item * type - Can be one of CollateX, CSV, JSON, nCritic, TEI, Tabular. +=item * type - Can be one of CollateX, CTE, CSV, JSON, nCritic, TEI, Tabular. =item * data - The collation data itself. @@ -35,6 +35,54 @@ following form parameters in the body: =head1 COLLATION URLs +=head2 parse + + GET microservice/parse + POST microservice/parse { + type: $type + file: $uploadfile + } + +Attempt a parse of the passed collation data, and return diagnostic information about whether it was successful. + +=cut + +sub parse :Local :Args(0) { + my( $self, $c ) = @_; + if( $c->req->method eq 'POST' ) { + # Get the passed options... + my $warnings = []; + $DB::single = 1; + my %newopts = ( + 'name' => $c->request->param('name') || 'Uploaded tradition', + 'file' => $c->request->upload('file')->tempname, + 'warnings_to' => $warnings, + ); + my $type = $c->request->param( 'type' ); + if( $type eq 'csv' ) { + $newopts{'input'} = 'Tabular'; + $newopts{'sep_char'} = ','; + } elsif( $type eq 'tsv' ) { + $newopts{'input'} = 'Tabular'; + $newopts{'sep_char'} = "\t"; + } elsif( $type =~ /^xls/ ) { + $newopts{'input'} = 'Tabular'; + $newopts{'excel'} = $type; + } else { + $newopts{'input'} = $type; + } + # Now try the parse. + my $tradition; + try { + $c->stash->{'result'} = Text::Tradition->new( %newopts ); + } catch ( Text::Tradition::Error $e ) { + $c->stash->{'errormsg'} = $e->message; + } + $c->stash->{'warnings'} = join( "\n", @$warnings ); + } + $c->stash->{template} = 'testparse.tt'; +} + =head2 renderSVG POST microservice/renderSVG diff --git a/root/css/style.css b/root/css/style.css index 5d55a48..99c7400 100644 --- a/root/css/style.css +++ b/root/css/style.css @@ -140,6 +140,10 @@ div.pager_left_button.greyed_out, div.pager_left_button.greyed_out:hover { font-weight: bold; color: #ff3333; } +.warning { + font-weight: bold; + color: #ff8000; +} .notification { font-weight: bold; color: #33ff33;