add collaboration page
|
1 |
<% |
2 |
# API |
|
3 |
my $api = gitprep_api; |
|
revert encoding support
|
4 |
my $manager = app->manager; |
add collaborator register lo...
|
5 | |
add collaboration page
|
6 |
# Parameters |
7 |
my $op = param('op') || ''; |
|
fix collaboration
|
8 |
my $user_id = param('user') || ''; |
cleanup
|
9 |
my $project_id = param('project'); |
add collaboration page
|
10 |
|
11 |
# Authentication |
|
fix collaboration
|
12 |
unless ($api->logined($user_id)) { |
add collaboration page
|
13 |
$self->redirect_to('/'); |
14 |
return; |
|
15 |
} |
|
16 |
|
|
fix collaboration
|
17 |
my $project_row_id = app->dbi->model('project')->select( |
18 |
'project.row_id', |
|
remove table __ prefix
|
19 |
where => {'user.id' => $user_id, 'project.id' => $project_id} |
fix user page
|
20 |
)->value; |
21 |
|
|
add collaboration page
|
22 |
# Rename project |
revert encoding support
|
23 |
my $git = app->git; |
add collaboration page
|
24 |
my $errors; |
add collaborator remove logi...
|
25 |
if (lc $self->req->method eq 'post') { |
26 |
if ($op eq 'add') { |
|
fix collaboration
|
27 |
my $collaborator_id = param('collaborator'); |
cleanup collaboration valida...
|
28 |
|
29 |
# Validator |
|
30 |
my $vc = app->vc; |
|
31 |
|
|
32 |
# Validation result |
|
33 |
my $validation = $vc->validation; |
|
34 |
|
|
35 |
# collaborator check |
|
fix collaboration
|
36 |
if (!length $collaborator_id) { |
cleanup collaboration valida...
|
37 |
$validation->add_failed(collaborator => "collaborator is empty"); |
38 |
} |
|
fix collaboration
|
39 |
elsif ($collaborator_id eq $user_id) { |
40 |
$validation->add_failed(collaborator => "User $collaborator_id is yourself"); |
|
cleanup collaboration valida...
|
41 |
} |
42 |
else { |
|
43 |
my $row = app->dbi->model('user')->select( |
|
fix collaboration
|
44 |
where => {id => $collaborator_id} |
cleanup collaboration valida...
|
45 |
)->one; |
46 |
if (!$row) { |
|
fix collaboration
|
47 |
$validation->add_failed(collaborator => "User $collaborator_id don't exists"); |
48 |
} |
|
49 |
else { |
|
50 |
my $row = app->dbi->model('collaboration')->select( |
|
remove table __ prefix
|
51 |
where => {project => $project_row_id, 'user.id' => $collaborator_id} |
fix collaboration
|
52 |
)->one; |
53 |
if ($row) { |
|
54 |
$validation->add_failed(collaborator => "Collaborator $collaborator_id already exists"); |
|
55 |
} |
|
cleanup collaboration valida...
|
56 |
} |
57 |
} |
|
58 |
|
|
59 |
if ($validation->is_valid) { |
|
add collaborator remove logi...
|
60 |
|
fix collaboration
|
61 |
my $collaborator_row_id = $api->get_user_row_id($collaborator_id); |
62 |
|
|
add collaborator remove logi...
|
63 |
# Insert |
64 |
eval { |
|
65 |
app->dbi->model('collaboration')->insert( |
|
66 |
{ |
|
fix collaboration
|
67 |
project => $project_row_id, |
68 |
user => $collaborator_row_id |
|
add collaborator remove logi...
|
69 |
} |
70 |
); |
|
71 |
}; |
|
72 |
if (my $e = $@) { |
|
73 |
app->log->error(url_with . ": $e"); |
|
74 |
$errors = ['Internal Error']; |
|
75 |
} |
|
76 |
else { |
|
fix collaboration
|
77 |
flash(message => "Collaborator $collaborator_id is added."); |
add collaborator remove logi...
|
78 |
$self->redirect_to('current'); |
79 |
return; |
|
add collaborator register lo...
|
80 |
} |
add collaborator remove logi...
|
81 |
} |
82 |
else { |
|
cleanup collaboration valida...
|
83 |
$errors = $validation->messages; |
add collaborator remove logi...
|
84 |
} |
85 |
} |
|
86 |
elsif ($op eq 'remove') { |
|
fix collaboration
|
87 |
my $collaborator_id = param('collaborator'); |
88 |
|
|
89 |
my $collaborator_row_id = $api->get_user_row_id($collaborator_id); |
|
add collaborator register lo...
|
90 |
|
add collaborator remove logi...
|
91 |
# Delete |
add collaborator register lo...
|
92 |
eval { |
add collaborator remove logi...
|
93 |
app->dbi->model('collaboration')->delete( |
94 |
where => { |
|
fix collaboration
|
95 |
project => $project_row_id, |
96 |
user => $collaborator_row_id |
|
add collaborator register lo...
|
97 |
} |
98 |
); |
|
99 |
}; |
|
100 |
if (my $e = $@) { |
|
101 |
app->log->error(url_with . ": $e"); |
|
102 |
$errors = ['Internal Error']; |
|
103 |
} |
|
104 |
else { |
|
fix collaboration
|
105 |
flash(message => "Collaborator $collaborator_id is removed."); |
add collaborator register lo...
|
106 |
$self->redirect_to('current'); |
107 |
return; |
|
108 |
} |
|
add collaboration page
|
109 |
} |
110 |
} |
|
add collaborator remove logi...
|
111 |
|
112 |
my $collaborators = app->dbi->model('collaboration')->select( |
|
remove table __ prefix
|
113 |
{user => ['id']}, |
fix collaboration
|
114 |
where => {project => $project_row_id}, |
115 |
append => 'order by collaboration.user' |
|
116 |
)->all; |
|
add collaboration page
|
117 |
%> |
118 | ||
119 |
% layout 'common', title => 'Collaboration'; |
|
120 |
|
|
121 |
%= include '/include/header'; |
|
122 |
|
|
123 |
<div class="container"> |
|
124 |
%= include '/include/errors', errors => $errors; |
|
125 |
%= include '/include/message', message => flash('message'); |
|
126 |
|
|
improve collabaration design
|
127 |
<div class="project-settings"> |
128 |
<div class="left"> |
|
129 |
<ul> |
|
fix collaboration
|
130 |
<li><a href="<%= url_for("/$user_id/$project_id/settings") %>">Options</a></li> |
improve collabaration design
|
131 |
<li><b>Collaborators</b></li> |
add collaboration page
|
132 |
</ul> |
133 |
</div> |
|
improve collabaration design
|
134 |
<div class="right"> |
135 |
<div class="collaboration"> |
|
136 |
<div>Manage Collaborators</div> |
|
137 |
% if (@$collaborators) { |
|
138 |
<table> |
|
139 |
% for my $collaborator (@$collaborators) { |
|
140 |
<tr> |
|
141 |
<td> |
|
remove table __ prefix
|
142 |
<a href="<%= url_for("/$collaborator->{'user.id'}") %>"><%= $collaborator->{'user.id'} %></a> |
improve collabaration design
|
143 |
<form action="<%= url_for->query(op => 'remove') %>" method="post" style="display:inline-block"> |
remove table __ prefix
|
144 |
<%= hidden_field 'collaborator' => $collaborator->{'user.id'} %> |
improve collabaration design
|
145 |
(<a href="javascript:void(0)" onclick="$(this).closest('form').submit();" style="color:red">remove</a>) |
146 |
</form> |
|
147 |
</td> |
|
148 |
</tr> |
|
149 |
% } |
|
150 |
</table> |
|
add collaborator remove logi...
|
151 |
% } |
improve collabaration design
|
152 |
<form action="<%= url_for->query(op => 'add') %>" method="post"> |
153 |
<div> |
|
154 |
<%= text_field 'collaborator' %> |
|
improve button design
|
155 |
<input type="submit" value="Add" class="btn" > |
improve collabaration design
|
156 |
</div> |
157 |
</form> |
|
add collaboration page
|
158 |
</div> |
improve collabaration design
|
159 |
</div> |
add collaboration page
|
160 |
</div> |
161 |
</div> |
|
162 |
</div> |
|
163 | ||
164 |
%= include '/include/footer'; |