another $col_changed cleanup
authorDobrica Pavlinusic <dpavlin@rot13.org>
Sun, 20 Jun 2010 12:04:31 +0000 (14:04 +0200)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Sun, 20 Jun 2010 12:04:31 +0000 (14:04 +0200)
0 denotes used column (extracted from source using regex),
while positive numbers denote added columns.
This allow allow us to color used and created columns differently

lib/MojoFacets/Data.pm
public/mojo_facets.css
templates/data/items/table.html.ep

index 1382fe2..d74763f 100644 (file)
@@ -614,8 +614,7 @@ sub items {
                                $column =~ s/$1$//;
                        }
                        next if $column =~ m/\$/; # hide columns with vars in them
-                       next if grep { /$column/ } @columns;
-                       $cols_changed->{$column}++;
+                       $cols_changed->{$column} = 0;
                }
        }
 
@@ -694,14 +693,14 @@ sub items {
                                warn "EVAL ",dump($row);
                                $old->{$_}-- foreach keys %$row;
                                warn "columns changed ",dump($old);
-                               $cols_changed->{$_} += 2 foreach grep { $old->{$_} == -1 } keys %$old;
+                               $cols_changed->{$_}++ foreach grep { $old->{$_} == -1 } keys %$old;
                        }
                }
                $row->{_row_id} ||= $id;
                push @$sorted_items, $row;
        }
 
-       my @added_columns = sort grep { $cols_changed->{$_} > 1 } keys %$cols_changed;
+       my @added_columns = sort grep { $cols_changed->{$_} > 0 } keys %$cols_changed;
        unshift @columns, @added_columns;
 
        if ( $commit ) {
@@ -712,7 +711,7 @@ sub items {
        warn "# sorted_items ", $#$sorted_items + 1, " offset $offset limit $limit order $sort";
 
        my $code_depends = $self->param('code_depends')||
-       join(',', sort grep { $cols_changed->{$_} == 1 } keys %$cols_changed );
+       join(',', sort grep { $cols_changed->{$_} == 0 } keys %$cols_changed );
        my $code_description = $self->param('code_description') ||
        join(',', @added_columns);
 
index d57d687..f667e13 100644 (file)
@@ -150,6 +150,10 @@ span.d {
        background: #ffe;
 }
 
+.used {
+       background: #eee;
+}
+
 form.action_filter {
        float: right;
 }
index f3866e5..eb18192 100644 (file)
@@ -1,10 +1,11 @@
+<pre class=debug><%= dumper $cols_changed %></pre>
 <table border=1>
 
 <tr>
 % my $commit = param('commit');
 % foreach my $n ( @$columns ) {
-% if ( $cols_changed->{$n} > 1 && ! $commit ) {
-<th class=changed>
+% if ( defined $cols_changed->{$n} && ! $commit ) {
+<th class=<%= $cols_changed->{$n} ? 'changed' : 'used' %>>
 <%= $n %>
 % } else {
 <th>
@@ -36,11 +37,12 @@ filter
 % foreach my $row ( @$sorted ) {
 <tr title="<%= $row->{_row_id} %>">
 % foreach my $col ( @$columns ) {
-%  my $class = '';
-%  $class .= ' numeric' if $numeric->{$col};
-%  $class .= ' changed' if $cols_changed->{$col};
-%  $class =~ s/^ / class="/ && $class =~ s/$/"/;
-<td<%== $class %>>
+%  my @class ;
+%  push @class, 'numeric' if $numeric->{$col};
+%  if ( defined $cols_changed->{$col} ) {
+%   push @class, $cols_changed->{$col} ? 'changed' : 'used';
+%  }
+<td class="<%= join(' ',@class) %>">
 %  if ( ref $row->{$col} eq 'ARRAY' ) {
 %   my $last = $#{ $row->{$col} };
 %   foreach ( 0 .. $last ) {