save selected column in views and load them
authorDobrica Pavlinusic <dpavlin@rot13.org>
Thu, 1 Jul 2010 20:35:33 +0000 (22:35 +0200)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Thu, 1 Jul 2010 20:35:33 +0000 (22:35 +0200)
This allows easy switch between clusters (chunks) of columns
in similar scale for easy graphing

lib/MojoFacets/Data.pm
templates/data/columns.html.ep

index b0cc4fa..314e72e 100644 (file)
@@ -382,12 +382,30 @@ sub _export_path {
 sub columns {
     my $self = shift;
 
+       my $view_path = $self->_permanent_path( 'views' );
+
        if ( $self->param('columns') ) {
                my @columns = $self->_param_array('columns');
                write_file( $self->_permanent_path( 'columns' ), { binmode => ':utf8' }, map { "$_\n" } @columns );
+               if ( my $view = $self->param('view') ) {
+                       mkdir $view_path unless -e $view_path;
+                       write_file( "$view_path/$view", { binmode => ':utf8' }, map { "$_\n" } @columns );
+                       warn "view $view_path/$view ", -s "$view_path/$view", " bytes\n";
+               }
+
                $self->redirect_to('/data/items');
        }
 
+       if ( my $id = $self->param('id') ) {
+               my $view_full = "$view_path/$id";
+               if ( -f $view_full ) {
+                       my @columns = map { chomp; $_ } read_file $view_full, binmode => ':utf8';
+                       warn "view $view_full loaded ", dump @columns;
+                       $self->session( 'columns' => [ @columns ] );
+                       $self->redirect_to('/data/items');
+               }
+       }
+
        my $stats = $self->_loaded( 'stats' );
 
        my @columns;
@@ -397,11 +415,18 @@ sub columns {
                push @columns, $c unless grep { /^\Q$c\E$/ } @columns;
        }
 
+       my @views;
+       if ( -d $view_path ) {
+               @views = map { s{^\Q$view_path\E/*}{}; $_ } glob "$view_path/*";
+               warn "# views ",dump @views;
+       }
+
     $self->render(
                message => 'Select columns to display',
                stats => $stats,
                columns => \@columns,
                checked => $self->_checked( $self->_param_array('columns') ),
+               views => \@views,
        );
 }
 
index 0eb4e34..8c8c1e7 100644 (file)
@@ -17,6 +17,16 @@ $(document).ready(function() {
 </script>
 
 
+<div style="float:right">
+% if ( $views ) {
+Load view:
+<ul>
+%  foreach my $view ( @$views ) {
+<li><a href="/data/columns/<%= $view %>"><%= $view %></a>
+%  }
+</ul>
+% }
+</div>
 
 
 <h2>Select and reorder columns</h2>
@@ -46,7 +56,9 @@ $(document).ready(function() {
 
 <input type=submit value="Select">
 
-from <input type=text name=path value="<%= session('path') %>" readonly>
+<input type=hidden name=path value="<%= session('path') %>" readonly>
+
+<input type=text name=view placeholder="save view">
 
 <a href="<%= url_for( action => 'stats' ) %>">rebuild stats</a>