rename edits to changes
authorDobrica Pavlinusic <dpavlin@rot13.org>
Sat, 5 Jun 2010 17:38:51 +0000 (19:38 +0200)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Sat, 5 Jun 2010 17:41:50 +0000 (19:41 +0200)
lib/MojoFacets/Actions.pm
lib/MojoFacets/Data.pm
script/actions-to-changes [new file with mode: 0755]
script/changes [deleted file]
templates/actions/changes.html.ep [new file with mode: 0644]
templates/actions/edits.html.ep [deleted file]
templates/admin.html.ep
templates/data/index.html.ep

index e33310e..b1ff1e4 100644 (file)
@@ -42,13 +42,13 @@ sub view {
        $self->render( change => retrieve( "/tmp/actions/$uid" ), uid => $uid );
 }
 
-sub _edit_path {
+sub _changes_path {
        my $self = shift;
        my $path = $self->param('path') || $self->session('path');
-       $self->app->home->rel_dir('data') . '/' . $path . '.edits';
+       $self->app->home->rel_dir('data') . '/' . $path . '.changes';
 }
 
-sub edits {
+sub changes {
        my ( $self ) = @_;
        my $path = $self->param('path') || $self->session('path');
        my $commit = $self->param('commit');
@@ -58,9 +58,9 @@ sub edits {
                die "no $apply_on_path" unless $items;
                warn "using $items for $apply_on_path\n";
        }
-       my $edits;
+       my $changes;
        my $stats;
-       my $glob = $self->_edit_path . '/*';
+       my $glob = $self->_changes_path . '/*';
        foreach my $t ( sort { $a cmp $b } glob $glob ) {
                my $e = retrieve($t);
                if ( $items ) {
@@ -84,23 +84,23 @@ sub edits {
                        $e->{_status} = $status;
                        $stats->{$status}++;
                }
-               push @$edits, $e;
+               push @$changes, $e;
        }
 
        my @loaded = MojoFacets::Data::__loaded_paths();
        warn "# loaded paths ",dump @loaded;
 
-       $self->render( edits => $edits, loaded => \@loaded, stats => $stats );
+       $self->render( changes => $changes, loaded => \@loaded, stats => $stats );
 }
 
-sub edit {
+sub remove {
        my $self = shift;
 
-       if ( my $t = $self->param('remove') ) {
-               unlink $self->_edit_path . '/' . $t;
+       if ( my $t = $self->param('time') ) {
+               unlink $self->_changes_path . '/' . $t;
        }
 
-       $self->redirect_to('/actions/edits');
+       $self->redirect_to('/actions/changes');
 }
 
 1;
index 1a08e3c..fd30c1b 100644 (file)
@@ -26,14 +26,14 @@ sub index {
        die "no data dir $data_dir" unless -d $data_dir;
 
        my @files;
-       my $edits;
+       my $changes;
        find( sub {
                my $file = $File::Find::name;
                if ( -f $file && $file =~ m/\.(js(on)?|txt)$/ ) {
                        $file =~ s/$data_dir\/*//;
                        push @files, $file;
-               } elsif ( -f $file && $file =~ m/([^\/]+)\.edits\/(\d+\.\d+.+)/ ) {
-                       push @{ $edits->{$1} }, $2
+               } elsif ( -f $file && $file =~ m/([^\/]+)\.changes\/(\d+\.\d+.+)/ ) {
+                       push @{ $changes->{$1} }, $2
                } elsif ( -d $file && $file =~ m/\.html$/ ) {
                        $file =~ s/$data_dir\/*//;
                        push @files, $file;
@@ -52,7 +52,7 @@ sub index {
                loaded => $loaded,
                filters => $filters,
                dump_path => { map { $_ => $self->_dump_path($_) } @files },
-               edits => $edits,
+               changes => $changes,
        );
 }
 
@@ -752,7 +752,7 @@ sub edit {
                if ( $old ne $new
                        && ! ( $old eq 'undef' && length($new_content) == 0 ) # new value empty, previous undef
                ) {
-                       my $edit = {
+                       my $change = {
                                path => $path,
                                column => $name,
                                pos => $i,
@@ -766,14 +766,14 @@ sub edit {
                                        keys %{ $loaded->{$path}->{stats} }
                                },
                        };
-                       my $edit_path = $self->_permanent_path( 'edits' );
-                       mkdir $edit_path unless -d $edit_path;
-                       $edit_path .= '/' . $edit->{time};
-                       store $edit, $edit_path;
-                       utime $edit->{time}, $edit->{time}, $edit_path;
-                       warn "# $edit_path ", dump($edit);
-
-                       warn "# edit $path $i $old -> $new\n";
+                       my $change_path = $self->_permanent_path( 'changes' );
+                       mkdir $change_path unless -d $change_path;
+                       $change_path .= '/' . $change->{time};
+                       store $change, $change_path;
+                       utime $change->{time}, $change->{time}, $change_path;
+                       warn "# $change_path ", dump($change);
+
+                       warn "# change $path $i $old -> $new\n";
                        $loaded->{$path}->{data}->{items}->[$i]->{$name} = $v;
 
                        if ( defined $loaded->{$path}->{sorted}->{$name} ) {
diff --git a/script/actions-to-changes b/script/actions-to-changes
new file mode 100755 (executable)
index 0000000..ca31147
--- /dev/null
@@ -0,0 +1,36 @@
+#!/usr/bin/env perl
+
+use strict;
+use warnings;
+
+use Storable;
+use Mojo::Client;
+use Data::Dump qw(dump);
+
+my $url = 'http://localhost:3000/data/edit';
+my $max = 1;
+
+my @changes = @ARGV;
+
+my $t = Mojo::Client->new;
+$t->max_redirects( 1 );
+
+foreach my $c ( @changes ) {
+
+       print "# $c\n";
+
+       my $params = retrieve $c;
+       my $hash = $params->to_hash;
+       $hash->{time} = $1 if $c =~ m{/(\d+\.\d+)\.data\.edit};
+
+       warn "# hash ",dump($hash);
+
+       my $tx = $t->post_form( $url => $hash );
+       if ( my $res = $tx->success) { print $res->body }
+       else {
+               my ($code, $message) = $tx->error;
+               die "Error: $message";
+       }
+
+#      last if $max-- == 0;
+}
diff --git a/script/changes b/script/changes
deleted file mode 100755 (executable)
index ca31147..0000000
+++ /dev/null
@@ -1,36 +0,0 @@
-#!/usr/bin/env perl
-
-use strict;
-use warnings;
-
-use Storable;
-use Mojo::Client;
-use Data::Dump qw(dump);
-
-my $url = 'http://localhost:3000/data/edit';
-my $max = 1;
-
-my @changes = @ARGV;
-
-my $t = Mojo::Client->new;
-$t->max_redirects( 1 );
-
-foreach my $c ( @changes ) {
-
-       print "# $c\n";
-
-       my $params = retrieve $c;
-       my $hash = $params->to_hash;
-       $hash->{time} = $1 if $c =~ m{/(\d+\.\d+)\.data\.edit};
-
-       warn "# hash ",dump($hash);
-
-       my $tx = $t->post_form( $url => $hash );
-       if ( my $res = $tx->success) { print $res->body }
-       else {
-               my ($code, $message) = $tx->error;
-               die "Error: $message";
-       }
-
-#      last if $max-- == 0;
-}
diff --git a/templates/actions/changes.html.ep b/templates/actions/changes.html.ep
new file mode 100644 (file)
index 0000000..cb5f9a8
--- /dev/null
@@ -0,0 +1,75 @@
+% layout 'ui';
+
+
+% my $dump = param('dump');
+% my $apply_on_path = param('apply_on_path');
+
+<form method=post>
+<input type=submit value="Apply"> on
+<select name=apply_on_path>
+% foreach my $p ( @$loaded ) {
+<option<%= $p eq $apply_on_path ? ' selected' : '' %>><%= $p %></option>
+% }
+</select>
+<label><input type=checkbox name=dump <%= $dump ? 'checked' : '' %>>dump</label>
+
+% if ( $apply_on_path ) {
+<ul id=status>
+%  foreach my $status ( keys %$stats ) {
+<li><label>
+<input name=show type=checkbox value="<%= $status %>" checked>
+<%= $status %>
+<span class=count><%= $stats->{$status} %></span>
+</label>
+%  }
+</ul>
+
+<input type=submit name=commit value="Commit changes">
+
+% }
+
+</form>
+
+<table>
+<tr><th></th><th>old</th><th>new</th></tr>
+
+% foreach my $e ( @$changes ) {
+<tr class="change <%= $e->{_status} || 'unknown' %>">
+<td>
+<%= $e->{time} %>
+<tt><%= $e->{column} %></tt>
+%  if ( my $status = $e->{_status} ) {
+%    my ( $pk, $id ) = %{ $e->{unique} };
+<a href="<%= url_for( controller => 'data', action => 'filter' )->query( filter_name => $pk, filter_vals => $id ) %>"><%= $id %></a>
+<%= $status %>
+%  } else {
+<a href="<%= url_for( action => 'remove' )->query( time => $e->{time} ) %>">remove</a>
+%  }
+
+</td><td><%== defined $e->{old} && join('<span class=d>&para;</span>', @{$e->{old}}) %>
+</td><td><%== defined $e->{new} && join('<span class=d>&para;</span>', @{$e->{new}}) %>
+
+%  if ( $dump ) {
+</td><td><pre class=debug><%= dumper $e %></pre>
+%  }
+</tr>
+% }
+
+</table>
+
+<pre class=debug>
+<%= dumper( $stats ) %>
+</pre>
+
+<script type="text/javascript">
+
+$(document).ready( function(){
+       console.debug('ready');
+       $('ul#status > li input[type=checkbox]').click( function(){
+               var toggle = this.value;
+               console.debug('click',this,toggle);
+               $('tr.'+toggle).toggleClass('hidden');
+       });
+});
+
+</script>
diff --git a/templates/actions/edits.html.ep b/templates/actions/edits.html.ep
deleted file mode 100644 (file)
index 953b989..0000000
+++ /dev/null
@@ -1,75 +0,0 @@
-% layout 'ui';
-
-
-% my $dump = param('dump');
-% my $apply_on_path = param('apply_on_path');
-
-<form method=post>
-<input type=submit value="Apply"> on
-<select name=apply_on_path>
-% foreach my $p ( @$loaded ) {
-<option<%= $p eq $apply_on_path ? ' selected' : '' %>><%= $p %></option>
-% }
-</select>
-<label><input type=checkbox name=dump <%= $dump ? 'checked' : '' %>>dump</label>
-
-% if ( $apply_on_path ) {
-<ul id=status>
-%  foreach my $status ( keys %$stats ) {
-<li><label>
-<input name=show type=checkbox value="<%= $status %>" checked>
-<%= $status %>
-<span class=count><%= $stats->{$status} %></span>
-</label>
-%  }
-</ul>
-
-<input type=submit name=commit value="Commit changes">
-
-% }
-
-</form>
-
-<table>
-<tr><th></th><th>old</th><th>new</th></tr>
-
-% foreach my $e ( @$edits ) {
-<tr class="edit <%= $e->{_status} || 'unknown' %>">
-<td>
-<%= $e->{time} %>
-<tt><%= $e->{column} %></tt>
-%  if ( my $status = $e->{_status} ) {
-%    my ( $pk, $id ) = %{ $e->{unique} };
-<a href="<%= url_for( controller => 'data', action => 'filter' )->query( filter_name => $pk, filter_vals => $id ) %>"><%= $id %></a>
-<%= $status %>
-%  } else {
-<a href="<%= url_for( action => 'edit' )->query( remove => $e->{time} ) %>">remove</a>
-%  }
-
-</td><td><%== defined $e->{old} && join('<span class=d>&para;</span>', @{$e->{old}}) %>
-</td><td><%== defined $e->{new} && join('<span class=d>&para;</span>', @{$e->{new}}) %>
-
-%  if ( $dump ) {
-</td><td><pre class=debug><%= dumper $e %></pre>
-%  }
-</tr>
-% }
-
-</table>
-
-<pre class=debug>
-<%= dumper( $stats ) %>
-</pre>
-
-<script type="text/javascript">
-
-$(document).ready( function(){
-       console.debug('ready');
-       $('ul#status > li input[type=checkbox]').click( function(){
-               var toggle = this.value;
-               console.debug('click',this,toggle);
-               $('tr.'+toggle).toggleClass('hidden');
-       });
-});
-
-</script>
index b3865c4..b0aea4c 100644 (file)
@@ -18,7 +18,7 @@ items:
 % if ( $self->can('_export_path') && glob $self->_export_path('*') ) {
 <a href="<%= url_for( controller => 'data', action => 'export' ) %>">export</a>
 % }
-<a href="<%= url_for( controller => 'actions', action => 'edits' ) %>">edits</a>
+<a href="<%= url_for( controller => 'actions', action => 'changes' ) %>">changes</a>
 <a href="<%= url_for( controller => 'actions', action => 'index' ) %>">actions</a>
 </span>
 
index 3406459..150d335 100644 (file)
@@ -8,7 +8,7 @@
 <input type=submit value="Load">
 
 <table>
-<tr><th rowspan=2>name</th><th colspan=2>size</th><th rowspan=2>items</th><th rowspan=2>edits</th><th rowspan=2 title="loaded in memory">m</th><th colspan=2>columns</th></tr>
+<tr><th rowspan=2>name</th><th colspan=2>size</th><th rowspan=2>items</th><th rowspan=2>changes</th><th rowspan=2 title="loaded in memory">m</th><th colspan=2>columns</th></tr>
 <tr><th>disk</th><th>storable</th></tr>
 % foreach my $n ( @$files ) {
 <tr><td>
@@ -19,7 +19,7 @@
 </td><td class=bytes><%= $size->{$n} %>
 </td><td class=bytes><%= -s $dump_path->{$n} %>
 </td><td align=right><%= defined $loaded->{$n}->{data} ? $#{ $loaded->{$n}->{data}->{items} } + 1 : '' %>
-</td><td align=right><%= defined $edits->{$n} ? $#{ $edits->{$n} } + 1 : '' %>
+</td><td align=right><%= defined $changes->{$n} ? $#{ $changes->{$n} } + 1 : '' %>
 </td><td><input name=paths type=checkbox value="<%= $n %>" <%= defined $loaded->{$n}->{stats} ? 'checked' : '' %>>
 </td><td>
 %  if ( defined $loaded->{$n}->{columns} ) {
@@ -36,7 +36,7 @@
 
 </form>
 
-<pre class=debug><%= dumper $edits %></pre>
+<pre class=debug><%= dumper $changes %></pre>
 <pre class=debug><%= dumper $loaded %></pre>
 <pre class=debug><%= dumper $filters %></pre>
 <pre class=debug><%= dumper $dump_path %></pre>