--- trunk/lib/Frey/SVK.pm 2008/11/28 16:53:12 594 +++ trunk/lib/Frey/SVK.pm 2008/12/02 22:05:25 690 @@ -3,14 +3,24 @@ extends 'Frey'; with 'Frey::Web'; +with 'Frey::Path'; -has commit_path => ( - documentation => 'path to commit', +use Moose::Util::TypeConstraints; + +enum 'SVK_Action' => ( 'commit', 'revert', 'postpone' ); + +has action => ( is => 'rw', - isa => 'Str', + isa => 'SVK_Action', +); + +has path => ( + documentation => 'path to work with', + is => 'rw', + isa => 'Str|ArrayRef', ); -has message => ( +has commit_message => ( documentation => 'commit message', is => 'rw', isa => 'Str', @@ -54,14 +64,44 @@ } } -sub status_as_markup { +sub checkbox { + my ($self,$name,$value) = @_; + my $checked = ''; + my $all_checkboxes = $self->$name; + $all_checkboxes = [ $all_checkboxes ] unless ref($all_checkboxes) eq 'ARRAY'; # sigh, too chatty + $checked = ' checked' if grep { $_ eq $value } @$all_checkboxes; + warn "# checkbox $name $value $checked\t", $self->dump( $self->$name ); + qq||; +} + +sub commit_as_markup { my ($self) = @_; my $status = `svk status -q`; - $status =~ s{^(\w+\s+)(\S+)$}{$1$2}gm; - $self->add_css( qq| pre.l a { text-decoration: none; } | ); - $status = qq|
$status
|; - $self->add_status( $status ); - warn "status_as_markup ",length($status)," bytes"; + $status =~ s{^(\w+[\+\s]+)(\S+)$}{$1 . $self->checkbox('path',$2) . qq|$2|}egm; + if ( $status ) { + $self->add_css(qq| + pre.l a { text-decoration: none; } + form.commit { + background: #eee; + padding: 1em 1em; + position: fixed; + top: 1em; + right: 1em; + z-index: 10; + } + | ); + + + $status = qq| +
+
$status
+ +
+
+ |; + $self->add_status( status => $status ); + warn "commit_as_markup ",length($status)," bytes"; + } return $status; } @@ -69,33 +109,76 @@ my ($self) = @_; my $diff = `svk diff`; + $self->add_status( diff => $diff ); $diff = $self->html_escape( $diff ); $self->add_css( qq| pre span.add { background: #dfd } pre span.del { background: #fdd } + pre form.inline { display: inline } | ); $diff =~ s{^(\+.+?)$}{$1}gm; $diff =~ s{^(\-.+?)$}{$1}gm; - $diff =~ s{^(===\s+)(\S+)$}{$1$2}gm; + sub form { + my ( $path, $action ) = @_; + qq|
|; + }; + $diff =~ s{^(===\s+)(\S+)$}{$1 . form($2,'revert') . qq| $2 | . form($2,'postpone') }gem; $diff = qq|
$diff
|; warn "diff_as_markup ",length($diff)," bytes"; return $diff; } -sub as_markup { +sub action_as_markup { my ($self) = @_; - if ( ! $self->can('html_escape') ) { - Frey::Web->meta->apply( $self ); - $self->TODO( "Frey::Web role missing" ); + my $cmd; + + if ( $self->action eq 'postpone' ) { + my $old = $self->path; + my $new = $old; + $new =~ s{/([^/]+)$}{/.postponed.$1}; + + die "Allready have ", $self->path_size($new) if -e $new; + $cmd = "mv $old $new && svk revert $old"; + } elsif ( $self->action ) { + $cmd = 'svk ' . $self->action; + if ( $self->action eq 'commit' ) { + my $msg = $self->commit_message || return $self->error( "need commit message\n" ); + $msg =~ s{"}{\\"}gs; + $cmd .= qq{ -m "$msg"}; + } else { + confess "need path" unless $self->path; + } + $cmd .= ' ' . join(' ',$self->path); + } + if ( $cmd ) { + $cmd .= ' 2>&1'; + warn "# cmd $cmd"; + + my $out = `$cmd`; + warn "# output of $cmd is: $out"; + + return qq| + Command $cmd produced output: + + $out + + |; } - my $html - = ( $self->status_as_markup || $self->error('no status_or_markup output') ) - . ( $self->diff_as_markup || $self->error('no diff_as_markup output') ) - ; +} + +sub as_markup { + my ($self) = @_; + + my $html = $self->action_as_markup; + + $self->title( 'svk' . ( $self->action ? ' - ' . $self->action : '' ) ); # XXX without this we get wrong icon and title + + $html .= $self->commit_as_markup . $self->diff_as_markup; + warn "as_markup ",length($html)," bytes"; return $html;