Commit 0704f96f authored by Keith Jolley's avatar Keith Jolley
Browse files

Respect isolate set view.

parent dcacf1a9
...@@ -106,8 +106,8 @@ hook before => sub { ...@@ -106,8 +106,8 @@ hook before => sub {
} }
$self->db_connect; $self->db_connect;
$self->setup_datastore; $self->setup_datastore;
$self->{'page_size'} = $self->_initiate_view;
( BIGSdb::Utils::is_int( param('page_size') ) && param('page_size') > 0 ) ? param('page_size') : PAGE_SIZE; $self->{'page_size'} = ( BIGSdb::Utils::is_int( param('page_size') ) && param('page_size') > 0 ) ? param('page_size') : PAGE_SIZE;
return; return;
}; };
...@@ -118,6 +118,29 @@ hook after => sub { ...@@ -118,6 +118,29 @@ hook after => sub {
$self->{'dataConnector'}->drop_connection( { host => $self->{'system'}->{'host'}, dbase_name => $self->{'system'}->{'db'} } ); $self->{'dataConnector'}->drop_connection( { host => $self->{'system'}->{'host'}, dbase_name => $self->{'system'}->{'db'} } );
}; };
sub get_set_id {
my ($self) = @_;
if ( ( $self->{'system'}->{'sets'} // '' ) eq 'yes' ) {
my $set_id = $self->{'system'}->{'set_id'};
return $set_id if $set_id && BIGSdb::Utils::is_int($set_id);
}
return;
}
#Set view if defined in set.
sub _initiate_view {
my ($self) = @_;
return if $self->{'system'}->{'dbtype'} ne 'isolates';
my $set_id = $self->get_set_id;
if ( defined $self->{'system'}->{'view'} && $set_id ) {
if ( $self->{'system'}->{'views'} && BIGSdb::Utils::is_int($set_id) ) {
my $view = $self->{'datastore'}->run_query( "SELECT view FROM set_view WHERE set_id=?", $set_id );
$self->{'system'}->{'view'} = $view if defined $view;
}
}
return;
}
#Get the contents of the rest_db database. #Get the contents of the rest_db database.
sub get_resources { sub get_resources {
my ($self) = @_; my ($self) = @_;
......
...@@ -52,13 +52,13 @@ get '/db/:db' => sub { ...@@ -52,13 +52,13 @@ get '/db/:db' => sub {
} }
if ( $self->{'system'}->{'dbtype'} eq 'isolates' ) { if ( $self->{'system'}->{'dbtype'} eq 'isolates' ) {
my $count = $self->{'datastore'}->run_query("SELECT COUNT(*) FROM $self->{'system'}->{'view'}"); my $count = $self->{'datastore'}->run_query("SELECT COUNT(*) FROM $self->{'system'}->{'view'}");
return { return [
records => $count, { records => $count },
isolates => request->uri_for("/db/$db/isolates")->as_string, { isolates => request->uri_for("/db/$db/isolates")->as_string },
fields => request->uri_for("/db/$db/fields")->as_string, { fields => request->uri_for("/db/$db/fields")->as_string },
schemes => request->uri_for("/db/$db/schemes")->as_string, { schemes => request->uri_for("/db/$db/schemes")->as_string },
loci => request->uri_for("/db/$db/loci")->as_string, { loci => request->uri_for("/db/$db/loci")->as_string }
}; ];
} elsif ( $self->{'system'}->{'dbtype'} eq 'sequences' ) { } elsif ( $self->{'system'}->{'dbtype'} eq 'sequences' ) {
} else { } else {
return { title => 'Database configuration is invalid' }; return { title => 'Database configuration is invalid' };
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment