# HG changeset patch # User Paul Boddie # Date 1329690167 -3600 # Node ID b8931fcf1482bce75940d084d6657fd10d4546bb # Parent f8f45be34bafa817b827922e0894f8323936a902 Added support for viewing, choosing and changing the sort direction of columns. Simplified the link generation. diff -r f8f45be34baf -r b8931fcf1482 ImprovedTableParser.py --- a/ImprovedTableParser.py Sun Feb 19 21:42:32 2012 +0100 +++ b/ImprovedTableParser.py Sun Feb 19 23:22:47 2012 +0100 @@ -38,6 +38,11 @@ leading_number_regexp = re.compile(r"\d*") +# Constants. + +up_arrow = u'\u2191' +down_arrow = u'\u2193' + # Functions. def parse(s): @@ -419,6 +424,7 @@ columnfn, columnascending = column_types.get(columnnumber, (to_plain_text, True)) newsortcolumn = columnnumber, columnfn, columnascending + newsortcolumn_reverse = columnnumber, columnfn, not columnascending newlabel = columns[columnnumber][1].strip() # Show this column in all possible places in the sorting criteria. @@ -432,25 +438,35 @@ new_sort_columns.insert(i, newsortcolumn) label = columns[column][1].strip() - # Pop-up element showing the column inserted before the sort column. + arrow = columnascending and down_arrow or up_arrow + arrow_reverse = not columnascending and down_arrow or up_arrow + + sortcolumns = get_sort_column_output(new_sort_columns) + new_sort_columns[i] = newsortcolumn_reverse + sortcolumns_reverse = get_sort_column_output(new_sort_columns) + + # Columns permitting the insertion of the selected column. if column != columnnumber and not just_had_this_column: write(fmt.listitem(1, css_class="sortcolumn")) + # Pop-up element showing the column inserted before the sort column. + write(fmt.span(1, css_class="sortcolumn-container")) write(fmt.span(1, css_class="newsortcolumn")) write(formatText(newlabel, request, fmt)) + + write_sort_link(write, request, fmt, table_name, sortcolumns, arrow, "sortdirection") + write_sort_link(write, request, fmt, table_name, sortcolumns_reverse, arrow_reverse, "sortdirection") + write(fmt.span(0)) write(fmt.span(0)) # Link for selection of the modified sort criteria. - write(fmt.url(1, "?%s#%s" % ( - wikiutil.makeQueryString("%s-sortcolumns=%s" % (table_name, get_sort_column_output(new_sort_columns))), - fmt.qualify_id(fmt.sanitize_to_id(table_name)) - ))) - write(formatText(label, request, fmt)) - write(fmt.url(0)) + write_sort_link(write, request, fmt, table_name, sortcolumns, u"%s %s" % (label, arrow), "") + + # Columns permitting removal or modification. else: write(fmt.listitem(1)) @@ -468,13 +484,12 @@ else: just_had_this_column = True - write(fmt.url(1, "?%s#%s" % ( - wikiutil.makeQueryString("%s-sortcolumns=%s" % (table_name, get_sort_column_output(revised_sort_columns))), - fmt.qualify_id(fmt.sanitize_to_id(table_name)) - ), - css_class="removecolumn")) - write(formatText(label, request, fmt)) - write(fmt.url(0)) + sortcolumns_revised = get_sort_column_output(revised_sort_columns) + write_sort_link(write, request, fmt, table_name, sortcolumns_revised, u"%s %s" % (label, arrow), "removecolumn") + + # Alternative sort direction. + + write_sort_link(write, request, fmt, table_name, sortcolumns_reverse, arrow_reverse, "altdirection") write(fmt.listitem(0)) @@ -485,6 +500,13 @@ new_sort_columns = revised_sort_columns[:] new_sort_columns.append(newsortcolumn) + sortcolumns = get_sort_column_output(new_sort_columns) + new_sort_columns[-1] = newsortcolumn_reverse + sortcolumns_reverse = get_sort_column_output(new_sort_columns) + + arrow = columnascending and down_arrow or up_arrow + arrow_reverse = not columnascending and down_arrow or up_arrow + write(fmt.listitem(1, css_class="sortcolumn", style="list-style-type: none")) # Pop-up element showing the column inserted before the sort column. @@ -492,15 +514,14 @@ write(fmt.span(1, css_class="sortcolumn-container")) write(fmt.span(1, css_class="newsortcolumn")) write(formatText(newlabel, request, fmt)) + + write_sort_link(write, request, fmt, table_name, sortcolumns, arrow, "sortdirection") + write_sort_link(write, request, fmt, table_name, sortcolumns_reverse, arrow_reverse, "sortdirection") + write(fmt.span(0)) write(fmt.span(0)) - write(fmt.url(1, "?%s#%s" % ( - wikiutil.makeQueryString("%s-sortcolumns=%s" % (table_name, get_sort_column_output(new_sort_columns))), - fmt.qualify_id(fmt.sanitize_to_id(table_name)) - ))) - write(fmt.text(_("..."))) - write(fmt.url(0)) + write_sort_link(write, request, fmt, table_name, sortcolumns, _("..."), "") write(fmt.listitem(0)) @@ -508,6 +529,17 @@ write(fmt.div(0)) +def write_sort_link(write, request, fmt, table_name, sortcolumns, label, css_class): + + "Write a link expressing sort criteria." + + write(fmt.url(1, "?%s#%s" % ( + wikiutil.makeQueryString("%s-sortcolumns=%s" % (table_name, sortcolumns)), + fmt.qualify_id(fmt.sanitize_to_id(table_name)) + ), css_class=css_class)) + write(formatText(label, request, fmt)) + write(fmt.url(0)) + def get_sort_column_output(columns, start=0): "Return the output criteria for the given 'columns' indexed from 'start'." diff -r f8f45be34baf -r b8931fcf1482 css/improvedtableparser.css --- a/css/improvedtableparser.css Sun Feb 19 21:42:32 2012 +0100 +++ b/css/improvedtableparser.css Sun Feb 19 23:22:47 2012 +0100 @@ -31,15 +31,7 @@ display: block; } -.sortcolumn-container { - position: relative; - padding-right: 0.25em; -} - -a.removecolumn, -.unlinkedcolumn { - margin-left: 0.25em; /* replaces the container used for the pop-up */ -} +/* Column listings. */ .sortcolumns ol { margin: 0.5em; @@ -51,7 +43,7 @@ border-top: 2px solid #fff; } -.sortcolumn a { +.sortcolumns a { text-decoration: none !important; color: inherit !important; } @@ -60,19 +52,12 @@ border-top: 2px solid #f66; } -.sortcolumn .newsortcolumn { - display: none; - position: absolute; - bottom: 0.5em; - right: 0.25em; - z-index: 4; - background-color: #f66; - color: #000; - padding: 0.5em; -} +/* Column removal and inactive columns. */ -.sortcolumn:hover .newsortcolumn { - display: block; +a.altdirection, +a.removecolumn, +.unlinkedcolumn { + margin-left: 0.25em; /* replaces the container used for the pop-up */ } a.removecolumn { @@ -82,3 +67,30 @@ a.removecolumn:hover { text-decoration: line-through !important; } + +/* Positioning of pop-up elements. */ + +.sortcolumn-container { + position: relative; + padding-right: 0.25em; +} + +/* New column pop-up. */ + +.sortcolumn .newsortcolumn { + display: none; + position: absolute; + bottom: 0.5em; + right: 0.25em; + z-index: 4; +} + +.sortcolumn:hover .newsortcolumn { + display: block; +} + +.newsortcolumn { + background-color: #f66; + color: #000; + padding: 0.5em; +}