mark all columns used in code
authorDobrica Pavlinusic <dpavlin@rot13.org>
Fri, 18 Jun 2010 15:54:00 +0000 (17:54 +0200)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Fri, 18 Jun 2010 15:56:01 +0000 (17:56 +0200)
lib/MojoFacets/Data.pm
templates/data/items/table.html.ep

index 62b03e1..32f532e 100644 (file)
@@ -619,7 +619,7 @@ sub items {
        my $commit = $self->param('commit');
        my $test = $self->param('test');
 
-       my $cols_added;
+       my $cols_changed;
 
        if ( $code && ( $test || $commit ) ) {
                # XXX find columns used in code snippet and show them to user
@@ -627,9 +627,10 @@ sub items {
                        if ( $column =~ s/^(['"])// ) {
                                $column =~ s/$1$//;
                        }
+                       $cols_changed->{$column}++;
                        next if grep { /$column/ } @columns;
+                       $cols_changed->{$column}++;
                        unshift @columns, $column;
-                       $cols_added->{$column}++;
                        if ( $commit ) {
                                $self->session('columns', [ @columns ]);
                                $loaded->{$path}->{columns} = [ @columns ];
@@ -682,7 +683,7 @@ sub items {
                numeric => { map { $_, $self->_is_numeric($_) } @columns },
                filters => $self->_current_filters,
                code => $code,
-               cols_added => $cols_added,
+               cols_changed => $cols_changed,
        );
 
 }
index a71db30..24159c3 100644 (file)
@@ -1,9 +1,12 @@
-<pre class=debug><%= dumper $cols_added %></pre>
-
 <table border=1>
 
 <tr>
+% my $commit = param('commit');
 % foreach my $n ( @$columns ) {
+% if ( $cols_changed->{$n} == 2 && ! $commit ) {
+<th class=changed>
+<%= $n %>
+% } else {
 <th>
 % if ( session('order') ne $n ) {
 <a href="<%= url_for( action => 'order' )->query( order => $n, sort => 'a' ) %>"><%= $n %></a>
@@ -21,6 +24,8 @@ filter
 % }
 </a>
 </div>
+
+% }
 </th>
 % }
 </tr>
@@ -28,7 +33,11 @@ filter
 % foreach my $row ( @$sorted ) {
 <tr title="<%= $row->{_row_id} %>">
 % foreach my $col ( @$columns ) {
-<td<%= $numeric->{$col} ? ' class=numeric' : $cols_added->{$col} ? ' class=changed' : '' %>>
+%  my $class = '';
+%  $class .= ' numeric' if $numeric->{$col};
+%  $class .= ' changed' if $cols_changed->{$col};
+%  $class =~ s/^ / class="/ && $class =~ s/$/"/;
+<td<%== $class %>>
 %  if ( ref $row->{$col} eq 'ARRAY' ) {
 %   my $last = $#{ $row->{$col} };
 %   foreach ( 0 .. $last ) {
@@ -88,3 +97,4 @@ $(document).ready( function(){
 
 <script type="text/javascript" src="/edit_table.js"></script>
 
+%#<pre class=debug><%= dumper $cols_changed %></pre>