gitprep / templates / include / blob_diff_body.html.ep /
d7a564c 7 years ago
1 contributor
157 lines | 5.382kb
<%
  my $user_id = stash('user');
  my $project_id = stash('project');
  my $rev = stash('rev');
  my $from_rev = stash('from_rev');
  
  my $git = app->git;
  
  my $diff_tree = stash('diff_tree');
  my $blob_diff = stash('blob_diff');
  my $from_mode_str = $diff_tree->{from_mode_str};
  my $to_mode_str = $diff_tree->{to_mode_str};
  my $lines = $blob_diff->{lines} || [];
  my $file = $blob_diff->{file};
  $file = '' unless defined $file;
  my $from_file = $blob_diff->{from_file};
  $from_file = $file unless defined $from_file;
  my $status = $diff_tree->{status} || '';
  
  my $binary_rev_shown;
  my $binary_from_rev_shown;
  my $binary_not_shown;
  
  if ($blob_diff->{binary}) {
    if ($status eq 'A') {
      if ($git->blob_is_image(app->rep_info($user_id, $project_id), $rev, $file)) {
        $binary_rev_shown = 1;
      }
      else {
        $binary_not_shown = 1;
      }
    } elsif ($status eq 'D') {
      if ($git->blob_is_image(app->rep_info($user_id, $project_id), $from_rev, $file)) {
        $binary_from_rev_shown = 1;
      }
      else {
        $binary_not_shown = 1;
      }
    } else {
      if ($git->blob_is_image(app->rep_info($user_id, $project_id), $from_rev, $file)
        && $git->blob_is_image(app->rep_info($user_id, $project_id), $from_rev, $file)) {
        $binary_from_rev_shown = 1;
        $binary_rev_shown = 1;
      }
      else {
        $binary_not_shown = 1;
      }
    }
  }
%>

  <div class="commit-diff">
    <div class="commit-diff-header">
      <div>
        %= include '/include/diff_status_bar', diff_tree => $diff_tree;
        % if ($status eq 'R' || $status eq 'C') {
          <%= $from_file %> → <%= $file %>
        % } else {
          <%= $file %>
        % }
        % if ($status ne 'A' && $status ne 'D' && $from_mode_str ne $to_mode_str) {
          <%= "100$from_mode_str → 100$to_mode_str" %>
        % }
      </div>
      <div class="last-child">
        % if ($status eq 'D') {
          <a class="btn" href="<%= url_for("/$user_id/$project_id/blob/$from_rev/$file") %>">
            <b>View</b>
          </a>
        % } else {
          <a class="btn" href="<%= url_for("/$user_id/$project_id/blob/$rev/$file") %>">
            <b>View</b>
          </a>
        % }
      </div>
    </div>
    <div class="commit-diff-body">
        <%
          my $not_shown;
          my $from_rev_shown;
          my $rev_shown;
        %>
        

        % if ($blob_diff->{binary}) {
          % if ($binary_not_shown) {
            <div class="commit-diff-plain">
              Binary file not shown.
            </div>
          % } else {
            <div class="commit-diff-image">
              % if ($binary_from_rev_shown) {
                <a href="<%= url_for("/$user_id/$project_id/blob/$from_rev/$file") %>">
                  <img src="<%= url_for("/$user_id/$project_id/raw/$from_rev/$file") %>" style="border:1px solid red;padding:1px;margin-right:20px">
                </a>          
              % }
              
              % if ($binary_rev_shown) {
                <a href="<%= url_for("/$user_id/$project_id/blob/$rev/$file") %>">
                  <img src="<%= url_for("/$user_id/$project_id/raw/$rev/$file") %>" style="border:1px solid green;padding:1px;margin-left:20px">
                </a>
              % }
            </div>
          % }
        % } elsif (@$lines) {
          <table>

            % for my $line (@$lines) {
              % my $class = $line->{class};
              % my $value = $line->{value};

              <%
                my $bk_color_line = '';
                my $bk_color = '';
                my $border_color;
                if ($value =~ /^@/) {
                  $bk_color_line = '#f3f3ff';
                  $border_color = '#e4e4ff';
                  $bk_color = '#f8f8ff';
                } elsif ($value =~ /^\+/) {
                  $bk_color_line = '#ceffce';
                  $border_color = '#b4e2b4';
                  $bk_color = '#ddffdd';
                } elsif ($value =~ /^-/) {
                  $bk_color_line = '#f7c8c8';
                  $border_color = '#e9aeae';
                  $bk_color = '#fdd';
                } else {
                  $border_color = '#e5e5e5';
                }
              %>
              <tr >
                <td style="font-size:12px;color:#aaa;padding:0 7px;border-right:1px <%= $border_color %> solid;background:<%= $bk_color_line %>;">
                  <%= $line->{before_line_num} %>
                </td>
                <td style="font-size:12px;color:#aaa;padding:0 7px;border-right:1px <%= $border_color %> solid;background:<%= $bk_color_line %>;">
                  <%= $line->{after_line_num} %>
                </td>
                <td style="width:100%;padding-left:7px;background:<%= $bk_color %>;">
                  <pre style="border:none;background:none;padding:0;margin:0"><%= $value %></pre>
                </td>
              </tr>
            % }
          </table>
        % } else {
          <div class="commit-diff-plain">
            % if ($status eq 'R') {
              File renamed without changes.
            % } elsif ($status eq 'A' || $status eq 'D') {
               No changes.
            % } elsif ($from_mode_str ne $to_mode_str) {
              File mode changed.
            % }
          </div>
        % }
    </div>
  </div>