Skip to content

Commit

Permalink
role types
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian Duggan committed May 27, 2015
1 parent f93d1a3 commit 4f1871f
Show file tree
Hide file tree
Showing 9 changed files with 157 additions and 6 deletions.
3 changes: 3 additions & 0 deletions lib/Tuba.pm
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,9 @@ sub startup {
$r->get("/model_run/:model_identifier/:scenario_identifier/:range_start/:range_end/:spatial_resolution/:time_resolution/:sequence")
->to("model_run#lookup")->name('model_run_lookup');

# Roles
$r->resource('role_type');

# Lexicons
$r->resource('lexicon');
my $lex = $r->lookup('select_lexicon');
Expand Down
6 changes: 5 additions & 1 deletion lib/Tuba/Controller.pm
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,17 @@ sub common_tree_fields {
);
}

sub _default_list_order {
return "identifier";
}

sub list {
my $c = shift;
my $objects = $c->stash('objects');
my $all = $c->param('all') ? 1 : 0;
unless ($objects) {
my $manager_class = $c->stash('manager_class') || $c->_guess_manager_class;
$objects = $manager_class->get_objects(sort_by => "identifier", $all ? () : (page => $c->page, per_page => $c->per_page));
$objects = $manager_class->get_objects(sort_by => $c->_default_list_order, $all ? () : (page => $c->page, per_page => $c->per_page));
$c->set_pages($manager_class->get_objects_count) unless $all;
}
my $object_class = $c->stash('object_class') || $c->_guess_object_class;
Expand Down
18 changes: 18 additions & 0 deletions lib/Tuba/Organization.pm
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,24 @@ sub show {
return $c->SUPER::show(@_);
}

sub list {
my $c = shift;
my @q;
my $role;
if (my $r = $c->param('role')) {
@q = (query => [role_type_identifier => $r, person_id => undef], with_objects => [qw/contributors/]);
$role = RoleType->new(identifier => $r)->load(speculative => 1);
}
$c->stash(role => $role);
if ($c->param('all')) {
$c->stash(objects => Organizations->get_objects(@q));
} else {
$c->stash(objects => scalar Organizations->get_objects(@q, sort_by => 'name', page => $c->page));
$c->set_pages(Organizations->get_objects_count(@q));
}
$c->SUPER::list(@_);
}

sub update_rel {
my $c = shift;
my $org = $c->_this_object;
Expand Down
13 changes: 10 additions & 3 deletions lib/Tuba/Person.pm
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,18 @@ use Tuba::DB::Objects qw/-nicknames/;

sub list {
my $c = shift;
my @q;
my $role;
if (my $r = $c->param('role')) {
@q = (query => [role_type_identifier => $r], with_objects => [qw/contributors/]);
$role = RoleType->new(identifier => $r)->load(speculative => 1);
}
$c->stash(role => $role);
if ($c->param('all')) {
$c->stash(objects => Persons->get_objects);
$c->stash(objects => Persons->get_objects(@q));
} else {
$c->stash(objects => scalar Persons->get_objects(sort_by => 'last_name, first_name', page => $c->page));
$c->set_pages(Persons->get_objects_count);
$c->stash(objects => scalar Persons->get_objects(@q, sort_by => 'last_name, first_name', page => $c->page));
$c->set_pages(Persons->get_objects_count(@q));
}
$c->SUPER::list(@_);
}
Expand Down
42 changes: 42 additions & 0 deletions lib/Tuba/RoleType.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
=head1 NAME
Tuba::RoleType : Controller class for roles.
=cut

package Tuba::RoleType;
use Mojo::Base qw/Tuba::Controller/;
use Tuba::DB::Objects qw/-nicknames/;

sub _default_list_order {
return "identifier";
}

=head1 show
Show metadata about a role.
=cut

sub show {
my $c = shift;
my $identifier = $c->stash('role_type_identifier');
my $meta = RoleType->meta;
my $object = RoleType->new( identifier => $identifier )
->load( speculative => 1 ) or return $c->reply->not_found;
$c->stash(object => $object);
$c->stash(meta => $meta);
my $stats = $c->dbs->query(<<SQL,$identifier)->hashes->[0];
select
count(nullif(person_id is null,true)) as people,
count(nullif(person_id is null,false)) as orgs
from contributor
where role_type_identifier = ?
SQL
$c->stash(stats => $stats);
$c->SUPER::show(@_);
}


1;

6 changes: 5 additions & 1 deletion lib/Tuba/files/templates/organization/objects.html.ep
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@

<center>
<h2>
%= (stash 'plural') || ucfirst($meta->table) .'s'
% if ($role) {
<h2>Organizations <small>who have had the role <b><%= $role->label %></b></small></h2>
% } else {
<h2>Organizations</h2>
% }
</h2>
</center>

Expand Down
6 changes: 5 additions & 1 deletion lib/Tuba/files/templates/person/objects.html.ep
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
% layout 'default';

<center>
<h2>People </h2>
% if ($role) {
<h2>People <small>who have had the role <b><%= $role->label %></b></small></h2>
% } else {
<h2>People</h2>
% }
</center>

%= include 'list_formats';
Expand Down
32 changes: 32 additions & 0 deletions lib/Tuba/files/templates/role_type/object.html.ep
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@

% layout 'default', title => "Role ".$role_type->label;

<center>
<h2><%= $role_type->label %></h2>
</center>

% if (user_can('update')) {
%= include 'history_modal';

<span style='float:right;'>
<%= link_to obj_uri_for($object,'update_form') => class => "btn" => begin %>edit<%= end %>
<a href="#myModal" role="button" class="btn" data-toggle="modal">history</a>
</span>
% }

<div class='row-fluid'>
<div class='well span6 offset3'>
<center><b>role identifier: <%= $role_type->identifier %></b></center>
Organizations:
<%= link_to url_for('list_organization')->query(role => $role_type_identifier) => begin %>
<%= $stats->{orgs} %><br>
<%= end %>
People:
<%= link_to url_for('list_person')->query(role => $role_type_identifier) => begin %>
<%= $stats->{people} %><br>
<%= end %>
</div>
</div>

<%= include 'h/other_formats'; =%>

37 changes: 37 additions & 0 deletions lib/Tuba/files/templates/role_type/objects.html.ep
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@

% layout 'default';

<center>
<h2>
Role Types
</h2>
</center>

%= include 'list_formats';

% if (my $page = stash 'page') {
%= include 'pager', page => $page;
% }
<table class='table table-condensed table-bordered table-striped'>
<caption>
</caption>
<tr>
<th>Identifier</th>
<th>Label</th>
</th>
</tr>
% for my $o (@$objects) {
<tr>
<td>
%= link_to $o->uri($self) => begin
<%= $o->identifier %>
%= end
</td>
<td><%= $o->label %></td>
</tr>
% }
</table>
% if (my $page = stash 'page') {
%= include 'pager', page => $page, bottom => 1;
% }

0 comments on commit 4f1871f

Please sign in to comment.