[Bps-public-commit] Prophet - A disconnected, replicated p2p database branch, master, updated. 060cf539aa2f1707b2bf6673c8dc3dc051cd3c72

jesse jesse at bestpractical.com
Sun Jan 18 23:59:43 EST 2009


The branch, master has been updated
       via  060cf539aa2f1707b2bf6673c8dc3dc051cd3c72 (commit)
      from  75430ca4ba0c0a08c5f746a81866485d01f6bda9 (commit)

Summary of changes:
 lib/Prophet/Record.pm                      |   19 +++++++-
 lib/Prophet/Server/View.pm                 |   61 +++++++++++++++------------
 lib/Prophet/Server/ViewHelpers/Function.pm |    8 ++--
 lib/Prophet/Server/ViewHelpers/Widget.pm   |    6 ++-
 4 files changed, 59 insertions(+), 35 deletions(-)

- Log -----------------------------------------------------------------
commit 060cf539aa2f1707b2bf6673c8dc3dc051cd3c72
Author: Jesse Vincent <jesse at bestpractical.com>
Date:   Sun Jan 18 23:57:55 2009 -0500

    More flexible canonicalizers
    Show canonical prop values in the web ui

diff --git a/lib/Prophet/Record.pm b/lib/Prophet/Record.pm
index 01565e9..edce48a 100644
--- a/lib/Prophet/Record.pm
+++ b/lib/Prophet/Record.pm
@@ -511,13 +511,26 @@ sub canonicalize_props {
     my $props  = shift;
     my $errors = {};
     for my $key ( uniq( keys %$props, $self->declared_props ) ) {
-        if ( my $sub = $self->can( 'canonicalize_prop_' . $key ) ) {
-            $sub->( $self, props => $props, errors => $errors );
-        }
+        $self->canonicalize_prop($key, $props, $errors);
     }
     return 1;
 }
 
+sub canonicalize_prop {
+    my $self = shift;
+    my $prop = shift;
+    my $props = shift;
+    my $errors = shift;
+        if ( my $sub = $self->can( 'canonicalize_prop_' . $prop ) ) {
+            $sub->( $self, props => $props, errors => $errors );
+            return 1;
+        }
+
+
+    return 0;
+}
+
+
 =head2 default_props $props_ref
 
 Takes a reference to a hash of props and looks up the defaults for those
diff --git a/lib/Prophet/Server/View.pm b/lib/Prophet/Server/View.pm
index 9c8d4f0..fc6301f 100644
--- a/lib/Prophet/Server/View.pm
+++ b/lib/Prophet/Server/View.pm
@@ -41,35 +41,42 @@ sub server {
 
 
 template '_prophet_autocompleter' => sub {
-        my $self = shift;
-        my %args;
-        for (qw(q function record type class prop)) {
-            $args{$_} = $self->cgi->param($_);
-        }
-        my $obj = Prophet::Util->instantiate_record(
-            class      => $self->cgi->param('class'),
-            uuid       => $self->cgi->param('uuid'),
-            app_handle => $self->app_handle
-        );
-        
-        my @possible;
-        if ($obj->loaded) {
-            push @possible,$obj->prop($self->cgi->param('prop'));
-        }  else {
-            my $params = { $self->cgi->param('prop') => undef };
-            $obj->default_props($params);
-            push @possible, $params->{ $self->cgi->param('prop') };
-            # XXX fill in defaults;
-        }
-        
-        push @possible, $obj->recommended_values_for_prop($self->cgi->param('prop'));
-       
-       my %seen; 
-        for (grep {defined && !$seen{$_}++ } @possible) {
-                outs($_ ."\n");#." | ".$_."\n");
+    my $self = shift;
+    my %args;
+    for (qw(q function record type class prop)) {
+        $args{$_} = $self->cgi->param($_);
+    }
+    my $obj = Prophet::Util->instantiate_record(
+        class      => $self->cgi->param('class'),
+        uuid       => $self->cgi->param('uuid'),
+        app_handle => $self->app_handle
+    );
 
+    my @possible;
+    if ( $obj->loaded ) {
+        my $canon = { $args{prop} => $args{q} };
+        $obj->canonicalize_prop( $args{'prop'}, $canon, {} );
+        if ( $canon->{ $args{prop} } ne $args{q} ) {
+            push @possible, $canon->{ $args{'prop'} };
         }
-        
+
+        push @possible, $obj->prop( $args{'prop'} );
+    } else {
+        my $params = { $args{'prop'} => undef };
+        $obj->default_props($params);
+        push @possible, $params->{ $args{'prop'} };
+
+        # XXX fill in defaults;
+    }
+
+    push @possible, $obj->recommended_values_for_prop( $args{'prop'} );
+
+    my %seen;
+    for ( grep { defined && !$seen{$_}++ } @possible ) {
+        outs( $_ . "\n" );    #." | ".$_."\n");
+
+    }
+
 };
 
 
diff --git a/lib/Prophet/Server/ViewHelpers/Function.pm b/lib/Prophet/Server/ViewHelpers/Function.pm
index 07d5f49..dc638b5 100644
--- a/lib/Prophet/Server/ViewHelpers/Function.pm
+++ b/lib/Prophet/Server/ViewHelpers/Function.pm
@@ -49,11 +49,11 @@ has name => (
 
 
 
- sub new {
+sub new {
     my $self = shift->SUPER::new(@_);
     $self->name ( ($self->record->loaded ? $self->record->uuid : 'new') . "-" . $self->action ) unless ($self->name);
     return $self;
-};
+}
 
 sub render {
     my $self = shift;
@@ -78,7 +78,7 @@ sub render {
 }
 
 
-    __PACKAGE__->meta->make_immutable;
-    no Moose;
+__PACKAGE__->meta->make_immutable;
+no Moose;
 1;
 
diff --git a/lib/Prophet/Server/ViewHelpers/Widget.pm b/lib/Prophet/Server/ViewHelpers/Widget.pm
index a5d0685..cb38bd3 100644
--- a/lib/Prophet/Server/ViewHelpers/Widget.pm
+++ b/lib/Prophet/Server/ViewHelpers/Widget.pm
@@ -33,6 +33,8 @@ has type => ( isa => 'Maybe[Str]', is => 'rw');
 
 has autocomplete => (isa => 'Bool', is => 'rw', default => 1);
 
+has default => ( isa => 'Maybe[Str]', is => 'rw');
+
 sub render {
     my $self = shift;
 
@@ -42,7 +44,9 @@ sub render {
 
     my $value;
 
-    if ( $self->function->action eq 'create' ) {
+    if (defined $self->default) {
+        $value = $self->default;
+    } elsif ( $self->function->action eq 'create' ) {
         if ( my $method = $self->function->record->can( 'default_prop_' . $self->prop ) ) {
             $value = $method->( $self->function->record );
         } else {

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



More information about the Bps-public-commit mailing list