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 { |
|
add website URL settings. yo...
|
87 |
flash(message => 'Description is changed.'); |
add validation to settings p...
|
88 |
$self->redirect_to('current'); |
89 |
return; |
|
90 |
} |
|
added project rename feature
|
91 |
} |
92 |
} |
|
add website URL settings. yo...
|
93 | |
94 |
# Change website URL |
|
95 |
elsif ($op eq 'change-website-url') { |
|
96 |
|
|
97 |
# Parameters |
|
98 |
my $website_url = param('website-url'); |
|
99 |
$website_url = '' unless defined $website_url; |
|
100 |
|
|
101 |
# Validator |
|
102 |
my $vc = app->vc; |
|
103 |
|
|
104 |
# Validation result |
|
105 |
my $validation = $vc->validation; |
|
106 |
|
|
107 |
if (length $website_url > 300) { |
|
108 |
$validation->add_failed('website-url' => 'Website URL is too long'); |
|
109 |
} |
|
110 |
|
|
111 |
if ($validation->is_valid) { |
|
112 |
app->dbi->model('project')->update( |
|
113 |
{website_url => $website_url}, |
|
114 |
where => {user => $user_row_id, id => $project_id} |
|
115 |
); |
|
116 |
|
|
117 |
flash(message => 'Website URL is changed.'); |
|
118 |
$self->redirect_to('current'); |
|
119 |
return; |
|
120 |
} |
|
121 |
} |
|
cleanup change default branc...
|
122 |
|
cleanup settings
|
123 |
# Change default branch |
cleanup settings page logic
|
124 |
elsif ($op eq 'save-settings') { |
125 |
|
|
126 |
# Parameters |
|
cleanup settings
|
127 |
my $default_branch = param('default-branch'); |
cleanup settings page logic
|
128 |
my $private = param('private'); |
remove [basic]show_ignore_sp...
|
129 |
my $ignore_space_change = param('ignore_space_change'); |
add guess_encoding column an...
|
130 |
my $guess_encoding = param('guess_encoding'); |
add validation to settings p...
|
131 | |
132 |
# Validator |
|
133 |
my $vc = app->vc; |
|
134 |
|
|
135 |
# Validation result |
|
136 |
my $validation = $vc->validation; |
|
137 |
|
|
138 |
# Check default branch |
|
fix warnings
|
139 |
if (defined $default_branch && length $default_branch > 300) { |
add validation to settings p...
|
140 |
$validation->add_failed('default-branch' => 'default branch is too long'); |
141 |
} |
|
142 |
|
|
143 |
# Check private |
|
144 |
$private = $private ? 1 : 0; |
|
145 |
|
|
146 |
# Check ignore space change |
|
147 |
$ignore_space_change = $ignore_space_change ? 1 : 0; |
|
148 |
|
|
149 |
# Check guess encoding |
|
150 |
$guess_encoding //= ''; |
|
151 |
if (length $guess_encoding > 300) { |
|
152 |
$validation->add_failed(guess_encoding => 'guess_encoding is too long'); |
|
153 |
} |
|
remove [basic]show_ignore_sp...
|
154 |
|
cleanup settings page logic
|
155 |
my $params = {}; |
156 |
if (defined $default_branch) { |
|
157 |
$params->{default_branch} = $default_branch; |
|
158 |
} |
|
159 |
if (defined $private) { |
|
add validation to settings p...
|
160 |
$params->{private} = $private; |
cleanup settings page logic
|
161 |
}; |
remove [basic]show_ignore_sp...
|
162 |
if (defined $ignore_space_change) { |
add validation to settings p...
|
163 |
$params->{ignore_space_change} = $ignore_space_change; |
remove [basic]show_ignore_sp...
|
164 |
} |
add guess_encoding column an...
|
165 |
if (defined $guess_encoding) { |
166 |
$params->{guess_encoding} = $guess_encoding; |
|
167 |
} |
|
cleanup settings
|
168 |
|
169 |
my $dbi = app->dbi; |
|
170 |
eval { |
|
171 |
$dbi->model('project')->update( |
|
cleanup settings page logic
|
172 |
$params, |
fix setting page
|
173 |
where => {user => $user_row_id, id => $project_id} |
cleanup settings
|
174 |
); |
175 |
}; |
|
176 |
|
|
177 |
if (my $e = $@) { |
|
fix setting page
|
178 |
app->log->error("/$user_id/$project_id/settings?op=save-settings: $e"); |
cleanup settings
|
179 |
$errors = ['Internal Error']; |
180 |
} |
|
181 |
else { |
|
cleanup settings page logic
|
182 |
flash(message => "Settings is saved"); |
cleanup settings
|
183 |
$self->redirect_to('current'); |
184 |
return; |
|
185 |
} |
|
add private checkbox
|
186 |
} |
added project delete feature
|
187 |
|
cleanup settings
|
188 |
# Delete project |
189 |
elsif ($op eq 'delete-project') { |
|
190 |
|
|
fix setting page
|
191 |
my $user_id = param('user'); |
192 |
my $project_id = param('project'); |
|
cleanup settings
|
193 |
|
fix setting page
|
194 |
eval { app->manager->delete_project($user_id, $project_id) }; |
cleanup settings
|
195 |
if (my $e = $@) { |
fix setting page
|
196 |
app->log->error("/$user_id/$project_id/settings: $e"); |
cleanup settings
|
197 |
$errors = ['Internal Error']; |
198 |
} |
|
199 |
else { |
|
fix setting page
|
200 |
flash(message => "Repository $project_id is deleted."); |
201 |
$self->redirect_to("/$user_id"); |
|
cleanup settings
|
202 |
return; |
203 |
} |
|
added project delete feature
|
204 |
} |
205 |
} |
|
setting page
|
206 |
%> |
207 | ||
add title
|
208 |
% layout 'common', title => 'Options'; |
setting page
|
209 |
|
added description changed fe...
|
210 |
%= javascript begin |
added project delete feature
|
211 |
|
added description changed fe...
|
212 |
$(document).ready(function () { |
added project delete feature
|
213 |
|
simplify rename project
|
214 |
// Rename project |
added project rename feature
|
215 |
$('#rename').on('click', function () { |
simplify rename project
|
216 |
$('#form-rename-project').submit(); |
added description changed fe...
|
217 |
}); |
added default branch change ...
|
218 | |
added project delete feature
|
219 |
// Check matching deleted project |
220 |
$('input[name="deleted-project"]').on('keyup', function () { |
|
221 |
var deleted_project = $(this).val(); |
|
fix setting page
|
222 |
var project = "<%= $project_id %>"; |
added project delete feature
|
223 |
|
224 |
if (deleted_project == project) { |
|
225 |
$('#delete').attr('class', 'btn btn-danger') |
|
226 |
.removeAttr('disabled'); |
|
227 |
} |
|
228 |
else { |
|
229 |
$('#delete').attr('class', 'btn btn-danger disabled') |
|
230 |
.attr('disabled', 'disabled'); |
|
231 |
} |
|
232 |
}); |
|
added default branch change ...
|
233 |
|
added project delete feature
|
234 |
// Delete project |
235 |
$('#delete').on('click', function () { |
|
simplify delete project
|
236 |
$('#form-delete-project').submit(); |
added project delete feature
|
237 |
}); |
added description changed fe...
|
238 |
}); |
239 |
% end |
|
240 |
|
|
setting page
|
241 |
%= include '/include/header'; |
242 |
|
|
243 |
<div class="container"> |
|
simplify rename project
|
244 |
%= include '/include/errors', errors => $errors; |
245 |
%= include '/include/message', message => flash('message'); |
|
setting page
|
246 |
|
improve settings page design
|
247 |
<div class="project-settings"> |
248 |
<div class="left"> |
|
249 |
<ul> |
|
250 |
<li><b>Options</b></li> |
|
fix setting page
|
251 |
<li><a href="<%= url_for("/$user_id/$project_id/settings/collaboration") %>">Collaborators</a></li> |
add collaboration page
|
252 |
</ul> |
setting page
|
253 |
</div> |
improve settings page design
|
254 |
<div class="right"> |
repository name setting is s...
|
255 | |
improve settings page design
|
256 |
<ul class="project-settings-main"> |
257 |
<li> |
|
add collaboration page
|
258 |
<h4> |
repository name setting is s...
|
259 |
Repository name |
add collaboration page
|
260 |
</h4> |
improve settings page design
|
261 |
</li> |
262 |
<li> |
|
263 |
<form id="form-rename-project" action="<%= url_for->query(op => 'rename-project') %>" method="post"> |
|
add collaboration page
|
264 |
<div> |
fix setting page
|
265 |
%= text_field 'to-project' => $project_id, style => "width:80%"; |
add collaboration page
|
266 |
<a href="#rename-confirm" role="button" class="btn" data-toggle="modal"> |
267 |
Rename |
|
268 |
</a> |
|
269 |
</div> |
|
270 |
</form> |
|
improve settings page design
|
271 |
</li> |
repository name setting is s...
|
272 |
</ul> |
setting description is separ...
|
273 | |
repository name setting is s...
|
274 |
<ul class="project-settings-main"> |
275 |
<li> |
|
276 |
<h4> |
|
setting description is separ...
|
277 |
Description |
repository name setting is s...
|
278 |
</h4> |
279 |
</li> |
|
improve settings page design
|
280 |
<li> |
281 |
<form action="<%= url_for->query(op => 'change-description') %>" method="post"> |
|
add collaboration page
|
282 |
<div> |
fix setting page
|
283 |
% my $description = $git->description(app->rep_info($user_id, $project_id)); |
add collaboration page
|
284 |
% $description = '' unless defined $description; |
setting description is separ...
|
285 |
%= text_field 'description' => $description, style => "width:90%"; |
add collaboration page
|
286 |
<input type="submit" class="btn" value="Save"> |
287 |
</div> |
|
288 |
</form> |
|
improve settings page design
|
289 |
</li> |
setting description is separ...
|
290 |
</ul> |
add website URL settings. yo...
|
291 | |
292 |
<ul class="project-settings-main"> |
|
293 |
<li> |
|
294 |
<h4> |
|
295 |
Website URL |
|
296 |
</h4> |
|
297 |
</li> |
|
298 |
<li> |
|
299 |
<form action="<%= url_for->query(op => 'change-website-url') %>" method="post"> |
|
300 |
<div> |
|
301 |
<% |
|
302 |
my $website_url = app->dbi->model('project')->select('website_url', where => {user => $user_row_id, id => $project_id})->value; |
|
303 |
$website_url = '' unless defined $website_url; |
|
304 |
%> |
|
305 |
|
|
306 |
%= text_field 'website-url' => $website_url, style => "width:90%"; |
|
307 |
<input type="submit" class="btn" value="Save"> |
|
308 |
</div> |
|
309 |
</form> |
|
310 |
</li> |
|
311 |
</ul> |
|
setting description is separ...
|
312 |
|
cleanup settings page logic
|
313 |
<form id="form-default-branch" action="<%= url_for %>" method="post"> |
314 |
%= hidden_field op => 'save-settings'; |
|
315 |
<ul class="project-settings-main"> |
|
316 |
<li> |
|
317 |
<h4> |
|
318 |
Settings |
|
319 |
</h4> |
|
320 |
</li> |
|
improve default branch link
|
321 |
<li id="default-branch"> |
add collaboration page
|
322 |
Default Branch |
improve settings page design
|
323 |
<% |
fix setting page
|
324 |
my $branches = $git->branches($self->app->rep_info($user_id, $project_id)); |
improve settings page design
|
325 |
my $branch_names = [map { $_->{name} } @$branches]; |
fix setting page
|
326 |
my $default_branch = app->manager->default_branch($user_id, $project_id); |
improve settings page design
|
327 |
push @$branch_names, $default_branch unless @$branch_names; |
328 |
param('default-branch', $default_branch); |
|
329 |
%> |
|
330 |
%= select_field 'default-branch' => $branch_names; |
|
cleanup settings page logic
|
331 |
</li> |
332 |
<li> |
|
add collaboration page
|
333 |
<span>Make this repository private</span> |
fix setting page
|
334 |
% my $private = app->manager->is_private_project($user_id, $project_id); |
335 |
% my @private_checked = $private ? (checked => undef) : (); |
|
remove [basic]show_ignore_sp...
|
336 |
%= hidden_field 'private' => 0; |
fix setting page
|
337 |
%= check_box 'private' => 1, @private_checked; |
cleanup settings page logic
|
338 |
</li> |
remove [basic]show_ignore_sp...
|
339 |
<li> |
340 |
<% |
|
341 |
my $ignore_space_change = app->dbi->model('project')->select( |
|
342 |
'ignore_space_change', |
|
fix setting page
|
343 |
where => {user => $user_row_id, id => $project_id} |
remove [basic]show_ignore_sp...
|
344 |
)->value; |
add guess_encoding column an...
|
345 |
my @ignore_space_change_checked = $ignore_space_change ? (checked => undef) : (); |
remove [basic]show_ignore_sp...
|
346 |
%> |
347 |
<span>Ignore space change in diff</span> |
|
348 |
|
|
349 |
%= hidden_field 'ignore_space_change' => 0; |
|
add guess_encoding column an...
|
350 |
%= check_box 'ignore_space_change' => 1, @ignore_space_change_checked; |
351 |
</li> |
|
352 |
<li> |
|
353 |
<% |
|
354 |
my $guess_encoding = app->dbi->model('project')->select( |
|
355 |
'guess_encoding', |
|
fix setting page
|
356 |
where => {user => $user_row_id, id => $project_id} |
add guess_encoding column an...
|
357 |
)->value; |
358 |
%> |
|
359 |
<div>Guess encoding</div> |
|
360 |
(Guess encoding from the following encoding list. default is "UTF-8". |
|
361 |
if your source code is different from UTF-8, set comma separated encoding list. |
|
362 |
For example "cp932,UTF-8") |
|
363 |
%= text_field 'guess_encoding' => $guess_encoding; |
|
remove [basic]show_ignore_sp...
|
364 |
</li> |
cleanup settings page logic
|
365 |
<li> |
add collaboration page
|
366 |
<input type="submit" class="btn" value="Save"> |
cleanup settings page logic
|
367 |
</li> |
368 |
</ul> |
|
369 |
</form> |
|
repository name setting is s...
|
370 | |
improve settings page design
|
371 |
<ul class="project-settings-danger"> |
372 |
<li style="background:red;padding-left:5px"> |
|
add collaboration page
|
373 |
<h4 style="color:white">Danger Zone</h4> |
improve settings page design
|
374 |
</li> |
375 |
<li class="border-gray radius-bottom" style="padding:5px 10px;border-top:none"> |
|
add collaboration page
|
376 |
<form id="form-delete-project" action="<%= url_for->query(op => 'delete-project') %>" method="post"> |
377 |
<div><b>Delete this repository</b></div> |
|
378 |
<span class="muted"> |
|
379 |
Once you delete a repository, there is no going back. |
|
380 |
</span> |
|
381 |
<a style="color:red" href="#delete-confirm" role="button" class="btn" data-toggle="modal"> |
|
382 |
Delete this repository |
|
383 |
</a> |
|
fix setting page
|
384 |
%= hidden_field user => $user_id; |
385 |
%= hidden_field project => $project_id; |
|
add collaboration page
|
386 |
</form> |
improve settings page design
|
387 |
</li> |
388 |
</ul> |
|
simplify delete project
|
389 |
</div> |
setting page
|
390 |
</div> |
391 |
</div> |
|
392 |
|
|
move project delete feature ...
|
393 |
<div id="modal-message" class="modal hide"> |
added description changed fe...
|
394 |
<div class="modal-header"> |
move project delete feature ...
|
395 |
<div id="modal-message-text" style="font-weight:bold"></div> |
added description changed fe...
|
396 |
</div> |
397 |
<div class="modal-body"> |
|
398 |
<button class="btn" data-dismiss="modal" aria-hidden="true">OK</button> |
|
399 |
</div> |
|
400 |
</div> |
|
added project rename feature
|
401 | |
402 |
<div id="rename-confirm" class="modal hide" tabindex="-1" role="dialog" aria-labelledby="rename-confirm-label" aria-hidden="true"> |
|
403 |
<div class="modal-header"> |
|
revert encoding support
|
404 |
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button> |
improve settings page design
|
405 |
<div style="font-weight:bold;">Are you sure you want to rename?</div> |
added project rename feature
|
406 |
</div> |
407 |
<div class="modal-body"> |
|
408 |
<p> |
|
409 |
Unexpected bad things will happen if you don't read this |
|
410 |
</p> |
|
411 |
<ul> |
|
412 |
<li> |
|
413 |
We will not set up any redirects from the old location |
|
414 |
</li> |
|
415 |
<li> |
|
416 |
You will need to update your local repositories to point to the new location |
|
417 |
</li> |
|
418 |
</ul> |
|
419 |
</div> |
|
420 |
<div class="modal-footer"> |
|
421 |
<button id="rename" class="btn" data-dismiss="modal" aria-hidden="true"> |
|
422 |
I understand, rename this repository |
|
423 |
</button> |
|
424 |
</div> |
|
425 |
</div> |
|
426 | ||
added project delete feature
|
427 |
<div id="delete-confirm" class="modal hide" tabindex="-1" role="dialog" aria-labelledby="delete-confirm-label" aria-hidden="true"> |
428 |
<div class="modal-header"> |
|
revert encoding support
|
429 |
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button> |
move project delete feature ...
|
430 |
<div style="font-weight:bold">Are you ABSOLUTELY sure?</div> |
added project delete feature
|
431 |
</div> |
432 |
<div class="modal-body"> |
|
433 |
<p> |
|
434 |
Unexpected bad things will happen if you don't read this. |
|
435 |
</p> |
|
436 |
<p> |
|
fix setting page
|
437 |
This action <b>CANNOT</b> be undone. This will delete the <b><%= "$user_id/$project_id" %></b> |
added project delete feature
|
438 |
repository, wiki, issues, and comments permanently. |
439 |
</p> |
|
440 |
<p> |
|
fix setting page
|
441 |
Please type in the name of the repository(<b><%= $project_id %></b>) to confirm. |
added project delete feature
|
442 |
</p> |
improve settings page design
|
443 |
%= text_field 'deleted-project'; |
added project delete feature
|
444 |
</div> |
445 |
<div class="modal-footer"> |
|
446 |
<button id="delete" class="btn btn-danger disabled" disabled data-dismiss="modal" aria-hidden="true"> |
|
447 |
I understand the consequences, delete this repository |
|
448 |
</button> |
|
449 |
</div> |
|
450 |
</div> |
|
added description changed fe...
|
451 | |
setting page
|
452 |
%= include '/include/footer'; |