don't redirect to index if we didn't change current dataset
[MojoFacets.git] / lib / MojoFacets / Data.pm
index ceb0d8e..d5a7284 100644 (file)
@@ -13,7 +13,7 @@ use File::Find;
 use Storable;
 use Time::HiRes qw(time);
 use File::Path qw(mkpath);
-use Text::Unaccent::PurePerl;
+use Text::Unaccent;
 use Digest::MD5;
 use Statistics::Descriptive;
 
@@ -267,8 +267,6 @@ sub _load_path {
 sub load {
        my $self = shift;
 
-       my $path = $self->param('path') || return $self->redirect_to( '/data/index' );
-
        my @paths = $self->param('paths');
        warn "# paths ", dump @paths;
 
@@ -280,6 +278,8 @@ sub load {
 
        $self->_load_path( $_ ) foreach @paths;
 
+       my $path = $self->param('path') || $self->session('path') || @paths[0] || $self->redirect_to('/data/index');
+
        warn "# path $path\n";
        $self->_load_path( $path );
 
@@ -364,7 +364,7 @@ sub _permanent_path {
 
 sub __unac {
        my $n = shift;
-       $n = unac_string($n);
+       $n = unac_string('utf-8',$n);
        $n =~ s/\W+/_/g;
        return $n;
 }
@@ -491,8 +491,11 @@ sub _param_scalar {
 
        if ( ! defined $scalar ) {
                $scalar = $default;
-               die "no default for $name" unless defined $scalar;
-               $self->session($name => $scalar);
+               if ( defined $scalar ) {
+                       $self->session($name => $scalar);
+               } else {
+                       warn "no default for $name";
+               }
        }
 
        warn "# _param_scalar $name ",dump $scalar;
@@ -813,6 +816,9 @@ sub items {
        $code =~ s{\r}{}gs;
        $code =~ s{\n+$}{\n}s;
 
+       # XXX convert @row->{foo} into @{$row->{foo}}
+       $code =~ s|\@(row->{[^}]+})|\@{\$$1}|gs;
+
        my $commit = $self->param('commit');
        my $test = $self->param('test');
 
@@ -834,6 +840,8 @@ sub items {
        my $code_path = $self->app->home->rel_dir('public') . "/code";
        if ( $commit ) {
 
+               __path_modified( $path, 'commit' );
+
                warn "# commit on ", $#$filtered + 1, " items:\n$code\n";
                ( $key, $value, $out ) = ( 'key', 'value' );
                foreach ( 0 .. $#$filtered ) {
@@ -1329,6 +1337,14 @@ sub __loaded_paths {
                keys %$loaded;
 }
 
+sub reload {
+       my $self = shift;
+       $self->stash( reload => 1 );
+       $self->remove;
+#      $self->_load_path( $self->param('path') );
+       $self->redirect_to('/data/load?path=' . $self->param('path') );
+}
+
 sub remove {
        my $self = shift;
        my $path = $self->param('path');
@@ -1342,6 +1358,7 @@ sub remove {
        } else {
                warn "WARNING: $path unlink ignored";
        }
+       return if $self->stash('reload');
        return $self->redirect_to( '/data/load' );
 }