Browse Source

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 <hoxu@users.sf.net>
Tobias Gruetzmacher 17 years ago
parent
commit
072723fb71
3 changed files with 29 additions and 16 deletions
  1. 12
    10
      gitstats
  2. 10
    0
      gitstats.css
  3. 7
    6
      sortable.js

+ 12
- 10
gitstats View File

436
 		ReportCreator.create(self, data, path)
436
 		ReportCreator.create(self, data, path)
437
 		self.title = data.projectname
437
 		self.title = data.projectname
438
 
438
 
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)
443
 
444
 
444
 		f = open(path + "/index.html", 'w')
445
 		f = open(path + "/index.html", 'w')
445
 		format = '%Y-%m-%d %H:%m:%S'
446
 		format = '%Y-%m-%d %H:%m:%S'
605
 		# Authors :: List of authors
606
 		# Authors :: List of authors
606
 		f.write(html_header(2, 'List of Authors'))
607
 		f.write(html_header(2, 'List of Authors'))
607
 
608
 
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>')
610
 		for author in sorted(data.getAuthors()):
611
 		for author in sorted(data.getAuthors()):
611
 			info = data.getAuthorInfo(author)
612
 			info = data.getAuthorInfo(author)
612
 			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']))
613
 			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']))
614
 
615
 
615
 		# Authors :: Author of Month
616
 		# Authors :: Author of Month
616
 		f.write(html_header(2, 'Author of Month'))
617
 		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>')
619
 		for yymm in reversed(sorted(data.author_of_month.keys())):
620
 		for yymm in reversed(sorted(data.author_of_month.keys())):
620
 			authordict = data.author_of_month[yymm]
621
 			authordict = data.author_of_month[yymm]
621
 			authors = getkeyssortedbyvalues(authordict)
622
 			authors = getkeyssortedbyvalues(authordict)
627
 		f.write('</table>')
628
 		f.write('</table>')
628
 
629
 
629
 		f.write(html_header(2, 'Author of Year'))
630
 		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>')
631
 		for yy in reversed(sorted(data.author_of_year.keys())):
632
 		for yy in reversed(sorted(data.author_of_year.keys())):
632
 			authordict = data.author_of_year[yy]
633
 			authordict = data.author_of_year[yy]
633
 			authors = getkeyssortedbyvalues(authordict)
634
 			authors = getkeyssortedbyvalues(authordict)
667
 
668
 
668
 		# Files :: Extensions
669
 		# Files :: Extensions
669
 		f.write(html_header(2, 'Extensions'))
670
 		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>')
671
 		for ext in sorted(data.extensions.keys()):
672
 		for ext in sorted(data.extensions.keys()):
672
 			files = data.extensions[ext]['files']
673
 			files = data.extensions[ext]['files']
673
 			lines = data.extensions[ext]['lines']
674
 			lines = data.extensions[ext]['lines']
850
 	<title>GitStats - %s</title>
851
 	<title>GitStats - %s</title>
851
 	<link rel="stylesheet" href="gitstats.css" type="text/css" />
852
 	<link rel="stylesheet" href="gitstats.css" type="text/css" />
852
 	<meta name="generator" content="GitStats" />
853
 	<meta name="generator" content="GitStats" />
854
+	<script type="text/javascript" src="sortable.js"></script>
853
 </head>
855
 </head>
854
 <body>
856
 <body>
855
 """ % self.title)
857
 """ % self.title)

+ 10
- 0
gitstats.css View File

37
 	background-color: #ddf;
37
 	background-color: #ddf;
38
 }
38
 }
39
 
39
 
40
+th a {
41
+	text-decoration: none;
42
+}
43
+
40
 tr:hover {
44
 tr:hover {
41
 	background-color: #ddf;
45
 	background-color: #ddf;
42
 }
46
 }
85
 	background-color: white;
89
 	background-color: white;
86
 }
90
 }
87
 
91
 
92
+th img {
93
+	border: 0px;
94
+	padding: 0px;
95
+	background-color: #ddf;
96
+}
97
+
88
 h1 a, h2 a {
98
 h1 a, h2 a {
89
 	color: black;
99
 	color: black;
90
 	text-decoration: none;
100
 	text-decoration: none;

+ 7
- 6
sortable.js View File

9
 */
9
 */
10
 
10
 
11
 /* You can change these values */
11
 /* 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";
16
 var europeandate = true;
16
 var europeandate = true;
17
 var alternate_row_colors = true;
17
 var alternate_row_colors = true;
18
 
18
 
91
 	// Work out a type for the column
91
 	// Work out a type for the column
92
 	if (t.rows.length <= 1) return;
92
 	if (t.rows.length <= 1) return;
93
 	var itm = "";
93
 	var itm = "";
94
-	var i = 0;
94
+	var i = 1;
95
 	while (itm == "" && i < t.tBodies[0].rows.length) {
95
 	while (itm == "" && i < t.tBodies[0].rows.length) {
96
 		var itm = ts_getInnerText(t.tBodies[0].rows[i].cells[column]);
96
 		var itm = ts_getInnerText(t.tBodies[0].rows[i].cells[column]);
97
 		itm = trim(itm);
97
 		itm = trim(itm);
105
 	if (itm.match(/^\d\d[\/\.-][a-zA-z][a-zA-Z][a-zA-Z][\/\.-]\d\d\d\d$/)) sortfn = ts_sort_date;
105
 	if (itm.match(/^\d\d[\/\.-][a-zA-z][a-zA-Z][a-zA-Z][\/\.-]\d\d\d\d$/)) sortfn = ts_sort_date;
106
 	if (itm.match(/^\d\d[\/\.-]\d\d[\/\.-]\d\d\d{2}?$/)) sortfn = ts_sort_date;
106
 	if (itm.match(/^\d\d[\/\.-]\d\d[\/\.-]\d\d\d{2}?$/)) sortfn = ts_sort_date;
107
 	if (itm.match(/^-?[£$€Û¢´]\d/)) sortfn = ts_sort_numeric;
107
 	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;
109
 	SORT_COLUMN_INDEX = column;
110
 	SORT_COLUMN_INDEX = column;
110
 	var firstRow = new Array();
111
 	var firstRow = new Array();
111
 	var newRows = new Array();
112
 	var newRows = new Array();