Showing 3 changed files with 137 additions and 157 deletions
+1 -1
lib/Gitprep.pm
... ...
@@ -319,7 +319,7 @@ sub startup {
319 319
             $r->get('/commits/*rev_file' => template '/commits');
320 320
             
321 321
             # Branches
322
-            $r->any('/branches/*base_branch' => {base_branch => undef} => template '/branches');
322
+            $r->any('/branches/:display' => {display => undef} => template '/branches');
323 323
 
324 324
             # Tags
325 325
             $r->get('/tags' => template '/tags');
+136 -151
templates/branches.html.ep
... ...
@@ -7,6 +7,7 @@
7 7
   my $user = param('user');
8 8
   my $project = param('project');
9 9
   my $op = param('op') || '';
10
+  my $display = param('display') || 'overview';
10 11
   
11 12
   # Git
12 13
   my $git = $self->app->git;
... ...
@@ -52,176 +53,160 @@
52 53
   }
53 54
   
54 55
   # Default branch
55
-  my $base_branch_name = param('base_branch') || app->manager->default_branch($user, $project);
56
-  my $base_branch = $git->branch($user, $project, $base_branch_name);
56
+  my $default_branch_name = app->manager->default_branch($user, $project);
57
+  my $default_branch = $git->branch($user, $project, $default_branch_name);
58
+  
59
+  # Branches
60
+  my $branch_types = ['default', 'active', 'stale', 'all'];
61
+  my $branches_h = {
62
+    default => [],
63
+    active => [],
64
+    stale => [],
65
+    all => []
66
+  };
57 67
   
58
-  # No merged branches
59 68
   my $branches = $git->branches($user, $project);
60 69
   my $max = 0;
61 70
   for my $branch (@$branches) {
62
-    $branch->{status} = $git->branch_status($user, $project, $base_branch->{name}, $branch->{name});
71
+    $branch->{status} = $git->branch_status($user, $project, $default_branch->{name}, $branch->{name});
63 72
     $max = $branch->{status}{ahead} if $max < $branch->{status}{ahead};
64 73
     $max = $branch->{status}{behind} if $max < $branch->{status}{behind};
74
+    
75
+    if ($display eq 'overview') {
76
+      if ($branch->{name} eq $default_branch_name) {
77
+        push @{$branches_h->{default}}, $branch;
78
+      }
79
+      else {
80
+        push @{$branches_h->{active}}, $branch;
81
+      }
82
+    }
83
+    elsif ($display eq 'active') {
84
+      push @{$branches_h->{active}}, $branch;
85
+    }
86
+    elsif ($display eq 'stale') {
87
+      push @{$branches_h->{stale}}, $branch;
88
+    }
89
+    elsif ($display eq 'all') {
90
+      push @{$branches_h->{all}}, $branch;
91
+    }
65 92
   }
66
-  my $branches_count = $git->branches_count($user, $project);
67
-  my $no_merged_branches_count = $git->no_merged_branches_count($user, $project);
68
-  my $merged_branches_count = $branches_count - $no_merged_branches_count - 1;
69
-  
70
-  # Global variable
71
-  stash(rev => $base_branch_name);
72 93
 %>
73 94
 
74 95
 % layout 'common', title => "branches  \x{30fb} $user/$project";
75 96
 
76
-  %= javascript begin
77
-    $('document').ready(function () {
78
-      
79
-      // Switch merged branch or not merged branch
80
-      var display_no_merged = true;
81
-      $('#toggle-branch').on('click', function () {
82
-        if (display_no_merged) {
83
-          $(this).text('View unmerged branches');
84
-          $('#no-merged-branch-message').hide();
85
-          $('#merged-branch-message').show();
86
-          $('.no-merged-branch').css('display', 'none');
87
-          $('.merged-branch').css('display', 'block');
88
-        }
89
-        else {
90
-          $(this).text('View merged branches');
91
-          $('#no-merged-branch-message').show();
92
-          $('#merged-branch-message').hide();
93
-          $('.no-merged-branch').css('display', 'block');
94
-          $('.merged-branch').css('display', 'none');
95
-        }
96
-        display_no_merged = !display_no_merged;
97
-      });
98
-      
99
-      // Click delete button
100
-      $('.delete-branch').on('click', function () {
101
-        if (window.confirm('Are you sure you want to remove this branch?')) {
102
-          return true;
103
-        }
104
-        else {
105
-          return false;
106
-        }
107
-      });
108
-    });
109
-  % end
110
-  
111 97
   %= include '/include/header';
112 98
   
113 99
   <div class="container" style="padding-bottom:30px">
114 100
     %= include '/include/errors', errors => $errors;
115 101
     %= include '/include/message', message => flash('message');
116 102
     
117
-    <h3 style="font-size:19px">Branches</h3>
103
+    <!-- Branches (for tests) -->
118 104
     
119
-    <div style="margin-bottom:10px">
120
-      Showing
121
-      <span id="no-merged-branch-message">
122
-         <%= $no_merged_branches_count %> branches not merged
123
-      </span>
124
-      <span style="display:none" id="merged-branch-message">
125
-        <%= $merged_branches_count %> branches merged
126
-      </span>
127
-      into <%= $base_branch->{name} %>.
128
-      <a id="toggle-branch" href="#">View merged branches</a>
129
-    </div>
130
-    <div class="bk-black" style="padding:5px 10px">
131
-      <div class="row">
132
-        <div class="span8" style="line-height:1.2em">
133
-          <div style="color:white;font-size:16px;">
134
-            <b><%= $base_branch->{name} %></b>
135
-          </div>
136
-          <div class="muted" style="font-size:12px">
137
-            Last updated
138
-            <span title="<%= $base_branch->{commit}{age_string_datetime_local} %>">
139
-              <%= $base_branch->{commit}{age_string} %>
140
-            </span>
141
-            by
142
-            <span title="<%= $base_branch->{commit}{author_email} %>" style="color:white">
143
-              <%= $base_branch->{commit}{author_name} %>
144
-            </span>
145
-          </div>
146
-        </div>
147
-        <div class="text-right font-white" style="padding-top:6px">
148
-          Base branch
149
-        </div>
150
-      </div>
151
-    </div>
152
-    % for (my $i = 0; $i < @$branches; $i++) {
153
-      % my $branch = $branches->[$i];
154
-      % my $bname = $branch->{name};
155
-      % next if $bname eq $base_branch->{name};
156
-      <div class="<%= $branch->{no_merged} ? 'no-merged-branch' : 'merged-branch' %> border-bottom-gray" style="padding:10px 0px 5px 0px;<%= $branch->{no_merged} ? '' : 'display:none' %>">
157
-        <div class="row">
158
-          <div class="span5" style="line-height:1.2em">
159
-            <div style="font-size:16px;">
160
-              <a href="<%= url_for("/$user/$project/tree/$bname") %>">
161
-                <b><%= $bname %></b>
162
-              </a>
163
-            </div>
164
-            <div style="font-size:12px">
165
-              Last updated
166
-              <span title="<%= $branch->{commit}{age_string_datetime_local} %>">
167
-                <%= $branch->{commit}{age_string} %>
168
-              </span>
169
-              by
170
-              <span title="<%= $branch->{commit}{author_email} %>">
171
-                <%= $branch->{commit}{author_name} %>
172
-              </span>
173
-            </div>
174
-          </div>
175
-          <div class="span3 muted" style="line-height:1em;font-size:11px">
176
-            <table>
177
-              <tr>
178
-                <td>
179
-                </td>
180
-                <td style="background:#333">
181
-                </td>
182
-                <td style="padding-left:3px">
183
-                  <%= $branch->{status}{ahead} %> ahead
184
-                </td>
185
-              </tr>
186
-              <tr>
187
-                <td style="width:100px">
188
-                  <div style="margin-left:auto;margin-right:0;background:#b2d0dd;width:<%= $max != 0 ? 100 * ($branch->{status}{behind} / $max) : 0 %>%;height:8px"></div>
189
-                </td>
190
-                <td style="background:#333">
191
-                </td>
192
-                <td style="width:100px">
193
-                  <div style="background:#b2d0dd;width:<%= $max != 0 ? 100 * ($branch->{status}{ahead} / $max) : 0 %>%;height:8px"></div>
194
-                </td>
195
-              </tr>
196
-              <tr>
197
-                <td>
198
-                  <%= $branch->{status}{behind} %> behind
199
-                </td>
200
-                <td style="background:#333">
201
-                </td>
202
-                <td>
203
-                </td>
204
-              </tr>
205
-            </table>
206
-          </div>
207
-          <div class="span4 text-right" style="padding-top:0px">
208
-            % if ($api->logined($user)) {
209
-              <form action="<%= url_for->query(op => 'delete') %>" method="post" style="display:inline-block">
210
-                <input type="submit" class="btn delete-branch" style="color:#900;" value="Delete branch">
211
-                %= hidden_field branch => $bname;
212
-              </form>
213
-            % }
214
-            <a class="btn" href="<%= url_for("/$user/$project/compare/$base_branch->{name}...$bname") %>">
215
-              Compare
216
-            </a>
217
-            % if (app->config->{basic}{show_ignore_space_change_link}) {
218
-              (<a style="font-size:90%;color:#9999FF" href="<%= url_for("/$user/$project/compare/$base_branch->{name}...$bname?w=") %>">
219
-                ignore space
220
-              </a>)
221
-            % }
222
-          </div>
105
+    <ul>
106
+      <li>
107
+        <a href="<%= url_for("/$user/$project/branches") %>">Overview</a>
108
+      </li>
109
+      <li>
110
+        <a href="<%= url_for("/$user/$project/branches/active") %>">Active</a>
111
+      </li>
112
+      <li>
113
+        <a href="<%= url_for("/$user/$project/branches/stale") %>">Stale</a>
114
+      </li>
115
+      <li>
116
+        <a href="<%= url_for("/$user/$project/branches/all") %>">All branches</a>
117
+      </li>
118
+    </ul>
119
+    
120
+    % for my $branch_type (@$branch_types) {
121
+      % my $branches = $branches_h->{$branch_type};
122
+      % if (@$branches) {
123
+        <div>
124
+          % if ($branch_type eq 'default') {
125
+            Default branch
126
+          % } elsif ($branch_type eq 'active') {
127
+            Active branch
128
+          % } elsif ($branch_type eq 'stale') {
129
+            Stale branch
130
+          % } elsif ($branch_type eq 'all') {
131
+            All branches
132
+          % }
223 133
         </div>
224
-      </div>
134
+        <ul>
135
+          % for (my $i = 0; $i < @$branches; $i++) {
136
+            % my $branch = $branches->[$i];
137
+            % my $bname = $branch->{name};
138
+            <li>
139
+              <div class="row">
140
+                <div class="span5" style="line-height:1.2em">
141
+                  <div style="font-size:16px;">
142
+                    <a href="<%= url_for("/$user/$project/tree/$bname") %>">
143
+                      <b><%= $bname %></b>
144
+                    </a>
145
+                  </div>
146
+                  <div style="font-size:12px">
147
+                    Updated
148
+                    <span title="<%= $branch->{commit}{age_string_datetime_local} %>">
149
+                      <%= $branch->{commit}{age_string} %>
150
+                    </span>
151
+                    by
152
+                    <span title="<%= $branch->{commit}{author_email} %>">
153
+                      <%= $branch->{commit}{author_name} %>
154
+                    </span>
155
+                  </div>
156
+                </div>
157
+                <div class="span3 muted" style="line-height:1em;font-size:11px">
158
+                  <table>
159
+                    <tr>
160
+                      <td>
161
+                      </td>
162
+                      <td style="background:#333">
163
+                      </td>
164
+                      <td style="padding-left:3px">
165
+                        <%= $branch->{status}{ahead} %> ahead
166
+                      </td>
167
+                    </tr>
168
+                    <tr>
169
+                      <td style="width:100px">
170
+                        <div style="margin-left:auto;margin-right:0;background:#b2d0dd;width:<%= $max != 0 ? 100 * ($branch->{status}{behind} / $max) : 0 %>%;height:8px"></div>
171
+                      </td>
172
+                      <td style="background:#333">
173
+                      </td>
174
+                      <td style="width:100px">
175
+                        <div style="background:#b2d0dd;width:<%= $max != 0 ? 100 * ($branch->{status}{ahead} / $max) : 0 %>%;height:8px"></div>
176
+                      </td>
177
+                    </tr>
178
+                    <tr>
179
+                      <td>
180
+                        <%= $branch->{status}{behind} %> behind
181
+                      </td>
182
+                      <td style="background:#333">
183
+                      </td>
184
+                      <td>
185
+                      </td>
186
+                    </tr>
187
+                  </table>
188
+                </div>
189
+                <div class="span4 text-right" style="padding-top:0px">
190
+                  % if ($api->logined($user)) {
191
+                    <form action="<%= url_for->query(op => 'delete') %>" method="post" style="display:inline-block">
192
+                      <input type="submit" class="btn delete-branch" style="color:#900;" value="Delete branch">
193
+                      %= hidden_field branch => $bname;
194
+                    </form>
195
+                  % }
196
+                  <a class="btn" href="<%= url_for("/$user/$project/compare/$default_branch->{name}...$bname") %>">
197
+                    Compare
198
+                  </a>
199
+                  % if (app->config->{basic}{show_ignore_space_change_link}) {
200
+                    (<a style="font-size:90%;color:#9999FF" href="<%= url_for("/$user/$project/compare/$default_branch->{name}...$bname?w=") %>">
201
+                      ignore space
202
+                    </a>)
203
+                  % }
204
+                </div>
205
+              </div>
206
+            </li>
207
+          % }
208
+        </ul>
209
+      % }
225 210
     % }
226 211
   </div>
227 212
   
-5
xt/basic.t
... ...
@@ -412,11 +412,6 @@ note 'Branches';
412 412
   $t->get_ok("/$user/$project/branches");
413 413
   $t->content_like(qr/Branches/);
414 414
   
415
-  # No merged branch
416
-  $t->content_like(qr/no-merged-branch.*?no_merged/s);
417
-  
418
-  # Marged branch
419
-  $t->content_like(qr/"merged-branch.*?b2/s);
420 415
 }
421 416
 
422 417
 note 'Compare';