Changeset - 25bdf9f62ab6
[Not reviewed]
stable
0 1 0
Thomas De Schampheleire - 7 years ago 2019-04-16 20:39:13
thomas.de_schampheleire@nokia.com
files: reduce duplication in display of file entries

Avoid special casing of the 'parent directory' link (..) by extracting some
logic to a helper function. This avoids duplication.

A subsequent commit will make changes to this logic and by introducing this
helper function we only need to change in one place.
1 file changed with 5 insertions and 2 deletions:
0 comments (0 inline, 0 general)
kallithea/templates/files/files_browser.html
Show inline comments
 
@@ -7,33 +7,36 @@
 
        <%return "submodule-dir"%>
 
    %else:
 
        <%return "browser-dir"%>
 
    %endif
 
</%def>
 
<%def name="file_url(node, c)">
 
    %if node.is_submodule():
 
        <%return node.url or '#'%>
 
    %else:
 
        <%return h.url('files_home', repo_name=c.repo_name, revision=c.changeset.raw_id, f_path=h.safe_unicode(node.path))%>
 
    %endif
 
</%def>
 
<%def name="_file_name(iconclass, name)">
 
    <%return h.literal('<i class="%s"></i><span>%s</span>' % (iconclass, name))%>
 
</%def>
 
<%def name="file_name(node)">
 
    <%
 
        c = "icon-folder-open"
 
        if node.is_file():
 
            c = "icon-doc"
 
        elif node.is_submodule():
 
            c = "icon-file-submodule"
 
    %>
 
    <%return h.literal('<i class="%s"></i><span>%s</span>' % (c, h.escape(node.name)))%>
 
    <%return _file_name(c, h.escape(node.name))%>
 
</%def>
 
<div id="body" class="panel panel-default">
 
    <div class="panel-heading clearfix">
 
        ${base.parent_child_navigation()}
 
    </div>
 

	
 
    <div class="panel-body">
 
        ${h.form(h.url.current())}
 
        <div id="search_activate_id" class="search_activate">
 
            <a class="btn btn-default btn-xs" id="filter_activate" href="#">${_('Search File List')}</a>
 
        </div>
 
        ${h.end_form()}
 
@@ -51,25 +54,25 @@
 
                    <th>${_('Name')}</th>
 
                    <th>${_('Size')}</th>
 
                    <th>${_('Last Revision')}</th>
 
                    <th>${_('Last Modified')}</th>
 
                    <th>${_('Last Committer')}</th>
 
                </tr>
 
            </thead>
 

	
 
            <tbody id="tbody">
 
                %if c.file.parent:
 
                <tr class="parity0">
 
                    <td>
 
                        ${h.link_to(h.literal('<i class="icon-folder-open"></i><span>..</span>'),h.url('files_home',repo_name=c.repo_name,revision=c.changeset.raw_id,f_path=c.file.parent.path),class_="browser-dir ypjax-link")}
 
                        ${h.link_to(_file_name('icon-folder-open', '..'),h.url('files_home',repo_name=c.repo_name,revision=c.changeset.raw_id,f_path=c.file.parent.path),class_="browser-dir ypjax-link")}
 
                    </td>
 
                    <td></td>
 
                    <td></td>
 
                    <td></td>
 
                    <td></td>
 
                </tr>
 
                %endif
 

	
 
            %for cnt,node in enumerate(c.file):
 
                <tr class="parity${cnt%2}">
 
                     <td>
 
                         ${h.link_to(file_name(node),file_url(node,c),class_=file_class(node)+(" ypjax-link" if not node.is_submodule() else ""), target_="_blank" if node.is_submodule() else None)}
0 comments (0 inline, 0 general)