4 |
extends 'Frey'; |
extends 'Frey'; |
5 |
with 'Frey::Web'; |
with 'Frey::Web'; |
6 |
|
|
7 |
has commit_path => ( |
use Moose::Util::TypeConstraints; |
8 |
documentation => 'path to commit', |
|
9 |
|
enum 'SVK_Action' => ( 'commit', 'revert', 'postpone' ); |
10 |
|
|
11 |
|
has action => ( |
12 |
is => 'rw', |
is => 'rw', |
13 |
isa => 'ArrayRef|Str', |
isa => 'SVK_Action', |
14 |
); |
); |
15 |
|
|
16 |
has message => ( |
has path => ( |
17 |
|
documentation => 'path to work with', |
18 |
|
is => 'rw', |
19 |
|
isa => 'Str', |
20 |
|
); |
21 |
|
|
22 |
|
has commit_message => ( |
23 |
documentation => 'commit message', |
documentation => 'commit message', |
24 |
is => 'rw', |
is => 'rw', |
25 |
isa => 'Str', |
isa => 'Str', |
66 |
sub status_as_markup { |
sub status_as_markup { |
67 |
my ($self) = @_; |
my ($self) = @_; |
68 |
my $status = `svk status -q`; |
my $status = `svk status -q`; |
69 |
$status =~ s{^(\w+\s+)(\S+)$}{$1<input name="commit_path" value="$2" type="checkbox"><a href="#$2">$2</a>}gm; |
# $status =~ s{^(\w+\s+)(\S+)$}{$1<input name="commit_path" value="$2" type="checkbox"><a href="#$2">$2</a>}gm; # FIXME |
70 |
$self->add_css( qq| pre.l a { text-decoration: none; } | ); |
$status =~ s{^(\w+[\+\s]+)(\S+)$}{$1<a href="#$2">$2</a>}gm; |
71 |
$status = qq| |
if ( $status ) { |
72 |
<form> |
$self->add_css(qq| |
73 |
<div style="background: #ffd; float: right; padding: 1em;"> |
pre.l a { text-decoration: none; } |
74 |
<textarea name="message" width=20 height=4></textarea> |
div.commit { |
75 |
<br><input type="submit" value="Commit"> |
background: #ffd; |
76 |
</div> |
padding: 1em 1em; |
77 |
<pre class="l">$status</pre> |
position: fixed; |
78 |
</form> |
top: 1em; |
79 |
|; |
right: 1em; |
80 |
$self->add_status( $status ); |
z-index: 10; |
81 |
|
} |
82 |
|
| ); |
83 |
|
|
84 |
|
$status = qq| |
85 |
|
<div class="commit" method="post"> |
86 |
|
<form> |
87 |
|
<textarea name="commit_message" cols=40 rows=4></textarea> |
88 |
|
<br><input type="submit" name="action" value="commit"> |
89 |
|
</form> |
90 |
|
</div> |
91 |
|
<pre class="l">$status</pre> |
92 |
|
|; |
93 |
|
$self->add_status( $status ); |
94 |
|
|
95 |
|
} |
96 |
warn "status_as_markup ",length($status)," bytes"; |
warn "status_as_markup ",length($status)," bytes"; |
97 |
return $status; |
return $status; |
98 |
} |
} |
106 |
$self->add_css( qq| |
$self->add_css( qq| |
107 |
pre span.add { background: #dfd } |
pre span.add { background: #dfd } |
108 |
pre span.del { background: #fdd } |
pre span.del { background: #fdd } |
109 |
|
pre form.inline { display: inline } |
110 |
| ); |
| ); |
111 |
$diff =~ s{^(\+.+?)$}{<span class="add">$1</span>}gm; |
$diff =~ s{^(\+.+?)$}{<span class="add">$1</span>}gm; |
112 |
$diff =~ s{^(\-.+?)$}{<span class="del">$1</span>}gm; |
$diff =~ s{^(\-.+?)$}{<span class="del">$1</span>}gm; |
113 |
$diff =~ s{^(===\s+)(\S+)$}{$1<a name="$2">$2</a>}gm; |
sub form { |
114 |
|
my ( $path, $action ) = @_; |
115 |
|
qq|<form class="inline"><input type="hidden" name="path" value="$path"><input type="submit" name="action" value="$action"></form>|; |
116 |
|
}; |
117 |
|
$diff =~ s{^(===\s+)(\S+)$}{$1 . form($2,'revert') . qq| <a name="$2" target="editor" href="/editor+$2+1">$2</a> | . form($2,'postpone') }gem; |
118 |
|
|
119 |
$diff = qq|<pre>$diff</pre>|; |
$diff = qq|<pre>$diff</pre>|; |
120 |
warn "diff_as_markup ",length($diff)," bytes"; |
warn "diff_as_markup ",length($diff)," bytes"; |
124 |
sub as_markup { |
sub as_markup { |
125 |
my ($self) = @_; |
my ($self) = @_; |
126 |
|
|
127 |
|
my $html = ''; |
128 |
|
my $cmd; |
129 |
|
|
130 |
|
if ( $self->action eq 'postpone' ) { |
131 |
|
my $old = $self->path; |
132 |
|
my $new = $old . '.postponed'; |
133 |
|
die "Allready have $new" if -e $new; |
134 |
|
$cmd = "mv $old $new && svk revert $old"; |
135 |
|
} elsif ( $self->action ) { |
136 |
|
$cmd = 'svk ' . $self->action . ' ' . $self->path; |
137 |
|
if ( $self->action eq 'commit' ) { |
138 |
|
confess "need commit message" unless $self->commit_message; |
139 |
|
my $msg = $self->commit_message; |
140 |
|
$msg =~ s{"}{\\"}gs; |
141 |
|
$cmd .= qq{ -m "$msg"}; |
142 |
|
} else { |
143 |
|
confess "need path" unless $self->path; |
144 |
|
} |
145 |
|
} |
146 |
|
if ( $cmd ) { |
147 |
|
$cmd .= ' 2>&1'; |
148 |
|
my $out = `$cmd`; |
149 |
|
warn "$cmd $out"; |
150 |
|
|
151 |
|
$html .= qq| |
152 |
|
<code style="background: #ff8;"> |
153 |
|
$cmd\n |
154 |
|
<b>$out</b> |
155 |
|
</code> |
156 |
|
|; |
157 |
|
} |
158 |
|
|
159 |
|
$self->title( 'svk' . ( $self->action ? ' - ' . $self->action : '' ) ); # XXX without this we get wrong icon and title |
160 |
|
|
161 |
if ( ! $self->can('html_escape') ) { |
if ( ! $self->can('html_escape') ) { |
162 |
Frey::Web->meta->apply( $self ); |
Frey::Web->meta->apply( $self ); |
163 |
$self->TODO( "Frey::Web role missing" ); |
$self->TODO( "Frey::Web role missing" ); |
164 |
} |
} |
165 |
|
|
166 |
my $html |
$html .= $self->status_as_markup || 'No changes in files tracked by SVK'; |
167 |
= ( $self->status_as_markup || $self->error('no status_or_markup output') ) |
$html .= $self->diff_as_markup; |
168 |
. ( $self->diff_as_markup || $self->error('no diff_as_markup output') ) |
|
|
; |
|
169 |
warn "as_markup ",length($html)," bytes"; |
warn "as_markup ",length($html)," bytes"; |
170 |
|
|
171 |
return $html; |
return $html; |