}
if ( $unique ) {
$stats->{$n}->{unique} = 1;
- warn "# $n unique ",dump( $unique );
+ #warn "# $n unique ",dump( $unique );
}
}
}
$self->_load_path( $path );
$self->session( 'path' => $path );
- $self->session( 'modified' => $loaded->{$path}->{modified} );
my $redirect_to = '/data/items';
my $path = $self->session('path') || $self->param('path');
$self->redirect_to('/data/index') unless $path;
- if ( $loaded->{$path}->{modified} > 1 ) {
- warn "rebuild stats for $path forced by modified\n";
- $loaded->{$path}->{stats} = __stats( $loaded->{$path}->{data}->{items} );
- $loaded->{$path}->{modified} = 1;
+ if ( defined $loaded->{$path}->{modified} && $loaded->{$path}->{modified} > 1 ) {
+ my $caller = (caller(1))[3];
+ if ( $caller =~ m/::edit/ ) {
+ warn "rebuild stats for $path ignored caller $caller\n";
+ } else {
+ warn "rebuild stats for $path FORCED by modified caller $caller\n";
+ $loaded->{$path}->{stats} = __stats( $loaded->{$path}->{data}->{items} );
+ $loaded->{$path}->{modified} = 1;
+ }
}
if ( ! defined $loaded->{$path}->{$name} ) {
warn "$path $name isn't loaded\n";
$self->_load_path( $path );
- $self->redirect_to('/data/index')
- unless defined $loaded->{$path}->{$name};
if ( ! defined $loaded->{$path}->{stats} ) {
warn "rebuild stats for $path\n";
$loaded->{$path}->{stats} = __stats( $loaded->{$path}->{data}->{items} );
}
+ if ( ! defined $loaded->{$path}->{$name} ) {
+ warn "MISSING $name for $path\n";
+ $self->redirect_to('/data/index')
+ }
}
+
+ $self->session( 'modified' => $loaded->{$path}->{modified} );
+
return $loaded->{$path}->{$name};
}
sub items {
my $self = shift;
+ if ( my $show = $self->param('id') ) {
+ $self->param('show', $show);
+ warn "show $show\n";
+ }
+
my $path = $self->session('path');
- $self->redirect_to('/data/index') unless defined $loaded->{ $path };
my @columns = $self->_param_array('columns');
$self->redirect_to('/data/columns') unless @columns;
);
}
+
+sub __invalidate_path_column {
+ my ( $path, $name ) = @_;
+
+ if ( defined $loaded->{$path}->{sorted}->{$name} ) {
+ delete $loaded->{$path}->{sorted}->{$name};
+ warn "# invalidate $path sorted $name\n";
+ }
+
+ foreach ( grep { m/$name/ } keys %{ $loaded->{$path}->{filtered} } ) {
+ delete $loaded->{$path}->{filtered}->{$_};
+ warn "# invalidate $path filtered $_\n";
+ }
+}
+
+sub __path_modified {
+ my ( $path, $value ) = @_;
+ $value = 1 unless defined $value;
+
+ $loaded->{$path}->{modified} = $value;
+
+ warn "# __path_modified $path $value\n";
+}
+
sub edit {
my $self = shift;
my $new_content = $self->param('new_content');
warn "# change $path $i $old -> $new\n";
$loaded->{$path}->{data}->{items}->[$i]->{$name} = $v;
- if ( defined $loaded->{$path}->{sorted}->{$name} ) {
- delete $loaded->{$path}->{sorted}->{$name};
- warn "# invalidate $path sorted $name\n";
- }
-
- foreach ( grep { m/$name/ } keys %{ $loaded->{$path}->{filtered} } ) {
- delete $loaded->{$path}->{filtered}->{$_};
- warn "# invalidate $path filtered $_\n";
- }
+ __invalidate_path_column( $path, $name );
$status = 201; # created
# modified = 2 -- force rebuild of stats
- $loaded->{$path}->{modified} = 2;
- $self->session( 'modified' => 2 );
+ __path_modified( $path, 2 );
$new_content = join("\xB6",@$v);
my $self = shift;
my $path = $self->_param_or_session('path');
my $dump_path = $self->_save( $path );
- $loaded->{$path}->{modified} = 0;
- $self->session( 'modified' => 0 );
+ __path_modified( $path, 0 );
$self->redirect_to( '/data/items' );
}