1 package MojoFacets::Actions;
6 use base 'Mojolicious::Controller';
9 use Data::Dump qw(dump);
15 my $max = $self->param('max') || 50;
16 my $action_regex = join('|', $self->param('action_filter'));
17 warn "# action_regex $action_regex\n";
22 foreach my $path ( sort { $b cmp $a } glob '/tmp/actions/*' ) {
23 if ( $path =~ m{/((\d+\.\d+)\.data\.(.+))$} ) {
24 my ( $uid, $t, $action ) = ( $1, $2, $3 );
26 next if $action_regex && $action !~ m/^($action_regex)$/;
27 push @$actions, { uid => $uid, t => $t, action => $action }
30 warn "ignore: $path\n";
34 # Render template "actions/index.html.ep" with message
35 $self->render(actions => $actions, stats => $stats );
41 my $uid = $self->param('uid');
42 $self->render( change => retrieve( "/tmp/actions/$uid" ), uid => $uid );
47 my $path = $self->param('path') || $self->session('path');
48 $self->app->home->rel_dir('data') . '/' . $path . '.changes';
53 my $path = $self->param('path') || $self->session('path');
54 my $commit = $self->param('commit');
55 my ( $items, $unique2id );
56 if ( my $apply_on_path = $self->param('apply_on_path') ) {
57 $items = $MojoFacets::Data::loaded->{$apply_on_path}->{data}->{items};
58 die "no $apply_on_path" unless $items;
59 warn "using $items for $apply_on_path\n";
61 my $invalidate_columns;
64 my $glob = $self->_changes_path . '/*';
65 foreach my $t ( sort { $a cmp $b } glob $glob ) {
67 $e->{old} = [ $e->{old} ] unless ref $e->{old} eq 'ARRAY';
69 die "no unique in ", dump($e) unless exists $e->{unique};
70 my ($pk,$id) = %{ $e->{unique} };
72 $e->{_status} = 'skip';
77 if ( ! defined $unique2id->{$pk} ) {
78 warn "unique2id $pk on ", $#$items + 1 ," items\n";
79 foreach my $i ( 0 .. $#$items ) {
80 $unique2id->{$pk}->{ $items->[$i]->{$pk}->[0] } = $i;
83 my $status = 'missing';
84 if ( my $i = $unique2id->{$pk}->{$id} ) {
87 my $column = $e->{column} or die "no column";
88 $items->[$i]->{$column} = $e->{new};
89 warn "# commit $i $column ",dump( $e->{new} );
90 $invalidate_columns->{$column}++;
93 $e->{_status} = $status;
99 foreach my $name ( keys %$invalidate_columns ) {
100 MojoFacets::Data::__invalidate_path_column( $path, $name );
103 MojoFacets::Data::__path_modified( $path );
105 my @loaded = MojoFacets::Data::__loaded_paths();
106 warn "# loaded paths ",dump @loaded;
108 $self->render( changes => $changes, loaded => \@loaded, stats => $stats );
114 if ( my $t = $self->param('time') ) {
115 unlink $self->_changes_path . '/' . $t;
118 $self->redirect_to('/actions/changes');