App-SD

 view release on metacpan or  search on metacpan

lib/App/SD/Model/Ticket.pm  view on Meta::CPAN

}

sub has_active_status {
    my $self = shift;
    return 1 if grep { $_ eq $self->prop('status') } @{$ACTIVE_STATUSES};
}

=head2 default_prop_reporter

Returns a string of the default value of the C<reporter> prop.
(Currently, this is the config variable C<email_address> or
the environmental variable C<EMAIL>.)

=cut

sub default_prop_reporter {
    my $self = shift;
    my $reporter = $self->app_handle->current_user_email;
    if ( $reporter ) {
        return $reporter;
    }
    else {
        die "Cannot determine an email to attribute your changes to."
           ." You can\nfix this by setting the config variable"
           ." 'user.email-address'.\n";
    }
}

=head2 canonicalize_prop_status

resolved is called closed.

=cut

my %canonicalize_status = (
    resolved => 'closed',
);

sub canonicalize_prop_status {
    my $self = shift;
    my %args = @_;

    my $props = $args{props};

    if (defined $canonicalize_status{ $props->{status} }) {
        $props->{status} = $canonicalize_status{ $props->{status} };
    }

    return 1;
}


sub canonicalize_prop_due {
    my $self = shift;
    my %args = @_;
    my $props = $args{props};
    # skip blank
    return 1 unless $props->{due};
    #skip well formed
    return 1 if $props->{due} =~ /^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/; 
    require DateTime::Format::Natural;
    my $parser = DateTime::Format::Natural->new;
    my $dt = $parser->parse_datetime($props->{due});
    if ($parser->success) {
     # operate on $dt/@dt, for example:
        $props->{due} = sprintf( "%04d-%02d-%02d %02d:%02d:%02d", $dt->year, $dt->month, $dt->day, $dt->hour, $dt->min, $dt->sec);
    }
    return 1;
}


=head2 _default_summary_format

The default ticket summary format (used for displaying tickets in a
list, generally).

=cut

sub _default_summary_format { '%s,$luid | %s,summary | %s,status' }

=head2 validate_prop_status { props = $hashref, errors = $hashref }

Determines whether the status prop value given in C<$args{props}{status}>
is valid.

Returns true if the status is valid. If the status is invalid, sets
C<$args{errors}{status}> to an error message and returns false.

=cut

sub validate_prop_status {
    my ( $self, %args ) = @_;
    return $self->validate_prop_from_recommended_values( 'status', \%args );
}

sub validate_prop_component {
    my ( $self, %args ) = @_;
    return $self->validate_prop_from_recommended_values( 'component', \%args );
}

sub validate_prop_milestone {
    my ( $self, %args ) = @_;
    return $self->validate_prop_from_recommended_values( 'milestone', \%args );
}

sub _recommended_values_for_prop_milestone {
   return @{ shift->app_handle->setting( label => 'milestones' )->get() };
}

sub _recommended_values_for_prop_status {
   return @{ shift->app_handle->setting( label => 'statuses' )->get() };
}

sub _recommended_values_for_prop_component {
   return @{ shift->app_handle->setting( label => 'components' )->get() };
}

=head2 props_to_show { 'verbose' => 1, update => 0 }

A list of which properties to display for the C<show> command (in order
from first to last).

lib/App/SD/Model/Ticket.pm  view on Meta::CPAN


Given references to a hash and an array, return an array of the keys of the
hash in the order specified by the array, with any extra keys at the end of the
ordering.

If called with update as a true value, will add keys in the ordering to the
returned order even if they're not in the hash.

=cut

sub _create_prop_ordering {
    my %args = @_;
    my %props = %{$args{hash_to_order}};
    my @order = @{$args{order}};
    my @new_props_list;

    # if props in the ordering are in the hash, add them to
    # the new ordering
    for my $prop (@order) {
        if ( $props{$prop} || $prop eq 'id' || $args{update} ) {
            push @new_props_list, $prop;
            delete $props{$prop};
        }
    }
    # add hash keys not in the ordering to the end of the new ordering
    push @new_props_list, keys %props;

    return @new_props_list;
}

=head2 immutable_props

A pattern of props not to show in an editor (when creating or updating a
ticket, for example). Could also be used to determine which props shouldn't be
user-modifiable.

=cut

sub immutable_props { qw(id creator created original_replica) }

=head2 is_overdue [$date]

Takes an ISO date (or uses the C<date> prop value if no date is given).

Returns false if the date is not a valid ISO date or its due date is
in the future. Returns true if the due date has passed.

=cut

sub is_overdue {
    my $self = shift;
    my $date = shift || $self->prop('due');

    my $then = App::SD::Util::string_to_datetime($date);

    if (!$then) {
        warn "Unknown date format '$date'";
        return 0;
    }

    if ($then < DateTime->now()){ 
        return 1;
    }

    return 0;
}


__PACKAGE__->meta->make_immutable;
no Any::Moose;
1;



( run in 1.632 second using v1.01-cache-2.11-cpan-d7f47b0818f )