gitprep / templates / settings / collaboration.html.ep /
Newer Older
164 lines | 4.834kb
add collaboration page
Yuki Kimoto authored on 2013-11-17
1
<%
2
  # API
3
  my $api = gitprep_api;
revert encoding support
Yuki Kimoto authored on 2013-11-22
4
  my $manager = app->manager;
add collaborator register lo...
Yuki Kimoto authored on 2013-11-17
5

            
add collaboration page
Yuki Kimoto authored on 2013-11-17
6
  # Parameters
7
  my $op = param('op') || '';
fix collaboration
Yuki Kimoto authored on 2016-04-22
8
  my $user_id = param('user') || '';
cleanup
Yuki Kimoto authored on 2016-04-22
9
  my $project_id = param('project');
add collaboration page
Yuki Kimoto authored on 2013-11-17
10
  
11
  # Authentication
fix collaboration
Yuki Kimoto authored on 2016-04-22
12
  unless ($api->logined($user_id)) {
add collaboration page
Yuki Kimoto authored on 2013-11-17
13
    $self->redirect_to('/');
14
    return;
15
  }
16
  
fix collaboration
Yuki Kimoto authored on 2016-04-22
17
  my $project_row_id = app->dbi->model('project')->select(
18
    'project.row_id',
remove table __ prefix
Yuki Kimoto authored on 2016-06-11
19
    where => {'user.id' => $user_id, 'project.id' => $project_id}
fix user page
Yuki Kimoto authored on 2016-04-21
20
  )->value;
21
  
add collaboration page
Yuki Kimoto authored on 2013-11-17
22
  # Rename project
revert encoding support
Yuki Kimoto authored on 2013-11-22
23
  my $git = app->git;
add collaboration page
Yuki Kimoto authored on 2013-11-17
24
  my $errors;
add collaborator remove logi...
Yuki Kimoto authored on 2013-11-17
25
  if (lc $self->req->method eq 'post') {
26
    if ($op eq 'add') {
fix collaboration
Yuki Kimoto authored on 2016-04-22
27
      my $collaborator_id = param('collaborator');
cleanup collaboration valida...
Yuki Kimoto authored on 2016-02-09
28
      
29
      # Validator
30
      my $vc = app->vc;
31
      
32
      # Validation result
33
      my $validation = $vc->validation;
34
      
35
      # collaborator check
fix collaboration
Yuki Kimoto authored on 2016-04-22
36
      if (!length $collaborator_id) {
cleanup collaboration valida...
Yuki Kimoto authored on 2016-02-09
37
        $validation->add_failed(collaborator => "collaborator is empty");
38
      }
fix collaboration
Yuki Kimoto authored on 2016-04-22
39
      elsif ($collaborator_id eq $user_id) {
40
        $validation->add_failed(collaborator => "User $collaborator_id is yourself");
cleanup collaboration valida...
Yuki Kimoto authored on 2016-02-09
41
      }
42
      else {
43
        my $row = app->dbi->model('user')->select(
fix collaboration
Yuki Kimoto authored on 2016-04-22
44
          where => {id => $collaborator_id}
cleanup collaboration valida...
Yuki Kimoto authored on 2016-02-09
45
        )->one;
46
        if (!$row) {
fix collaboration
Yuki Kimoto authored on 2016-04-22
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
Yuki Kimoto authored on 2016-06-11
51
            where => {project => $project_row_id, 'user.id' => $collaborator_id}
fix collaboration
Yuki Kimoto authored on 2016-04-22
52
          )->one;
53
          if ($row) {
54
            $validation->add_failed(collaborator => "Collaborator $collaborator_id already exists");
55
          }
cleanup collaboration valida...
Yuki Kimoto authored on 2016-02-09
56
        }
57
      }
58
      
59
      if ($validation->is_valid) {
add collaborator remove logi...
Yuki Kimoto authored on 2013-11-17
60
        
fix collaboration
Yuki Kimoto authored on 2016-04-22
61
        my $collaborator_row_id = $api->get_user_row_id($collaborator_id);
62
        
add collaborator remove logi...
Yuki Kimoto authored on 2013-11-17
63
        # Insert
64
        eval {
65
          app->dbi->model('collaboration')->insert(
66
            {
fix collaboration
Yuki Kimoto authored on 2016-04-22
67
              project => $project_row_id,
68
              user => $collaborator_row_id
add collaborator remove logi...
Yuki Kimoto authored on 2013-11-17
69
            }
70
          );
71
        };
72
        if (my $e = $@) {
73
          app->log->error(url_with . ": $e");
74
          $errors = ['Internal Error'];
75
        }
76
        else {
fix collaboration
Yuki Kimoto authored on 2016-04-22
77
          flash(message => "Collaborator $collaborator_id is added.");
add collaborator remove logi...
Yuki Kimoto authored on 2013-11-17
78
          $self->redirect_to('current');
79
          return;
add collaborator register lo...
Yuki Kimoto authored on 2013-11-17
80
        }
add collaborator remove logi...
Yuki Kimoto authored on 2013-11-17
81
      }
82
      else {
cleanup collaboration valida...
Yuki Kimoto authored on 2016-02-09
83
        $errors = $validation->messages;
add collaborator remove logi...
Yuki Kimoto authored on 2013-11-17
84
      }
85
    }
86
    elsif ($op eq 'remove') {
fix collaboration
Yuki Kimoto authored on 2016-04-22
87
      my $collaborator_id = param('collaborator');
88
      
89
      my $collaborator_row_id = $api->get_user_row_id($collaborator_id);
add collaborator register lo...
Yuki Kimoto authored on 2013-11-17
90
      
add collaborator remove logi...
Yuki Kimoto authored on 2013-11-17
91
      # Delete
add collaborator register lo...
Yuki Kimoto authored on 2013-11-17
92
      eval {
add collaborator remove logi...
Yuki Kimoto authored on 2013-11-17
93
        app->dbi->model('collaboration')->delete(
94
          where => {
fix collaboration
Yuki Kimoto authored on 2016-04-22
95
            project => $project_row_id,
96
            user => $collaborator_row_id
add collaborator register lo...
Yuki Kimoto authored on 2013-11-17
97
          }
98
        );
99
      };
100
      if (my $e = $@) {
101
        app->log->error(url_with . ": $e");
102
        $errors = ['Internal Error'];
103
      }
104
      else {
fix collaboration
Yuki Kimoto authored on 2016-04-22
105
        flash(message => "Collaborator $collaborator_id is removed.");
add collaborator register lo...
Yuki Kimoto authored on 2013-11-17
106
        $self->redirect_to('current');
107
        return;
108
      }
add collaboration page
Yuki Kimoto authored on 2013-11-17
109
    }
110
  }
add collaborator remove logi...
Yuki Kimoto authored on 2013-11-17
111
  
112
  my $collaborators = app->dbi->model('collaboration')->select(
remove table __ prefix
Yuki Kimoto authored on 2016-06-11
113
    {user => ['id']},
fix collaboration
Yuki Kimoto authored on 2016-04-22
114
    where => {project => $project_row_id},
115
    append => 'order by collaboration.user'
116
  )->all;
add collaboration page
Yuki Kimoto authored on 2013-11-17
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
Yuki Kimoto authored on 2016-01-19
127
    <div class="project-settings">
128
      <div class="left">
129
        <ul>
fix collaboration
Yuki Kimoto authored on 2016-04-22
130
          <li><a href="<%= url_for("/$user_id/$project_id/settings") %>">Options</a></li>
improve collabaration design
Yuki Kimoto authored on 2016-01-19
131
          <li><b>Collaborators</b></li>
add collaboration page
Yuki Kimoto authored on 2013-11-17
132
        </ul>
133
      </div>
improve collabaration design
Yuki Kimoto authored on 2016-01-19
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
Yuki Kimoto authored on 2016-06-11
142
                      <a href="<%= url_for("/$collaborator->{'user.id'}") %>"><%= $collaborator->{'user.id'} %></a>
improve collabaration design
Yuki Kimoto authored on 2016-01-19
143
                      <form action="<%= url_for->query(op => 'remove') %>" method="post" style="display:inline-block">
remove table __ prefix
Yuki Kimoto authored on 2016-06-11
144
                        <%= hidden_field 'collaborator' => $collaborator->{'user.id'} %>
improve collabaration design
Yuki Kimoto authored on 2016-01-19
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...
Yuki Kimoto authored on 2013-11-17
151
            % }
improve collabaration design
Yuki Kimoto authored on 2016-01-19
152
            <form action="<%= url_for->query(op => 'add') %>" method="post">
153
              <div>
154
                <%= text_field 'collaborator' %>
improve button design
Yuki Kimoto authored on 2016-11-30
155
                <input type="submit" value="Add" class="btn" >
improve collabaration design
Yuki Kimoto authored on 2016-01-19
156
              </div>
157
            </form>
add collaboration page
Yuki Kimoto authored on 2013-11-17
158
          </div>
improve collabaration design
Yuki Kimoto authored on 2016-01-19
159
        </div>
add collaboration page
Yuki Kimoto authored on 2013-11-17
160
      </div>
161
    </div>
162
  </div>
163

            
164
  %= include '/include/footer';