... | ... |
@@ -20,14 +20,24 @@ sub admin_user { |
20 | 20 |
} |
21 | 21 |
|
22 | 22 |
sub default_branch { |
23 |
- my ($self, $user, $project) = @_; |
|
24 |
- |
|
25 |
- # Default branch |
|
26 |
- my $default_branch = $self->app->dbi->model('project') |
|
27 |
- ->select('default_branch', id => [$user, $project]) |
|
28 |
- ->value; |
|
23 |
+ my ($self, $user, $project, $default_branch) = @_; |
|
29 | 24 |
|
30 |
- return $default_branch; |
|
25 |
+ # Set default branch |
|
26 |
+ my $dbi = $self->app->dbi; |
|
27 |
+ if (defined $default_branch) { |
|
28 |
+ $dbi->model('project')->update( |
|
29 |
+ {default_branch => $default_branch}, |
|
30 |
+ id => [$user, $project] |
|
31 |
+ ); |
|
32 |
+ } |
|
33 |
+ else { |
|
34 |
+ # Get default branch |
|
35 |
+ my $default_branch = $dbi->model('project') |
|
36 |
+ ->select('default_branch', id => [$user, $project]) |
|
37 |
+ ->value; |
|
38 |
+ |
|
39 |
+ return $default_branch; |
|
40 |
+ } |
|
31 | 41 |
} |
32 | 42 |
|
33 | 43 |
sub fork_project { |
... | ... |
@@ -542,8 +552,6 @@ sub exists_project { |
542 | 552 |
my $dbi = $self->app->dbi; |
543 | 553 |
my $row = $dbi->model('project')->select(id => [$user, $project])->one; |
544 | 554 |
|
545 |
- use D;d $row; |
|
546 |
- |
|
547 | 555 |
return $row ? 1 : 0; |
548 | 556 |
} |
549 | 557 |
|
... | ... |
@@ -68,7 +68,7 @@ |
68 | 68 |
|
69 | 69 |
eval { $git->description($user, $project, $description) }; |
70 | 70 |
if ($@) { |
71 |
- app->log->error("/settings?op=change-description: $@"); |
|
71 |
+ app->log->error("/$user/$project/settings?op=description: $@"); |
|
72 | 72 |
$errors = ['Internal Error']; |
73 | 73 |
} |
74 | 74 |
else { |
... | ... |
@@ -79,6 +79,22 @@ |
79 | 79 |
} |
80 | 80 |
} |
81 | 81 |
|
82 |
+ # Change default branch |
|
83 |
+ elsif ($op eq 'default-branch' && $post) { |
|
84 |
+ my $default_branch = param('default-branch'); |
|
85 |
+ eval { app->manager->default_branch($user, $project, $default_branch) }; |
|
86 |
+ if ($@) { |
|
87 |
+ app->log->error("/$user/$project/settings?op=default-branch: $@"); |
|
88 |
+ $errors = ['Internal Error']; |
|
89 |
+ } |
|
90 |
+ else { |
|
91 |
+ flash(message => "Default branch is changed to $default_branch."); |
|
92 |
+ $self->redirect_to('current'); |
|
93 |
+ $self->finish_rendering; |
|
94 |
+ return; |
|
95 |
+ } |
|
96 |
+ } |
|
97 |
+ |
|
82 | 98 |
# Delete project |
83 | 99 |
elsif ($op eq 'delete-project' && $post) { |
84 | 100 |
|
... | ... |
@@ -128,6 +144,11 @@ |
128 | 144 |
$('#form-rename-project').submit(); |
129 | 145 |
}); |
130 | 146 |
|
147 |
+ // Select default branch |
|
148 |
+ $('[name=default-branch]').on('change', function () { |
|
149 |
+ $('#form-default-branch').submit(); |
|
150 |
+ }); |
|
151 |
+ |
|
131 | 152 |
// Check matching deleted project |
132 | 153 |
$('input[name="deleted-project"]').on('keyup', function () { |
133 | 154 |
var deleted_project = $(this).val(); |
... | ... |
@@ -142,7 +163,7 @@ |
142 | 163 |
.attr('disabled', 'disabled'); |
143 | 164 |
} |
144 | 165 |
}); |
145 |
- |
|
166 |
+ |
|
146 | 167 |
// Delete project |
147 | 168 |
$('#delete').on('click', function () { |
148 | 169 |
var deleted_project = $('input[name="deleted-project"]').val(); |
... | ... |
@@ -163,10 +184,6 @@ |
163 | 184 |
} |
164 | 185 |
}); |
165 | 186 |
}); |
166 |
- |
|
167 |
- // Select default branch |
|
168 |
- var default_branch = "<%= app->manager->default_branch($user, $project) %>"; |
|
169 |
- $('select[name="default_branch"]').val(default_branch); |
|
170 | 187 |
}); |
171 | 188 |
|
172 | 189 |
% end |
... | ... |
@@ -207,11 +224,15 @@ |
207 | 224 |
</form> |
208 | 225 |
</div> |
209 | 226 |
<div class="border-gray" style="padding:5px;border-top:none"> |
210 |
- Default Branch |
|
211 |
- % my $branches = $git->branches($user, $project); |
|
212 |
- % my $branch_names = [map { $_->{name} } @$branches]; |
|
213 |
- % push @$branch_names, app->manager->default_branch($user, $project) unless @$branch_names; |
|
214 |
- %= select_field 'default_branch' => $branch_names, style => 'margin-top:5px'; |
|
227 |
+ <form id="form-default-branch" action="<%= url_for->query(op => 'default-branch') %>" method="post" style="margin-bottom:0px"> |
|
228 |
+ Default Branch |
|
229 |
+ % my $branches = $git->branches($user, $project); |
|
230 |
+ % my $branch_names = [map { $_->{name} } @$branches]; |
|
231 |
+ % my $default_branch = app->manager->default_branch($user, $project); |
|
232 |
+ % push @$branch_names, unless @$branch_names; |
|
233 |
+ % param('default-branch', $default_branch); |
|
234 |
+ %= select_field 'default-branch' => $branch_names, style => 'margin-top:5px'; |
|
235 |
+ </form> |
|
215 | 236 |
</div> |
216 | 237 |
</div> |
217 | 238 |
|