show all applicable code snippets
authorDobrica Pavlinusic <dpavlin@rot13.org>
Sat, 19 Jun 2010 13:30:02 +0000 (15:30 +0200)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Sat, 19 Jun 2010 13:30:02 +0000 (15:30 +0200)
This required us to check if current dataset (using columns) has all
applicable columns for given dataset

lib/MojoFacets/Code.pm
templates/code/index.html.ep

index 5b87a16..7388ca4 100644 (file)
@@ -12,6 +12,7 @@ sub index {
        my $self = shift;
 
        $self->redirect_to('/data/columns') unless $self->session('columns');
+       my $columns = { map { $_ => 1 } @{ $self->session('columns') } };
 
        my $dir = $self->app->home->rel_dir('public') . '/code';
 
@@ -21,8 +22,15 @@ sub index {
                my $path = $full_path;
                $path =~ s/^$dir\/*//;
                $path =~ s/\.pl$//;
-               my ( $column, $description ) = split(/\./,$path,2);
-               $snippets->{$column}->{$description} = read_file $full_path;
+               my ( $depends, $description ) = split(/\./,$path,2);
+
+               my @deps = split(/,/,$depends);
+               my $found = -1;
+               $found += $columns->{$_} foreach @deps;
+warn "# depends $depends $found $#deps\n";
+               next unless $found == $#deps;
+
+               $snippets->{$depends}->{$description} = read_file $full_path;
        }
 
        $self->render(
index 305b662..d2599b7 100644 (file)
@@ -1,21 +1,19 @@
 % layout 'default';
 
 <h1>Code snippets</h1>
-
-% foreach my $column ( @{ session('columns') } ) {
-%   next unless defined $snippets->{$column};
-<h2><%= $column %></h2>
+% foreach my $depends ( keys %$snippets ) {
+<h2><%= $depends %></h2>
 <ul>
-%   foreach my $desc ( keys %{ $snippets->{$column} } ) {
+%   foreach my $desc ( keys %{ $snippets->{$depends} } ) {
 <li>
 <form method=post action=/data/items>
 <input type=submit name=test value="Load and test">
-% my $path = "code/$column.$desc.pl";
+% my $path = "code/$depends.$desc.pl";
 <a target=code href="/<%= $path %>"><%= $desc %></a>
-<input name=code_depends value="<%= $column %>">
+<input name=code_depends value="<%= $depends %>">
 <input name=code_description value="<%= $desc %>">
 <br>
-% my $code = $snippets->{$column}->{$desc};
+% my $code = $snippets->{$depends}->{$desc};
 % my $rows = scalar split(/\n/,$code);
 <textarea name=code cols=80 rows=<%= $rows %> style="overflow:hidden">
 <%= $code %>