From: Tara L Andrews Date: Thu, 30 Aug 2012 00:04:00 +0000 (+0200) Subject: get new front page working, if poorly styled X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=98a45925bfa64fc1e29c0841ecf88aba96908de4;p=scpubgit%2Fstemmaweb.git get new front page working, if poorly styled --- diff --git a/lib/stemmaweb/Controller/Root.pm b/lib/stemmaweb/Controller/Root.pm index cf3086e..fbfd4f1 100644 --- a/lib/stemmaweb/Controller/Root.pm +++ b/lib/stemmaweb/Controller/Root.pm @@ -49,18 +49,48 @@ sub directory :Local :Args(0) { my( $self, $c ) = @_; my $m = $c->model('Directory'); # Is someone logged in? + my %usertexts; if( $c->user_exists ) { my $user = $c->user->get_object; - $c->stash->{usertexts} = [ $m->traditionlist( $user ) ]; + my @list = $m->traditionlist( $user ); + map { $usertexts{$_->{id}} = 1 } @list; + $c->stash->{usertexts} = \@list; $c->stash->{is_admin} = 1 if $user->is_admin; } - # Unless we have an admin user, list public texts separately from - # any user texts that exist. - $c->stash->{publictexts} = [ $m->traditionlist('public') ] - unless $c->stash->{is_admin}; + # List public (i.e. readonly) texts separately from any user (i.e. + # full access) texts that exist. Admin users therefore have nothing + # in this list. + my @plist = grep { !$usertexts{$_->{id}} } $m->traditionlist('public'); + $c->stash->{publictexts} = \@plist; $c->stash->{template} = 'directory.tt'; } +=head2 textinfo + + GET /textinfo/$textid + +Returns the page element populated with information about a particular text. + +=cut + +sub textinfo :Local :Args(1) { + my( $self, $c, $textid ) = @_; + my $tradition = $c->model('Directory')->tradition( $textid ); + # Need text name, witness list, scalar readings, scalar relationships, stemmata + my $textinfo = { + textid => $textid, + traditionname => $tradition->name, + witnesses => [ map { $_->sigil } $tradition->witnesses ], + readings => scalar $tradition->collation->readings, + relationships => scalar $tradition->collation->relationships + }; + my @stemmasvg = map { $_->as_svg({ size => [ 500, 375 ] }) } $tradition->stemmata; + map { $_ =~ s/\n/ /mg } @stemmasvg; + $textinfo->{stemmata} = \@stemmasvg; + $c->stash->{'result'} = $textinfo; + $c->forward('View::JSON'); +} + =head2 variantgraph GET /variantgraph/$textid @@ -71,8 +101,7 @@ Returns the variant graph for the text specified at $textid, in SVG form. sub variantgraph :Local :Args(1) { my( $self, $c, $textid ) = @_; - my $m = $c->model('Directory'); - my $tradition = $m->tradition( $textid ); + my $tradition = $c->model('Directory')->tradition( $textid ); my $collation = $tradition->collation; $c->stash->{'result'} = $collation->as_svg; $c->forward('View::SVG'); @@ -88,8 +117,8 @@ Returns an alignment table for the text specified at $textid. sub alignment :Local :Args(1) { my( $self, $c, $textid ) = @_; - my $m = $c->model('Directory'); - my $collation = $m->tradition( $textid )->collation; + my $tradition = $c->model('Directory')->tradition( $textid ); + my $collation = $tradition->collation; my $alignment = $collation->alignment_table; # Turn the table, so that witnesses are by column and the rows diff --git a/lib/stemmaweb/Controller/Stexaminer.pm b/lib/stemmaweb/Controller/Stexaminer.pm index 72f8fc8..d40ecbc 100644 --- a/lib/stemmaweb/Controller/Stexaminer.pm +++ b/lib/stemmaweb/Controller/Stexaminer.pm @@ -23,14 +23,15 @@ The stemma analysis tool with the pretty colored table. =head2 index - GET stexaminer/$textid + GET stexaminer/$textid/$stemmaid -Renders the application for the text identified by $textid. +Renders the application for the text identified by $textid, using the stemma +graph identified by $stemmaid. =cut -sub index :Path :Args(1) { - my( $self, $c, $textid ) = @_; +sub index :Path :Args(2) { + my( $self, $c, $textid, $stemid ) = @_; my $m = $c->model('Directory'); my $tradition = $m->tradition( $textid ); my $ok = _check_permission( $c, $tradition ); @@ -49,7 +50,9 @@ sub index :Path :Args(1) { $c->stash->{'show_type1'} = $use_type1; $c->stash->{'ignore_variant'} = $ignore_sort; # TODO Run the analysis as AJAX from the loaded page. - my %analysis_options = ( exclude_type1 => !$use_type1 ); + my %analysis_options = ( + stemma_id => $stemid, + exclude_type1 => !$use_type1 ); if( $ignore_sort eq 'spelling' ) { $analysis_options{'merge_types'} = [ qw/ spelling orthographic / ]; } elsif( $ignore_sort eq 'orthographic' ) { diff --git a/root/css/style.css b/root/css/style.css index 4aaa2b9..1f7b74b 100644 --- a/root/css/style.css +++ b/root/css/style.css @@ -84,7 +84,14 @@ div.button:hover span { border: 1px #c6dcf1 solid; } #directory { + height: 360px; margin-left: 10px; + overflow: auto; +} +#new_trad_button { + margin-left: 10px; + position: relative; + top: 10px; } .traditionname { text-decoration: underline; @@ -103,24 +110,10 @@ div.button:hover span { .mainnav a { color: #488dd2; } -#variant_container { - clear: both; - height: 400px; - padding-top: 20px; -} -#variant_graph { - /* width: 900px; */ - height: 350px; - clear: both; - overflow: auto; - text-align: center; -} -#variant_graph img { - margin-top: expression(( 400 - this.height ) / 2); -} -#stemma_container { +#textinfo_container { float: left; - height: 450px; + height: 500px; + width: 700px; margin-left: 40px; } #stemma_container h2 h3 { diff --git a/root/js/componentload.js b/root/js/componentload.js index 87cc0ef..2941538 100644 --- a/root/js/componentload.js +++ b/root/js/componentload.js @@ -1,23 +1,52 @@ -function loadTradition( textid, textname ) { - // First insert the placeholder image +function loadTradition( textid, textname, editable ) { + selectedTextID = textid; + // First insert the placeholder image and register an error handler var basepath = window.location.pathname if( basepath.lastIndexOf('/') == basepath.length - 1 ) { basepath = basepath.slice( 0, basepath.length - 1) }; - var imghtml = 'Loading SVG...' - $('#stemma_graph').empty(); - $('#stemma_graph').append( imghtml ); + $('#textinfo_waitbox').show(); + $('#textinfo_container').ajaxError( + function ( e, jqxhr, settings, exception ) { + if ( settings.url.indexOf( 'textinfo' ) > -1 ) { + $('#textinfo_waitbox').hide(); + var msg = "An error occurred: "; + var msghtml = $('').attr('class', 'error').text( + msg + jqxhr.status + " " + jqxhr.statusText); + $("#textinfo_container").append( msghtml ).show(); + } + } + ); // Then get and load the actual content. - // TODO: scale #stemma_grpah both horizontally and vertically + // TODO: scale #stemma_graph both horizontally and vertically // TODO: load svgs from SVG.Jquery (to make scaling react in Safari) - $('#stemma_graph').load( basepath + "/stemma/" + textid ); - - // Then populate the various elements with the right text name/ID. - // Stemma and variant graph titles - $('.texttitle').empty(); - $('.texttitle').append( textname ); - // Stexaminer submit action - $('#run_stexaminer').attr( 'action', basepath + "/stexaminer/" + textid ); - // Relationship mapper submit action - $('#run_relater').attr( 'action', basepath + "/relation/" + textid ); + $.getJSON( basepath + "/textinfo/" + textid, function (textdata) { + // Add the scalar data + $('#textinfo_waitbox').hide(); + $('#textinfo_container').show(); + $('.texttitle').append( textdata.traditionname ); + $('#witness_num').append( textdata.witnesses.size ); + $('#witness_list').append( textdata.witnesses.join( ', ' ) ); + $('#reading_num').append( textdata.readings ); + $('#relationship_num').append( textdata.relationships ); + // Add the stemma(ta) and set up the stexaminer button + stemmata = textdata.stemmata; + if( stemmata.length ) { + selectedStemmaID = 0; + load_stemma( selectedStemmaID, basepath ); + } + // Set up the relationship mapper button + $('#run_relater').attr( 'action', basepath + "/relation/" + textid ); + }); +} + +function load_stemma( idx, basepath ) { + if( idx > -1 ) { + selectedStemmaID = idx; + $('#stemma_graph').empty(); + $('#stemma_graph').append( stemmata[idx] ); + // Stexaminer submit action + var stexpath = basepath + "/stexaminer/" + selectedTextID + "/" + idx; + $('#run_stexaminer').attr( 'action', stexpath ); + } } diff --git a/root/src/directory.tt b/root/src/directory.tt index d4f3084..d7d6266 100644 --- a/root/src/directory.tt +++ b/root/src/directory.tt @@ -1,11 +1,11 @@ [% IF usertexts.size -%] -

[% IF is_admin %]All[% ELSE %]My[% END %] text traditions

+

[% IF is_admin %]All[% ELSE %]My[% END %] text traditions (full access)

    [% SET i = 0 -%] [% FOREACH t IN usertexts -%] -
  • [% t.name %]
  • +
  • [% t.name %]
  • [% i = i + 1 -%] [% END -%]
@@ -13,12 +13,12 @@ [% END -%] [% IF publictexts.size -%] -

Public text traditions

+

Public text traditions (read-only)

    [% SET i = 0 -%] [% FOREACH t IN publictexts -%] -
  • [% t.name %]
  • +
  • [% t.name %]
  • [% i = i + 1 -%] [% END -%]
diff --git a/root/src/index.tt b/root/src/index.tt index 569968a..49f0266 100644 --- a/root/src/index.tt +++ b/root/src/index.tt @@ -4,8 +4,12 @@ %]