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
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');
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
=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 );
$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' ) {
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;
.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 {
-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 = '<img src="' + basepath + '/images/ajax-loader.gif" alt="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 = $('<span>').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 );
+ }
}
[% IF usertexts.size -%]
<!-- User texts -->
- <h3>[% IF is_admin %]All[% ELSE %]My[% END %] text traditions</h3>
+ <h3>[% IF is_admin %]All[% ELSE %]My[% END %] text traditions (full access)</h3>
<div class="text_list">
<ul>
[% SET i = 0 -%]
[% FOREACH t IN usertexts -%]
- <li><span class="traditionname" onClick="$('.traditionname').removeClass('selected');$(this).addClass('selected');loadTradition('[% t.id %]','[% t.name %]')">[% t.name %]</span></li>
+ <li><span class="traditionname" onClick="$('.traditionname').removeClass('selected');$(this).addClass('selected');loadTradition('[% t.id %]','[% t.name %]', 1)">[% t.name %]</span></li>
[% i = i + 1 -%]
[% END -%]
</ul>
[% END -%]
[% IF publictexts.size -%]
<!-- Public texts -->
- <h3>Public text traditions</h3>
+ <h3>Public text traditions (read-only)</h3>
<div class="text_list">
<ul>
[% SET i = 0 -%]
[% FOREACH t IN publictexts -%]
- <li><span class="traditionname" onClick="$('.traditionname').removeClass('selected');$(this).addClass('selected');loadTradition('[% t.id %]','[% t.name %]')">[% t.name %]</span></li>
+ <li><span class="traditionname" onClick="$('.traditionname').removeClass('selected');$(this).addClass('selected');loadTradition('[% t.id %]','[% t.name %]', 0)">[% t.name %]</span></li>
[% i = i + 1 -%]
[% END -%]
</ul>
%]
<script type="text/javascript">
var selectedTextID;
+var selectedStemmaID = -1;
+var stemmata = [];
$(document).ready(function() {
// call out to load the directory div
+ $('#textinfo_container').hide();
+ $('#textinfo_waitbox').hide();
$('#directory').load( "[% c.uri_for( 'directory' ) %]",
function(response, status, xhr) {
if (status == "error") {
<h3>Loading texts, please wait...</h3>
<img src="[% c.uri_for( 'images', 'ajax-loader.gif' ) %]" />
</div>
+[% IF c.user_exists -%]
+ <div class="button" id="new_trad_button" onClick="$('#new_trad_form').open()">
+ <span>Add a new text tradition</span>
+ </div>
+[% END %]
+ </div>
+ <div id="textinfo_waitbox">
+ <img src="[% c.uri_for( 'images', 'ajax-loader.gif' ) %]" alt="Loading tradition info..."/>
+ </div>
+ <div id="textinfo_container">
+ <h2>Text <span class="texttitle"></span></h2>
+ <ul>
+ <li>has <span id="witness_num"></span> witnesses: <span id="witness_list"></span></li>
+ <li>has <span id="reading_num"></span> distinct readings</li>
+ <li>has <span id="relationship_num"></span> distinct reading relationships</li>
+ </ul>
+
+ <!-- TODO buttons on either side of the graph div to flip through the stemmata -->
+ <div id="stemma_graph"></div>
+ <form id="run_stexaminer" action="" method="GET" name="run_stexaminer">
+ <div class="button" id="stexaminer_button" onClick="$('#run_stexaminer').submit()">
+ <span>Examine variants against this stemma</span>
+ </div>
+ </form>
+ <form id="run_relater" action="" method="GET" name="run_relater">
+ <div class="button" id="relater_button" onClick="$('#run_relater').submit()">
+ <span>Run relationship mapper</span>
+ </div>
+ </form>
</div>
- <div id="textinfo_container"></div>
- <div id="variant_container"></div>
[% PROCESS footer.tt %]
\ No newline at end of file