forked from yuki-kimoto/gitprep
-
Notifications
You must be signed in to change notification settings - Fork 0
/
branches.html.ep
231 lines (210 loc) · 7.77 KB
/
branches.html.ep
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
<%
# API
my $api = gitprep_api;
# Parameters
my $user = param('user');
my $project = param('project');
my $op = param('op') || '';
# Git
my $git = $self->app->git;
# Delete
my $errors;
if ($op eq 'delete' && lc $self->req->method eq 'post') {
# Forbbiden
unless ($api->logined($user)) {
$self->redirect_to('/');
return;
}
# Validation
my $params = $api->params;
my $vc = $self->app->vc;
my $rule = [
branch => [
[not_blank => 'Branch name is empty']
]
];
my $vresult = $vc->validate($params, $rule);
if ($vresult->is_ok) {
# Valid parameters
my $params = $vresult->data;
my $branch = $params->{branch};
# Delete branch
eval { $git->delete_branch($user, $project, $branch) };
if (my $e = $@) {
app->log->error(url_with . ": $e");
$errors = ['Internal Error'];
}
else {
$self->flash(message => "Branch $branch is deleted.");
$self->redirect_to;
return;
}
}
else { $errors = $vresult->messages }
}
# Default branch
my $base_branch_name = param('base_branch') || app->manager->default_branch($user, $project);
my $base_branch = $git->branch($user, $project, $base_branch_name);
# No merged branches
my $branches = $git->branches($user, $project);
my $max = 0;
for my $branch (@$branches) {
$branch->{status} = $git->branch_status($user, $project, $base_branch->{name}, $branch->{name});
$max = $branch->{status}{ahead} if $max < $branch->{status}{ahead};
$max = $branch->{status}{behind} if $max < $branch->{status}{behind};
}
my $branches_count = $git->branches_count($user, $project);
my $no_merged_branches_count = $git->no_merged_branches_count($user, $project);
my $merged_branches_count = $branches_count - $no_merged_branches_count - 1;
# Global variable
stash(rev => $base_branch_name);
%>
% layout 'common', title => "branches \x{30fb} $user/$project";
%= javascript begin
$('document').ready(function () {
// Switch merged branch or not merged branch
var display_no_merged = true;
$('#toggle-branch').on('click', function () {
if (display_no_merged) {
$(this).text('View unmerged branches');
$('#no-merged-branch-message').hide();
$('#merged-branch-message').show();
$('.no-merged-branch').css('display', 'none');
$('.merged-branch').css('display', 'block');
}
else {
$(this).text('View merged branches');
$('#no-merged-branch-message').show();
$('#merged-branch-message').hide();
$('.no-merged-branch').css('display', 'block');
$('.merged-branch').css('display', 'none');
}
display_no_merged = !display_no_merged;
});
// Click delete button
$('.delete-branch').on('click', function () {
if (window.confirm('Are you sure you want to remove this branch?')) {
return true;
}
else {
return false;
}
});
});
% end
%= include '/include/header';
<div class="container" style="padding-bottom:30px">
%= include '/include/errors', errors => $errors;
%= include '/include/message', message => flash('message');
%= include '/include/project_header';
%= include '/include/code_menu', display => 'branches', branches => $branches;
<h3 style="font-size:19px">Branches</h3>
<div style="margin-bottom:10px">
Showing
<span id="no-merged-branch-message">
<%= $no_merged_branches_count %> branches not merged
</span>
<span style="display:none" id="merged-branch-message">
<%= $merged_branches_count %> branches merged
</span>
into <%= $base_branch->{name} %>.
<a id="toggle-branch" href="#">View merged branches</a>
</div>
<div class="bk-black" style="padding:5px 10px">
<div class="row">
<div class="span8" style="line-height:1.2em">
<div style="color:white;font-size:16px;">
<b><%= $base_branch->{name} %></b>
</div>
<div class="muted" style="font-size:12px">
Last updated
<span title="<%= $base_branch->{commit}{age_string_datetime_local} %>">
<%= $base_branch->{commit}{age_string} %>
</span>
by
<span title="<%= $base_branch->{commit}{author_email} %>" style="color:white">
<%= $base_branch->{commit}{author_name} %>
</span>
</div>
</div>
<div class="text-right font-white" style="padding-top:6px">
Base branch
</div>
</div>
</div>
% for (my $i = 0; $i < @$branches; $i++) {
% my $branch = $branches->[$i];
% my $bname = $branch->{name};
% next if $bname eq $base_branch->{name};
<div class="<%= $branch->{no_merged} ? 'no-merged-branch' : 'merged-branch' %> border-bottom-gray" style="padding:10px 0px 5px 0px;<%= $branch->{no_merged} ? '' : 'display:none' %>">
<div class="row">
<div class="span5" style="line-height:1.2em">
<div style="font-size:16px;">
<a href="<%= url_for("/$user/$project/tree/$bname") %>">
<b><%= $bname %></b>
</a>
</div>
<div style="font-size:12px">
Last updated
<span title="<%= $branch->{commit}{age_string_datetime_local} %>">
<%= $branch->{commit}{age_string} %>
</span>
by
<span title="<%= $branch->{commit}{author_email} %>">
<%= $branch->{commit}{author_name} %>
</span>
</div>
</div>
<div class="span3 muted" style="line-height:1em;font-size:11px">
<table>
<tr>
<td>
</td>
<td style="background:#333">
</td>
<td style="padding-left:3px">
<%= $branch->{status}{ahead} %> ahead
</td>
</tr>
<tr>
<td style="width:100px">
<div style="margin-left:auto;margin-right:0;background:#b2d0dd;width:<%= $max != 0 ? 100 * ($branch->{status}{behind} / $max) : 0 %>%;height:8px"></div>
</td>
<td style="background:#333">
</td>
<td style="width:100px">
<div style="background:#b2d0dd;width:<%= $max != 0 ? 100 * ($branch->{status}{ahead} / $max) : 0 %>%;height:8px"></div>
</td>
</tr>
<tr>
<td>
<%= $branch->{status}{behind} %> behind
</td>
<td style="background:#333">
</td>
<td>
</td>
</tr>
</table>
</div>
<div class="span4 text-right" style="padding-top:0px">
% if ($api->logined($user)) {
<form action="<%= url_for->query(op => 'delete') %>" method="post" style="display:inline-block">
<input type="submit" class="btn delete-branch" style="color:#900;" value="Delete branch">
%= hidden_field branch => $bname;
</form>
% }
<a class="btn" href="<%= url_for("/$user/$project/compare/$base_branch->{name}...$bname") %>">
Compare
</a>
% if (app->config->{basic}{show_ignore_space_change_link}) {
(<a style="font-size:90%;color:#9999FF" href="<%= url_for("/$user/$project/compare/$base_branch->{name}...$bname?w=") %>">
ignore space
</a>)
% }
</div>
</div>
</div>
% }
</div>
%= include '/include/footer';