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 {
}
$self->db_connect;
$self->setup_datastore;
$self->{'page_size'} =
( BIGSdb::Utils::is_int( param('page_size') ) && param('page_size') > 0 ) ? param('page_size') : PAGE_SIZE;
$self->_initiate_view;
$self->{'page_size'} = ( BIGSdb::Utils::is_int( param('page_size') ) && param('page_size') > 0 ) ? param('page_size') : PAGE_SIZE;
return;
};
......@@ -118,6 +118,29 @@ hook after => sub {
$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.
sub get_resources {
my ($self) = @_;
......
......@@ -52,13 +52,13 @@ get '/db/:db' => sub {
}
if ( $self->{'system'}->{'dbtype'} eq 'isolates' ) {
my $count = $self->{'datastore'}->run_query("SELECT COUNT(*) FROM $self->{'system'}->{'view'}");
return {
records => $count,
isolates => request->uri_for("/db/$db/isolates")->as_string,
fields => request->uri_for("/db/$db/fields")->as_string,
schemes => request->uri_for("/db/$db/schemes")->as_string,
loci => request->uri_for("/db/$db/loci")->as_string,
};
return [
{ records => $count },
{ isolates => request->uri_for("/db/$db/isolates")->as_string },
{ fields => request->uri_for("/db/$db/fields")->as_string },
{ schemes => request->uri_for("/db/$db/schemes")->as_string },
{ loci => request->uri_for("/db/$db/loci")->as_string }
];
} elsif ( $self->{'system'}->{'dbtype'} eq 'sequences' ) {
} else {
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