<commit_before>package Qublog::Server::View::TD::Form;

use strict;
use warnings;

use Template::Declare::Tags;

use Qublog::Web;
use Qublog::Server::View::Common;

=head1 NAME

Qublog::Server::View::TD::Form - various form templates used with journal items

=head1 DESCRIPTION

Journal items may have forms attached to them by actions. This contains those
forms.

=head1 TEMPLATES

=head2 form/change_start_stop

This displays a form for changing the start or stop time of a timer. It expects
the following stash arguments:

=over

=item journal_timer

This is the L<Qublog::Schema::Result::JournalTimer> to edit.

=back

The request for this form should include a C<which> argument, set to "start" or
"stop" to select which time on the timer to edit.

=cut

template 'form/change_start_stop' => sub {
    my ($self, $c) = @_;
    my $timer  = $c->stash->{journal_timer};

    my $which = $c->request->params->{which} || 'start';
    $which = 'start' unless $which eq 'start' or $which eq 'stop';

    form {
        {
            method is 'POST',
            action is '/api/model/journal_timer/change_' . $which . '/'
                . $which . '-' . $timer->id,
        }

        my $action_class = 'JournalTimer::Change' . ucfirst($which);
        my $action = $c->action_form(schema => $action_class => {
            record => $timer,
            id     => $timer->id,
        });
        $action->prefill_from_record;
        $action->setup_and_render(
            moniker => $which . '-' . $timer->id,
            globals => {
                origin => $c->request->uri_with({
                    form       => 'change_start_stop',
                    form_place => 
                        join('-', 'JournalTimer', $timer->id, $which),
                    comment    => $timer->id,
                }),
                return_to => $c->request->uri_with({
                    form       => undef,
                    form_place => undef,
                    form_type  => undef,
                    comment    => undef,
                }),
            },
        );

        div { { class is 'submit' }
            $action->render_control(button => {
                name  => 'submit',
                label => 'Save',
            });
            $action->render_control(button => {
                name  => 'cancel',
                label => 'Cancel',
            });
        };
    };<commit_msg>Small DRY fix<commit_after>package Qublog::Server::View::TD::Form;

use strict;
use warnings;

use Template::Declare::Tags;

use Qublog::Web;
use Qublog::Server::View::Common;

=head1 NAME

Qublog::Server::View::TD::Form - various form templates used with journal items

=head1 DESCRIPTION

Journal items may have forms attached to them by actions. This contains those
forms.

=head1 TEMPLATES

=head2 form/change_start_stop

This displays a form for changing the start or stop time of a timer. It expects
the following stash arguments:

=over

=item journal_timer

This is the L<Qublog::Schema::Result::JournalTimer> to edit.

=back

The request for this form should include a C<which> argument, set to "start" or
"stop" to select which time on the timer to edit.

=cut

template 'form/change_start_stop' => sub {
    my ($self, $c) = @_;
    my $timer  = $c->stash->{journal_timer};

    my $which = $c->request->params->{which} || 'start';
    $which = 'start' unless $which eq 'start' or $which eq 'stop';

    my $moniker = join('-', $which, $timer->id);
    form {
        {
            method is 'POST',
            action is '/api/model/journal_timer/change_' . $which . '/' . $moniker,
        }

        my $action_class = 'JournalTimer::Change' . ucfirst($which);
        my $action = $c->action_form(schema => $action_class => {
            record => $timer,
            id     => $timer->id,
        });
        $action->prefill_from_record;
        $action->setup_and_render(
            moniker => $moniker,
            globals => {
                origin => $c->request->uri_with({
                    form       => 'change_start_stop',
                    form_place => 
                        join('-', 'JournalTimer', $timer->id, $which),
                    comment    => $timer->id,
                }),
                return_to => $c->request->uri_with({
                    form       => undef,
                    form_place => undef,
                    form_type  => undef,
                    comment    => undef,
                }),
            },
        );

        div { { class is 'submit' }
            $action->render_control(button => {
                name  => 'submit',
                label => 'Save',
            });
            $action->render_control(button => {
                name  => 'cancel',
                label => 'Cancel',
            });
        };
    };
{'fraction_non_alphanumeric': 0.13410836620303093, 'fraction_numerical': 0.001660784720780569, 'mean_word_length': 1.7673750717978174, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 88, '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': '226178', 'n_tokens_mistral': 1422, 'n_tokens_neox': 1358, 'n_words': 371}