<commit_before>
=head1 NAME

SGN::Controller::solGS::AJAX::solGS - a REST controller class to provide the
backend for objects linked with solgs

=head1 AUTHOR

<NAME> <<EMAIL>>

=cut

package SGN::Controller::solGS::AJAX::solGS;

use Moose;


BEGIN { extends 'Catalyst::Controller::REST' }

__PACKAGE__->config(
    default   => 'application/json',
    stash_key => 'rest',
    map       => { 'application/json' => 'JSON', 'text/html' => 'JSON' },
   );



sub solgs_trait_search_autocomplete :  Path('/solgs/ajax/trait/search') : ActionClass('REST') { }

sub solgs_trait_search_autocomplete_GET :Args(0) {
    my ( $self, $c ) = @_;

    my $term = $c->req->param('term');

    $term =~ s/(^\s+|\s+)$//g;
    $term =~ s/\s+/ /g;

    my $traits = $c->controller('solGS::Search')->model($c)->search_trait($term);

    $c->{stash}->{rest} = $traits;

}


sub solgs_population_search_autocomplete :  Path('/solgs/ajax/population/search') : ActionClass('REST') { }

sub solgs_population_search_autocomplete_GET :Args() {
    my ( $self, $c ) = @_;

    my $term = $c->req->param('term');
    $term =~ s/(^\s+|\s+)$//g;
    $term =~ s/\s+/ /g;

    my @response_list;
    my $rs = $c->controller('solGS::Search')->model($c)->project_details_by_name($term);

    while (my $row = $rs->next)
    {
        my $pop_id = $row->id;    
        my $page_type = $c->controller('solGS::Path')->page_type($c, $c->req->referer);
        my $is_computation = $c->controller('solGS::Search')->check_saved_analysis_trial($c, $pop_id);
        
        if ($page_type =~ /training model/) 
        {
            if (!$is_computation)
            {
            push @response_list, $row->name;
            }           
        }  
    else
	{  
        my $has_phenotype = $c->controller('solGS::Search')->model($c)->has_phenotype($pop_id);            
        if (!$is_computation && $has_phenotype)
        {
        push @response_list, $row->name;
        }
     }
    }

    $c->{stash}->{rest} = \@response_list;
}


sub begin : Private {
    my ($self, $c) = @_;

    $c->controller('solGS::Files')->get_solgs_dirs($c);

}

###
1;
###<commit_msg>tweak for readabilty<commit_after>
=head1 NAME

SGN::Controller::solGS::AJAX::solGS - a REST controller class to provide the
backend for objects linked with solgs

=head1 AUTHOR

<NAME> <<EMAIL>>

=cut

package SGN::Controller::solGS::AJAX::solGS;

use Moose;


BEGIN { extends 'Catalyst::Controller::REST' }

__PACKAGE__->config(
    default   => 'application/json',
    stash_key => 'rest',
    map       => { 'application/json' => 'JSON', 'text/html' => 'JSON' },
   );



sub solgs_trait_search_autocomplete :  Path('/solgs/ajax/trait/search') : ActionClass('REST') { }

sub solgs_trait_search_autocomplete_GET :Args(0) {
    my ( $self, $c ) = @_;

    my $term = $c->req->param('term');

    $term =~ s/(^\s+|\s+)$//g;
    $term =~ s/\s+/ /g;

    my $traits = $c->controller('solGS::Search')->model($c)->search_trait($term);

    $c->{stash}->{rest} = $traits;

}


sub solgs_population_search_autocomplete :  Path('/solgs/ajax/population/search') : ActionClass('REST') { }

sub solgs_population_search_autocomplete_GET :Args() {
    my ( $self, $c ) = @_;

    my $term = $c->req->param('term');
    $term =~ s/(^\s+|\s+)$//g;
    $term =~ s/\s+/ /g;

    my @response_list;
    my $rs = $c->controller('solGS::Search')->model($c)->project_details_by_name($term);

    while (my $row = $rs->next)
    {
        my $pop_id = $row->id;    
        my $page_type = $c->controller('solGS::Path')->page_type($c, $c->req->referer);
        my $is_computation = $c->controller('solGS::Search')->check_saved_analysis_trial($c, $pop_id);
        
        if ($page_type =~ /training model/) 
        {
            if (!$is_computation)
            {
                push @response_list, $row->name;
            }           
        }  
    else
	{  
        my $has_phenotype = $c->controller('solGS::Search')->model($c)->has_phenotype($pop_id);            
        if ($has_phenotype && !$is_computation)
        {
            push @response_list, $row->name;
        }
     }
    }

    $c->{stash}->{rest} = \@response_list;
}


sub begin : Private {
    my ($self, $c) = @_;

    $c->controller('solGS::Files')->get_solgs_dirs($c);

}

###
1;
###
{'fraction_non_alphanumeric': 0.1998599112771422, 'fraction_numerical': 0.0018678496381041327, 'mean_word_length': 2.7219808861859254, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 79, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7644610', 'n_tokens_mistral': 1616, 'n_tokens_neox': 1547, 'n_words': 260}