Changeset 1618

Show
Ignore:
Timestamp:
11/16/07 14:28:10 (7 years ago)
Author:
charsbar
Message:

lang/perl/Jipotter: now searchable; aggregator stopped using load_or_create, which seems somewhat unreliable

Location:
lang/perl/Jipotter/trunk
Files:
1 added
7 modified

Legend:

Unmodified
Added
Removed
  • lang/perl/Jipotter/trunk/lib/Jipotter/Plugin/Timelines.pm

    r1563 r1618  
    5858sub items_per_page { shift->{items_per_page} || 20 } 
    5959 
     60sub search_phrase { 
     61  my $self = shift; 
     62  if ( @_ ) { 
     63    $self->{search_phrase} = shift; 
     64  } 
     65  $self->{search_phrase}; 
     66} 
    6067 
    61681; 
  • lang/perl/Jipotter/trunk/lib/Jipotter/Plugin/Timelines/Action/Post.pm

    r1595 r1618  
    4040}; 
    4141 
    42 sub moniker { 'update' } 
     42sub moniker { 'timelines_post' } 
    4343 
    4444sub sticky_on_failure { 0 } 
     
    5757    if ( $self->argument_value( $service->name ) ) { 
    5858 
    59       Jifty->log->info( $service->name .' is updated at '. localtime ); 
     59      Jifty->log->info( 'Posted to '. $service->name .' at '. localtime ); 
    6060      $service->update( $message ); 
    6161    } 
  • lang/perl/Jipotter/trunk/lib/Jipotter/Plugin/Timelines/Dispatcher.pm

    r1522 r1618  
    55use Jifty::Dispatcher -base; 
    66 
    7 before qr{^/update} => run { 
     7before qr{^/timelines/post} => run { 
    88  Jifty->web->new_action( 
    99    class => 'Jipotter::Plugin::Timelines::Action::Post', 
    10     moniker => 'update' 
     10    moniker => 'timelines_post' 
     11  )->run; 
     12 
     13  redirect '/'; 
     14}; 
     15 
     16before qr{^/timelines/search} => run { 
     17  Jifty->web->new_action( 
     18    class => 'Jipotter::Plugin::Timelines::Action::Search', 
     19    moniker => 'timelines_search' 
    1120  )->run; 
    1221 
  • lang/perl/Jipotter/trunk/lib/Jipotter/Plugin/Timelines/View.pm

    r1595 r1618  
    55use Jifty::View::Declare -base; 
    66use Jipotter::Model::StatusCollection; 
     7use Time::Piece; 
     8 
     9template 'timelines' => sub { 
     10  set region => Jifty::Web::PageRegion->new( 
     11    name     => 'timelines_table', 
     12    path     => '/timelines/region', 
     13    defaults => { page => get('page') || 1 }, 
     14  ); 
     15 
     16  show '/timelines/form'; 
     17  show '/timelines/search'; 
     18  show '/timelines/table'; 
     19}; 
    720 
    821private template 'timelines/form' => sub { 
    922  my $action = Jifty->web->new_action( 
    10     class   => 'Jipotter::Plugin::Timelines::Action::Post', 
    11     moniker => 'update', 
     23    class    => 'Jipotter::Plugin::Timelines::Action::Post', 
     24    moniker  => 'timelines_post', 
    1225  ); 
    1326 
     27  my $plugin = Jifty->find_plugin('Jipotter::Plugin::Timelines'); 
     28 
    1429  div { attr { class => 'PostBox' }; 
    15     Jifty->web->form->start( submit_to => '/update' ); 
     30    Jifty->web->form->start( submit_to => '/timelines/post' ); 
    1631 
    1732    render_param( $action => 'message' ); 
     
    2035 
    2136    form_submit( label => 'Update', name => 'submit' ); 
    22  
    23     my $plugin = Jifty->find_plugin('Jipotter::Plugin::Timelines'); 
    2437 
    2538    foreach my $service ( $plugin->available_services ) { 
     
    3447}; 
    3548 
     49private template 'timelines/search' => sub { 
     50  my $action = Jifty->web->new_action( 
     51    class   => 'Jipotter::Plugin::Timelines::Action::Search', 
     52    moniker => 'timelines_search', 
     53  ); 
     54 
     55  my $region = get('region'); 
     56  my $plugin = Jifty->find_plugin('Jipotter::Plugin::Timelines'); 
     57 
     58  div { attr { class => 'timelines_search' }; 
     59    Jifty->web->form->start( submit_to => 'timelines/search' ); 
     60 
     61    render_param( 
     62      $action => 'phrase', sticky_value => $plugin->search_phrase 
     63    ); 
     64 
     65    form_submit( 
     66      label => 'Search', 
     67      name  => 'submit_search', 
     68      onclick => { 
     69        submit  => $action, 
     70        refresh => $region->name, 
     71        args    => { phrase => $plugin->search_phrase }, 
     72      } 
     73    ); 
     74 
     75    Jifty->web->form->end; 
     76  }; 
     77}; 
     78 
    3679private template 'timelines/table' => sub { 
    37   render_region( 
    38     name     => 'timelines_table', 
    39     path     => '/timelines/region', 
    40     defaults => { page => get('page') || 1 }, 
    41   ); 
     80  my $region = get('region'); 
     81 
     82  $region->render; 
    4283}; 
    4384 
    4485template 'timelines/region' => sub { 
    45   my $page = get('page') || 1; 
     86  my $page       = get('page') || 1; 
    4687  my $message_id = get('message_id') || ''; 
    4788 
    4889  my $plugin = Jifty->find_plugin('Jipotter::Plugin::Timelines'); 
     90  my $phrase = $plugin->search_phrase; 
    4991 
    5092  my $entries = Jipotter::Model::StatusCollection->new; 
    51      $entries->unlimit; 
    52      $entries->order_by( column => 'epoch', order => 'DESC' ); 
    53      $entries->set_page_info( 
    54        current_page => $page, 
    55        per_page     => $plugin->items_per_page, 
    56      ); 
     93  if ( defined $phrase ) { 
     94 
     95    # XXX: We need ESCAPE '\\' with them for SQLite actually... 
     96    $phrase =~ s/%/\\%/g; 
     97    $phrase =~ s/_/\\_/g; 
     98 
     99    $entries->limit( 
     100      column   => 'text', 
     101      value    => $phrase, 
     102      operator => 'MATCHES', 
     103    ); 
     104  } 
     105  else { 
     106    $entries->unlimit; 
     107  } 
     108  $entries->order_by( column => 'epoch', order => 'DESC' ); 
     109  $entries->set_page_info( 
     110    current_page => $page, 
     111    per_page     => $plugin->items_per_page, 
     112  ); 
    57113  set entries => $entries; 
    58114 
     
    60116 
    61117  table { attr { class => 'Statuses' }; 
     118    my $now = localtime; 
     119    caption { attr { class => 'timeline_caption' }; 
     120      'Last updated: '.$now->ymd.' '.$now->hms; 
     121    }; 
     122 
    62123    while ( my $entry = $entries->next ) { 
    63124 
     
    125186      } 
    126187      else { 
    127         span { attr { class => 'current' }; strong { "$num " } }; 
     188        span { attr { class => 'current' }; "$num " }; 
    128189      } 
    129190    } 
  • lang/perl/Jipotter/trunk/lib/Jipotter/Script/Aggregate.pm

    r1366 r1618  
    1919    Jifty->log->debug( 'registering '.$service->name ); 
    2020 
     21    my $ct = 0; 
    2122    foreach my $status ( $service->timelines ) { 
    2223      my $entry = Jipotter::Model::Status->new; 
    23          $entry->load_or_create( %{ $status } ); 
     24      $entry->load_by_cols( link => $status->link ); 
     25      unless ( $entry->id ) { 
     26        $entry->create( %{ $status } ); 
     27        $ct++; 
     28      } 
    2429    } 
     30    Jifty->log->debug( "registered $ct entries" ) if $ct; 
    2531  } 
    2632} 
  • lang/perl/Jipotter/trunk/lib/Jipotter/View.pm

    r1595 r1618  
    1313    body { 
    1414      div { attr { class => 'BodyContainer' }; 
    15         # see Timelines plugin 
    16         show 'timelines/form'; 
    17         show 'timelines/table'; 
     15        show 'timelines'; # see Timelines plugin 
    1816      } 
    1917    } 
  • lang/perl/Jipotter/trunk/share/web/static/css/jipotter.css

    r1563 r1618  
    7474} 
    7575 
     76.timeline_caption { 
     77    font-size: 90%; 
     78    margin-bottom: 20px; 
     79} 
     80 
     81.timelines_search { 
     82    background-color: #eeeeee; 
     83    width: 100%; 
     84    margin-bottom: 3px; 
     85    margin-top: 3px; 
     86    padding-top: 4px; 
     87    padding-bottom: 4px; 
     88} 
     89 
     90.timelines_search form { 
     91    margin-left: 10px; 
     92} 
     93 
     94.timelines_search div { 
     95    display: inline; 
     96    margin: auto; 
     97} 
     98