forked from yuki-kimoto/gitprep
-
Notifications
You must be signed in to change notification settings - Fork 0
/
settings.html.ep
452 lines (396 loc) · 14.4 KB
/
settings.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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
<%
# API
my $api = gitprep_api;
my $manager = app->manager;
# Parameters
my $op = param('op') || '';
my $user_id = param('user') || '';
my $user_row_id = $api->get_user_row_id($user_id);
my $project_id = param('project');
# Authentication
unless ($api->logined($user_id)) {
$self->redirect_to('/');
return;
}
# Rename project
my $git = app->git;
my $errors;
if (lc $self->req->method eq 'post') {
if ($op eq 'rename-project') {
# Parameters
my $to_project = param('to-project');
# Validator
my $vc = app->vc;
# Validation result
my $validation = $vc->validation;
# "to-project" check
if (!(defined $to_project && length $to_project)) {
$validation->add_failed('to-project' => 'Repository name is empty.');
}
elsif (length $to_project > 300) {
$validation->add_failed('to-project' => 'Repository name is too long.');
}
elsif (!$vc->check($to_project, 'project_name')) {
$validation->add_failed('to-project' => 'Repository name contains invalid charactor.');
}
elsif (app->manager->exists_project($user_id, $to_project)) {
$validation->add_failed('to-project' => "$to_project is already exists");
}
if ($validation->is_valid) {
# Rename
eval { app->manager->rename_project($user_id, $project_id, $to_project) };
if (my $e = $@) {
app->log->error($e);
$errors = ['Internal Error'];
}
else {
flash(message => "Repository name is renamed to $to_project");
$self->redirect_to("/$user_id/$to_project/settings");
return;
}
}
else { $errors = $validation->messages }
}
# Change description
elsif ($op eq 'change-description') {
# Parameters
my $description = param('description');
$description = '' unless defined $description;
# Validator
my $vc = app->vc;
# Validation result
my $validation = $vc->validation;
if (length $description > 300) {
$validation->add_failed(description => 'description is too long');
}
if ($validation->is_valid) {
eval { $git->description(app->rep_info($user_id, $project_id), $description) };
if (my $e = $@) {
app->log->error("/$user_id/$project_id/settings?op=description: $e");
$errors = ['Internal Error'];
}
else {
flash(message => 'Description is changed.');
$self->redirect_to('current');
return;
}
}
}
# Change website URL
elsif ($op eq 'change-website-url') {
# Parameters
my $website_url = param('website-url');
$website_url = '' unless defined $website_url;
# Validator
my $vc = app->vc;
# Validation result
my $validation = $vc->validation;
if (length $website_url > 300) {
$validation->add_failed('website-url' => 'Website URL is too long');
}
if ($validation->is_valid) {
app->dbi->model('project')->update(
{website_url => $website_url},
where => {user => $user_row_id, id => $project_id}
);
flash(message => 'Website URL is changed.');
$self->redirect_to('current');
return;
}
}
# Change default branch
elsif ($op eq 'save-settings') {
# Parameters
my $default_branch = param('default-branch');
my $private = param('private');
my $ignore_space_change = param('ignore_space_change');
my $guess_encoding = param('guess_encoding');
# Validator
my $vc = app->vc;
# Validation result
my $validation = $vc->validation;
# Check default branch
if (defined $default_branch && length $default_branch > 300) {
$validation->add_failed('default-branch' => 'default branch is too long');
}
# Check private
$private = $private ? 1 : 0;
# Check ignore space change
$ignore_space_change = $ignore_space_change ? 1 : 0;
# Check guess encoding
$guess_encoding //= '';
if (length $guess_encoding > 300) {
$validation->add_failed(guess_encoding => 'guess_encoding is too long');
}
my $params = {};
if (defined $default_branch) {
$params->{default_branch} = $default_branch;
}
if (defined $private) {
$params->{private} = $private;
};
if (defined $ignore_space_change) {
$params->{ignore_space_change} = $ignore_space_change;
}
if (defined $guess_encoding) {
$params->{guess_encoding} = $guess_encoding;
}
my $dbi = app->dbi;
eval {
$dbi->model('project')->update(
$params,
where => {user => $user_row_id, id => $project_id}
);
};
if (my $e = $@) {
app->log->error("/$user_id/$project_id/settings?op=save-settings: $e");
$errors = ['Internal Error'];
}
else {
flash(message => "Settings is saved");
$self->redirect_to('current');
return;
}
}
# Delete project
elsif ($op eq 'delete-project') {
my $user_id = param('user');
my $project_id = param('project');
eval { app->manager->delete_project($user_id, $project_id) };
if (my $e = $@) {
app->log->error("/$user_id/$project_id/settings: $e");
$errors = ['Internal Error'];
}
else {
flash(message => "Repository $project_id is deleted.");
$self->redirect_to("/$user_id");
return;
}
}
}
%>
% layout 'common', title => 'Options';
%= javascript begin
$(document).ready(function () {
// Rename project
$('#rename').on('click', function () {
$('#form-rename-project').submit();
});
// Check matching deleted project
$('input[name="deleted-project"]').on('keyup', function () {
var deleted_project = $(this).val();
var project = "<%= $project_id %>";
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');
<div class="project-settings">
<div class="left">
<ul>
<li><b>Options</b></li>
<li><a href="<%= url_for("/$user_id/$project_id/settings/collaboration") %>">Collaborators</a></li>
</ul>
</div>
<div class="right">
<ul class="project-settings-main">
<li>
<h4>
Repository name
</h4>
</li>
<li>
<form id="form-rename-project" action="<%= url_for->query(op => 'rename-project') %>" method="post">
<div>
%= text_field 'to-project' => $project_id, style => "width:80%";
<a href="#rename-confirm" role="button" class="btn" data-toggle="modal">
Rename
</a>
</div>
</form>
</li>
</ul>
<ul class="project-settings-main">
<li>
<h4>
Description
</h4>
</li>
<li>
<form action="<%= url_for->query(op => 'change-description') %>" method="post">
<div>
% my $description = $git->description(app->rep_info($user_id, $project_id));
% $description = '' unless defined $description;
%= text_field 'description' => $description, style => "width:90%";
<input type="submit" class="btn" value="Save">
</div>
</form>
</li>
</ul>
<ul class="project-settings-main">
<li>
<h4>
Website URL
</h4>
</li>
<li>
<form action="<%= url_for->query(op => 'change-website-url') %>" method="post">
<div>
<%
my $website_url = app->dbi->model('project')->select('website_url', where => {user => $user_row_id, id => $project_id})->value;
$website_url = '' unless defined $website_url;
%>
%= text_field 'website-url' => $website_url, style => "width:90%";
<input type="submit" class="btn" value="Save">
</div>
</form>
</li>
</ul>
<form id="form-default-branch" action="<%= url_for %>" method="post">
%= hidden_field op => 'save-settings';
<ul class="project-settings-main">
<li>
<h4>
Settings
</h4>
</li>
<li id="default-branch">
Default Branch
<%
my $branches = $git->branches($self->app->rep_info($user_id, $project_id));
my $branch_names = [map { $_->{name} } @$branches];
my $default_branch = app->manager->default_branch($user_id, $project_id);
push @$branch_names, $default_branch unless @$branch_names;
param('default-branch', $default_branch);
%>
%= select_field 'default-branch' => $branch_names;
</li>
<li>
<span>Make this repository private</span>
% my $private = app->manager->is_private_project($user_id, $project_id);
% my @private_checked = $private ? (checked => undef) : ();
%= hidden_field 'private' => 0;
%= check_box 'private' => 1, @private_checked;
</li>
<li>
<%
my $ignore_space_change = app->dbi->model('project')->select(
'ignore_space_change',
where => {user => $user_row_id, id => $project_id}
)->value;
my @ignore_space_change_checked = $ignore_space_change ? (checked => undef) : ();
%>
<span>Ignore space change in diff</span>
%= hidden_field 'ignore_space_change' => 0;
%= check_box 'ignore_space_change' => 1, @ignore_space_change_checked;
</li>
<li>
<%
my $guess_encoding = app->dbi->model('project')->select(
'guess_encoding',
where => {user => $user_row_id, id => $project_id}
)->value;
%>
<div>Guess encoding</div>
(Guess encoding from the following encoding list. default is "UTF-8".
if your source code is different from UTF-8, set comma separated encoding list.
For example "cp932,UTF-8")
%= text_field 'guess_encoding' => $guess_encoding;
</li>
<li>
<input type="submit" class="btn" value="Save">
</li>
</ul>
</form>
<ul class="project-settings-danger">
<li style="background:red;padding-left:5px">
<h4 style="color:white">Danger Zone</h4>
</li>
<li 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_id;
%= hidden_field project => $project_id;
</form>
</li>
</ul>
</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_id/$project_id" %></b>
repository, wiki, issues, and comments permanently.
</p>
<p>
Please type in the name of the repository(<b><%= $project_id %></b>) to confirm.
</p>
%= text_field 'deleted-project';
</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';