Commit 09b5d575 authored by Joel Alarcón's avatar Joel Alarcón Committed by Francesc Guasch
Browse files

feat(frontend): display all users by default when <= 20

* 224_all_users: feat: display all users by default when total users <= 20. issue #224.

* 224_all_users: feat: user list now is ordered by name instead of id. issue #224
parent b2fb4655
...@@ -151,7 +151,7 @@ sub list_machines_user { ...@@ -151,7 +151,7 @@ sub list_machines_user {
); );
} }
$base{name_clone} = $clone->name; $base{name_clone} = $clone->name;
$base{screenshot} = ( $clone->_data('file_screenshot') $base{screenshot} = ( $clone->_data('file_screenshot')
or $base{screenshot}); or $base{screenshot});
$base{is_active} = $clone->is_active; $base{is_active} = $clone->is_active;
$base{id_clone} = $clone->id $base{id_clone} = $clone->id
...@@ -198,7 +198,7 @@ sub search_clone_data { ...@@ -198,7 +198,7 @@ sub search_clone_data {
$sth->execute( map { $args{$_} } sort keys %args ); $sth->execute( map { $args{$_} } sort keys %args );
my $row = $sth->fetchrow_hashref; my $row = $sth->fetchrow_hashref;
return ( $row or {}); return ( $row or {});
} }
=cut =cut
...@@ -223,7 +223,7 @@ sub list_domains { ...@@ -223,7 +223,7 @@ sub list_domains {
my $sth = $CONNECTOR->dbh->prepare($query); my $sth = $CONNECTOR->dbh->prepare($query);
$sth->execute(map { $args{$_} } sort keys %args); $sth->execute(map { $args{$_} } sort keys %args);
my @domains = (); my @domains = ();
while ( my $row = $sth->fetchrow_hashref) { while ( my $row = $sth->fetchrow_hashref) {
my $domain ; my $domain ;
...@@ -275,7 +275,7 @@ sub _where(%args) { ...@@ -275,7 +275,7 @@ sub _where(%args) {
sub list_clones { sub list_clones {
my $self = shift; my $self = shift;
my %args = @_; my %args = @_;
my $domains = list_domains(); my $domains = list_domains();
my @clones; my @clones;
for (@$domains ) { for (@$domains ) {
...@@ -446,9 +446,9 @@ Returns a reference to a list of the users ...@@ -446,9 +446,9 @@ Returns a reference to a list of the users
=cut =cut
sub list_users($self,$name=undef) { sub list_users($self,$name=undef) {
my $sth = $CONNECTOR->dbh->prepare("SELECT id, name FROM users "); my $sth = $CONNECTOR->dbh->prepare("SELECT id, name FROM users ORDER BY name");
$sth->execute(); $sth->execute();
my @users = (); my @users = ();
while ( my $row = $sth->fetchrow_hashref) { while ( my $row = $sth->fetchrow_hashref) {
next if defined $name && $row->{name} !~ /$name/; next if defined $name && $row->{name} !~ /$name/;
...@@ -459,6 +459,31 @@ sub list_users($self,$name=undef) { ...@@ -459,6 +459,31 @@ sub list_users($self,$name=undef) {
return \@users; return \@users;
} }
=head2 list_users_all
Returns a reference to a list of all the users if the total <= 20.
=cut
sub list_users_all {
my @users = ();
my $sth_aux = $CONNECTOR->dbh->prepare("SELECT COUNT(*) FROM users");
$sth_aux->execute();
my ($row_aux) = $sth_aux->fetchrow();
$sth_aux->finish;
if ($row_aux <= 20) {
my $sth = $CONNECTOR->dbh->prepare("SELECT id, name FROM users ORDER BY name");
$sth->execute();
while ( my $row = $sth->fetchrow_hashref) {
push @users, ($row);
}
$sth->finish;
}
return \@users;
}
=head2 create_domain =head2 create_domain
Request the creation of a new domain or virtual machine Request the creation of a new domain or virtual machine
...@@ -479,7 +504,7 @@ Waits for a request for some seconds. ...@@ -479,7 +504,7 @@ Waits for a request for some seconds.
=head3 Arguments =head3 Arguments
=over =over
=item * request =item * request
...@@ -814,7 +839,7 @@ sub list_bases_anonymous { ...@@ -814,7 +839,7 @@ sub list_bases_anonymous {
my $sth = $CONNECTOR->dbh->prepare("SELECT id, name, id_base, is_public FROM domains where is_base=1 AND is_public=1"); my $sth = $CONNECTOR->dbh->prepare("SELECT id, name, id_base, is_public FROM domains where is_base=1 AND is_public=1");
$sth->execute(); $sth->execute();
my @bases = (); my @bases = ();
while ( my $row = $sth->fetchrow_hashref) { while ( my $row = $sth->fetchrow_hashref) {
next if !$net->allowed_anonymous($row->{id}); next if !$net->allowed_anonymous($row->{id});
...@@ -826,7 +851,7 @@ sub list_bases_anonymous { ...@@ -826,7 +851,7 @@ sub list_bases_anonymous {
} }
=head2 disconnect_vm =head2 disconnect_vm
Disconnects all the conneted VMs Disconnects all the conneted VMs
......
...@@ -980,6 +980,9 @@ sub admin { ...@@ -980,6 +980,9 @@ sub admin {
if ( $c->param('name') ) { if ( $c->param('name') ) {
$c->stash(list_users => $RAVADA->list_users($c->param('name') )) $c->stash(list_users => $RAVADA->list_users($c->param('name') ))
} }
else {
$c->stash(list_users => $RAVADA->list_users_all());
}
} }
if ($page eq 'machines') { if ($page eq 'machines') {
$c->stash(hide_clones => 0 ); $c->stash(hide_clones => 0 );
......
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