[Bps-public-commit] App-Changeloggr branch, master, updated. a05e0d2975f31a52683061e247674174ee9c60ae

Alex M Vandiver alexmv at bestpractical.com
Wed Apr 29 18:25:36 EDT 2009


The branch, master has been updated
       via  a05e0d2975f31a52683061e247674174ee9c60ae (commit)
       via  acde18caeba0628837965d48d52dffd14cc2dd68 (commit)
      from  e4dfb826438154bd342f9ad60f7649cb96ceb5e0 (commit)

Summary of changes:
 etc/config.yml                                |    4 +++
 lib/App/Changeloggr/Action/AddChanges.pm      |    4 +-
 lib/App/Changeloggr/Dispatcher.pm             |    8 +-----
 lib/App/Changeloggr/Event/AddChanges.pm       |   19 ++++++++++++++++
 lib/App/Changeloggr/Model/ChangeCollection.pm |   29 +++++++++++++-----------
 lib/App/Changeloggr/Model/Changelog.pm        |   18 ++++-----------
 lib/App/Changeloggr/View/Admin.pm             |   20 +++++++++++++---
 7 files changed, 64 insertions(+), 38 deletions(-)
 create mode 100644 lib/App/Changeloggr/Event/AddChanges.pm

- Log -----------------------------------------------------------------
commit acde18caeba0628837965d48d52dffd14cc2dd68
Author: Alex Vandiver <alexmv at mit.edu>
Date:   Wed Apr 29 18:22:49 2009 -0400

    Fold create_from_text and create_from_parser into one method

diff --git a/lib/App/Changeloggr/Action/AddChanges.pm b/lib/App/Changeloggr/Action/AddChanges.pm
index 82034fd..a5f0d1b 100644
--- a/lib/App/Changeloggr/Action/AddChanges.pm
+++ b/lib/App/Changeloggr/Action/AddChanges.pm
@@ -26,10 +26,10 @@ sub take_action {
     my $changelog = $self->get_changelog;
 
     if ($parser->take_offline) {
-        Jifty->background( sub { $changelog->add_changes( $parser ) } );
+        Jifty->background( sub { $changelog->add_changes( parser => $parser ) } );
         $self->result->message(_("Importing your changes in the background."));
     } else {
-        my $changes = $changelog->add_changes( $parser );
+        my $changes = $changelog->add_changes( parser => $parser );
 
         if ($changes->count) {
             $self->result->message(_("Added your %quant(%1,change)!", $changes->count));
diff --git a/lib/App/Changeloggr/Model/ChangeCollection.pm b/lib/App/Changeloggr/Model/ChangeCollection.pm
index 65ff81c..a61585d 100644
--- a/lib/App/Changeloggr/Model/ChangeCollection.pm
+++ b/lib/App/Changeloggr/Model/ChangeCollection.pm
@@ -6,24 +6,16 @@ use Params::Validate qw(validate SCALAR);
 
 use constant results_are_readable => 1;
 
-sub create_from_text {
-    my $self = shift;
-    my %args = validate(@_, {
-        text      => { type => SCALAR },
-        changelog => { isa => 'App::Changeloggr::Model::Changelog' },
-    });
-
-    my $parser = App::Changeloggr::InputFormat->new( text => delete $args{text} );
-    return $self->create_from_parser( %args, parser => $parser );
-}
-
-sub create_from_parser {
+sub create_from {
     my $self = shift;
     my %args = validate(@_, {
+        text      => { type => SCALAR, default => '' },
         parser    => { isa => 'App::Changeloggr::InputFormat' },
         changelog => { isa => 'App::Changeloggr::Model::Changelog' },
     });
 
+    $args{parser} ||= App::Changeloggr::InputFormat->new( text => delete $args{text} );
+
     my $parser    = $args{parser};
     my $changelog = $args{changelog};
 
diff --git a/lib/App/Changeloggr/Model/Changelog.pm b/lib/App/Changeloggr/Model/Changelog.pm
index ae0b397..eb1e185 100644
--- a/lib/App/Changeloggr/Model/Changelog.pm
+++ b/lib/App/Changeloggr/Model/Changelog.pm
@@ -52,21 +52,13 @@ sub current_user_can {
 
 sub add_changes {
     my $self = shift;
-    my $arg = shift;
+    my %args = @_;
 
     my $changes = M('ChangeCollection');
-    if (ref $arg) {
-        $changes->create_from_parser(
-            parser    => $arg,
-            changelog => $self,
-        );
-    } else {
-        $changes->create_from_text(
-            text      => $arg,
-            changelog => $self,
-        );
-    }
-    
+    $changes->create_from(
+        changelog => $self,
+        @_,
+    );
 
     return $changes;
 }

commit a05e0d2975f31a52683061e247674174ee9c60ae
Author: Alex Vandiver <alexmv at mit.edu>
Date:   Wed Apr 29 18:25:16 2009 -0400

    Event-based update of changes in background

diff --git a/etc/config.yml b/etc/config.yml
index a0ee90f..4b5c0c1 100644
--- a/etc/config.yml
+++ b/etc/config.yml
@@ -21,6 +21,9 @@ framework:
   LogLevel: INFO
   Mailer: Sendmail
   MailerArgs: []
+  PubSub:
+    Backend: Memcached
+    Enable: 1
   Plugins: 
     - SkeletonApp: {}
     - REST: {}
@@ -37,6 +40,7 @@ framework:
   Web: 
     BaseURL: http://localhost
     Port: 8888
+    ServerClass: Jifty::Server::Fork
     ServeStaticFiles: 1
     StaticRoot: share/web/static
     TemplateRoot: share/web/templates
diff --git a/lib/App/Changeloggr/Action/AddChanges.pm b/lib/App/Changeloggr/Action/AddChanges.pm
index a5f0d1b..a487895 100644
--- a/lib/App/Changeloggr/Action/AddChanges.pm
+++ b/lib/App/Changeloggr/Action/AddChanges.pm
@@ -26,7 +26,7 @@ sub take_action {
     my $changelog = $self->get_changelog;
 
     if ($parser->take_offline) {
-        Jifty->background( sub { $changelog->add_changes( parser => $parser ) } );
+        Jifty->background( sub { $changelog->add_changes( parser => $parser, events => 2 ) } );
         $self->result->message(_("Importing your changes in the background."));
     } else {
         my $changes = $changelog->add_changes( parser => $parser );
diff --git a/lib/App/Changeloggr/Dispatcher.pm b/lib/App/Changeloggr/Dispatcher.pm
index ce09483..8bf8c9a 100644
--- a/lib/App/Changeloggr/Dispatcher.pm
+++ b/lib/App/Changeloggr/Dispatcher.pm
@@ -35,12 +35,8 @@ on '/changelog/*/*/Changes' => run {
 
 # match /admin/changelog/SUBTAB/UUID
 # or    /admin/changelog/UUID
-on qr{^/admin/changelog/([^/]+)(?:/([^/]+))?$} => run {
+on qr{^/admin/changelog((?:/[^/]+)*)/([^/]+)$} => run {
     my ($subpage, $uuid) = ($1, $2);
-    if (!$uuid) {
-        $uuid = $subpage;
-        undef $subpage;
-    }
 
     my $cl = Changelog(admin_token => $uuid);
     show "/errors/404" unless $cl->id;
@@ -64,7 +60,7 @@ on qr{^/admin/changelog/([^/]+)(?:/([^/]+))?$} => run {
     );
 
     set id => $cl->id;
-    show "/admin/changelog" . ($subpage ? "/$subpage" : "");
+    show "/admin/changelog$subpage";
 };
 
 1;
diff --git a/lib/App/Changeloggr/Event/AddChanges.pm b/lib/App/Changeloggr/Event/AddChanges.pm
new file mode 100644
index 0000000..ea9f7f4
--- /dev/null
+++ b/lib/App/Changeloggr/Event/AddChanges.pm
@@ -0,0 +1,19 @@
+package App::Changeloggr::Event::AddChanges;
+use strict;
+use warnings;
+use base 'App::Changeloggr::Event';
+
+sub match {
+    my $self    = shift;
+    my $query   = shift;
+
+    return if $query->{id} and $self->data->{id} != $query->{id};
+    return 1;
+}
+
+sub render_arguments {
+    my $self = shift;
+    return ( %{$self->data} );
+}
+
+1;
diff --git a/lib/App/Changeloggr/Model/ChangeCollection.pm b/lib/App/Changeloggr/Model/ChangeCollection.pm
index a61585d..8b4e97c 100644
--- a/lib/App/Changeloggr/Model/ChangeCollection.pm
+++ b/lib/App/Changeloggr/Model/ChangeCollection.pm
@@ -2,7 +2,7 @@ package App::Changeloggr::Model::ChangeCollection;
 use strict;
 use warnings;
 use base 'App::Changeloggr::Collection';
-use Params::Validate qw(validate SCALAR);
+use Params::Validate qw(validate SCALAR BOOLEAN);
 
 use constant results_are_readable => 1;
 
@@ -12,6 +12,7 @@ sub create_from {
         text      => { type => SCALAR, default => '' },
         parser    => { isa => 'App::Changeloggr::InputFormat' },
         changelog => { isa => 'App::Changeloggr::Model::Changelog' },
+        events    => { type => SCALAR, default => 0 },
     });
 
     $args{parser} ||= App::Changeloggr::InputFormat->new( text => delete $args{text} );
@@ -19,6 +20,7 @@ sub create_from {
     my $parser    = $args{parser};
     my $changelog = $args{changelog};
 
+    my $last = 0;
     while (my $fields = $parser->next_match) {
         my $change = App::Changeloggr::Model::Change->new;
 
@@ -29,10 +31,19 @@ sub create_from {
 
         if ($ok) {
             $self->add_record($change);
+            if ($args{events} and time > $last + $args{events}) {
+                App::Changeloggr::Event::AddChanges->new(
+                    { id => $changelog->id, change => $change }
+                )->publish;
+                $last = time;
+            }
         } else {
             warn "Unable to create Change: $msg";
         }
     }
+    App::Changeloggr::Event::AddChanges->new(
+        { id => $changelog->id }
+    )->publish if $args{events};
 }
 
 sub limit_to_voted {
diff --git a/lib/App/Changeloggr/View/Admin.pm b/lib/App/Changeloggr/View/Admin.pm
index 9245c51..376f4bb 100644
--- a/lib/App/Changeloggr/View/Admin.pm
+++ b/lib/App/Changeloggr/View/Admin.pm
@@ -95,15 +95,27 @@ sub change_sections {
     return @sections;
 }
 
-sub add_changes_to {
-    my $changelog = shift;
-
+template '/changelog/changes/count' => sub {
+    my $id = get('id');
+    my $changelog = M('Changelog', id => $id);
     if ($changelog->changes->count) {
         p { _("This changelog has %quant(%1,change).", $changelog->changes->count) }
     }
+    Jifty->subs->update_on(
+        class   => 'AddChanges',
+        queries => [{ id => $id }],
+    );
+};
 
-    my $add_changes = new_action('AddChanges');
+sub add_changes_to {
+    my $changelog = shift;
 
+    render_region(
+        name => 'count',
+        path => '/admin/changelog/changes/count/'.$changelog->as_superuser->admin_token,
+    );
+
+    my $add_changes = new_action('AddChanges');
     form {
         render_action($add_changes => ['changes']);
 

-----------------------------------------------------------------------



More information about the Bps-public-commit mailing list