[Bps-public-commit] r17649 - in Prophet/trunk/lib/Prophet: Server Server/ViewHelpers Web

jesse at bestpractical.com jesse at bestpractical.com
Thu Jan 8 14:46:19 EST 2009


Author: jesse
Date: Thu Jan  8 14:46:19 2009
New Revision: 17649

Added:
   Prophet/trunk/lib/Prophet/Server/ViewHelpers/HiddenParam.pm
Modified:
   Prophet/trunk/lib/Prophet/App.pm
   Prophet/trunk/lib/Prophet/Replica.pm
   Prophet/trunk/lib/Prophet/Server.pm
   Prophet/trunk/lib/Prophet/Server/Controller.pm
   Prophet/trunk/lib/Prophet/Server/ViewHelpers.pm
   Prophet/trunk/lib/Prophet/Web/FunctionResult.pm

Log:
* work toward getting ticket create and edit working in sd


Modified: Prophet/trunk/lib/Prophet/App.pm
==============================================================================
--- Prophet/trunk/lib/Prophet/App.pm	(original)
+++ Prophet/trunk/lib/Prophet/App.pm	Thu Jan  8 14:46:19 2009
@@ -202,6 +202,12 @@
 
 =cut
 
+sub log_debug {
+    my $self = shift;
+    return unless ($ENV{'PROPHET_DEBUG'});
+    $self->log(@_);
+}
+
 sub log {
     my $self = shift;
     my ($msg) = validate_pos(@_, 1);

Modified: Prophet/trunk/lib/Prophet/Replica.pm
==============================================================================
--- Prophet/trunk/lib/Prophet/Replica.pm	(original)
+++ Prophet/trunk/lib/Prophet/Replica.pm	Thu Jan  8 14:46:19 2009
@@ -1089,8 +1089,7 @@
 sub log_debug { 
     my $self = shift;
     my $msg = shift;
-    return unless ($ENV{'PROPHET_DEBUG'});
-    $self->log($self->display_name_for_uuid." (".$self->scheme.":".$self->url." )".": " .$msg);
+    $self->app_handle->log_debug($self->display_name_for_uuid." (".$self->scheme.":".$self->url." )".": " .$msg);
 }
 
 =head2 log_fatal $MSG

Modified: Prophet/trunk/lib/Prophet/Server.pm
==============================================================================
--- Prophet/trunk/lib/Prophet/Server.pm	(original)
+++ Prophet/trunk/lib/Prophet/Server.pm	Thu Jan  8 14:46:19 2009
@@ -98,6 +98,7 @@
 sub handle_request {
     my ( $self, $cgi ) = validate_pos( @_, { isa => 'Prophet::Server' }, { isa => 'CGI' } );
     $self->cgi($cgi);
+    $self->app_handle->log( localtime()." [".$ENV{'REMOTE_ADDR'}."] ".$cgi->request_method . " ".$cgi->path_info);
     $self->nav( Prophet::Web::Menu->new( cgi => $self->cgi ) );
     $self->result( Prophet::Web::Result->new() );
     if ( $ENV{'PROPHET_DEVEL'} ) {

Modified: Prophet/trunk/lib/Prophet/Server/Controller.pm
==============================================================================
--- Prophet/trunk/lib/Prophet/Server/Controller.pm	(original)
+++ Prophet/trunk/lib/Prophet/Server/Controller.pm	Thu Jan  8 14:46:19 2009
@@ -28,7 +28,7 @@
     foreach my $param ( $self->cgi->all_parameters ) {
         next unless $param =~ /^prophet-function-(.*)$/;
         my $name = $1;
-        warn "Duplicate function definition for @{[$name]}." if ( exists $functions->{$name} );
+        $self->app_handle->log_fatal( "Duplicate function definition for @{[$name]}." ) if ( exists $functions->{$name} );
 
         my $function_data = $self->cgi->param($param);
         my $attr          = $self->string_to_hash($function_data);
@@ -46,7 +46,6 @@
         $functions->{$name} = $attr;
         $functions->{$name}->{params} = $self->params_for_function_from_cgi($name);
     }
-
     $self->functions($functions);
 }
 
@@ -60,8 +59,8 @@
             my $name = $1;
             $values->{$name} = {
                 prop           => $name,
-                value          => $self->cgi->param($field),
-                original_value => $self->cgi->param( "original-value-" . $field )
+                value          => ($self->cgi->param($field) || undef),
+                original_value => ($self->cgi->param( "original-value-" . $field ) || undef)
             };
         } elsif ( $field =~ /^prophet-fill-function-$function-prop-(.*)$/ ) {
             my $name  = $1;
@@ -92,15 +91,15 @@
        execute_functions    
     );
     eval {
-        $self->$_() for @workflow;
+        for (@workflow) { 
+        $self->$_() ;
+        }
     }; 
     
     if (my $err = $@) {
-        warn "This run failed - $err";
         $self->result->success(0);
         $self->result->message($err);   
     }
-
 }
 
 sub canonicalize_functions {
@@ -140,9 +139,9 @@
     my $functions = $self->functions;
 
     foreach my $function ( sort { $functions->{$a}->{order} <=> $functions->{$b}->{order}}  keys %{$functions}) {
+        $self->app_handle->log_debug("About to execute a function - ".$function);
         $self->_fill_params_from_previous_functions($function); 
 
-        $self->app_handle->log_debug("About to execute a function - ".$function);
 
         next unless ($functions->{$function}->{execute});
 
@@ -180,10 +179,11 @@
 
     my $functions = $self->functions;
         if ($functions->{$function}->{action} eq 'update') {
-            return Prophet::Util->instantiate_record( uuid => $function->{uuid}, class=>$function->{class}, app_handle=> $self->app_handle);
+
+            return Prophet::Util->instantiate_record( uuid => $functions->{$function}->{uuid}, class=>$functions->{$function}->{class}, app_handle=> $self->app_handle);
         } elsif ($functions->{$function}->{action} eq 'create') {
-                die $function->{class} ." is not a valid class " unless (UNIVERSAL::isa($function->{class}, 'Prophet::Record'));
-                return  $function->{class}->new(  app_handle => $self->app_handle);
+                die $functions->{$function}->{class} ." is not a valid class " unless (UNIVERSAL::isa($functions->{$function}->{class}, 'Prophet::Record'));
+                return  $functions->{$function}->{class}->new(  app_handle => $self->app_handle);
         } else {
             die "I don't know how to handle a ".$functions->{$function}->{action};
         }
@@ -195,29 +195,30 @@
     my $self = shift;
     my $function = shift;
 
-    my $object = $self->_get_record_for_function($function);
+    my $object = $self->_get_record_for_function($function->{name});
     my ( $val, $msg ) = $object->create(
         props => {
             map { $function->{params}->{$_}->{prop} => $function->{params}->{$_}->{value}
                 } keys %{ $function->{params} }
             }
 
-    );
+    ); 
 
     my $res = Prophet::Web::FunctionResult->new( function_name => $function->{name}, 
                                                  class => $function->{class},
                                                  success => $object->uuid? 1 :0,
                                                  record_uuid => $object->uuid,
                                                  msg => ($msg || 'Record created'));
-                                                
+                     
+
     $self->result->set($function->{name} => $res);
+
 }
 
 sub _exec_function_update {
     my $self = shift;
     my $function = shift;
-
-    my $object = $self->_get_record_for_function($function);
+    my $object = $self->_get_record_for_function($function->{name});
     my ( $val, $msg ) = $object->set_props(
         props => {
             map {

Modified: Prophet/trunk/lib/Prophet/Server/ViewHelpers.pm
==============================================================================
--- Prophet/trunk/lib/Prophet/Server/ViewHelpers.pm	(original)
+++ Prophet/trunk/lib/Prophet/Server/ViewHelpers.pm	Thu Jan  8 14:46:19 2009
@@ -7,10 +7,11 @@
 use Params::Validate qw/validate/;
 use Template::Declare::Tags;
 use Prophet::Web::Field;
-our @EXPORT = ( qw(form page content widget function param_from_function));
+our @EXPORT = ( qw(form page content widget function param_from_function hidden_param));
 use Prophet::Server::ViewHelpers::Widget;
 use Prophet::Server::ViewHelpers::Function;
 use Prophet::Server::ViewHelpers::ParamFromFunction;
+use Prophet::Server::ViewHelpers::HiddenParam;
 
 
 sub page (&;$) {
@@ -58,6 +59,11 @@
     return $w;
 }
 
+sub hidden_param {
+    my $w = Prophet::Server::ViewHelpers::HiddenParam->new(@_);
+    $w->render;
+    return $w;
+}
 sub widget {
     my $w = Prophet::Server::ViewHelpers::Widget->new(@_);
     $w->render;

Added: Prophet/trunk/lib/Prophet/Server/ViewHelpers/HiddenParam.pm
==============================================================================
--- (empty file)
+++ Prophet/trunk/lib/Prophet/Server/ViewHelpers/HiddenParam.pm	Thu Jan  8 14:46:19 2009
@@ -0,0 +1,44 @@
+package Prophet::Server::ViewHelpers::HiddenParam;
+
+use Template::Declare::Tags;
+
+BEGIN { delete ${__PACKAGE__."::"}{meta}; 
+ delete ${__PACKAGE__."::"}{with};
+}
+
+use Moose;
+
+extends 'Prophet::Server::ViewHelpers::Widget';
+
+
+use Moose::Util::TypeConstraints;
+
+
+has value => ( isa => 'Str', is => 'rw');
+
+
+sub render {
+    my $self = shift;
+
+    my $unique_name = $self->_generate_name();
+   
+    my $record = $self->function->record;
+
+    $self->field( Prophet::Web::Field->new(
+        name   => $unique_name,
+        id      => $unique_name,
+        record => $record,
+        class  => 'hidden-prop-'.$self->prop.' function-'.$self->function->name,
+        value  => $self->value,
+        type => 'hidden')
+        
+    );
+
+    outs_raw( $self->field->render_input );
+
+}
+__PACKAGE__->meta->make_immutable;
+no Moose;
+
+1;
+

Modified: Prophet/trunk/lib/Prophet/Web/FunctionResult.pm
==============================================================================
--- Prophet/trunk/lib/Prophet/Web/FunctionResult.pm	(original)
+++ Prophet/trunk/lib/Prophet/Web/FunctionResult.pm	Thu Jan  8 14:46:19 2009
@@ -15,7 +15,7 @@
 
 has class => ( isa => 'Str', is => 'rw');
 has function_name => ( isa => 'Str', is => 'rw');
-has record_uuid => (isa => 'Str', is => 'rw');
+has record_uuid => (isa => 'Maybe[Str]', is => 'rw');
 has success => (isa => 'Bool', is => 'rw');
 has message => (isa => 'Str', is => 'rw');
 



More information about the Bps-public-commit mailing list