[Bps-public-commit] r10060 - in SVKUI/trunk: lib lib/SVKUI/Model share/web/templates/project t

clsung at bestpractical.com clsung at bestpractical.com
Mon Dec 24 04:25:59 EST 2007


Author: clsung
Date: Mon Dec 24 04:25:59 2007
New Revision: 10060

Added:
   SVKUI/trunk/lib/SVKUI/Action/CreateBranch.pm
   SVKUI/trunk/t/00-action-CreateBranch.t
Modified:
   SVKUI/trunk/lib/SVKUI.pm
   SVKUI/trunk/lib/SVKUI/Model/Project.pm
   SVKUI/trunk/share/web/templates/project/index.html

Log:
- allow user to create branch on SVKUI

Modified: SVKUI/trunk/lib/SVKUI.pm
==============================================================================
--- SVKUI/trunk/lib/SVKUI.pm	(original)
+++ SVKUI/trunk/lib/SVKUI.pm	Mon Dec 24 04:25:59 2007
@@ -68,6 +68,7 @@
     $output = <$fh>;
     close $fh;
     $output =~ s,GET request.*\n,,g;
+    $output =~ s,POST request.*\n,,g;
     open $fh, '>', Jifty->config->app('output') or die $!;
     close $fh;
     $class->update_mirror();

Added: SVKUI/trunk/lib/SVKUI/Action/CreateBranch.pm
==============================================================================
--- (empty file)
+++ SVKUI/trunk/lib/SVKUI/Action/CreateBranch.pm	Mon Dec 24 04:25:59 2007
@@ -0,0 +1,90 @@
+use strict;
+use warnings;
+
+=head1 NAME
+
+SVKUI::Action::CreateBranch
+
+=cut
+
+package SVKUI::Action::CreateBranch;
+use base qw/SVKUI::Action Jifty::Action/;
+
+use Jifty::Param::Schema;
+use Jifty::Action schema {
+
+param
+    branch => type is 'text',
+    label is _('Branch Name'),
+    hints is 'name for the Project branch',
+    ajax canonicalizes,
+    is mandatory;
+
+param
+    islocal => type is 'checkbox',
+    label is _('is local branch');
+
+param
+    switchto => type is 'checkbox',
+    label is _('will switch to this  branch');
+};
+
+=head2 take_action
+
+=cut
+
+sub take_action {
+    my $self = shift;
+    
+    # Custom action code
+    
+    my $proj_name = $self->argument_value('proj_name');
+    my $branch = $self->argument_value('branch');
+    my $is_local = $self->argument_value('is_local');
+    my $project = SVKUI::Model::Project->new;
+    $project->load_by_cols( name => $proj_name );
+    my $projs = $project->branches();
+    if ($projs eq '' or !(grep {$branch} @{$projs}) ) {
+	$project->create_branch($branch, $is_local, undef, undef);
+    } else {
+	$self->result->field_error ( branch => 'Duplicat branches' );
+    }
+    $self->report_success if not $self->result->failure;
+    
+    return 1;
+}
+
+=head2 report_success
+
+=cut
+
+sub report_success {
+    my $self = shift;
+    # Your success message here
+    $self->result->message('Success');
+}
+
+=head2 canonicalize_XXX
+
+=cut
+
+sub canonicalize_branch {
+    my ($self, $value) = @_;
+
+    my $proj_name = $self->argument_value('proj_name');
+    my $project = SVKUI::Model::Project->new;
+    $project->load_by_cols( name => $proj_name );
+    my $projs = $project->branches();
+    $value =~ s/^ *//;
+    $value =~ s/ *$//;
+    if ($projs eq '' or !(grep {$value} @{$projs}) ) {
+    } else {
+	$self->canonicalization_note(
+	    url => _('Branch already exists')
+	);
+    }
+
+    return $value;
+}
+1;
+

Modified: SVKUI/trunk/lib/SVKUI/Model/Project.pm
==============================================================================
--- SVKUI/trunk/lib/SVKUI/Model/Project.pm	(original)
+++ SVKUI/trunk/lib/SVKUI/Model/Project.pm	Mon Dec 24 04:25:59 2007
@@ -104,12 +104,10 @@
     my $self = shift;
     my $rev = shift;
     return 1 unless defined($rev);
-    warn 'Project '.$self->name;
     if ($rev == $self->revision) {
-	warn 'Identical revision, skip!';
 	return 0;
     }
-    warn 'Updating revision from '.$self->revision.' to '.$rev;
+    warn 'Project '.$self->name.' updating revision from '.$self->revision.' to '.$rev;
     $self->_set(column => 'revision', value => $rev);
     return 0;
 }
@@ -301,13 +299,32 @@
     return 1 unless defined($self->repospath);
 }
 
-sub branches {
-    my ($self, $path) = @_;
-    $path ||= $self->repospath;
+sub project_cmd {
+    my ($self, @args) = @_;
     my $command = SVKUI::Model::Command->new();
-    $command->cmd('branch', '--list',$path);
+    $command->cmd('branch', @args);
     return $command->output_raw;
 }
 
+sub branches {
+    my ($self, $opt) = @_;
+    $opt ||= '';
+    my $path = $self->repospath;
+    return $self->project_cmd ('--list', $path, $opt);
+}
+
+sub create_branch {
+    my ($self, $target_path, $is_local, $switch_to, $from_path) = @_;
+    $is_local ||= 0;
+    $switch_to ||= 0;
+    my @args;
+    push @args, '--create';
+    push @args, $target_path;
+    push @args, '--local' if $is_local;
+    push @args, '--switch' if $switch_to;
+    push @args, '--from', $from_path if $from_path;
+    return $self->project_cmd(@args);
+}
+
 1;
 

Modified: SVKUI/trunk/share/web/templates/project/index.html
==============================================================================
--- SVKUI/trunk/share/web/templates/project/index.html	(original)
+++ SVKUI/trunk/share/web/templates/project/index.html	Mon Dec 24 04:25:59 2007
@@ -1,11 +1,16 @@
 <%args>
 $project
+$proj_name => undef
 $message => undef
+$branch => undef
+$is_local => 0
 </%args>
 <%init>
 my @outputs = SVKUI->output;
 my $output = join "", @outputs;
-my $edit = Jifty->web->new_action(class =>'UpdateProject', record => $project);
+my $edit = Jifty->web->new_action(class =>'CreateBranch');
+my $branches = $project->branches;
+my $localbranches = $project->branches('--local');
 </%init>
 <&|/_elements/wrapper,title => $project->name &>
 <div id="jifty-result-popup"></div>
@@ -38,6 +43,23 @@
 <h3>Repository</h3>
 <% $project->repospath %>
 
+% if ($project->trunkpath) {
+<h4>Project trunk</h4>
+<% '/mirror'.$project->trunkpath %>
+<h4>Project braches</h4>
+<% $branches %>
+<%	Jifty->web->form->start() %>
+<%	$edit->form_field('proj_name', type=> 'hidden', default_value => $project->name ) %>
+<%	$edit->form_field('branch', default_value => '') %>
+<%	$edit->form_field('is_local', type => 'checkbox', default_value => 0) %>
+<%      Jifty->web->form->submit( label => 'Add Branch' ) %>
+<%      Jifty->web->form->end() %>
+<h4>Project tags</h4>
+<% '/mirror'.$project->tagspath %>
+<h4>Project local branches</h4>
+<% $localbranches %>
+% }
+
 <h3>Local Repository</h3>
 
 % if ($project->localrepos) {

Added: SVKUI/trunk/t/00-action-CreateBranch.t
==============================================================================
--- (empty file)
+++ SVKUI/trunk/t/00-action-CreateBranch.t	Mon Dec 24 04:25:59 2007
@@ -0,0 +1,15 @@
+#!/usr/bin/env perl
+use warnings;
+use strict;
+
+=head1 DESCRIPTION
+
+A (very) basic test harness for the CreateBranch action.
+
+=cut
+
+use Jifty::Test tests => 1;
+
+# Make sure we can load the action
+use_ok('SVKUI::Action::CreateBranch');
+



More information about the Bps-public-commit mailing list