Kaynağa Gözat

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 yıl önce
ebeveyn
işleme
072723fb71
3 değiştirilmiş dosya ile 29 ekleme ve 16 silme
  1. 12
    10
      gitstats
  2. 10
    0
      gitstats.css
  3. 7
    6
      sortable.js

+ 12
- 10
gitstats Dosyayı Görüntüle

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

+ 10
- 0
gitstats.css Dosyayı Görüntüle

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

+ 7
- 6
sortable.js Dosyayı Görüntüle

@@ -9,10 +9,10 @@ Version 1.5.7
9 9
 */
10 10
 
11 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 16
 var europeandate = true;
17 17
 var alternate_row_colors = true;
18 18
 
@@ -91,7 +91,7 @@ function ts_resortTable(lnk, clid) {
91 91
 	// Work out a type for the column
92 92
 	if (t.rows.length <= 1) return;
93 93
 	var itm = "";
94
-	var i = 0;
94
+	var i = 1;
95 95
 	while (itm == "" && i < t.tBodies[0].rows.length) {
96 96
 		var itm = ts_getInnerText(t.tBodies[0].rows[i].cells[column]);
97 97
 		itm = trim(itm);
@@ -105,7 +105,8 @@ function ts_resortTable(lnk, clid) {
105 105
 	if (itm.match(/^\d\d[\/\.-][a-zA-z][a-zA-Z][a-zA-Z][\/\.-]\d\d\d\d$/)) sortfn = ts_sort_date;
106 106
 	if (itm.match(/^\d\d[\/\.-]\d\d[\/\.-]\d\d\d{2}?$/)) sortfn = ts_sort_date;
107 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 110
 	SORT_COLUMN_INDEX = column;
110 111
 	var firstRow = new Array();
111 112
 	var newRows = new Array();