Changeset - 52adce4ffe89
[Not reviewed]
default
0 1 1
Mads Kiilerich - 8 years ago 2017-08-27 16:39:35
mads@kiilerich.com
changelog: make the table a re-usable template element

This moves the changelog table to a separate template file, without further
changes, except the necessary renaming to make it fully parameterized without
accessing c directly.

Based on work by Dominik Ruf.
2 files changed with 127 insertions and 113 deletions:
0 comments (0 inline, 0 general)
kallithea/templates/changelog/changelog.html
Show inline comments
 
@@ -2,6 +2,8 @@
 

	
 
<%inherit file="/base/base.html"/>
 

	
 
<%namespace name="changelog_table" file="changelog_table.html"/>
 

	
 
<%block name="title">
 
    ${_('%s Changelog') % c.repo_name}
 
    %if c.changelog_for_path:
 
@@ -67,114 +69,13 @@ ${self.repo_context_bar('changelog', c.f
 
                <div id="graph_nodes">
 
                    <canvas id="graph_canvas" style="width:0"></canvas>
 
                </div>
 

	
 
                <div id="graph_content" style="${'margin: 0px' if c.changelog_for_path else ''}">
 

	
 
                <table class="table" id="changesets">
 
                <tbody>
 
                %for cnt,cs in enumerate(c.cs_pagination):
 
                    <tr id="chg_${cnt+1}" class="${'mergerow' if len(cs.parents) > 1 else ''}">
 
                        %if not c.changelog_for_path:
 
                        <td class="checkbox-column">
 
                            ${h.checkbox(cs.raw_id,class_="changeset_range")}
 
                        </td>
 
                        %endif
 
                        <td class="status">
 
                          %if c.cs_statuses.get(cs.raw_id):
 
                            %if c.cs_statuses.get(cs.raw_id)[2]:
 
                              <a data-toggle="tooltip" title="${_('Changeset status: %s by %s\nClick to open associated pull request %s') % (c.cs_statuses.get(cs.raw_id)[1], c.cs_statuses.get(cs.raw_id)[5].username, c.cs_statuses.get(cs.raw_id)[4])}" href="${h.url('pullrequest_show',repo_name=c.cs_statuses.get(cs.raw_id)[3],pull_request_id=c.cs_statuses.get(cs.raw_id)[2])}">
 
                                <i class="icon-circle changeset-status-${c.cs_statuses.get(cs.raw_id)[0]}"></i>
 
                              </a>
 
                            %else:
 
                              <a data-toggle="tooltip" title="${_('Changeset status: %s by %s') % (c.cs_statuses.get(cs.raw_id)[1], c.cs_statuses.get(cs.raw_id)[5].username)}"
 
                                 href="${c.cs_comments[cs.raw_id][0].url()}">
 
                                  <i class="icon-circle changeset-status-${c.cs_statuses.get(cs.raw_id)[0]}"></i>
 
                              </a>
 
                            %endif
 
                          %endif
 
                        </td>
 
                        <td class="author" data-toggle="tooltip" title="${cs.author}">
 
                            ${h.gravatar(h.email_or_none(cs.author), size=16)}
 
                            <span class="user">${h.person(cs.author)}</span>
 
                        </td>
 
                        <td class="hash">
 
                            ${h.link_to(h.show_id(cs),h.url('changeset_home',repo_name=c.repo_name,revision=cs.raw_id), class_='changeset_hash')}
 
                        </td>
 
                        <td class="date">
 
                            <div class="date" data-toggle="tooltip" title="${h.fmt_date(cs.date)}">${h.age(cs.date,True)}</div>
 
                        </td>
 
                        <% message_lines = cs.message.splitlines() %>
 
                        %if len(message_lines) > 1:
 
                        <td class="expand_commit" title="${_('Expand commit message')}">
 
                            <i class="icon-align-left"></i>
 
                        </td>
 
                        %else:
 
                        <td></td>
 
                        %endif
 
                        <td class="mid">
 
                            <div class="log-container">
 
                                <div class="message">
 
                                    <div class="message-firstline">${h.urlify_text(message_lines[0], c.repo_name,h.url('changeset_home',repo_name=c.repo_name,revision=cs.raw_id))}</div>
 
                                    %if len(message_lines) > 1:
 
                                    <div class="message-full hidden">${h.urlify_text(cs.message, c.repo_name)}</div>
 
                                    %endif
 
                                </div>
 
                                <div class="extra-container">
 
                                    %if c.cs_comments.get(cs.raw_id):
 
                                        <a class="comments-container comments-cnt" href="${c.cs_comments[cs.raw_id][0].url()}" data-toggle="tooltip" title="${_('%s comments') % len(c.cs_comments[cs.raw_id])}">
 
                                            ${len(c.cs_comments[cs.raw_id])}
 
                                            <i class="icon-comment-discussion"></i>
 
                                        </a>
 
                                    %endif
 
                                    %if cs.bumped:
 
                                        <span class="bumpedtag" title="Bumped">
 
                                            Bumped
 
                                        </span>
 
                                    %endif
 
                                    %if cs.divergent:
 
                                        <span class="divergenttag" title="Divergent">
 
                                            Divergent
 
                                        </span>
 
                                    %endif
 
                                    %if cs.extinct:
 
                                        <span class="extincttag" title="Extinct">
 
                                            Extinct
 
                                        </span>
 
                                    %endif
 
                                    %if cs.unstable:
 
                                        <span class="unstabletag" title="Unstable">
 
                                            Unstable
 
                                        </span>
 
                                    %endif
 
                                    %if cs.phase:
 
                                        <span class="phasetag" title="Phase">
 
                                            ${cs.phase}
 
                                        </span>
 
                                    %endif
 
                                    %for book in cs.bookmarks:
 
                                        <span class="booktag" title="${_('Bookmark %s') % book}">
 
                                            ${h.link_to(book,h.url('changeset_home',repo_name=c.repo_name,revision=cs.raw_id))}
 
                                        </span>
 
                                    %endfor
 
                                    %for tag in cs.tags:
 
                                        <span class="tagtag" title="${_('Tag %s') % tag}">
 
                                            ${h.link_to(tag,h.url('changeset_home',repo_name=c.repo_name,revision=cs.raw_id))}
 
                                        </span>
 
                                    %endfor
 
                                    %if (not c.branch_name) and cs.branch:
 
                                        <span class="branchtag" title="${_('Branch %s' % cs.branch)}">
 
                                            ${h.link_to(cs.branch,h.url('changelog_home',repo_name=c.repo_name,branch=cs.branch))}
 
                                        </span>
 
                                    %endif
 
                                </div>
 
                            </div>
 
                        </td>
 
                    </tr>
 
                %endfor
 
                </tbody>
 
                </table>
 

	
 
                  ${changelog_table.changelog(c.repo_name, c.cs_pagination, c.cs_statuses, c.cs_comments,
 
                                              show_checkbox=not c.changelog_for_path,
 
                                              show_branch=not c.branch_name,
 
                                              resize_js='graph.render(jsdata)')}
 
                <input type="checkbox" id="singlerange" style="display:none"/>
 

	
 
                </div>
 

	
 
                ${c.cs_pagination.pager()}
 
@@ -291,13 +192,6 @@ ${self.repo_context_bar('changelog', c.f
 
                    }
 
                });
 

	
 
                $('.expand_commit').on('click',function(e){
 
                    $(this).next('.mid').find('.message > div').toggleClass('hidden');
 

	
 
                    //redraw the graph, r and jsdata are bound outside function
 
                    graph.render(jsdata);
 
                });
 

	
 
                // change branch filter
 
                $("#branch_filter").select2({
 
                    dropdownAutoWidth: true,
kallithea/templates/changelog/changelog_table.html
Show inline comments
 
new file 100644
 
## Render changelog table with id 'changesets' with the range of changesets,
 
## statuses, and comments.
 
## Optionally, pass a js snippet to run whenever a table resize is triggered.
 
<%def name="changelog(repo_name, cs_range, cs_statuses, cs_comments, show_checkbox=False, show_branch=True, resize_js='')">
 
    <table class="table" id="changesets">
 
    <tbody>
 
      %for cnt,cs in enumerate(cs_range):
 
      <tr id="chg_${cnt+1}" class="${'mergerow' if len(cs.parents) > 1 else ''}">
 
        %if show_checkbox:
 
        <td class="checkbox-column">
 
          ${h.checkbox(cs.raw_id,class_="changeset_range")}
 
        </td>
 
        %endif
 
        <td class="status">
 
          %if cs_statuses.get(cs.raw_id):
 
            %if cs_statuses.get(cs.raw_id)[2]:
 
              <a data-toggle="tooltip"
 
                  title="${_('Changeset status: %s by %s\nClick to open associated pull request %s') % (cs_statuses.get(cs.raw_id)[1], cs_statuses.get(cs.raw_id)[5].username, cs_statuses.get(cs.raw_id)[4])}"
 
                  href="${h.url('pullrequest_show',repo_name=cs_statuses.get(cs.raw_id)[3],pull_request_id=cs_statuses.get(cs.raw_id)[2])}">
 
                <i class="icon-circle changeset-status-${cs_statuses.get(cs.raw_id)[0]}"></i>
 
              </a>
 
            %else:
 
              <a data-toggle="tooltip"
 
                  title="${_('Changeset status: %s by %s') % (cs_statuses.get(cs.raw_id)[1], cs_statuses.get(cs.raw_id)[5].username)}"
 
                  href="${cs_comments[cs.raw_id][0].url()}">
 
                <i class="icon-circle changeset-status-${cs_statuses.get(cs.raw_id)[0]}"></i>
 
              </a>
 
            %endif
 
          %endif
 
        </td>
 
        <td class="author" data-toggle="tooltip" title="${cs.author}">
 
          ${h.gravatar(h.email_or_none(cs.author), size=16)}
 
          <span class="user">${h.person(cs.author)}</span>
 
        </td>
 
        <td class="hash">
 
          ${h.link_to(h.show_id(cs),h.url('changeset_home',repo_name=repo_name,revision=cs.raw_id), class_='changeset_hash')}
 
        </td>
 
        <td class="date">
 
          <div class="date" data-toggle="tooltip" title="${h.fmt_date(cs.date)}">${h.age(cs.date,True)}</div>
 
        </td>
 
        <% message_lines = cs.message.splitlines() %>
 
        %if len(message_lines) > 1:
 
        <td class="expand_commit" title="${_('Expand commit message')}">
 
          <i class="icon-align-left"></i>
 
        </td>
 
        %else:
 
        <td></td>
 
        %endif
 
        <td class="mid">
 
          <div class="log-container">
 
            <div class="message">
 
              <div class="message-firstline">${h.urlify_text(message_lines[0], c.repo_name,h.url('changeset_home',repo_name=repo_name,revision=cs.raw_id))}</div>
 
              %if len(message_lines) > 1:
 
              <div class="message-full hidden">${h.urlify_text(cs.message, repo_name)}</div>
 
              %endif
 
            </div>
 
            <div class="extra-container">
 
              %if cs_comments.get(cs.raw_id):
 
                <a class="comments-container comments-cnt" href="${cs_comments[cs.raw_id][0].url()}" data-toggle="tooltip" title="${_('%s comments') % len(cs_comments[cs.raw_id])}">
 
                  ${len(cs_comments[cs.raw_id])}
 
                  <i class="icon-comment-discussion"></i>
 
                </a>
 
              %endif
 
              %if cs.bumped:
 
                <span class="bumpedtag" title="Bumped">
 
                  Bumped
 
                </span>
 
              %endif
 
              %if cs.divergent:
 
                <span class="divergenttag" title="Divergent">
 
                  Divergent
 
                </span>
 
              %endif
 
              %if cs.extinct:
 
                <span class="extincttag" title="Extinct">
 
                  Extinct
 
                </span>
 
              %endif
 
              %if cs.unstable:
 
                <span class="unstabletag" title="Unstable">
 
                  Unstable
 
                </span>
 
              %endif
 
              %if cs.phase:
 
                <span class="phasetag" title="Phase">
 
                  ${cs.phase}
 
                </span>
 
              %endif
 
              %for book in cs.bookmarks:
 
                <span class="booktag" title="${_('Bookmark %s') % book}">
 
                  ${h.link_to(book,h.url('changeset_home',repo_name=repo_name,revision=cs.raw_id))}
 
                </span>
 
              %endfor
 
              %for tag in cs.tags:
 
                <span class="tagtag" title="${_('Tag %s') % tag}">
 
                  ${h.link_to(tag,h.url('changeset_home',repo_name=repo_name,revision=cs.raw_id))}
 
                </span>
 
              %endfor
 
              %if show_branch and cs.branch:
 
                <span class="branchtag" title="${_('Branch %s' % cs.branch)}">
 
                  ${h.link_to(cs.branch,h.url('changelog_home',repo_name=repo_name,branch=cs.branch))}
 
                </span>
 
              %endif
 
            </div>
 
          </div>
 
        </td>
 
      </tr>
 
      %endfor
 
    </tbody>
 
    </table>
 

	
 
<script type="text/javascript">
 
  $(document).ready(function() {
 
    $('#changesets .expand_commit').on('click',function(e){
 
      $(this).next('.mid').find('.message > div').toggleClass('hidden');
 
      ${resize_js};
 
    });
 
  });
 
</script>
 
</%def>
0 comments (0 inline, 0 general)