gitprep / templates / settings / collaboration.html.ep /
Newer Older
145 lines | 4.415kb
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') || '';
8
  my $user = param('user') || '';
add collaborator register lo...
Yuki Kimoto authored on 2013-11-17
9
  my $project = param('project');
add collaboration page
Yuki Kimoto authored on 2013-11-17
10
  
11
  # Authentication
12
  unless ($api->logined($user)) {
13
    $self->redirect_to('/');
14
    return;
15
  }
16
  
17
  # Rename project
revert encoding support
Yuki Kimoto authored on 2013-11-22
18
  my $git = app->git;
add collaboration page
Yuki Kimoto authored on 2013-11-17
19
  my $errors;
add collaborator remove logi...
Yuki Kimoto authored on 2013-11-17
20
  if (lc $self->req->method eq 'post') {
21
    if ($op eq 'add') {
22
      my $params = $api->params;
23
      my $rule = [
24
        collaborator => [
25
          ['not_blank' => 'collaborator is empty.'],
26
          # Check user
27
          sub {
28
            my $collaborator = shift || '';
add collaborator register lo...
Yuki Kimoto authored on 2013-11-17
29
            
add collaborator remove logi...
Yuki Kimoto authored on 2013-11-17
30
            if ($collaborator eq $user) {
31
              return {result => 0, message => "User $collaborator is yourself"};
32
            }
33
            else {
34
              my $row = app->dbi->model('user')->select(id => $collaborator)->one;
35
              
36
              return $row ? 1 : {result => 0, message => "User $collaborator don't exists"};
37
            }
add collaborator register lo...
Yuki Kimoto authored on 2013-11-17
38
          }
add collaborator remove logi...
Yuki Kimoto authored on 2013-11-17
39
        ]
40
      ];
rename validator to vc to up...
Yuki Kimoto authored on 2013-12-02
41
      my $vresult = app->vc->validate($params, $rule);
add collaborator remove logi...
Yuki Kimoto authored on 2013-11-17
42
      if ($vresult->is_ok) {
43
        my $safe_params = $vresult->data;
44
        my $collaborator = $safe_params->{collaborator};
45
        
46
        # Insert
47
        eval {
48
          app->dbi->model('collaboration')->insert(
49
            {
50
              user_id => $user,
51
              project_name => $project,
52
              collaborator_id => $collaborator
53
            }
54
          );
55
        };
56
        if (my $e = $@) {
57
          app->log->error(url_with . ": $e");
58
          $errors = ['Internal Error'];
59
        }
60
        else {
61
          flash(message => "Collaborator $collaborator is added.");
62
          $self->redirect_to('current');
63
          return;
add collaborator register lo...
Yuki Kimoto authored on 2013-11-17
64
        }
add collaborator remove logi...
Yuki Kimoto authored on 2013-11-17
65
      }
66
      else {
67
        $errors = $vresult->messages;
68
      }
69
    }
70
    elsif ($op eq 'remove') {
71
      my $collaborator = param('collaborator');
add collaborator register lo...
Yuki Kimoto authored on 2013-11-17
72
      
add collaborator remove logi...
Yuki Kimoto authored on 2013-11-17
73
      # Delete
add collaborator register lo...
Yuki Kimoto authored on 2013-11-17
74
      eval {
add collaborator remove logi...
Yuki Kimoto authored on 2013-11-17
75
        app->dbi->model('collaboration')->delete(
76
          where => {
add collaborator register lo...
Yuki Kimoto authored on 2013-11-17
77
            user_id => $user,
78
            project_name => $project,
79
            collaborator_id => $collaborator
80
          }
81
        );
82
      };
83
      if (my $e = $@) {
84
        app->log->error(url_with . ": $e");
85
        $errors = ['Internal Error'];
86
      }
87
      else {
add collaborator remove logi...
Yuki Kimoto authored on 2013-11-17
88
        flash(message => "Collaborator $collaborator is removed.");
add collaborator register lo...
Yuki Kimoto authored on 2013-11-17
89
        $self->redirect_to('current');
90
        return;
91
      }
add collaboration page
Yuki Kimoto authored on 2013-11-17
92
    }
93
  }
add collaborator remove logi...
Yuki Kimoto authored on 2013-11-17
94
  
95
  my $collaborators = app->dbi->model('collaboration')->select(
96
    'collaborator_id',
97
    where => {user_id => $user, project_name => $project},
98
    append => 'order by collaborator_id'
99
  )->values;
add collaboration page
Yuki Kimoto authored on 2013-11-17
100
%>
101

            
102
% layout 'common', title => 'Collaboration';
103
  
104
  %= include '/include/header';
105
  
106
  <div class="container">
107
    %= include '/include/errors', errors => $errors;
108
    %= include '/include/message', message => flash('message');
109
    %= include '/include/project_header';
110
    
111
    <div class="row">
112
      <div class="span2">
113
        <ul class="unstyled" style="font-size:13px;">
114
          <li class="border-gray" style="padding:6px;"><a href="<%= url_for("/$user/$project/settings") %>">Options</a></li>
115
          <li class="border-gray" style="border-top:none;padding:5px;"><b>Collaborators</b></li>
116
        </ul>
117
      </div>
118
      <div class="span10">
119
        <div style="font-size:16px;margin-top:10px;margin-bottom:10px"><b>Manage Collaborators</b></div>
add collaborator remove logi...
Yuki Kimoto authored on 2013-11-17
120
        % if (@$collaborators) {
121
          <table class="table" style="margin-bottom:0">
122
            % for my $collaborator (@$collaborators) {
123
              <tr>
124
                <td>
125
                  <a href="<%= url_for("/$collaborator") %>"><%= $collaborator %></a>
126
                  <form action="<%= url_for->query(op => 'remove') %>" method="post" style="display:inline-block">
127
                    <%= hidden_field 'collaborator' => $collaborator %>
128
                    (<a href="javascript:void(0)" onclick="$(this).closest('form').submit();" style="color:red">remove</a>)
129
                  </form>
130
                </td>
131
              </tr>
132
            % }
133
          </table>
134
        % }
add collaboration page
Yuki Kimoto authored on 2013-11-17
135
        <form action="<%= url_for->query(op => 'add') %>" method="post">
136
          <div class="well" style="padding:5px">
137
            <%= text_field 'collaborator', style => 'margin-bottom:0' %>
138
            <input type="submit" value="Add"" >
139
          </div>
140
        </form>
141
      </div>
142
    </div>
143
  </div>
144

            
145
  %= include '/include/footer';