<commit_before>package GADS::Role::Presentation::Datum::Curcommon;

use Moo::Role;

sub _presentation_details {
    my $self = shift;

    #return [] unless $self->as_string;

    my $rti = $self->column->refers_to_instance_id;

    my @links = map +{
        id                    => $_->{id},
        href                  => $_->{value},
        refers_to_instance_id => $rti,
        values                => $_->{values},
        presentation          => $_->{record}->presentation(curval_fields => $self->column->curval_fields),
    }, @{$self->values};

    return \@links;
}

sub presentation {
    my $self = shift;

    my $multivalue = $self->column->multivalue;

    my $base = $self->presentation_base;

    $base->{text}    = $base->{value};
    $base->{id_hash} = $self->id_hash;
    $base->{links}   = $self->_presentation_details;
    if ($self->column->value_selector eq 'typeahead' && !$multivalue)
    {
        # Currently autocomplete textboxes can only be single value. May want to
        # change this in the future.
        #
        # If this is a draft record, then the query should be used instead of
        # the ID. The query will only exist if it's a draft record
        if (my $q = $self->html_form->[0] && $self->html_form->[0]->{as_query})
        {
            $base->{autocomplete_value} = $q;
        }
        else {
            $base->{autocomplete_value} = $self->id;
        }
    }

    # Function to return the values for the drop-down selector, but only the
    # selected ones. This makes rendering the edit page quicker, as in the case of
    # a filtered drop-down, the values will be fetched each time it gets the
    # focus anyway
    $base->{selected_values} = [
        map { $self->column->_format_row($_->{record}) } @{$self->values}
    ];

    return $base;
}

1;<commit_msg>Fix presentation of autocomplete curval without add<commit_after>package GADS::Role::Presentation::Datum::Curcommon;

use Moo::Role;

sub _presentation_details {
    my $self = shift;

    #return [] unless $self->as_string;

    my $rti = $self->column->refers_to_instance_id;

    my @links = map +{
        id                    => $_->{id},
        href                  => $_->{value},
        refers_to_instance_id => $rti,
        values                => $_->{values},
        presentation          => $_->{record}->presentation(curval_fields => $self->column->curval_fields),
    }, @{$self->values};

    return \@links;
}

sub presentation {
    my $self = shift;

    my $multivalue = $self->column->multivalue;

    my $base = $self->presentation_base;

    $base->{text}    = $base->{value};
    $base->{id_hash} = $self->id_hash;
    $base->{links}   = $self->_presentation_details;
    if ($self->column->value_selector eq 'typeahead' && !$multivalue)
    {
        # Currently autocomplete textboxes can only be single value. May want to
        # change this in the future.
        #
        # If this is a draft record, then the query should be used instead of
        # the ID. The query will only exist if it's a draft record
        if ($self->column->show_add)
        {
            if (my $q = $self->html_form->[0] && $self->html_form->[0]->{as_query})
            {
                $base->{autocomplete_value} = $q;
            }
            else {
                $base->{autocomplete_value} = $self->id;
            }
        }
        else {
            $base->{autocomplete_value} = $self->id;
        }
    }

    # Function to return the values for the drop-down selector, but only the
    # selected ones. This makes rendering the edit page quicker, as in the case of
    # a filtered drop-down, the values will be fetched each time it gets the
    # focus anyway
    $base->{selected_values} = [
        map { $self->column->_format_row($_->{record}) } @{$self->values}
    ];

    return $base;
}

1;
{'fraction_non_alphanumeric': 0.1408632721633497, 'fraction_numerical': 0.0015507883173946756, 'mean_word_length': 2.1695331695331697, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 89, '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': '2003024', 'n_tokens_mistral': 1219, 'n_tokens_neox': 1169, 'n_words': 318}