1 contributor
<%
# API
my $api = gitprep_api;
# Parameters
my $op = param('op') || '';
my $user = param('user') || '';
# Authentication
unless ($api->logined($user)) {
$self->redirect_to('/');
return;
}
# Rename project
my $git = app->git;
my $errors;
my $post = lc $self->req->method eq 'post';
if ($op eq 'rename-project' && $post) {
# Validation
my $params = $api->params;
my $rule = [
'to-project' => [
['not_blank' => 'Repository name is empty.'],
['project_name' => 'Repository name contains invalid charactor.']
]
];
my $vresult = app->validator->validate($params, $rule);
if ($vresult->is_ok) {
# Valida parameters
my $data = $vresult->data;
my $to_project = $data->{'to-project'};
# Rename
if (app->manager->exists_project($user, $to_project)) {
$errors = ["$to_project is already exists"];
}
else {
eval { app->manager->rename_project($user, $project, $to_project) };
if ($@) {
app->log->error($@);
$errors = ['Internal Error'];
}
else {
flash(message => "Repository name is renamed to $to_project");
$self->redirect_to("/$user/$to_project/settings");
return;
}
}
}
else { $errors = $vresult->messages }
}
# Change description
elsif ($op eq 'change-description' && $post) {
my $description = param('description');
$description = '' unless defined $description;
eval { $git->description($user, $project, $description) };
if ($@) {
app->log->error("/$user/$project/settings?op=description: $@");
$errors = ['Internal Error'];
}
else {
flash(message => 'Description is saved.');
$self->redirect_to('current');
return;
}
}
# Change default branch
elsif ($op eq 'default-branch' && $post) {
my $default_branch = param('default-branch');
eval { app->manager->default_branch($user, $project, $default_branch) };
if ($@) {
app->log->error("/$user/$project/settings?op=default-branch: $@");
$errors = ['Internal Error'];
}
else {
flash(message => "Default branch is changed to $default_branch.");
$self->redirect_to('current');
return;
}
}
# Delete project
elsif ($op eq 'delete-project' && $post) {
my $user = param('user');
my $project = param('project');
eval { app->manager->delete_project($user, $project) };
if ($@) {
app->log->error("/$user/$project/settings:$@");
$errors = ['Internal Error'];
}
else {
flash(message => "Repository $project is deleted.");
$self->redirect_to("/$user");
return;
}
}
%>
% layout 'common', title => 'Options';
%= javascript begin
$(document).ready(function () {
// Rename project
$('#rename').on('click', function () {
$('#form-rename-project').submit();
});
// Select default branch
$('[name=default-branch]').on('change', function () {
$('#form-default-branch').submit();
});
// Check matching deleted project
$('input[name="deleted-project"]').on('keyup', function () {
var deleted_project = $(this).val();
var project = "<%= $project %>";
if (deleted_project == project) {
$('#delete').attr('class', 'btn btn-danger')
.removeAttr('disabled');
}
else {
$('#delete').attr('class', 'btn btn-danger disabled')
.attr('disabled', 'disabled');
}
});
// Delete project
$('#delete').on('click', function () {
$('#form-delete-project').submit();
});
});
% end
%= include '/include/header';
<div class="container">
%= include '/include/errors', errors => $errors;
%= include '/include/message', message => flash('message');
%= include '/include/project_header';
<div style="margin-bottom:20px">
<div class="border-gray bk-gray-light radius-top" style="padding-left:5px">
<h4>
Settings
</h4>
</div>
<div class="border-gray" style="padding:5px 10px;border-top:none">
<form id="form-rename-project" action="<%= url_for->query(op => 'rename-project') %>" method="post" style="margin-bottom:0px">
<div >Repository Name</div>
<div>
%= text_field 'to-project' => $project, style => 'margin-top:9px';
<a href="#rename-confirm" role="button" class="btn" data-toggle="modal">
Rename
</a>
</div>
</form>
</div>
<div class="border-gray" style="padding:5px 10px;border-top:none">
<form action="<%= url_for->query(op => 'change-description') %>" method="post" style="margin-bottom:0px">
<div >Description</div>
<div>
% my $description = $git->description($user, $project);
% $description = '' unless defined $description;
%= text_field 'description' => $description, class => 'span8', style => 'margin-top:9px';
<input type="submit" class="btn" value="Save">
</div>
</form>
</div>
<div class="border-gray radius-bottom" style="padding:5px 10px;border-top:none;">
<form id="form-default-branch" action="<%= url_for->query(op => 'default-branch') %>" method="post" style="margin-bottom:0px">
Default Branch
% my $branches = $git->branches($user, $project);
% my $branch_names = [map { $_->{name} } @$branches];
% my $default_branch = app->manager->default_branch($user, $project);
% push @$branch_names, $default_branch unless @$branch_names;
% param('default-branch', $default_branch);
%= select_field 'default-branch' => $branch_names, style => 'margin-top:5px';
</form>
</div>
</div>
<div style="margin-bottom:30px">
<div class="border-gray bk-gray-light radius-top" style="background:red;padding-left:5px">
<h4 style="color:white">Danger Zone</h4>
</div>
<div class="border-gray radius-bottom" style="padding:5px 10px;border-top:none">
<form id="form-delete-project" action="<%= url_for->query(op => 'delete-project') %>" method="post">
<div><b>Delete this repository</b></div>
<span class="muted">
Once you delete a repository, there is no going back.
</span>
<a style="color:red" href="#delete-confirm" role="button" class="btn" data-toggle="modal">
Delete this repository
</a>
%= hidden_field user => $user;
%= hidden_field project => $project;
</form>
</div>
</div>
</div>
<div id="modal-message" class="modal hide">
<div class="modal-header">
<div id="modal-message-text" style="font-weight:bold"></div>
</div>
<div class="modal-body">
<button class="btn" data-dismiss="modal" aria-hidden="true">OK</button>
</div>
</div>
<div id="rename-confirm" class="modal hide" tabindex="-1" role="dialog" aria-labelledby="rename-confirm-label" aria-hidden="true">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<div style="font-weight:bold">Are you sure you want to rename?</div>
</div>
<div class="modal-body">
<p>
Unexpected bad things will happen if you don't read this
</p>
<ul>
<li>
We will not set up any redirects from the old location
</li>
<li>
You will need to update your local repositories to point to the new location
</li>
</ul>
</div>
<div class="modal-footer">
<button id="rename" class="btn" data-dismiss="modal" aria-hidden="true">
I understand, rename this repository
</button>
</div>
</div>
<div id="delete-confirm" class="modal hide" tabindex="-1" role="dialog" aria-labelledby="delete-confirm-label" aria-hidden="true">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<div style="font-weight:bold">Are you ABSOLUTELY sure?</div>
</div>
<div class="modal-body">
<p>
Unexpected bad things will happen if you don't read this.
</p>
<p>
This action <b>CANNOT</b> be undone. This will delete the <b><%= "$user/$project" %></b>
repository, wiki, issues, and comments permanently.
</p>
<p>
Please type in the name of the repository(<b><%= $project %></b>) to confirm.
</p>
%= text_field 'deleted-project', class => 'span5';
</div>
<div class="modal-footer">
<button id="delete" class="btn btn-danger disabled" disabled data-dismiss="modal" aria-hidden="true">
I understand the consequences, delete this repository
</button>
</div>
</div>
%= include '/include/footer';