Skip to content

Commit 072723f

Browse files
TobiXhoxu
authored andcommitted
Use sortable.js to sort some tables.
This sorts tables on the authors and files pages. Slightly modifies the sortable.js to ignore additional info in parentheses after a number. Signed-off-by: Heikki Hokkanen <[email protected]>
1 parent 7b61c4b commit 072723f

File tree

3 files changed

+29
-16
lines changed

3 files changed

+29
-16
lines changed

gitstats

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -436,10 +436,11 @@ class HTMLReportCreator(ReportCreator):
436436
ReportCreator.create(self, data, path)
437437
self.title = data.projectname
438438

439-
# copy the CSS if it does not exist
440-
if not os.path.exists(path + '/gitstats.css'):
441-
basedir = os.path.dirname(os.path.abspath(__file__))
442-
shutil.copyfile(basedir + '/gitstats.css', path + '/gitstats.css')
439+
# copy static files if they do not exist
440+
for file in ('gitstats.css', 'sortable.js', 'arrow-up.gif', 'arrow-down.gif', 'arrow-none.gif'):
441+
if not os.path.exists(path + '/' + file):
442+
basedir = os.path.dirname(os.path.abspath(__file__))
443+
shutil.copyfile(basedir + '/' + file, path + '/' + file)
443444

444445
f = open(path + "/index.html", 'w')
445446
format = '%Y-%m-%d %H:%m:%S'
@@ -605,17 +606,17 @@ class HTMLReportCreator(ReportCreator):
605606
# Authors :: List of authors
606607
f.write(html_header(2, 'List of Authors'))
607608

608-
f.write('<table class="authors">')
609-
f.write('<tr><th>Author</th><th>Commits (%)</th><th>First commit</th><th>Last commit</th><th>Age</th><th># by commits</th></tr>')
609+
f.write('<table class="authors sortable" id="authors">')
610+
f.write('<tr><th>Author</th><th>Commits (%)</th><th>First commit</th><th>Last commit</th><th class="unsortable">Age</th><th># by commits</th></tr>')
610611
for author in sorted(data.getAuthors()):
611612
info = data.getAuthorInfo(author)
612613
f.write('<tr><td>%s</td><td>%d (%.2f%%)</td><td>%s</td><td>%s</td><td>%s</td><td>%d</td></tr>' % (author, info['commits'], info['commits_frac'], info['date_first'], info['date_last'], info['timedelta'], info['place_by_commits']))
613614
f.write('</table>')
614615

615616
# Authors :: Author of Month
616617
f.write(html_header(2, 'Author of Month'))
617-
f.write('<table>')
618-
f.write('<tr><th>Month</th><th>Author</th><th>Commits (%)</th><th>Next top 5</th></tr>')
618+
f.write('<table class="sortable" id="aom">')
619+
f.write('<tr><th>Month</th><th>Author</th><th>Commits (%)</th><th class="unsortable">Next top 5</th></tr>')
619620
for yymm in reversed(sorted(data.author_of_month.keys())):
620621
authordict = data.author_of_month[yymm]
621622
authors = getkeyssortedbyvalues(authordict)
@@ -627,7 +628,7 @@ class HTMLReportCreator(ReportCreator):
627628
f.write('</table>')
628629

629630
f.write(html_header(2, 'Author of Year'))
630-
f.write('<table><tr><th>Year</th><th>Author</th><th>Commits (%)</th><th>Next top 5</th></tr>')
631+
f.write('<table class="sortable" id="aoy"><tr><th>Year</th><th>Author</th><th>Commits (%)</th><th class="unsortable">Next top 5</th></tr>')
631632
for yy in reversed(sorted(data.author_of_year.keys())):
632633
authordict = data.author_of_year[yy]
633634
authors = getkeyssortedbyvalues(authordict)
@@ -667,7 +668,7 @@ class HTMLReportCreator(ReportCreator):
667668

668669
# Files :: Extensions
669670
f.write(html_header(2, 'Extensions'))
670-
f.write('<table><tr><th>Extension</th><th>Files (%)</th><th>Lines (%)</th><th>Lines/file</th></tr>')
671+
f.write('<table class="sortable" id="ext"><tr><th>Extension</th><th>Files (%)</th><th>Lines (%)</th><th>Lines/file</th></tr>')
671672
for ext in sorted(data.extensions.keys()):
672673
files = data.extensions[ext]['files']
673674
lines = data.extensions[ext]['lines']
@@ -850,6 +851,7 @@ plot 'lines_of_code.dat' using 1:2 w lines
850851
<title>GitStats - %s</title>
851852
<link rel="stylesheet" href="gitstats.css" type="text/css" />
852853
<meta name="generator" content="GitStats" />
854+
<script type="text/javascript" src="sortable.js"></script>
853855
</head>
854856
<body>
855857
""" % self.title)

gitstats.css

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ th {
3737
background-color: #ddf;
3838
}
3939

40+
th a {
41+
text-decoration: none;
42+
}
43+
4044
tr:hover {
4145
background-color: #ddf;
4246
}
@@ -85,6 +89,12 @@ img {
8589
background-color: white;
8690
}
8791

92+
th img {
93+
border: 0px;
94+
padding: 0px;
95+
background-color: #ddf;
96+
}
97+
8898
h1 a, h2 a {
8999
color: black;
90100
text-decoration: none;

sortable.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ Version 1.5.7
99
*/
1010

1111
/* You can change these values */
12-
var image_path = "http://www.joostdevalk.nl/code/sortable-table/";
13-
var image_up = "arrowup.gif";
14-
var image_down = "arrowdown.gif";
15-
var image_none = "arrownone.gif";
12+
var image_path = "";
13+
var image_up = "arrow-up.gif";
14+
var image_down = "arrow-down.gif";
15+
var image_none = "arrow-none.gif";
1616
var europeandate = true;
1717
var alternate_row_colors = true;
1818

@@ -91,7 +91,7 @@ function ts_resortTable(lnk, clid) {
9191
// Work out a type for the column
9292
if (t.rows.length <= 1) return;
9393
var itm = "";
94-
var i = 0;
94+
var i = 1;
9595
while (itm == "" && i < t.tBodies[0].rows.length) {
9696
var itm = ts_getInnerText(t.tBodies[0].rows[i].cells[column]);
9797
itm = trim(itm);
@@ -105,7 +105,8 @@ function ts_resortTable(lnk, clid) {
105105
if (itm.match(/^\d\d[\/\.-][a-zA-z][a-zA-Z][a-zA-Z][\/\.-]\d\d\d\d$/)) sortfn = ts_sort_date;
106106
if (itm.match(/^\d\d[\/\.-]\d\d[\/\.-]\d\d\d{2}?$/)) sortfn = ts_sort_date;
107107
if (itm.match(/^-?[£$Û¢´]\d/)) sortfn = ts_sort_numeric;
108-
if (itm.match(/^-?(\d+[,\.]?)+(E[-+][\d]+)?%?$/)) sortfn = ts_sort_numeric;
108+
// ignore stuff in () after the numbers.
109+
if (itm.match(/^-?(\d+[,\.]?)+(E[-+][\d]+)?%?( \(.*\))?$/)) sortfn = ts_sort_numeric;
109110
SORT_COLUMN_INDEX = column;
110111
var firstRow = new Array();
111112
var newRows = new Array();

0 commit comments

Comments
 (0)