quick and dirty parse validation form
Tara L Andrews [Fri, 29 Aug 2014 21:08:50 +0000 (23:08 +0200)]
lib/stemmaweb/Controller/Microservice.pm
root/css/style.css

index 3084367..0b5e9a6 100644 (file)
@@ -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
index 5d55a48..99c7400 100644 (file)
@@ -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;