diff --git a/lib/Tuba.pm b/lib/Tuba.pm index 58c36af5..b43a6aa3 100644 --- a/lib/Tuba.pm +++ b/lib/Tuba.pm @@ -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'); diff --git a/lib/Tuba/Controller.pm b/lib/Tuba/Controller.pm index 3441eb56..67459218 100644 --- a/lib/Tuba/Controller.pm +++ b/lib/Tuba/Controller.pm @@ -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; diff --git a/lib/Tuba/Organization.pm b/lib/Tuba/Organization.pm index bfd8c0e4..3b7e2546 100644 --- a/lib/Tuba/Organization.pm +++ b/lib/Tuba/Organization.pm @@ -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; diff --git a/lib/Tuba/Person.pm b/lib/Tuba/Person.pm index fc39357c..6cca36d0 100644 --- a/lib/Tuba/Person.pm +++ b/lib/Tuba/Person.pm @@ -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(@_); } diff --git a/lib/Tuba/RoleType.pm b/lib/Tuba/RoleType.pm new file mode 100644 index 00000000..3952f9ab --- /dev/null +++ b/lib/Tuba/RoleType.pm @@ -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(<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; + diff --git a/lib/Tuba/files/templates/organization/objects.html.ep b/lib/Tuba/files/templates/organization/objects.html.ep index 6a5ca310..3dc1961e 100644 --- a/lib/Tuba/files/templates/organization/objects.html.ep +++ b/lib/Tuba/files/templates/organization/objects.html.ep @@ -3,7 +3,11 @@

- %= (stash 'plural') || ucfirst($meta->table) .'s' +% if ($role) { +

Organizations who have had the role <%= $role->label %>

+% } else { +

Organizations

+% }
diff --git a/lib/Tuba/files/templates/person/objects.html.ep b/lib/Tuba/files/templates/person/objects.html.ep index 06d5baf3..74c5f49d 100644 --- a/lib/Tuba/files/templates/person/objects.html.ep +++ b/lib/Tuba/files/templates/person/objects.html.ep @@ -2,7 +2,11 @@ % layout 'default';
-

People

+% if ($role) { +

People who have had the role <%= $role->label %>

+% } else { +

People

+% }
%= include 'list_formats'; diff --git a/lib/Tuba/files/templates/role_type/object.html.ep b/lib/Tuba/files/templates/role_type/object.html.ep new file mode 100644 index 00000000..552e7971 --- /dev/null +++ b/lib/Tuba/files/templates/role_type/object.html.ep @@ -0,0 +1,32 @@ + +% layout 'default', title => "Role ".$role_type->label; + +
+

<%= $role_type->label %>

+
+ +% if (user_can('update')) { +%= include 'history_modal'; + + +<%= link_to obj_uri_for($object,'update_form') => class => "btn" => begin %>edit<%= end %> +history + +% } + +
+
+
role identifier: <%= $role_type->identifier %>
+ Organizations: + <%= link_to url_for('list_organization')->query(role => $role_type_identifier) => begin %> + <%= $stats->{orgs} %>
+ <%= end %> + People: + <%= link_to url_for('list_person')->query(role => $role_type_identifier) => begin %> + <%= $stats->{people} %>
+ <%= end %> +
+
+ +<%= include 'h/other_formats'; =%> + diff --git a/lib/Tuba/files/templates/role_type/objects.html.ep b/lib/Tuba/files/templates/role_type/objects.html.ep new file mode 100644 index 00000000..18fa78a7 --- /dev/null +++ b/lib/Tuba/files/templates/role_type/objects.html.ep @@ -0,0 +1,37 @@ + +% layout 'default'; + +
+

+ Role Types +

+
+ +%= include 'list_formats'; + +% if (my $page = stash 'page') { +%= include 'pager', page => $page; +% } + + + + + + + +% for my $o (@$objects) { + + + + +% } +
+
IdentifierLabel
+ %= link_to $o->uri($self) => begin + <%= $o->identifier %> + %= end + <%= $o->label %>
+% if (my $page = stash 'page') { +%= include 'pager', page => $page, bottom => 1; +% } +