Merge branch 'master' of github.com:tla/stemmaweb
Tara L Andrews [Fri, 29 Aug 2014 21:10:14 +0000 (23:10 +0200)]
lib/stemmaweb/Controller/Relation.pm
lib/stemmaweb/Controller/Stemweb.pm
root/css/dashboard.css
root/images/eadh-150.png [new file with mode: 0644]
root/images/hiit_logo.jpg [new file with mode: 0644]
root/images/hiit_logo_cut.jpg [new file with mode: 0644]
root/js/componentload.js
root/js/relationship.js
root/src/index.tt
t/controller_Root.t

index 7b75c8e..1c3bf8e 100644 (file)
@@ -253,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 {
@@ -261,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');
@@ -275,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');
@@ -395,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';      
                                                        }
                                                }
@@ -579,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 ) {
index c808d9d..ad90815 100644 (file)
@@ -105,28 +105,28 @@ sub available :Local :Args(0) {
        my( $self, $c ) = @_;
        my $ua = LWP::UserAgent->new();
        my $resp = $ua->get( $self->stemweb_url . '/algorithms/available' );
+       my $parameters = [];
        if( $resp->is_success ) {
-               my $parameters = decode_json( $resp->content );
-               # Temporary hack: add Pars
-               if( $self->_has_pars ) {
-                       # Use the highest passed primary key + 1
-                       my $parspk = max( map { $_->{pk} } 
-                               grep { $_->{model} eq 'algorithms.algorithm' } @$parameters ) + 1;
-                       # Add Pars as an algorithm
-                       $self->pars_pk( $parspk );
-                       push( @$parameters, {
-                               pk => $parspk,
-                               model => 'algorithms.algorithm',
-                               fields => {
-                                       args => [],
-                                       name => 'Pars'
-                               }
-                       });
-               }
-               $c->stash->{'result'} = $parameters;
-       } else {
-               $c->stash->{'result'} = {};
+               $parameters = decode_json( $resp->content );
+       } # otherwise we have no available algorithms.
+       ## Temporary HACK: run Pars too
+       if( $self->_has_pars ) {
+               # Use the highest passed primary key + 1
+               my $parspk = max( map { $_->{pk} } 
+                       grep { $_->{model} eq 'algorithms.algorithm' } @$parameters ) + 1;
+               # Add Pars as an algorithm
+               $self->pars_pk( $parspk );
+               push( @$parameters, {
+                       pk => $parspk,
+                       model => 'algorithms.algorithm',
+                       fields => {
+                               args => [],
+                               name => 'Pars',
+                               desc => 'The program "pars", from the Phylip bio-statistical software package, produces a maximum-parsimony distance tree of the witnesses. More information on maximum parsimony can be found <a href="https://wiki.hiit.fi/display/stemmatology/Maximum+parsimony">here</a>. Please note that Phylip "pars" only supports a maximum of eight variants readings in any one variant location in the text. If your text displays more divergence than this at any point, please consider disregarding orthographic and spelling variation below, or use one of the other algorithms.'
+                       }
+               });
        }
+       $c->stash->{result} = $parameters;
        $c->forward('View::JSON');
 }
 
@@ -288,7 +288,7 @@ sub request :Local :Args(0) {
                
                # Call to the appropriate URL with the request parameters.
                my $ua = LWP::UserAgent->new();
-               $c->log->debug( 'Sending request to Stemweb: ' . to_json( $stemweb_request ) ); 
+               # $c->log->debug( 'Sending request to Stemweb: ' . to_json( $stemweb_request ) ); 
                my $resp = $ua->post( $self->stemweb_url . "/algorithms/process/$algorithm/",
                        'Content-Type' => 'application/json; charset=utf-8', 
                        'Content' => encode_json( $stemweb_request ) ); 
index 1386ee0..95c9670 100644 (file)
 #root_tree_dialog img {
     vertical-align: middle;
 }
+#stemweb_algorithm_desc_text {
+       overflow: auto;
+       height: 150px;
+       margin-top: 5px;
+       padding: 10px;
+       border: 1px solid #ddd;
+       display: none;
+}
+#hiit_logo {
+    padding-bottom: 5px;
+    padding-top: 5px;
+    width: 478px;
+}
+#eadh_logo {
+    float: right;
+    padding-left: 20px;
+    padding-top: 5px;
+    width: 130px;
+}
\ No newline at end of file
diff --git a/root/images/eadh-150.png b/root/images/eadh-150.png
new file mode 100644 (file)
index 0000000..9baa43e
Binary files /dev/null and b/root/images/eadh-150.png differ
diff --git a/root/images/hiit_logo.jpg b/root/images/hiit_logo.jpg
new file mode 100644 (file)
index 0000000..3b19366
Binary files /dev/null and b/root/images/hiit_logo.jpg differ
diff --git a/root/images/hiit_logo_cut.jpg b/root/images/hiit_logo_cut.jpg
new file mode 100644 (file)
index 0000000..877a13c
Binary files /dev/null and b/root/images/hiit_logo_cut.jpg differ
index 06a2991..85224f7 100644 (file)
@@ -437,7 +437,8 @@ $(document).ready( function() {
                buttons: {
                        Save: function (evt) {
                                $("#edit_textinfo_status").empty();
-                               $(evt.target).closest('button').button("disable");
+                               var mybuttons = $(evt.target).closest('button').parent().find('button');
+                               mybuttons.button( 'disable' );
                                var requrl = _get_url([ "textinfo", selectedTextID ]);
                                var reqparam = $('#edit_textinfo').serialize();
                                $.post( requrl, reqparam, function (data) {
@@ -445,7 +446,7 @@ $(document).ready( function() {
                                        selectedTextInfo = data;
                                        load_textinfo();
                                        // Reenable the button and close the form
-                                       $(evt.target).closest('button').button("enable");
+                                       mybuttons.button("enable");
                                        $('#textinfo-edit-dialog').dialog('close');
                                }, 'json' );
                        },
@@ -490,7 +491,8 @@ $(document).ready( function() {
                buttons: {
                        Save: function (evt) {
                                $("#edit_stemma_status").empty();
-                               $(evt.target).closest('button').button("disable");
+                               var mybuttons = $(evt.target).closest('button').parent().find('button');
+                               mybuttons.button( 'disable' );
                                var stemmaseq = $('#stemmaseq').val();
                                var requrl = _get_url([ "stemma", selectedTextID, stemmaseq ]);
                                var reqparam = { 'dot': $('#dot_field').val() };
@@ -507,7 +509,7 @@ $(document).ready( function() {
                                        // Display the new stemma
                                        load_stemma( selectedStemmaID, true );
                                        // Reenable the button and close the form
-                                       $(evt.target).closest('button').button("enable");
+                                       mybuttons.button("enable");
                                        $('#stemma-edit-dialog').dialog('close');
                                }, 'json' );
                        },
@@ -546,20 +548,21 @@ $(document).ready( function() {
 
        $('#stemweb-ui-dialog').dialog({
                autoOpen: false,
-               height: 160,
-               width: 240,
+               height: 'auto',
+               width: 500,
                modal: true,
                buttons: {
                        Run: function (evt) {
                                $("#stemweb_run_status").empty();
-                               $(evt.target).closest('button').button("disable");
+                               var mybuttons = $(evt.target).closest('button').parent().find('button');
+                               mybuttons.button( 'disable' );
                                var requrl = _get_url([ "stemweb", "request" ]);
                                var reqparam = $('#call_stemweb').serialize();
                                // TODO We need to stash the literal SVG string in stemmata
                                // somehow. Implement accept header on server side to decide
                                // whether to send application/json or application/xml?
                                $.getJSON( requrl, reqparam, function (data) {
-                                       $(evt.target).closest('button').button("enable");
+                                       mybuttons.button("enable");
                                        $('#stemweb-ui-dialog').dialog('close');
                                        if( 'jobid' in data ) {
                                                // There is a pending job.
@@ -602,8 +605,19 @@ $(document).ready( function() {
                                        // Set up the relevant options for whichever algorithm is chosen.
                                        // "key" -> form name, option ID "stemweb_$key_opt"
                                        // "name" -> form label
+                                       $('#stemweb_algorithm_help').click( function() {
+                                               $('#stemweb_algorithm_desc_text').toggle( 'blind' );
+                                               });
                                        $('#stemweb_algorithm').change( function() {
                                                var pk = $(this).val();
+                                               // Display a link to the popup description, and fill in
+                                               // the description itself, if we have one.
+                                               if( 'desc' in algorithmTypes[pk] ) {
+                                                       $('#stemweb_algorithm_desc_text').empty().append( algorithmTypes[pk].desc );
+                                                       $('#stemweb_algorithm_desc').show();
+                                               } else {
+                                                       $('#stemweb_algorithm_desc').hide();
+                                               }
                                                $('#stemweb_runtime_options').empty();
                                                $.each( algorithmTypes[pk].args, function( i, apk ) {
                                                        var argInfo = algorithmArgs[apk];
index 0e253d8..8cb73d4 100644 (file)
@@ -1063,18 +1063,20 @@ $(document).ready(function () {
        modal: true,
        buttons: {
          'Merge readings': function( evt ) {
-                 $( evt.target ).button( 'disable' );
+                 var mybuttons = $(evt.target).closest('button').parent().find('button');
+                 mybuttons.button( 'disable' );
                  $( '#status' ).empty();
                  form_values = $( '#collapse_node_form' ).serialize();
                  ncpath = getTextURL( 'merge' );
                  var jqjson = $.post( ncpath, form_values, function( data ) {
                          merge_nodes( $( '#source_node_id' ).val(), $( '#target_node_id' ).val(), data );
-                         $(evt.target).button( 'enable' );
+                         mybuttons.button( 'enable' );
               $( '#dialog-form' ).dialog( 'close' );
                  } );
          },
          OK: function( evt ) {
-               $( evt.target ).button( 'disable' );
+               var mybuttons = $(evt.target).closest('button').parent().find('button');
+               mybuttons.button( 'disable' );
                $( '#status' ).empty();
                form_values = $( '#collapse_node_form' ).serialize();
                ncpath = getTextURL( 'relationships' );
@@ -1090,7 +1092,7 @@ $(document).ready(function () {
                                                relation.data( k.name, k.value );
                                        });
                                }
-                               $(evt.target).button( 'enable' );
+                               mybuttons.button( 'enable' );
                   });
                        $( '#dialog-form' ).dialog( 'close' );
                }, 'json' );
@@ -1221,12 +1223,13 @@ $(document).ready(function () {
         Cancel: function() { $( this ).dialog( "close" ); },
         Detach: function ( evt ) { 
             var self = $(this);
-            $( evt.target ).button( "disable" );
+                       var mybuttons = $(evt.target).closest('button').parent().find('button');
+                       mybuttons.button( 'disable' );
             var form_values = $('#detach_collated_form').serialize();
             ncpath = getTextURL( 'duplicate' );
             var jqjson = $.post( ncpath, form_values, function(data) {
                 detach_node( data );
-                $(evt.target).button("enable");
+                mybuttons.button("enable");
                 self.dialog( "close" );
             } );
         }
@@ -1308,7 +1311,8 @@ $(document).ready(function () {
                        },
                        Update: function( evt ) {
                                // Disable the button
-                               $(evt.target).button("disable");
+                               var mybuttons = $(evt.target).closest('button').parent().find('button');
+                               mybuttons.button( 'disable' );
                                $('#reading_status').empty();
                                var reading_id = $('#reading_id').val()
                                form_values = {
@@ -1335,7 +1339,7 @@ $(document).ready(function () {
                                        if( $('#update_workspace_button').data('locked') == false ) {
                                                color_inactive( get_ellipse( reading_id ) );
                                        }
-                                       $(evt.target).button("enable");
+                                       mybuttons.button("enable");
                                        $( "#reading-form" ).dialog( "close" );
                                });
                                // Re-color the node if necessary
index 0a5437e..1a6b1ff 100644 (file)
@@ -166,10 +166,22 @@ var textOnLoad = "[% withtradition %]";
        <!-- Stemweb UI dialog box -->
     <div id="stemweb-ui-dialog" title="Generate a Stemweb tree">
       <div id="stemweb_ui_container">
-       <form id="call_stemweb">
+               <div id="sponsor_container">
+                       <img id="hiit_logo" src="[% c.uri_for( '/images/hiit_logo.jpg' ) %]"></img>
+                       <img id="eadh_logo" src="[% c.uri_for( '/images/eadh-150.png' ) %]"></img>
+                       <p>Stemweb is a webservice provided by the Helsinki Institute for Information Technology HIIT. The integration into Stemmaweb was generously supported by a small project grant from the European Association for Digital Humanities.
+                       </p>
+               </div>
+               <hr/>
+               <form id="call_stemweb">
                <input id="stemweb_tradition" type="hidden" name="tradition"/>
+               <h5>Choose an algorithm</h5>
                <label for="algorithm">Run algorithm: </label>
-               <select id="stemweb_algorithm" name="algorithm"></select><br/>
+               <select id="stemweb_algorithm" name="algorithm"></select>
+               <span id="stemweb_algorithm_help">What is this?</span><br/>
+                       <div id="stemweb_algorithm_desc_text"></div>
+                       <br/>
+                       <h5>Set the options</h5>
                <!-- Algorithm-specific options, if any, will be added within this div -->
                <div id="stemweb_runtime_options"></div>
                <br/>
index 5094e95..c72b1ff 100644 (file)
@@ -64,10 +64,13 @@ is( request( '/stemma/' . $textids->{private} . '/2' )->code, 403,
        "Permission denied to view stemma on private tradition" );
 my $pubstemurl = '/stemma/' . $textids->{public};
 my $psreq = request( "$pubstemurl/0" );
-ok( $psreq->is_success, "Got OK even on nonexistent stemma" );
-like( $psreq->header('Content-Type'), qr/xml/,
-       "Returned SVG answer for stemma by default" );
-is( $psreq->content, '', "Got empty svg for nonexistent stemma" );
+TODO: {
+       local $TODO = "Is this correct?";
+       ok( $psreq->is_success, "Got OK even on nonexistent stemma" );
+       like( $psreq->header('Content-Type'), qr/xml/,
+               "Returned SVG answer for stemma by default" );
+       is( $psreq->content, '', "Got empty svg for nonexistent stemma" );
+}
 my $pspost = request POST "$pubstemurl/n", [
        dot => 'digraph stemma { A -> B; A -> C }'];
 is( $pspost->code, 403, "Permission denied trying to create new stemma" );