gitprep / templates / branches.html.ep /
Newer Older
308 lines | 11.821kb
added Tags link
Yuki Kimoto authored on 2012-11-28
1
<%
2
  # API
cleanup
Yuki Kimoto authored on 2013-03-19
3
  my $api = gitprep_api;
added Tags link
Yuki Kimoto authored on 2012-11-28
4

            
cleanup branches page
Yuki Kimoto authored on 2013-01-29
5
  # Parameters
improve branches page open c...
Yuki Kimoto authored on 2016-04-23
6
  my $user_id = param('user');
7
  my $project_id = param('project');
improved branches page desig...
Yuki Kimoto authored on 2013-05-06
8
  my $op = param('op') || '';
improve tags page design
Yuki Kimoto authored on 2016-02-01
9
  my $page = param('page') || 1;
added Tags link
Yuki Kimoto authored on 2012-11-28
10
  
11
  # Git
revert encoding support
Yuki Kimoto authored on 2013-11-22
12
  my $git = $self->app->git;
added branch deleting featur...
Yuki Kimoto authored on 2013-05-05
13

            
14
  # Delete
15
  my $errors;
fix branch not deleted bug a...
Yuki Kimoto authored on 2013-05-29
16
  if ($op eq 'delete' && lc $self->req->method eq 'post') {
17
    
18
    # Forbbiden
improve branches page open c...
Yuki Kimoto authored on 2016-04-23
19
    unless ($api->logined($user_id)) {
fix branch not deleted bug a...
Yuki Kimoto authored on 2013-05-29
20
      $self->redirect_to('/');
21
      return;    
22
    }
cleanup branch page validati...
Yuki Kimoto authored on 2016-02-11
23
    
24
    # Parameters
25
    my $branch = param('branch');
26
    
27
    # Validator
28
    my $vc = app->vc;
29
    
30
    # Validation result
31
    my $validation = $vc->validation;
32
    
33
    # "branch"
34
    if (!(defined $branch && length $branch)) {
35
      $validation->add_failed(branch => 'Branch name is empty');
36
    }
added branch deleting featur...
Yuki Kimoto authored on 2013-05-05
37

            
cleanup branch page validati...
Yuki Kimoto authored on 2016-02-11
38
    if ($validation->is_valid) {
added branch deleting featur...
Yuki Kimoto authored on 2013-05-05
39
      # Delete branch
improve branches page open c...
Yuki Kimoto authored on 2016-04-23
40
      eval { $git->delete_branch(app->rep_info($user_id, $project_id), $branch) };
improve error message
Yuki Kimoto authored on 2014-02-13
41
      if (my $e = $@) {
42
        app->log->error(url_with . ": $e");
fix branch not deleted bug a...
Yuki Kimoto authored on 2013-05-29
43
        $errors = ['Internal Error'];
added branch deleting featur...
Yuki Kimoto authored on 2013-05-05
44
      }
45
      else {
fix branch not deleted bug a...
Yuki Kimoto authored on 2013-05-29
46
        $self->flash(message => "Branch $branch is deleted.");
47
        $self->redirect_to;
added branch deleting featur...
Yuki Kimoto authored on 2013-05-05
48
        return;
49
      }
50
    }
cleanup branch page validati...
Yuki Kimoto authored on 2016-02-11
51
    else { $errors = $validation->messages }
added branch deleting featur...
Yuki Kimoto authored on 2013-05-05
52
  }
fix branch not deleted bug a...
Yuki Kimoto authored on 2013-05-29
53
  
54
  # Default branch
improve branches page open c...
Yuki Kimoto authored on 2016-04-23
55
  my $default_branch_name = app->manager->default_branch($user_id, $project_id);
56
  my $default_branch = $git->branch($self->app->rep_info($user_id, $project_id), $default_branch_name);
improve some branches page
Yuki Kimoto authored on 2015-12-23
57
  
58
  # Branches
simplify branches
Yuki Kimoto authored on 2016-10-12
59
  my $branches = [];
improve tags page design
Yuki Kimoto authored on 2016-02-01
60

            
61
  # Pagenation
62
  my $page_count = 20;
63
  my $skip = $page_count * ($page - 1);
fix branch not deleted bug a...
Yuki Kimoto authored on 2013-05-29
64
  
fix branch paging
Yuki Kimoto authored on 2016-10-12
65
  my $all_branches = $git->branches($self->app->rep_info($user_id, $project_id));
fix branch not deleted bug a...
Yuki Kimoto authored on 2013-05-29
66
  my $max = 0;
improve tags page design
Yuki Kimoto authored on 2016-02-01
67
  my $all_count = 0;
fix branch paging
Yuki Kimoto authored on 2016-10-12
68
  for my $branch (@$all_branches) {
cleanup branch_status
Yuki Kimoto authored on 2016-04-16
69
    $branch->{status} = $git->branch_status(
improve branches page open c...
Yuki Kimoto authored on 2016-04-23
70
      $self->app->rep_info($user_id, $project_id),
cleanup rep_info
Yuki Kimoto authored on 2016-04-16
71
      $default_branch->{name},
72
      $branch->{name}
cleanup branch_status
Yuki Kimoto authored on 2016-04-16
73
    );
fix branch not deleted bug a...
Yuki Kimoto authored on 2013-05-29
74
    $max = $branch->{status}{ahead} if $max < $branch->{status}{ahead};
75
    $max = $branch->{status}{behind} if $max < $branch->{status}{behind};
improve some branches page
Yuki Kimoto authored on 2015-12-23
76
    
fix branches bar
Yuki Kimoto authored on 2016-02-12
77
    if ($branch->{status}{ahead} > 100) {
78
      $branch->{status}{ahead_bar} = 100;
79
    }
80
    else {
81
      $branch->{status}{ahead_bar} = $branch->{status}{ahead};
82
    }
83
    if ($branch->{status}{behind} > 100) {
84
      $branch->{status}{behind_bar} = 100;
85
    }
86
    else {
87
      $branch->{status}{behind_bar} = $branch->{status}{behind};
88
    }
89
    
90
    $max = 100 if $max > 100;
91
    
simplify branches
Yuki Kimoto authored on 2016-10-12
92
    if ($all_count >= $skip && $all_count < $skip + $page_count) {
93
      push @$branches, $branch;
improve some branches page
Yuki Kimoto authored on 2015-12-23
94
    }
simplify branches
Yuki Kimoto authored on 2016-10-12
95
    $all_count++;
added branch deleting featur...
Yuki Kimoto authored on 2013-05-05
96
  }
improve tags page design
Yuki Kimoto authored on 2016-02-01
97
  
fix branches page pull reque...
Yuki Kimoto authored on 2016-04-26
98
  my $original_project_row_id = app->dbi->model('project')->select(
99
    'original_project',
remove table __ prefix
Yuki Kimoto authored on 2016-06-11
100
    where => {'user.id' => $user_id, 'project.id' => $project_id}
fix branches page pull reque...
Yuki Kimoto authored on 2016-04-26
101
  )->value;
102
  
103
  my $original_project;
104
  if ($original_project_row_id) {
105
    $original_project = app->dbi->model('project')->select(
106
      [
107
        {__MY__ => '*'},
remove table __ prefix
Yuki Kimoto authored on 2016-06-11
108
        {user => ['id']}
fix branches page pull reque...
Yuki Kimoto authored on 2016-04-26
109
      ],
110
      where => {'project.row_id' => $original_project_row_id}
111
    )->one;
112
  }
added Tags link
Yuki Kimoto authored on 2012-11-28
113
%>
114

            
improve branches page open c...
Yuki Kimoto authored on 2016-04-23
115
% layout 'common', title => "branches  \x{30fb} $user_id/$project_id";
added merged branches to bra...
Yuki Kimoto authored on 2013-05-03
116

            
cleanup
Yuki Kimoto authored on 2013-01-28
117
  %= include '/include/header';
cleanup
Yuki Kimoto authored on 2013-03-15
118
  
added branch deleting featur...
Yuki Kimoto authored on 2013-05-05
119
  <div class="container" style="padding-bottom:30px">
fix branch not deleted bug a...
Yuki Kimoto authored on 2013-05-29
120
    %= include '/include/errors', errors => $errors;
121
    %= include '/include/message', message => flash('message');
added branch deleting featur...
Yuki Kimoto authored on 2013-05-05
122
    
improve some branches page
Yuki Kimoto authored on 2015-12-23
123
    <!-- Branches (for tests) -->
design branches page
Yuki Kimoto authored on 2012-12-06
124
    
simplify branches
Yuki Kimoto authored on 2016-10-12
125
    <h1 class="topic1">Branches</h1>
126
      % if (@$branches) {
improve branch design
Yuki Kimoto authored on 2016-01-27
127
        <ul class="branches">
improve branches design
Yuki Kimoto authored on 2016-01-30
128
          % if (@$branches) {
improve tags page design
Yuki Kimoto authored on 2016-02-01
129
            % my $branches_count;
improve branches design
Yuki Kimoto authored on 2016-01-30
130
            % for (my $i = 0; $i < @$branches; $i++) {
imrpove branches page
Yuki Kimoto authored on 2016-01-30
131
              <%
132
                my $branch = $branches->[$i];
improve branches page open c...
Yuki Kimoto authored on 2016-04-23
133
                my $branch_name = $branch->{name};
add user page link from user...
Yuki Kimoto authored on 2016-04-11
134

            
cleanup
Yuki Kimoto authored on 2016-04-22
135
                my $commit_author_email = $branch->{commit}{author_email};
add user page link from user...
Yuki Kimoto authored on 2016-04-11
136
                my $commit_author_id = app->dbi->model('user')->select(
137
                  'id',
fix mail bug
Yuki Kimoto authored on 2016-04-21
138
                  where => {email => $commit_author_email}
add user page link from user...
Yuki Kimoto authored on 2016-04-11
139
                )->value;
improve branches page open c...
Yuki Kimoto authored on 2016-04-23
140

            
141
                my $pull_request = app->dbi->model('pull_request')->select(
fix branches page bug
Yuki Kimoto authored on 2016-06-11
142
                  {__MY__ => ['row_id']},
improve branches page open c...
Yuki Kimoto authored on 2016-04-23
143
                  where => {
remove table __ prefix
Yuki Kimoto authored on 2016-06-11
144
                    'base_project.id' => $project_id,
145
                    'base_project__user.id' => $user_id,
fix pull_request table bug
Yuki Kimoto authored on 2016-04-27
146
                    base_branch => $default_branch_name,
147
                    target_branch => $branch_name
improve branches page open c...
Yuki Kimoto authored on 2016-04-23
148
                  }
149
                )->one;
fix branches page
Yuki Kimoto authored on 2016-06-11
150
                
151
                my $issue;
152
                if ($pull_request) {
153
                  $issue = app->dbi->model('issue')->select(
154
                    where => {pull_request => $pull_request->{row_id}}
155
                  )->one;
156
                }
157
                
imrpove branches page
Yuki Kimoto authored on 2016-01-30
158
              %>
159

            
simplify branches
Yuki Kimoto authored on 2016-10-12
160
              <li>
161
                <ul>
162
                  <li>
163
                    <div class="branches-name">
164
                      <a href="<%= url_for("/$user_id/$project_id/tree/$branch_name") %>">
165
                        <%= $branch_name %>
166
                      </a>
167
                    </div>
168
                    <div class="branches-age" title="<%= $branch->{commit}{age_string_datetime_local} %>">
169
                      Updated <%= $branch->{commit}{age_string} %> by
170
                    </div>
171
                    <div class="branches-author"  title="<%= $branch->{commit}{author_email} %>">
172
                      % if (defined $commit_author_id) {
173
                        <a href="<%= url_for("/$commit_author_id") %>"><%= $commit_author_id %></a>
imrpove branches page
Yuki Kimoto authored on 2016-01-30
174
                      % } else {
simplify branches
Yuki Kimoto authored on 2016-10-12
175
                        <%= $branch->{commit}{author_name} %>
improve branches design
Yuki Kimoto authored on 2016-01-30
176
                      % }
simplify branches
Yuki Kimoto authored on 2016-10-12
177
                    </div>
178
                  </li>
179
                  <li class="second-child">
180
                    % if ($branch_name eq $default_branch_name) {
181
                      <div style="padding-left:80px;padding-top:3px">
182
                        <div class="branches-default">
183
                          Default
184
                        </div>
185
                      </div>
186
                    % } else {
187
                      <table class="ahead-behind">
188
                        <tr>
189
                          <td class="ahead-behind-behind-count">
190
                            <%= $branch->{status}{behind} %>
191
                          </td>
192
                          <td class="ahead-behind-separate">
193
                          </td>
194
                          <td style="padding-left:3px">
195
                            <%= $branch->{status}{ahead} %>
196
                          </td>
197
                        </tr>
198
                        <tr>
199
                          <td style="width:100px">
200
                            <div style="margin-left:auto;margin-right:0;background:#dcdcdc;width:<%= $branch->{status}{behind_bar} %>%;height:4px"></div>
201
                          </td>
202
                          <td class="ahead-behind-separate">
203
                          </td>
204
                          <td style="width:100px">
205
                            <div style="background:#dcdcdc;width:<%= $branch->{status}{ahead_bar} %>%;height:4px"></div>
206
                          </td>
207
                        </tr>
208
                      </table>
209
                    % }
210
                  </li>
211
                  <li class="last-child">
212
                    % if ($branch_name eq $default_branch_name) {
213
                      % if ($api->logined($user_id)) {
214
                        <a href="<%= url_for("/$user_id/$project_id/settings#form-default-branch") %>" type="submit" class="btn btn-small">Change default branch</a>
215
                      % }
216
                    % } else {
217
                      % if ($api->logined) {
218
                        % if ($pull_request) {
219
                          #<%= $issue->{number} %>
220
                          % if ($issue->{open}) {
221
                            <a class="branches-open" href="<%= url_for("/$user/$project/pull/$issue->{number}") %>">
222
                              open
223
                            </a>
fix bug that repository with...
Yuki Kimoto authored on 2016-04-12
224
                          % } else {
simplify branches
Yuki Kimoto authored on 2016-10-12
225
                            <a class="branches-close" href="<%= url_for("/$user/$project/pull/$issue->{number}") %>">
226
                              closed
improve branches page open c...
Yuki Kimoto authored on 2016-04-23
227
                            </a>
228
                          % }
229
                        % } else {
simplify branches
Yuki Kimoto authored on 2016-10-12
230
                          <% 
231
                            my $compare_url;
232
                            if ($original_project) {
233
                              my $original_user_id = $original_project->{'user.id'};
234
                              my $original_project_id = $original_project->{id};
235
                              
236
                              my $exists_original_branch_name = app->git->exists_branch(
237
                                app->rep_info($original_user_id, $original_project_id),
238
                                $branch_name
239
                              );
240
                              if ($exists_original_branch_name) {
241
                                $compare_url = url_for("/$original_user_id/$original_project_id/compare/$branch_name...$user_id:$branch_name")->query(expand => 1);
242
                              }
243
                              else {
244
                                my $original_project_default_branch = app->manager->default_branch($original_user_id, $original_project_id);
245
                                $compare_url = url_for("/$original_user_id/$original_project_id/compare/$original_project_default_branch...$user_id:$branch_name")->query(expand => 1);
246
                              }
247
                            }
248
                            else {
249
                              $compare_url = url_for("/$user_id/$project_id/compare/$branch_name")->query(expand => 1);
250
                            }
251
                          %>
252
                          <a class="btn btn-small" href="<%= $compare_url %>">
253
                            New pull request
improve branches page open c...
Yuki Kimoto authored on 2016-04-23
254
                          </a>
255
                        % }
simplify branches
Yuki Kimoto authored on 2016-10-12
256
                      % } else {
257
                        <a class="btn btn-small" href="<%= url_for("/$user_id/$project_id/compare/$branch_name")->query(expand => 1) %>">
258
                          Compare
259
                        </a>
260
                      % }
261
                      % if ($api->logined($user_id)) {
262
                        % if ($pull_request && $issue->{open}) {
263
                          <button class="btn btn-small disabled delete-branch"value="Delete">Delete</button>
264
                        % } else {
265
                          <form action="<%= url_for->query(op => 'delete') %>" method="post" style="display:inline-block">
266
                            <input type="submit" class="btn btn-small delete-branch" style="color:#900;" value="Delete">
267
                            %= hidden_field branch => $branch_name;
268
                          </form>
imrpove branches page
Yuki Kimoto authored on 2016-01-30
269
                        % }
improve branches design
Yuki Kimoto authored on 2016-01-30
270
                      % }
simplify branches
Yuki Kimoto authored on 2016-10-12
271
                    % }
272
                  </li>
273
                </ul>
274
              </li>
improve tags page design
Yuki Kimoto authored on 2016-02-01
275
              % $branches_count++;
276
            % }
277

            
278

            
simplify branches
Yuki Kimoto authored on 2016-10-12
279
            <div class="pagenation-container" style="margin-top:20px">
280
              <ul class="pagenation">
281
                % if ($page == 1) {
282
                  <li><span>Newer</span></li>
283
                % } else {
284
                  % my $newer_page = $page - 1;
285
                  <li>
fix branch paging
Yuki Kimoto authored on 2016-10-12
286
                    <a href="<%= url_for("/$user_id/$project_id/branches?page=$newer_page") %>">Newer</a>
simplify branches
Yuki Kimoto authored on 2016-10-12
287
                  </li>
288
                % }
289
                % if ($branches_count < $page_count) {
290
                  <li><span>Older</span></li>
291
                % } else {
292
                  % my $older_page = $page + 1;
293
                  <li>
fix branch paging
Yuki Kimoto authored on 2016-10-12
294
                    <a href="<%= url_for("/$user_id/$project_id/branches?page=$older_page") %>">Older</a>
simplify branches
Yuki Kimoto authored on 2016-10-12
295
                  </li>
296
                % }
297
              </ul>
298
            </div>
improve branches design
Yuki Kimoto authored on 2016-01-30
299
          % } else {
300
            <li style="text-align:center;text-color:#767676">
simplify branches
Yuki Kimoto authored on 2016-10-12
301
              There aren’t any branches.
improve some branches page
Yuki Kimoto authored on 2015-12-23
302
            </li>
303
          % }
304
        </ul>
305
      % }
added branches link
Yuki Kimoto authored on 2012-11-28
306
  </div>
design branches page
Yuki Kimoto authored on 2012-12-06
307
  
308
  %= include '/include/footer';