Simplify column sort code, so that clicking the sort column header

reverses the sort order, while clicking on other headers sorts by
that column in ascending order.  This matches how most GUIs handle
sorting in columned lists.

Also port the sort handling from dir_alternate.ezt to directory.ezt
to reduce differences between the two templates.


git-svn-id: http://viewvc.tigris.org/svn/viewvc/trunk@886 8cb11bc2-c004-0410-86c3-e597b4017df7
remotes/tags/1.0.0-rc1
jhenstridge 2004-07-21 14:58:30 +00:00
parent 57c58fde9b
commit cc970525ac
3 changed files with 91 additions and 93 deletions

View File

@ -1462,13 +1462,16 @@ def view_directory(request):
'tarball_href' : None,
'search_re' : search_re and htmlify(search_re) or None,
'dir_pagestart' : None,
'sortby_file_href' : request.get_url(params={'sortby': 'file'}),
'sortby_rev_href' : request.get_url(params={'sortby': 'rev'}),
'sortby_date_href' : request.get_url(params={'sortby': 'date'}),
'sortby_author_href' : request.get_url(params={'sortby': 'author'}),
'sortby_log_href' : request.get_url(params={'sortby': 'log'}),
'sortdir_down_href' : request.get_url(params={'sortdir': 'down'}),
'sortdir_up_href' : request.get_url(params={'sortdir': 'up'}),
'sortby_file_href' : request.get_url(params={'sortby': 'file',
'sortdir': None}),
'sortby_rev_href' : request.get_url(params={'sortby': 'rev',
'sortdir': None}),
'sortby_date_href' : request.get_url(params={'sortby': 'date',
'sortdir': None}),
'sortby_author_href' : request.get_url(params={'sortby': 'author',
'sortdir': None}),
'sortby_log_href' : request.get_url(params={'sortby': 'log',
'sortdir': None}),
'num_files' : num_files,
'files_shown' : num_displayed,
'no_match' : ezt.boolean(num_files and not num_displayed),
@ -1480,6 +1483,15 @@ def view_directory(request):
'nav_path' : clickable_path(request, 0, 0),
})
# clicking on sort column reverses sort order
if sortdir == 'down':
revsortdir = None # 'up'
else:
revsortdir = 'down'
if sortby in ['file', 'rev', 'date', 'log', 'author']:
data['sortby_%s_href' % sortby] = request.get_url(params={'sortdir':
revsortdir})
# set cvs-specific fields
if request.roottype == 'cvs':
plain_tags = options['cvs_tags']

View File

@ -2,60 +2,43 @@
<table width="100%" border=0 cellspacing=1 cellpadding=2>
<tr>
[is sortby "rev"]
<th class="vc_header_sort">Rev.&nbsp;[is sortdir "up"]<a
href="[sortdir_down_href]#dirlist"><img
src="[docroot]/images/down.png"></a>[else]<a
href="[sortdir_up_href]#dirlist"><img
src="[docroot]/images/up.png"></a>[end]</th>
[else]
<th class="vc_header"
><a href="[sortby_rev_href]#dirlist">Rev.</a></th>
[end]
[is sortby "file"]
<th class="vc_header_sort"
[is cfg.options.use_cvsgraph "1"]colspan=2[end]
>File&nbsp;[is sortdir "up"]<a
href="[sortdir_down_href]#dirlist"><img
src="[docroot]/images/down.png"></a>[else]<a
href="[sortdir_up_href]#dirlist"><img
src="[docroot]/images/up.png"></a>[end]</th>
[else]
<th class="vc_header"
[is cfg.options.use_cvsgraph "1"]colspan=2[end]
><a href="[sortby_file_href]#dirlist">File</a></th>
[end]
[is sortby "date"]
<th class="vc_header_sort">Age&nbsp;[is sortdir "up"]<a
href="[sortdir_down_href]#dirlist"><img
src="[docroot]/images/down.png"></a>[else]<a
href="[sortdir_up_href]#dirlist"><img
src="[docroot]/images/up.png"></a>[end]</th>
[else]
<th class="vc_header"
><a href="[sortby_date_href]#dirlist">Age</a></th>
[end]
[is sortby "author"]
<th class="vc_header_sort">Author&nbsp;[is sortdir "up"]<a
href="[sortdir_down_href]#dirlist"><img
src="[docroot]/images/down.png"></a>[else]<a
href="[sortdir_up_href]#dirlist"><img
src="[docroot]/images/up.png"></a>[end]</th>
[else]
<th class="vc_header"
><a href="[sortby_author_href]#dirlist">Author</a></th>
[end]
<th class="vc_header[is sortby "rev"]_sort[end]">
<a href="[sortby_rev_href]#dirlist">Rev.</a>
[is sortby "rev"]
<img class="vc_sortarrow" alt="[is sortdir "down"](rev)[end]"
src="[docroot]/images/[is sortdir "up"]down[else]up[end].png" />
[end]
</th>
<th class="vc_header[is sortby "file"]_sort[end]"
[is cfg.options.use_cvsgraph "1"]colspan=2[end]>
<a href="[sortby_file_href]#dirlist">File</a>
[is sortby "file"]
<img class="vc_sortarrow" alt="[is sortdir "down"](rev)[end]"
src="[docroot]/images/[is sortdir "up"]down[else]up[end].png" />
[end]
</th>
<th class="vc_header[is sortby "date"]_sort[end]">
<a href="[sortby_date_href]#dirlist">Age</a>
[is sortby "date"]
<img class="vc_sortarrow" alt="[is sortdir "down"](rev)[end]"
src="[docroot]/images/[is sortdir "up"]down[else]up[end].png" />
[end]
</th>
<th class="vc_header[is sortby "author"]_sort[end]">
<a href="[sortby_author_href]#dirlist">Author</a>
[is sortby "author"]
<img class="vc_sortarrow" alt="[is sortdir "down"](rev)[end]"
src="[docroot]/images/[is sortdir "up"]down[else]up[end].png" />
[end]
</th>
[is cfg.options.show_logs "1"]
[is sortby "log"]
<th class="vc_header_sort">Last log entry&nbsp;[is sortdir "up"]<a
href="[sortdir_down_href]#dirlist"><img
src="[docroot]/images/down.png"></a>[else]<a
href="[sortdir_up_href]#dirlist"><img
src="[docroot]/images/up.png"></a>[end]</th>
[else]
<th class="vc_header"
><a href="[sortby_log_href]#dirlist">Last log entry</a></th>
[end]
<th class="vc_header[is sortby "log"]_sort[end]">
<a href="[sortby_log_href]#dirlist">Last log entry</a>
[is sortby "log"]
<img class="vc_sortarrow" alt="[is sortdir "down"](rev)[end]"
src="[docroot]/images/[is sortdir "up"]down[else]up[end].png" />
[end]
</th>
[end]
</tr>

View File

@ -2,40 +2,43 @@
<table width="100%" border=0 cellspacing=1 cellpadding=2>
<tr>
[is sortby "file"]
<th class="vc_header_sort"
[is cfg.options.use_cvsgraph "1"]colspan=2[end]
>File</th>
[else]
<th class="vc_header"
[is cfg.options.use_cvsgraph "1"]colspan=2[end]
><a href="[sortby_file_href]#dirlist">File</a></th>
[end]
[is sortby "rev"]
<th class="vc_header_sort">Rev.</th>
[else]
<th class="vc_header"
><a href="[sortby_rev_href]"#dirlist>Rev.</a></th>
[end]
[is sortby "date"]
<th class="vc_header_sort">Age</th>
[else]
<th class="vc_header"
><a href="[sortby_date_href]#dirlist">Age</a></th>
[end]
[is sortby "author"]
<th class="vc_header_sort">Author</th>
[else]
<th class="vc_header"
><a href="[sortby_author_href]#dirlist">Author</a></th>
[end]
<th class="vc_header[is sortby "file"]_sort[end]"
[is cfg.options.use_cvsgraph "1"]colspan=2[end]>
<a href="[sortby_file_href]#dirlist">File</a>
[is sortby "file"]
<img class="vc_sortarrow" alt="[is sortdir "down"](rev)[end]"
src="[docroot]/images/[is sortdir "up"]down[else]up[end].png" />
[end]
</th>
<th class="vc_header[is sortby "rev"]_sort[end]">
<a href="[sortby_rev_href]#dirlist">Rev.</a>
[is sortby "rev"]
<img class="vc_sortarrow" alt="[is sortdir "down"](rev)[end]"
src="[docroot]/images/[is sortdir "up"]down[else]up[end].png" />
[end]
</th>
<th class="vc_header[is sortby "date"]_sort[end]">
<a href="[sortby_date_href]#dirlist">Age</a>
[is sortby "date"]
<img class="vc_sortarrow" alt="[is sortdir "down"](rev)[end]"
src="[docroot]/images/[is sortdir "up"]down[else]up[end].png" />
[end]
</th>
<th class="vc_header[is sortby "author"]_sort[end]">
<a href="[sortby_author_href]#dirlist">Author</a>
[is sortby "author"]
<img class="vc_sortarrow" alt="[is sortdir "down"](rev)[end]"
src="[docroot]/images/[is sortdir "up"]down[else]up[end].png" />
[end]
</th>
[is cfg.options.show_logs "1"]
[is sortby "log"]
<th class="vc_header_sort">Last log entry</th>
[else]
<th class="vc_header"
><a href="[sortby_log_href]#dirlist">Last log entry</a></th>
[end]
<th class="vc_header[is sortby "log"]_sort[end]">
<a href="[sortby_log_href]#dirlist">Last log entry</a>
[is sortby "log"]
<img class="vc_sortarrow" alt="[is sortdir "down"](rev)[end]"
src="[docroot]/images/[is sortdir "up"]down[else]up[end].png" />
[end]
</th>
[end]
</tr>