[Bps-public-commit] r14959 - in Prophet/trunk: . lib/Prophet/Server

sartak at bestpractical.com sartak at bestpractical.com
Sat Aug 9 16:31:30 EDT 2008


Author: sartak
Date: Sat Aug  9 16:31:30 2008
New Revision: 14959

Modified:
   Prophet/trunk/   (props changed)
   Prophet/trunk/lib/Prophet/Record.pm
   Prophet/trunk/lib/Prophet/Server/View.pm

Log:
 r69033 at onn:  sartak | 2008-08-09 16:31:15 -0400
 Use REFERENCES in the html render to display linked records


Modified: Prophet/trunk/lib/Prophet/Record.pm
==============================================================================
--- Prophet/trunk/lib/Prophet/Record.pm	(original)
+++ Prophet/trunk/lib/Prophet/Record.pm	Sat Aug  9 16:31:30 2008
@@ -51,9 +51,13 @@
 );
 
 class_has REFERENCES => (
-    is      => 'rw',
-    isa     => 'HashRef',
-    default => sub { {} },
+    metaclass => 'Collection::Hash',
+    is        => 'rw',
+    isa       => 'HashRef',
+    default   => sub { {} },
+    provides  => {
+        keys => 'reference_methods',
+    },
     documentation => 'A hash of accessor_name => collection_class references.',
 );
 

Modified: Prophet/trunk/lib/Prophet/Server/View.pm
==============================================================================
--- Prophet/trunk/lib/Prophet/Server/View.pm	(original)
+++ Prophet/trunk/lib/Prophet/Server/View.pm	Sat Aug  9 16:31:30 2008
@@ -14,58 +14,70 @@
     }
 };
 
-template record_table => sub {
-    my $self = shift;
-    my $records = shift;
+sub record_table {
+    my %args = validate(@_, {
+        records    => 1,
+        url_prefix => { default => '' },
+    });
 
-    html {
-        body {
-            table {
-                my @items = $records ? $records->items : ();
-                if (@items) {
-                    my @headers = $items[0]->_parse_format_summary;
-                    row {
-                        for (@headers) {
-                            th { $_->{prop} }
-                        }
-                    }
+    my $records = $args{records};
+    my $prefix  = $args{url_prefix};
+
+    table {
+        my @items = $records ? $records->items : ();
+        if (@items) {
+            my @headers = $items[0]->_parse_format_summary;
+            row {
+                for (@headers) {
+                    th { $_->{prop} }
                 }
+            }
+        }
 
-                for my $record (sort { $a->luid <=> $b->luid } @items) {
-                    my $type = $record->type;
-                    my $uuid = $record->uuid;
-                    my @atoms = $record->format_summary;
-
-                    row {
-                        attr { id => "$type-$uuid", class => "$type" };
-
-                        for my $i (0 .. $#atoms) {
-                            my $atom = $atoms[$i];
-                            my $prop = $atom->{prop};
+        for my $record (sort { $a->luid <=> $b->luid } @items) {
+            my $type = $record->type;
+            my $uuid = $record->uuid;
+            my @atoms = $record->format_summary;
+
+            row {
+                attr { id => "$type-$uuid", class => "$type" };
+
+                for my $i (0 .. $#atoms) {
+                    my $atom = $atoms[$i];
+                    my $prop = $atom->{prop};
+
+                    cell {
+                        attr {
+                            class => "prop-$prop",
+                        };
 
-                            cell {
+                        if ($i == 0) {
+                            a {
                                 attr {
-                                    class => "prop-$prop",
+                                    href => "$prefix$uuid.html",
                                 };
-
-                                if ($i == 0) {
-                                    a {
-                                        attr {
-                                            href => "$uuid.html",
-                                        };
-                                        outs $atom->{value};
-                                    }
-                                }
-                                else {
-                                    outs $atom->{value};
-                                }
+                                outs $atom->{value};
                             }
                         }
+                        else {
+                            outs $atom->{value};
+                        }
                     }
                 }
             }
         }
     }
+}
+
+template record_table => sub {
+    my $self = shift;
+    my $records = shift;
+
+    html {
+        body {
+            record_table(records => $records);
+        }
+    }
 };
 
 template record => sub {
@@ -94,11 +106,29 @@
                     dt { $prop }
                     dd { $props->{$prop} }
                 }
-            }
+            };
+
             hr {}
             h3 { "History" };
 
             show record_changesets => $record;
+
+            # linked records
+            for my $method ($record->reference_methods) {
+                my $collection = $record->$method;
+                next if $collection->count == 0;
+
+                my $type = $collection->record_class->type;
+
+                hr {}
+                h3 { "Linked $type records" }
+
+                record_table(
+                    records    => $collection,
+                    url_prefix => "../$type/",
+                );
+            }
+
         }
     }
 };



More information about the Bps-public-commit mailing list