[Bps-public-commit] jifty-plugin-recordhistory branch, master, updated. 0c4b3ea605fee54ac6eac4578f25fc627ed07760

Shawn Moore sartak at bestpractical.com
Wed Feb 9 22:21:30 EST 2011


The branch, master has been updated
       via  0c4b3ea605fee54ac6eac4578f25fc627ed07760 (commit)
       via  b68cdc06cbafd9f1298c8dc9beea8f6e34bee042 (commit)
       via  94b8dfdafa576ffe35a8696a671cc84c9ff1ea2b (commit)
      from  841bae474d81aae54102730b81361f9e869bd4c9 (commit)

Summary of changes:
 lib/Jifty/Plugin/RecordHistory/View.pm |  133 ++++++++++++++++++++++++++++++++
 1 files changed, 133 insertions(+), 0 deletions(-)
 create mode 100644 lib/Jifty/Plugin/RecordHistory/View.pm

- Log -----------------------------------------------------------------
commit 94b8dfdafa576ffe35a8696a671cc84c9ff1ea2b
Author: Shawn M Moore <sartak at bestpractical.com>
Date:   Wed Feb 9 22:15:19 2011 -0500

    Begin adding a View class for viewing and customization

diff --git a/lib/Jifty/Plugin/RecordHistory/View.pm b/lib/Jifty/Plugin/RecordHistory/View.pm
new file mode 100644
index 0000000..f576006
--- /dev/null
+++ b/lib/Jifty/Plugin/RecordHistory/View.pm
@@ -0,0 +1,133 @@
+package Jifty::Plugin::RecordHistory::View;
+use strict;
+use warnings;
+use Jifty::View::Declare -base;
+
+sub mount_view {
+    my ($class, $model, $vclass, $path) = @_;
+    my $caller = caller(0);
+
+    # Sanitize the arguments
+    $model = ucfirst($model);
+    $vclass ||= $caller.'::'.$model;
+    $path ||= '/'.lc($model);
+
+    # Load the view class, alias it, and define its object_type method
+    Jifty::Util->require($vclass);
+    eval qq{package $caller;
+            alias $vclass under '$path'; 1} or die $@;
+
+    # Override object_type
+    no strict 'refs';
+    my $object_type = $vclass."::object_type";
+
+    # Avoid the override if object_type() is already defined
+    *{$object_type} = sub { $model } unless defined *{$object_type};
+}
+
+sub object_type {
+    my $self = shift;
+    my $object_type = $self->package_variable('object_type') || get('object_type');
+
+    warn "No object type found for $self"
+        if !$object_type;
+
+    return $object_type;
+}
+
+sub page_title {
+    my $self = shift;
+    return _('History for %1', $self->object_type);
+}
+
+sub record_class {
+    my $self = shift;
+
+    # If object_type is set via set, don't cache
+    if (!$self->package_variable('object_type') && get('object_type')) {
+        return Jifty->app_class('Model', $self->object_type);
+    }
+
+    # Otherwise, assume object_type is permanent
+    else {
+        return ($self->package_variable('record_class')
+            or ($self->package_variable( record_class =>
+                    Jifty->app_class('Model', $self->object_type))));
+    }
+}
+
+sub load_record {
+    my $self = shift;
+
+    my $id = get('id');
+
+    my $record = $self->record_class->new;
+    $record->load($id);
+    return $record;
+}
+
+template 'index.html' => page { title => shift->page_title } content {
+    show './list';
+};
+
+template 'header' => sub {
+    my $self = shift;
+    h1 { _('History for %1', $self->object_type) };
+};
+
+template 'footer' => sub {
+};
+
+template 'list' => sub {
+    show 'header';
+
+    show 'changes';
+
+    show 'footer';
+};
+
+template 'changes' => sub {
+    my $record = $self->load_record;
+
+    while (my $change = $record->changes) {
+        show 'change' => $change;
+    }
+};
+
+template 'change' => sub {
+    my $self   = shift;
+    my $change = shift;
+
+    my $template = 'change-' . $change->type;
+
+    show $template => $change;
+};
+
+template 'change-create' => sub {
+    my $self   = shift;
+    my $change = shift;
+};
+
+template 'change-update' => sub {
+    my $self   = shift;
+    my $change = shift;
+
+    my $change_fields = $change->change_fields;
+    while (my $change_field = $change_fields->next) {
+        show 'change_field' => $change_field;
+    }
+};
+
+template 'change_field' => sub {
+    my $self         = shift;
+    my $change_field = shift;
+
+    my $field = $change_field->field;
+    my $old   = $change_fied->old_value;
+    my $new   = $change_fied->new_value;
+
+    outs _("%1 changed from '%2' to '%3'.", $field, $old, $new);
+};
+
+1;
+

commit b68cdc06cbafd9f1298c8dc9beea8f6e34bee042
Author: Shawn M Moore <sartak at bestpractical.com>
Date:   Wed Feb 9 22:21:19 2011 -0500

    Fix changes template

diff --git a/lib/Jifty/Plugin/RecordHistory/View.pm b/lib/Jifty/Plugin/RecordHistory/View.pm
index f576006..ce01c69 100644
--- a/lib/Jifty/Plugin/RecordHistory/View.pm
+++ b/lib/Jifty/Plugin/RecordHistory/View.pm
@@ -80,16 +80,16 @@ template 'footer' => sub {
 
 template 'list' => sub {
     show 'header';
-
     show 'changes';
-
     show 'footer';
 };
 
 template 'changes' => sub {
+    my $self = shift;
     my $record = $self->load_record;
+    my $changes = $record->changes;
 
-    while (my $change = $record->changes) {
+    while (my $change = $changes->next) {
         show 'change' => $change;
     }
 };

commit 0c4b3ea605fee54ac6eac4578f25fc627ed07760
Author: Shawn M Moore <sartak at bestpractical.com>
Date:   Wed Feb 9 22:21:25 2011 -0500

    Typo fix

diff --git a/lib/Jifty/Plugin/RecordHistory/View.pm b/lib/Jifty/Plugin/RecordHistory/View.pm
index ce01c69..6225b9d 100644
--- a/lib/Jifty/Plugin/RecordHistory/View.pm
+++ b/lib/Jifty/Plugin/RecordHistory/View.pm
@@ -123,8 +123,8 @@ template 'change_field' => sub {
     my $change_field = shift;
 
     my $field = $change_field->field;
-    my $old   = $change_fied->old_value;
-    my $new   = $change_fied->new_value;
+    my $old   = $change_field->old_value;
+    my $new   = $change_field->new_value;
 
     outs _("%1 changed from '%2' to '%3'.", $field, $old, $new);
 };

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



More information about the Bps-public-commit mailing list