use MojoFacets::Import::File;
use MojoFacets::Import::HTMLTable;
+use MojoFacets::Import::CSV;
our $loaded;
our $filters;
} elsif ( -d $file && $file =~ m/\.html$/ ) {
$file =~ s/$data_dir\/*//;
push @files, $file;
+ } elsif ( -f $file && $file =~ m/\.csv$/i ) {
+ $file =~ s/$data_dir\/*//;
+ push @files, $file;
} else {
#warn "IGNORE: $file\n";
}
return if defined $loaded->{$path}->{'generated'};
my $full_path = $self->app->home->rel_file( 'data/' . $path );
- die "$full_path $!" unless -r $full_path;
+ $self->redirect_to('/data/index') unless -r $full_path;
my $dump_path = $self->_dump_path( $path );
my $data;
if ( -f $full_path ) {
- $data = MojoFacets::Import::File->new( full_path => $full_path, path => $path )->data;
+ if ( $full_path =~ m/.csv/i ) {
+ $data = MojoFacets::Import::CSV->new( full_path => $full_path )->data;
+ } else {
+ $data = MojoFacets::Import::File->new( full_path => $full_path, path => $path )->data;
+ }
} elsif ( -d $full_path && $full_path =~ m/.html/ ) {
$data = MojoFacets::Import::HTMLTable->new( dir => $full_path )->data;
} else {
$self->session('columns', [ @columns ]);
$self->session('order', $key);
$self->redirect_to('/data/items');
+ return; # FIXME needed to correctly show columns
}
# this might move before $out to recalculate stats on source dataset?
$i = $from_end - $i if $from_end;
my $id = $filtered->[$i];
my $row = Storable::dclone $data->{items}->[ $id ];
- my $old = { map { $_ => 1 } keys %$row };
if ( $code && $test ) {
+ my $update;
eval $code;
if ( $@ ) {
warn "ERROR evaling\n$code\n$@";
$self->stash('eval_error', $@) if $@;
} else {
- warn "EVAL ",dump($row);
- $old->{$_}-- foreach keys %$row;
- warn "columns changed ",dump($old);
- $cols_changed->{$_}++ foreach grep { $old->{$_} == -1 } keys %$old;
+ warn "EVAL ",dump($update);
+ foreach ( keys %$update ) {
+ $cols_changed->{$_}++;
+ $row->{$_} = $update->{$_};
+ }
}
}
$row->{_row_id} ||= $id;