Skip to content
Browse files

Remove classbuilder stuff, it's now in the branch

  • Loading branch information...
1 parent 4c5ab96 commit 7824ff0883168f1344933ab4a455e2c17297959d @sartak sartak committed Aug 3, 2008
Showing with 59 additions and 117 deletions.
  1. +59 −15 lib/Net/Hiveminder.pm
  2. +0 −102 lib/Net/Hiveminder/Task.pm
View
74 lib/Net/Hiveminder.pm
@@ -2,7 +2,6 @@
package Net::Hiveminder;
use Moose;
extends 'Net::Jifty';
-use Net::Hiveminder::Task;
use Number::RecordLocator;
my $LOCATOR = Number::RecordLocator->new;
@@ -80,25 +79,76 @@ The arguments currently respected are:
Make the record locator (C<#foo>) into an HTML link, pointing to the task on
C<site>.
-=item color
-
-Use ANSI escape-sequence colors.
-
=back
=cut
sub display_tasks {
my $self = shift;
+ my @out;
+ my $now = DateTime->now;
my %email_of;
my %args;
if (ref($_[0]) eq 'ARRAY') {
%args = @{ shift(@_) };
}
- my @out = map { $_->display } @_;
+ for my $task (@_) {
+ my $locator = $self->id2loc($task->{id});
+ my $display;
+
+ if ($task->{complete}) {
+ $display .= '* ';
+ }
+
+ if ($args{linkify_locator}) {
+ $display .= sprintf '<a href="%s/task/%s">#%s</a>: %s',
+ $self->site,
+ $locator,
+ $locator,
+ $task->{summary};
+ }
+ else {
+ $display .= "#$locator: $task->{summary}";
+ }
+
+ # don't display start date if it's <= today
+ delete $task->{starts}
+ if $task->{starts}
+ && $self->load_date($task->{starts}) < $now;
+
+ $display .= " [$task->{tags}]" if $task->{tags};
+ for my $field (qw/due starts group/) {
+ $display .= " [$field: $task->{$field}]"
+ if $task->{$field};
+ }
+
+ $display .= " [priority: " . $self->priority($task->{priority}) . "]"
+ if $task->{priority} != 3;
+
+ my $helper = sub {
+ my ($field, $name) = @_;
+
+ my $id = $task->{$field}
+ or return;
+
+ # this wants to be //=. oh well
+ my $email = $email_of{$id} ||= $self->email_of($id)
+ or return;
+
+ $self->is_me($email)
+ and return;
+
+ $display .= " [$name: $email]";
+ };
+
+ $helper->('requestor_id', 'for');
+ $helper->('owner_id', 'by');
+
+ push @out, $display;
+ }
return wantarray ? @out : join "\n", @out;
}
@@ -118,10 +168,7 @@ sub get_tasks {
my @args = @_;
unshift @args, "tokens" if @args == 1;
- $self->create_model_class('Task');
-
- return map { Net::Hiveminder::Task->new(_interface => $self, %$_) }
- @{ $self->act('TaskSearch', @args)->{content}{tasks} };
+ return @{ $self->act('TaskSearch', @args)->{content}{tasks} };
}
=head2 todo_tasks [ARGS]
@@ -206,8 +253,7 @@ sub read_task {
my $loc = shift;
my $id = $self->loc2id($loc);
- $self->create_model_class('Task');
- return Net::Hiveminder::Task->load($self, $id);
+ return $self->read(Task => id => $id);
}
=head2 update_task LOCATOR, ARGS
@@ -352,9 +398,7 @@ sub braindump {
return @{ $ret->{content}->{ids} || [] };
}
elsif ($args{returns} eq 'tasks') {
- $self->create_model_class('Task');
- return map { Net::Hiveminder::Task->new(_interface => $self, %$_) }
- @{ $ret->{content}->{created} || [] };
+ return @{ $ret->{content}->{created} || [] };
}
return $ret->{message};
View
102 lib/Net/Hiveminder/Task.pm
@@ -1,102 +0,0 @@
-#!/usr/bin/env perl
-package Net::Hiveminder::Task;
-use Moose;
-extends 'Net::Jifty::Record';
-
-use Number::RecordLocator;
-my $LOCATOR = Number::RecordLocator->new;
-
-sub record_locator {
- my $self = shift;
- return $LOCATOR->encode($self->id);
-}
-
-sub priority_word {
- my $self = shift;
- return (undef, qw/lowest low normal high highest/)[$self->priority];
-}
-
-# XXX: datetime and timestamp fields should already be DateTime
-sub starts_datetime {
- my $self = shift;
- return undef if !$self->starts;
- $self->_interface->load_date($self->starts);
-}
-
-sub starts_after {
- my $self = shift;
- my $time = shift || time;
-
- my $starts = $self->starts_datetime;
- return 0 if !defined($starts);
- return $starts >= $time if blessed($time);
- return $starts->epoch >= $time;
-}
-
-sub display {
- my $self = shift;
- my %args = @_;
-
- my $locator = $self->record_locator;
- my $display;
-
- if ($self->complete) {
- $display .= '* ';
- }
-
- my $loc_display = "#$locator";
- if ($args{color}) {
- my $color = $self->priority >= 5 ? "\e[31m" # red
- : $self->priority == 4 ? "\e[33m" # yellow
- : $self->priority == 2 ? "\e[36m" # cyan
- : $self->priority <= 1 ? "\e[34m" # blue
- : "";
- $loc_display = "$color$loc_display\e[m" if $color;
- }
-
- if ($args{linkify_locator}) {
- $display .= sprintf '<a href="%s/task/%s">%s</a>: %s',
- $self->_interface->site,
- $locator,
- $loc_display,
- $self->summary;
- }
- else {
- $display .= "$loc_display: " . $self->summary;
- }
-
- $display .= " [". $self->tags ."]" if $self->tags;
- $display .= " [". $self->due ."]" if $self->due;
-
- # display start date only if it's in the future
- $display .= " [". $self->starts ."]"
- if $self->starts_after(time);
-
- $display .= " [priority: " . $self->priority_word . "]"
- if $self->priority != 3;
-
- my $helper = sub {
- my ($field, $name) = @_;
-
- my $id = $self->$field
- or return;
-
- my $email = $self->_interface->email_of($id)
- or return;
-
- $self->_interface->is_me($email)
- and return;
-
- $display .= " [$name: $email]";
- };
-
- $helper->('requestor_id', 'for');
- $helper->('owner_id', 'by');
-
- return $display;
-}
-
-no Moose;
-
-1;
-

0 comments on commit 7824ff0

Please sign in to comment.
Something went wrong with that request. Please try again.