setting page
|
1 |
<% |
add create repository tests
|
2 |
# API |
added description changed fe...
|
3 |
my $api = gitprep_api; |
revert encoding support
|
4 |
my $manager = app->manager; |
add create repository tests
|
5 |
|
6 |
# Parameters |
|
added description changed fe...
|
7 |
my $op = param('op') || ''; |
fix setting page
|
8 |
my $user_id = param('user') || ''; |
9 |
my $user_row_id = $api->get_user_row_id($user_id); |
|
10 |
my $project_id = param('project'); |
|
added description changed fe...
|
11 |
|
add create repository tests
|
12 |
# Authentication |
fix setting page
|
13 |
unless ($api->logined($user_id)) { |
add create repository tests
|
14 |
$self->redirect_to('/'); |
cleanup
|
15 |
return; |
16 |
} |
|
added description changed fe...
|
17 |
|
add create repository tests
|
18 |
# Rename project |
revert encoding support
|
19 |
my $git = app->git; |
simplify rename project
|
20 |
my $errors; |
cleanup settings
|
21 |
if (lc $self->req->method eq 'post') { |
22 |
if ($op eq 'rename-project') { |
|
23 |
|
|
24 |
# Parameters |
|
25 |
my $to_project = param('to-project'); |
|
26 |
|
|
27 |
# Validator |
|
28 |
my $vc = app->vc; |
|
29 |
|
|
30 |
# Validation result |
|
31 |
my $validation = $vc->validation; |
|
32 |
|
|
33 |
# "to-project" check |
|
34 |
if (!(defined $to_project && length $to_project)) { |
|
35 |
$validation->add_failed('to-project' => 'Repository name is empty.'); |
|
36 |
} |
|
add validation to settings p...
|
37 |
elsif (length $to_project > 300) { |
38 |
$validation->add_failed('to-project' => 'Repository name is too long.'); |
|
39 |
} |
|
cleanup settings
|
40 |
elsif (!$vc->check($to_project, 'project_name')) { |
41 |
$validation->add_failed('to-project' => 'Repository name contains invalid charactor.'); |
|
42 |
} |
|
fix setting page
|
43 |
elsif (app->manager->exists_project($user_id, $to_project)) { |
cleanup settings
|
44 |
$validation->add_failed('to-project' => "$to_project is already exists"); |
45 |
} |
|
46 |
|
|
47 |
if ($validation->is_valid) { |
|
48 |
# Rename |
|
fix setting page
|
49 |
eval { app->manager->rename_project($user_id, $project_id, $to_project) }; |
cleanup settings
|
50 |
if (my $e = $@) { |
51 |
app->log->error($e); |
|
52 |
$errors = ['Internal Error']; |
|
53 |
} |
|
54 |
else { |
|
55 |
flash(message => "Repository name is renamed to $to_project"); |
|
fix setting page
|
56 |
$self->redirect_to("/$user_id/$to_project/settings"); |
cleanup settings
|
57 |
return; |
58 |
} |
|
59 |
} |
|
60 |
else { $errors = $validation->messages } |
|
cleanup setting validation
|
61 |
} |
62 |
|
|
cleanup settings
|
63 |
# Change description |
64 |
elsif ($op eq 'change-description') { |
|
add validation to settings p...
|
65 |
|
66 |
# Parameters |
|
cleanup settings
|
67 |
my $description = param('description'); |
68 |
$description = '' unless defined $description; |
|
add validation to settings p...
|
69 |
|
70 |
# Validator |
|
71 |
my $vc = app->vc; |
|
72 |
|
|
73 |
# Validation result |
|
74 |
my $validation = $vc->validation; |
|
cleanup settings
|
75 |
|
add validation to settings p...
|
76 |
if (length $description > 300) { |
77 |
$validation->add_failed(description => 'description is too long'); |
|
added project rename feature
|
78 |
} |
add validation to settings p...
|
79 |
|
80 |
if ($validation->is_valid) { |
|
81 |
eval { $git->description(app->rep_info($user_id, $project_id), $description) }; |
|
82 |
if (my $e = $@) { |
|
83 |
app->log->error("/$user_id/$project_id/settings?op=description: $e"); |
|
84 |
$errors = ['Internal Error']; |
|
85 |
} |
|
86 |
else { |
|
87 |
flash(message => 'Description is saved.'); |
|
88 |
$self->redirect_to('current'); |
|
89 |
return; |
|
90 |
} |
|
added project rename feature
|
91 |
} |
92 |
} |
|
cleanup change default branc...
|
93 |
|
cleanup settings
|
94 |
# Change default branch |
cleanup settings page logic
|
95 |
elsif ($op eq 'save-settings') { |
96 |
|
|
97 |
# Parameters |
|
cleanup settings
|
98 |
my $default_branch = param('default-branch'); |
cleanup settings page logic
|
99 |
my $private = param('private'); |
remove [basic]show_ignore_sp...
|
100 |
my $ignore_space_change = param('ignore_space_change'); |
add guess_encoding column an...
|
101 |
my $guess_encoding = param('guess_encoding'); |
add validation to settings p...
|
102 | |
103 |
# Validator |
|
104 |
my $vc = app->vc; |
|
105 |
|
|
106 |
# Validation result |
|
107 |
my $validation = $vc->validation; |
|
108 |
|
|
109 |
# Check default branch |
|
110 |
if (length $default_branch > 300) { |
|
111 |
$validation->add_failed('default-branch' => 'default branch is too long'); |
|
112 |
} |
|
113 |
|
|
114 |
# Check private |
|
115 |
$private = $private ? 1 : 0; |
|
116 |
|
|
117 |
# Check ignore space change |
|
118 |
$ignore_space_change = $ignore_space_change ? 1 : 0; |
|
119 |
|
|
120 |
# Check guess encoding |
|
121 |
$guess_encoding //= ''; |
|
122 |
if (length $guess_encoding > 300) { |
|
123 |
$validation->add_failed(guess_encoding => 'guess_encoding is too long'); |
|
124 |
} |
|
remove [basic]show_ignore_sp...
|
125 |
|
cleanup settings page logic
|
126 |
my $params = {}; |
127 |
if (defined $default_branch) { |
|
128 |
$params->{default_branch} = $default_branch; |
|
129 |
} |
|
130 |
if (defined $private) { |
|
add validation to settings p...
|
131 |
$params->{private} = $private; |
cleanup settings page logic
|
132 |
}; |
remove [basic]show_ignore_sp...
|
133 |
if (defined $ignore_space_change) { |
add validation to settings p...
|
134 |
$params->{ignore_space_change} = $ignore_space_change; |
remove [basic]show_ignore_sp...
|
135 |
} |
add guess_encoding column an...
|
136 |
if (defined $guess_encoding) { |
137 |
$params->{guess_encoding} = $guess_encoding; |
|
138 |
} |
|
cleanup settings
|
139 |
|
140 |
my $dbi = app->dbi; |
|
141 |
eval { |
|
142 |
$dbi->model('project')->update( |
|
cleanup settings page logic
|
143 |
$params, |
fix setting page
|
144 |
where => {user => $user_row_id, id => $project_id} |
cleanup settings
|
145 |
); |
146 |
}; |
|
147 |
|
|
148 |
if (my $e = $@) { |
|
fix setting page
|
149 |
app->log->error("/$user_id/$project_id/settings?op=save-settings: $e"); |
cleanup settings
|
150 |
$errors = ['Internal Error']; |
151 |
} |
|
152 |
else { |
|
cleanup settings page logic
|
153 |
flash(message => "Settings is saved"); |
cleanup settings
|
154 |
$self->redirect_to('current'); |
155 |
return; |
|
156 |
} |
|
add private checkbox
|
157 |
} |
added project delete feature
|
158 |
|
cleanup settings
|
159 |
# Delete project |
160 |
elsif ($op eq 'delete-project') { |
|
161 |
|
|
fix setting page
|
162 |
my $user_id = param('user'); |
163 |
my $project_id = param('project'); |
|
cleanup settings
|
164 |
|
fix setting page
|
165 |
eval { app->manager->delete_project($user_id, $project_id) }; |
cleanup settings
|
166 |
if (my $e = $@) { |
fix setting page
|
167 |
app->log->error("/$user_id/$project_id/settings: $e"); |
cleanup settings
|
168 |
$errors = ['Internal Error']; |
169 |
} |
|
170 |
else { |
|
fix setting page
|
171 |
flash(message => "Repository $project_id is deleted."); |
172 |
$self->redirect_to("/$user_id"); |
|
cleanup settings
|
173 |
return; |
174 |
} |
|
added project delete feature
|
175 |
} |
176 |
} |
|
setting page
|
177 |
%> |
178 | ||
add title
|
179 |
% layout 'common', title => 'Options'; |
setting page
|
180 |
|
added description changed fe...
|
181 |
%= javascript begin |
added project delete feature
|
182 |
|
added description changed fe...
|
183 |
$(document).ready(function () { |
added project delete feature
|
184 |
|
simplify rename project
|
185 |
// Rename project |
added project rename feature
|
186 |
$('#rename').on('click', function () { |
simplify rename project
|
187 |
$('#form-rename-project').submit(); |
added description changed fe...
|
188 |
}); |
added default branch change ...
|
189 | |
added project delete feature
|
190 |
// Check matching deleted project |
191 |
$('input[name="deleted-project"]').on('keyup', function () { |
|
192 |
var deleted_project = $(this).val(); |
|
fix setting page
|
193 |
var project = "<%= $project_id %>"; |
added project delete feature
|
194 |
|
195 |
if (deleted_project == project) { |
|
196 |
$('#delete').attr('class', 'btn btn-danger') |
|
197 |
.removeAttr('disabled'); |
|
198 |
} |
|
199 |
else { |
|
200 |
$('#delete').attr('class', 'btn btn-danger disabled') |
|
201 |
.attr('disabled', 'disabled'); |
|
202 |
} |
|
203 |
}); |
|
added default branch change ...
|
204 |
|
added project delete feature
|
205 |
// Delete project |
206 |
$('#delete').on('click', function () { |
|
simplify delete project
|
207 |
$('#form-delete-project').submit(); |
added project delete feature
|
208 |
}); |
added description changed fe...
|
209 |
}); |
210 |
% end |
|
211 |
|
|
setting page
|
212 |
%= include '/include/header'; |
213 |
|
|
214 |
<div class="container"> |
|
simplify rename project
|
215 |
%= include '/include/errors', errors => $errors; |
216 |
%= include '/include/message', message => flash('message'); |
|
setting page
|
217 |
|
improve settings page design
|
218 |
<div class="project-settings"> |
219 |
<div class="left"> |
|
220 |
<ul> |
|
221 |
<li><b>Options</b></li> |
|
fix setting page
|
222 |
<li><a href="<%= url_for("/$user_id/$project_id/settings/collaboration") %>">Collaborators</a></li> |
add collaboration page
|
223 |
</ul> |
setting page
|
224 |
</div> |
improve settings page design
|
225 |
<div class="right"> |
repository name setting is s...
|
226 | |
improve settings page design
|
227 |
<ul class="project-settings-main"> |
228 |
<li> |
|
add collaboration page
|
229 |
<h4> |
repository name setting is s...
|
230 |
Repository name |
add collaboration page
|
231 |
</h4> |
improve settings page design
|
232 |
</li> |
233 |
<li> |
|
234 |
<form id="form-rename-project" action="<%= url_for->query(op => 'rename-project') %>" method="post"> |
|
add collaboration page
|
235 |
<div> |
fix setting page
|
236 |
%= text_field 'to-project' => $project_id, style => "width:80%"; |
add collaboration page
|
237 |
<a href="#rename-confirm" role="button" class="btn" data-toggle="modal"> |
238 |
Rename |
|
239 |
</a> |
|
240 |
</div> |
|
241 |
</form> |
|
improve settings page design
|
242 |
</li> |
repository name setting is s...
|
243 |
</ul> |
setting description is separ...
|
244 | |
repository name setting is s...
|
245 |
<ul class="project-settings-main"> |
246 |
<li> |
|
247 |
<h4> |
|
setting description is separ...
|
248 |
Description |
repository name setting is s...
|
249 |
</h4> |
250 |
</li> |
|
improve settings page design
|
251 |
<li> |
252 |
<form action="<%= url_for->query(op => 'change-description') %>" method="post"> |
|
add collaboration page
|
253 |
<div> |
fix setting page
|
254 |
% my $description = $git->description(app->rep_info($user_id, $project_id)); |
add collaboration page
|
255 |
% $description = '' unless defined $description; |
setting description is separ...
|
256 |
%= text_field 'description' => $description, style => "width:90%"; |
add collaboration page
|
257 |
<input type="submit" class="btn" value="Save"> |
258 |
</div> |
|
259 |
</form> |
|
improve settings page design
|
260 |
</li> |
setting description is separ...
|
261 |
</ul> |
262 |
|
|
cleanup settings page logic
|
263 |
<form id="form-default-branch" action="<%= url_for %>" method="post"> |
264 |
%= hidden_field op => 'save-settings'; |
|
265 |
<ul class="project-settings-main"> |
|
266 |
<li> |
|
267 |
<h4> |
|
268 |
Settings |
|
269 |
</h4> |
|
270 |
</li> |
|
improve default branch link
|
271 |
<li id="default-branch"> |
add collaboration page
|
272 |
Default Branch |
improve settings page design
|
273 |
<% |
fix setting page
|
274 |
my $branches = $git->branches($self->app->rep_info($user_id, $project_id)); |
improve settings page design
|
275 |
my $branch_names = [map { $_->{name} } @$branches]; |
fix setting page
|
276 |
my $default_branch = app->manager->default_branch($user_id, $project_id); |
improve settings page design
|
277 |
push @$branch_names, $default_branch unless @$branch_names; |
278 |
param('default-branch', $default_branch); |
|
279 |
%> |
|
280 |
%= select_field 'default-branch' => $branch_names; |
|
cleanup settings page logic
|
281 |
</li> |
282 |
<li> |
|
add collaboration page
|
283 |
<span>Make this repository private</span> |
fix setting page
|
284 |
% my $private = app->manager->is_private_project($user_id, $project_id); |
285 |
% my @private_checked = $private ? (checked => undef) : (); |
|
remove [basic]show_ignore_sp...
|
286 |
%= hidden_field 'private' => 0; |
fix setting page
|
287 |
%= check_box 'private' => 1, @private_checked; |
cleanup settings page logic
|
288 |
</li> |
remove [basic]show_ignore_sp...
|
289 |
<li> |
290 |
<% |
|
291 |
my $ignore_space_change = app->dbi->model('project')->select( |
|
292 |
'ignore_space_change', |
|
fix setting page
|
293 |
where => {user => $user_row_id, id => $project_id} |
remove [basic]show_ignore_sp...
|
294 |
)->value; |
add guess_encoding column an...
|
295 |
my @ignore_space_change_checked = $ignore_space_change ? (checked => undef) : (); |
remove [basic]show_ignore_sp...
|
296 |
%> |
297 |
<span>Ignore space change in diff</span> |
|
298 |
|
|
299 |
%= hidden_field 'ignore_space_change' => 0; |
|
add guess_encoding column an...
|
300 |
%= check_box 'ignore_space_change' => 1, @ignore_space_change_checked; |
301 |
</li> |
|
302 |
<li> |
|
303 |
<% |
|
304 |
my $guess_encoding = app->dbi->model('project')->select( |
|
305 |
'guess_encoding', |
|
fix setting page
|
306 |
where => {user => $user_row_id, id => $project_id} |
add guess_encoding column an...
|
307 |
)->value; |
308 |
%> |
|
309 |
<div>Guess encoding</div> |
|
310 |
(Guess encoding from the following encoding list. default is "UTF-8". |
|
311 |
if your source code is different from UTF-8, set comma separated encoding list. |
|
312 |
For example "cp932,UTF-8") |
|
313 |
%= text_field 'guess_encoding' => $guess_encoding; |
|
remove [basic]show_ignore_sp...
|
314 |
</li> |
cleanup settings page logic
|
315 |
<li> |
add collaboration page
|
316 |
<input type="submit" class="btn" value="Save"> |
cleanup settings page logic
|
317 |
</li> |
318 |
</ul> |
|
319 |
</form> |
|
repository name setting is s...
|
320 | |
improve settings page design
|
321 |
<ul class="project-settings-danger"> |
322 |
<li style="background:red;padding-left:5px"> |
|
add collaboration page
|
323 |
<h4 style="color:white">Danger Zone</h4> |
improve settings page design
|
324 |
</li> |
325 |
<li class="border-gray radius-bottom" style="padding:5px 10px;border-top:none"> |
|
add collaboration page
|
326 |
<form id="form-delete-project" action="<%= url_for->query(op => 'delete-project') %>" method="post"> |
327 |
<div><b>Delete this repository</b></div> |
|
328 |
<span class="muted"> |
|
329 |
Once you delete a repository, there is no going back. |
|
330 |
</span> |
|
331 |
<a style="color:red" href="#delete-confirm" role="button" class="btn" data-toggle="modal"> |
|
332 |
Delete this repository |
|
333 |
</a> |
|
fix setting page
|
334 |
%= hidden_field user => $user_id; |
335 |
%= hidden_field project => $project_id; |
|
add collaboration page
|
336 |
</form> |
improve settings page design
|
337 |
</li> |
338 |
</ul> |
|
simplify delete project
|
339 |
</div> |
setting page
|
340 |
</div> |
341 |
</div> |
|
342 |
|
|
move project delete feature ...
|
343 |
<div id="modal-message" class="modal hide"> |
added description changed fe...
|
344 |
<div class="modal-header"> |
move project delete feature ...
|
345 |
<div id="modal-message-text" style="font-weight:bold"></div> |
added description changed fe...
|
346 |
</div> |
347 |
<div class="modal-body"> |
|
348 |
<button class="btn" data-dismiss="modal" aria-hidden="true">OK</button> |
|
349 |
</div> |
|
350 |
</div> |
|
added project rename feature
|
351 | |
352 |
<div id="rename-confirm" class="modal hide" tabindex="-1" role="dialog" aria-labelledby="rename-confirm-label" aria-hidden="true"> |
|
353 |
<div class="modal-header"> |
|
revert encoding support
|
354 |
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button> |
improve settings page design
|
355 |
<div style="font-weight:bold;">Are you sure you want to rename?</div> |
added project rename feature
|
356 |
</div> |
357 |
<div class="modal-body"> |
|
358 |
<p> |
|
359 |
Unexpected bad things will happen if you don't read this |
|
360 |
</p> |
|
361 |
<ul> |
|
362 |
<li> |
|
363 |
We will not set up any redirects from the old location |
|
364 |
</li> |
|
365 |
<li> |
|
366 |
You will need to update your local repositories to point to the new location |
|
367 |
</li> |
|
368 |
</ul> |
|
369 |
</div> |
|
370 |
<div class="modal-footer"> |
|
371 |
<button id="rename" class="btn" data-dismiss="modal" aria-hidden="true"> |
|
372 |
I understand, rename this repository |
|
373 |
</button> |
|
374 |
</div> |
|
375 |
</div> |
|
376 | ||
added project delete feature
|
377 |
<div id="delete-confirm" class="modal hide" tabindex="-1" role="dialog" aria-labelledby="delete-confirm-label" aria-hidden="true"> |
378 |
<div class="modal-header"> |
|
revert encoding support
|
379 |
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button> |
move project delete feature ...
|
380 |
<div style="font-weight:bold">Are you ABSOLUTELY sure?</div> |
added project delete feature
|
381 |
</div> |
382 |
<div class="modal-body"> |
|
383 |
<p> |
|
384 |
Unexpected bad things will happen if you don't read this. |
|
385 |
</p> |
|
386 |
<p> |
|
fix setting page
|
387 |
This action <b>CANNOT</b> be undone. This will delete the <b><%= "$user_id/$project_id" %></b> |
added project delete feature
|
388 |
repository, wiki, issues, and comments permanently. |
389 |
</p> |
|
390 |
<p> |
|
fix setting page
|
391 |
Please type in the name of the repository(<b><%= $project_id %></b>) to confirm. |
added project delete feature
|
392 |
</p> |
improve settings page design
|
393 |
%= text_field 'deleted-project'; |
added project delete feature
|
394 |
</div> |
395 |
<div class="modal-footer"> |
|
396 |
<button id="delete" class="btn btn-danger disabled" disabled data-dismiss="modal" aria-hidden="true"> |
|
397 |
I understand the consequences, delete this repository |
|
398 |
</button> |
|
399 |
</div> |
|
400 |
</div> |
|
added description changed fe...
|
401 | |
setting page
|
402 |
%= include '/include/footer'; |