| ... | ... |
@@ -235,24 +235,16 @@ sub rename_project {
|
| 235 | 235 |
# Rename project |
| 236 | 236 |
my $git = $self->app->git; |
| 237 | 237 |
my $dbi = $self->app->dbi; |
| 238 |
- my $error = {};
|
|
| 239 |
- if ($self->exists_project($user, $to_project)) |
|
| 240 |
- {
|
|
| 241 |
- $error->{message} = 'Already exists';
|
|
| 242 |
- return $error; |
|
| 243 |
- } |
|
| 244 |
- else {
|
|
| 238 |
+ my $error; |
|
| 239 |
+ eval {
|
|
| 245 | 240 |
$dbi->connector->txn(sub {
|
| 246 |
- $self->_rename_project($user, $project, $to_project); |
|
| 247 |
- $self->_rename_rep($user, $project, $to_project); |
|
| 241 |
+ eval { $self->_rename_project($user, $project, $to_project) };
|
|
| 242 |
+ croak $error = $@ if $@; |
|
| 243 |
+ eval { $self->_rename_rep($user, $project, $to_project) };
|
|
| 244 |
+ croak $error = $@ if $@; |
|
| 248 | 245 |
}); |
| 249 |
- if ($@) {
|
|
| 250 |
- $error->{message} = 'Rename failed';
|
|
| 251 |
- return $error; |
|
| 252 |
- } |
|
| 253 |
- } |
|
| 254 |
- |
|
| 255 |
- return 1; |
|
| 246 |
+ }; |
|
| 247 |
+ croak $error if $error; |
|
| 256 | 248 |
} |
| 257 | 249 |
|
| 258 | 250 |
sub setup_database {
|
| ... | ... |
@@ -550,6 +542,8 @@ sub exists_project {
|
| 550 | 542 |
my $dbi = $self->app->dbi; |
| 551 | 543 |
my $row = $dbi->model('project')->select(id => [$user, $project])->one;
|
| 552 | 544 |
|
| 545 |
+ use D;d $row; |
|
| 546 |
+ |
|
| 553 | 547 |
return $row ? 1 : 0; |
| 554 | 548 |
} |
| 555 | 549 |
|
| ... | ... |
@@ -0,0 +1,11 @@ |
| 1 |
+<% |
|
| 2 |
+ my $errors = stash('errors');
|
|
| 3 |
+%> |
|
| 4 |
+% if ($errors) {
|
|
| 5 |
+ <div class="alert alert-error"> |
|
| 6 |
+ <button type="button" class="close" data-dismiss="alert">×</button> |
|
| 7 |
+ % for my $error (@$errors) {
|
|
| 8 |
+ <p><%= $error %></p> |
|
| 9 |
+ % } |
|
| 10 |
+ </div> |
|
| 11 |
+% } |
| ... | ... |
@@ -0,0 +1,9 @@ |
| 1 |
+<% |
|
| 2 |
+ my $message = stash('message');
|
|
| 3 |
+%> |
|
| 4 |
+% if (defined $message) {
|
|
| 5 |
+ <div class="alert alert-success"> |
|
| 6 |
+ <button type="button" class="close" data-dismiss="alert">×</button> |
|
| 7 |
+ <p><%= $message %></p> |
|
| 8 |
+ </div> |
|
| 9 |
+% } |
| ... | ... |
@@ -15,7 +15,9 @@ |
| 15 | 15 |
|
| 16 | 16 |
# Rename project |
| 17 | 17 |
my $git = app->git; |
| 18 |
- if ($op eq 'rename-project') {
|
|
| 18 |
+ my $errors; |
|
| 19 |
+ my $post = lc $self->req->method eq 'post'; |
|
| 20 |
+ if ($op eq 'rename-project' && $post) {
|
|
| 19 | 21 |
|
| 20 | 22 |
# Validation |
| 21 | 23 |
my $params = $api->params; |
| ... | ... |
@@ -26,7 +28,7 @@ |
| 26 | 28 |
project => [ |
| 27 | 29 |
'project_name' |
| 28 | 30 |
], |
| 29 |
- 'renamed-project' => [ |
|
| 31 |
+ 'to-project' => [ |
|
| 30 | 32 |
'project_name' |
| 31 | 33 |
] |
| 32 | 34 |
]; |
| ... | ... |
@@ -37,36 +39,48 @@ |
| 37 | 39 |
my $data = $vresult->data; |
| 38 | 40 |
my $user = $data->{user};
|
| 39 | 41 |
my $project = $data->{project};
|
| 40 |
- my $renamed_project = $data->{'renamed-project'};
|
|
| 42 |
+ my $to_project = $data->{'to-project'};
|
|
| 41 | 43 |
|
| 42 | 44 |
# Rename |
| 43 |
- my $manager = app->manager; |
|
| 44 |
- my $error = $manager->rename_project($user, $project, $renamed_project); |
|
| 45 |
- if (ref $error) {
|
|
| 46 |
- $self->render(json => {ok => 0, message => $error->{message}});
|
|
| 45 |
+ if (app->manager->exists_project($user, $to_project)) {
|
|
| 46 |
+ $errors = ["$to_project is already exists"]; |
|
| 47 | 47 |
} |
| 48 | 48 |
else {
|
| 49 |
- $self->render(json => {ok => 1});
|
|
| 49 |
+ eval { app->manager->rename_project($user, $project, $to_project) };
|
|
| 50 |
+ if ($@) {
|
|
| 51 |
+ $errors = ['Internal Error']; |
|
| 52 |
+ } |
|
| 53 |
+ else {
|
|
| 54 |
+ flash(message => "Repository name is renamed to $to_project"); |
|
| 55 |
+ $self->redirect_to("/$user/$to_project/settings");
|
|
| 56 |
+ $self->finish_rendering; |
|
| 57 |
+ return; |
|
| 58 |
+ } |
|
| 50 | 59 |
} |
| 51 |
- return $self->res->body; |
|
| 52 |
- } |
|
| 53 |
- else {
|
|
| 54 |
- $self->render(json => {ok => 0, message => 'Invalid Parameters'});
|
|
| 55 | 60 |
} |
| 61 |
+ else { $errors = $vresult->messages }
|
|
| 56 | 62 |
} |
| 57 | 63 |
|
| 58 | 64 |
# Change description |
| 59 |
- elsif ($op eq 'change_description') {
|
|
| 65 |
+ elsif ($op eq 'change-description' && $post) {
|
|
| 60 | 66 |
my $description = param('description');
|
| 61 | 67 |
$description = '' unless defined $description; |
| 62 | 68 |
|
| 63 |
- $git->description($user, $project, $description); |
|
| 64 |
- $self->render(json => {ok => 1});
|
|
| 65 |
- return $self->res->body; |
|
| 69 |
+ eval { $git->description($user, $project, $description) };
|
|
| 70 |
+ if ($@) {
|
|
| 71 |
+ app->log->error("/settings?op=change-description: $@");
|
|
| 72 |
+ $errors = ['Internal Error']; |
|
| 73 |
+ } |
|
| 74 |
+ else {
|
|
| 75 |
+ flash(message => 'Description is saved.'); |
|
| 76 |
+ $self->redirect_to('current');
|
|
| 77 |
+ $self->finish_rendering; |
|
| 78 |
+ return; |
|
| 79 |
+ } |
|
| 66 | 80 |
} |
| 67 | 81 |
|
| 68 | 82 |
# Delete project |
| 69 |
- elsif ($op eq 'delete-project') {
|
|
| 83 |
+ elsif ($op eq 'delete-project' && $post) {
|
|
| 70 | 84 |
|
| 71 | 85 |
# Validation |
| 72 | 86 |
my $params = $api->params; |
| ... | ... |
@@ -109,38 +123,9 @@ |
| 109 | 123 |
|
| 110 | 124 |
$(document).ready(function () {
|
| 111 | 125 |
|
| 112 |
- // Rename project name |
|
| 126 |
+ // Rename project |
|
| 113 | 127 |
$('#rename').on('click', function () {
|
| 114 |
- var renamed_project = $('input[name="renamed-project"]').val();
|
|
| 115 |
- |
|
| 116 |
- var url = "<%= url_for %>"; |
|
| 117 |
- var data = {
|
|
| 118 |
- op : "rename-project", |
|
| 119 |
- user: "<%= $user %>", |
|
| 120 |
- project: "<%= $project %>", |
|
| 121 |
- 'renamed-project': renamed_project |
|
| 122 |
- }; |
|
| 123 |
- $.post(url, data, function (result) {
|
|
| 124 |
- if (result.ok) {
|
|
| 125 |
- location.href = "<%= url_for("/$user") %>" + '/' + renamed_project;
|
|
| 126 |
- } |
|
| 127 |
- else {
|
|
| 128 |
- $('#modal-message-text').text('Rename failed:' + result.message);
|
|
| 129 |
- $('#modal-message').modal('show');
|
|
| 130 |
- } |
|
| 131 |
- }); |
|
| 132 |
- }); |
|
| 133 |
- |
|
| 134 |
- // Change description |
|
| 135 |
- $('a[href="#description"]').on('click', function () {
|
|
| 136 |
- var description = $('input[name="description"]').val();
|
|
| 137 |
- var url = "<%= url_for %>?op=change_description&description=" + description; |
|
| 138 |
- $.post(url, function (result) {
|
|
| 139 |
- if (result.ok) {
|
|
| 140 |
- $('#modal-message-text').text('Description is changed');
|
|
| 141 |
- $('#modal-message').modal('show');
|
|
| 142 |
- } |
|
| 143 |
- }); |
|
| 128 |
+ $('#form-rename-project').submit();
|
|
| 144 | 129 |
}); |
| 145 | 130 |
|
| 146 | 131 |
// Check matching deleted project |
| ... | ... |
@@ -189,6 +174,8 @@ |
| 189 | 174 |
%= include '/include/header'; |
| 190 | 175 |
|
| 191 | 176 |
<div class="container"> |
| 177 |
+ %= include '/include/errors', errors => $errors; |
|
| 178 |
+ %= include '/include/message', message => flash('message');
|
|
| 192 | 179 |
%= include '/include/project_header'; |
| 193 | 180 |
|
| 194 | 181 |
<div style="margin-bottom:20px"> |
| ... | ... |
@@ -198,26 +185,26 @@ |
| 198 | 185 |
</h4> |
| 199 | 186 |
</div> |
| 200 | 187 |
<div class="border-gray" style="padding:5px;border-top:none"> |
| 201 |
- <div >Repository Name</div> |
|
| 202 |
- <div> |
|
| 203 |
- %= text_field 'renamed-project' => $project, style => 'margin-top:9px'; |
|
| 204 |
- <a href="#rename-confirm" role="button" class="btn" data-toggle="modal"> |
|
| 205 |
- Rename |
|
| 206 |
- </a> |
|
| 207 |
- </div> |
|
| 188 |
+ <form id="form-rename-project" action="<%= url_for->query(op => 'rename-project') %>" method="post" style="margin-bottom:0px"> |
|
| 189 |
+ <div >Repository Name</div> |
|
| 190 |
+ <div> |
|
| 191 |
+ %= text_field 'to-project' => $project, style => 'margin-top:9px'; |
|
| 192 |
+ <a href="#rename-confirm" role="button" class="btn" data-toggle="modal"> |
|
| 193 |
+ Rename |
|
| 194 |
+ </a> |
|
| 195 |
+ </div> |
|
| 196 |
+ </form> |
|
| 208 | 197 |
</div> |
| 209 | 198 |
<div class="border-gray" style="padding:5px;border-top:none"> |
| 210 |
- <div >Description</div> |
|
| 211 |
- <div> |
|
| 212 |
- % my $description = $git->description($user, $project); |
|
| 213 |
- % $description = '' unless defined $description; |
|
| 214 |
- %= text_field 'description' => $description, class => 'span8', style => 'margin-top:9px'; |
|
| 215 |
- <a class="btn" href="#description">Save</a> |
|
| 216 |
- </div> |
|
| 217 |
- <div id="description-success" class="alert alert-success" style="width:150px;display:none"> |
|
| 218 |
- <button type="button" class="close" data-dismiss="alert">×</button> |
|
| 219 |
- Savaed! |
|
| 220 |
- </div> |
|
| 199 |
+ <form action="<%= url_for->query(op => 'change-description') %>" method="post" style="margin-bottom:0px"> |
|
| 200 |
+ <div >Description</div> |
|
| 201 |
+ <div> |
|
| 202 |
+ % my $description = $git->description($user, $project); |
|
| 203 |
+ % $description = '' unless defined $description; |
|
| 204 |
+ %= text_field 'description' => $description, class => 'span8', style => 'margin-top:9px'; |
|
| 205 |
+ <input type="submit" class="btn" value="Save"> |
|
| 206 |
+ </div> |
|
| 207 |
+ </form> |
|
| 221 | 208 |
</div> |
| 222 | 209 |
<div class="border-gray" style="padding:5px;border-top:none"> |
| 223 | 210 |
Default Branch |
| ... | ... |
@@ -332,7 +332,17 @@ note 'User Account Settings'; |
| 332 | 332 |
->content_like(qr/first commit/) |
| 333 | 333 |
->content_like(qr/t2\.git/) |
| 334 | 334 |
->content_like(qr/README/) |
| 335 |
- ; |
|
| 335 |
+ ; |
|
| 336 |
+ |
|
| 337 |
+ # Settings page(don't has README) |
|
| 338 |
+ $t->get_ok('/kimoto1/t1/settings')
|
|
| 339 |
+ ->content_like(qr/Settings/) |
|
| 340 |
+ ; |
|
| 341 |
+ |
|
| 342 |
+ # Settings page(has README) |
|
| 343 |
+ $t->get_ok('/kimoto1/t2/settings')
|
|
| 344 |
+ ->content_like(qr/Settings/) |
|
| 345 |
+ ; |
|
| 336 | 346 |
} |
| 337 | 347 |
} |
| 338 | 348 |
|