1 package MojoFacets::Changes;
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/changes/*' ) {
23 if ( $path =~ m{/((\d+\.\d+)\.data\.(.+))$} ) {
24 my ( $uid, $t, $action ) = ( $1, $2, $3 );
25 $actions->{$action}++;
26 next if $action_regex && $action !~ m/^($action_regex)$/;
27 push @$changes, { uid => $uid, t => $t, action => $action }
30 warn "ignore: $path\n";
34 # Render template "changes/index.html.ep" with message
35 $self->render(message => 'Latest Changes', changes => $changes, actions => $actions );
41 my $uid = $self->param('uid');
42 $self->render( change => retrieve( "/tmp/changes/$uid" ), uid => $uid );
47 my $path = $self->param('path') || $self->session('path');
48 $self->app->home->rel_dir('data') . '/' . $path . '.edits';
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";
63 my $glob = $self->_edit_path . '/*';
64 foreach my $t ( sort { $b cmp $a } glob $glob ) {
67 my ($pk,$id) = %{ $e->{unique} };
68 if ( ! defined $unique2id->{$pk} ) {
69 warn "unique2id $pk on ", $#$items + 1 ," items\n";
70 foreach my $i ( 0 .. $#$items ) {
71 $unique2id->{$pk}->{ $items->[$i]->{$pk}->[0] } = $i;
74 my $status = 'missing';
75 if ( my $i = $unique2id->{$pk}->{$id} ) {
77 $items->[$i]->{$pk} = $e->{new} if $commit;
79 $e->{_status} = $status;
85 my @loaded = MojoFacets::Data::__loaded_paths();
86 warn "# loaded paths ",dump @loaded;
88 $self->render( edits => $edits, loaded => \@loaded, stats => $stats );
94 if ( my $t = $self->param('remove') ) {
95 unlink $self->_edit_path . '/' . $t;
98 $self->redirect_to('/changes/edits');