requires 'Catalyst::Plugin::Static::Simple';
requires 'Catalyst::Plugin::Unicode::Encoding';
requires 'Catalyst::Action::RenderView';
+requires 'Catalyst::Authentication::Credential::OpenID';
requires 'Catalyst::Model::KiokuDB';
requires 'Catalyst::View::Download::Plain';
requires 'Catalyst::View::JSON';
sub directory :Local :Args(0) {
my( $self, $c ) = @_;
my $m = $c->model('Directory');
- my $user = $c->user_exists ? $c->user->get_object : 'public';
- my @textlist = $m->traditionlist($user);
- $c->stash->{texts} = \@textlist;
+ # Is someone logged in?
+ if( $c->user_exists ) {
+ my $user = $c->user->get_object;
+ $c->stash->{usertexts} = [ $m->traditionlist( $user ) ];
+ $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};
$c->stash->{template} = 'directory.tt';
}
- <h3>Choose a text to examine</h3>
- <div id="text_list">
+[% IF usertexts.size -%]
+ <!-- User texts -->
+ <h3>[% IF is_admin %]All[% ELSE %]My[% END %] text traditions</h3>
+ <div class="text_list">
<ul>
[% SET i = 0 -%]
-[% FOREACH t IN texts -%]
+[% FOREACH t IN usertexts -%]
<li><span class="traditionname" onClick="$('.traditionname').removeClass('selected');$(this).addClass('selected');loadTradition('[% t.id %]','[% t.name %]')">[% t.name %]</span></li>
[% i = i + 1 -%]
[% END -%]
- </table>
+ </ul>
</div>
+[% END -%]
+[% IF publictexts.size -%]
+ <!-- Public texts -->
+ <h3>Public text traditions</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>
+[% i = i + 1 -%]
+[% END -%]
+ </ul>
+ </div>
+[% END -%]
\ No newline at end of file
var selectedTextID;
$(document).ready(function() {
// call out to load the directory div
- $('#directory').load( "[% c.uri_for( 'directory' ) %]" );
-});
+ $('#directory').load( "[% c.uri_for( 'directory' ) %]",
+ function(response, status, xhr) {
+ if (status == "error") {
+ var msg = "An error occurred: ";
+ $("#directory").html(msg + xhr.status + " " + xhr.statusText);
+ }
+ });
+ });
</script>
[% END %]
<div id="topbanner">
<h1>Stemmaweb - a collection of tools for analysis of collated texts</h1>
- <span class="mainnav">[% IF c.user_exists %]Hello! [% c.user.get_object.email %] <a class="navlink" href="[% c.uri_for( '/logout' ) %]">Sign out</a> | [% ELSE %]<a class="navlink" onclick="window.open('[% c.uri_for( '/login' ) %]', 'loginwindow', 'height=385,width=445')">Login</a> | <a class="navlink" onclick="window.open('[% c.uri_for( '/register' ) %]', 'regwindow', 'height=385,width=445')">Register</a> | [% END %]<a class="navlink" href="[% c.uri_for( 'about.html' ) %]">About<a> </span>
+ <span class="mainnav">[% IF c.user_exists %]Hello! [% c.user.get_object.email %] <a class="navlink" href="[% c.uri_for( '/logout' ) %]">Sign out</a> | [% ELSE %]<a class="navlink" onclick="window.open('[% c.uri_for( '/login' ) %]', 'loginwindow', 'height=385,width=445')">Login</a> | <a class="navlink" onclick="window.open('[% c.uri_for( '/register' ) %]', 'regwindow', 'height=385,width=445')">Register</a> | [% END %]<a class="navlink" href="[% c.uri_for( 'about.html' ) %]">About</a> </span>
</div>
<div id="directory_container">
<h2>Text directory</h2>
<img src="[% c.uri_for( 'images', 'ajax-loader.gif' ) %]" />
</div>
</div>
- <div id="stemma_container">
- <h2>Stemma for <span class="texttitle">selected text</span></h2>
- <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="variant_container">
- </div>
+ <div id="textinfo_container"></div>
+ <div id="variant_container"></div>
[% PROCESS footer.tt %]
\ No newline at end of file
#!/usr/bin/env perl
use strict;
use warnings;
+use File::Temp;
use Test::More;
+use Text::Tradition::Directory;
use Catalyst::Test 'stemmaweb';
-ok( request('/')->is_success, 'Request should succeed' );
+use vars qw( $orig_db, $was_link );
+my $textids;
+my $dbfile = 'db/traditions.db';
+( $orig_db, $was_link, $textids ) = _make_testing_database();
+
+ok( request('/')->is_success, 'Got root HTML' );
+ok( request('/directory')->is_success, 'Got the text directory' );
+ok( request('/text/' . $textids->{'public'} . '/info')->is_success,
+ 'Got information listing for public text' );
+is( request('/text/' . $textids->{'public'} . '/info')->code, 403,
+ 'Denied information listing for public text' );
+
done_testing();
+
+
+sub _make_testing_database {
+ my $fh = File::Temp->new();
+ my $file = $fh->filename;
+ $fh->unlink_on_destroy( 0 );
+ $fh->close;
+ my $dsn = 'dbi:SQLite:dbname=' . $file;
+ my $dir = Text::Tradition::Directory->new( 'dsn' => $dsn,
+ 'extra_args' => { 'create' => 1 } );
+ my $scope = $dir->new_scope;
+
+ my $textids = {};
+ # Create a (public) tradition
+ my $pubtrad = Text::Tradition->new( input => 'Self', file => 't/data/john.xml' );
+ $textids->{'public'} = $dir->store( $pubtrad );
+
+ # Create a user
+ my $userobj = $dir->add_user( { username => 'swtest', password => 'swtestpass' } );
+ # Create a tradition for the user
+ my $privtrad = Text::Tradition->new( input => 'Tabular', sep_char => ','
+ file => 't/data/florilegium.csv', user => $userobj );
+ $privtrad->add_stemma( dotfile => 't/data/florilegium.dot' );
+ $textids->{'private'} = $dir->store( $privtrad );
+
+ ## Now replace the existing traditions database with the test one
+ my( $orig, $was_link );
+ if( -l $dbfile ) {
+ $was_link = 1;
+ $orig = readlink( $dbfile );
+ unlink( $dbfile ) or die "Could not replace database file $dbfile";
+ } else {
+ my $suffix = '.backup.' . time();
+ $orig = $dbfile.$suffix;
+ rename( $dbfile, $orig ) or die "Could not move database file $dbfile";
+ }
+ link( $file, $dbfile );
+ return( $orig, $was_link, $textids );
+}
+
+END {
+ # Restore the original database
+ unlink( readlink( $dbfile ) );
+ unlink( $dbfile );
+ if( $was_link ) {
+ link( $orig_db, $dbfile );
+ } else {
+ rename( $orig_db, $dbfile );
+ }
+}