Fossil

Check-in [10aaf0c971]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Implement sorting by event count on some of the stats_report pages.
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 10aaf0c9713e139dc1a21f5569967939e8376137
User & Date: drh 2013-05-05 23:49:41.593
Context
2013-05-05
23:53
On the stats_report?view=byuser page, order by events by default. ... (check-in: bff7f5b95e user: drh tags: trunk)
23:49
Implement sorting by event count on some of the stats_report pages. ... (check-in: 10aaf0c971 user: drh tags: trunk)
20:05
Attempt to make the stats_report?type=byuser tabls sortable by clicking on the column labels. Only works for the "User" column. Further debugging needed. ... (check-in: d0ce29b031 user: drh tags: trunk)
Changes
Unified Diff Ignore Whitespace Patch
Changes to src/report.c.
921
922
923
924
925
926
927





928
929
930
931
932
933
934

935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957








958
959
960
961
962
963
964
965
966
967
968
969
970

971
972
973
974
975
976
977
978
979
980
981
982
983
984
** Output Javascript code that will enables sorting of the table with
** the id zTableId by clicking.
**
** The javascript is derived from:
**
**     http://www.webtoolkit.info/sortable-html-table.html
**





*/
void output_table_sorting_javascript(const char *zTableId){
  @ <script>
  @ function SortableTable(tableEl){
  @   this.tbody = tableEl.getElementsByTagName('tbody');
  @   this.sort = function (cell) {
  @     var column = cell.cellIndex;

  @     this.sortIndex = column;
  @     var newRows = new Array();
  @     for (j = 0; j < this.tbody[0].rows.length; j++) {
  @        newRows[j] = this.tbody[0].rows[j];
  @     }
  @     newRows.sort(this.sortText);
  @     if (cell.getAttribute("sortdir") == 'down') {
  @        newRows.reverse();
  @        cell.setAttribute('sortdir','up');
  @     } else {
  @        cell.setAttribute('sortdir','down');
  @     }
  @     for (i=0;i<newRows.length;i++) {
  @       this.tbody[0].appendChild(newRows[i]);
  @     }
  @   }
  @   this.sortText = function(a,b) {
  @     var i = thisObject.sortIndex;
  @     aa = a.cells[i].textContent.replace(/^\W+/,'').toLowerCase();
  @     bb = b.cells[i].textContent.replace(/^\W+/,'').toLowerCase();
  @     if(aa==bb) return 0;
  @     if(aa<bb) return -1;
  @     return 1;








  @   }
  @   var thisObject = this;
  @   var x = tableEl.getElementsByTagName('thead');
  @   if(!(this.tbody && this.tbody[0].rows && this.tbody[0].rows.length>0)){
  @     return;
  @   }
  @   if(x && x[0].rows && x[0].rows.length > 0) {
  @     var sortRow = x[0].rows[0];
  @   } else {
  @     return;
  @   }
  @   for (var i=0; i<sortRow.cells.length; i++) {
  @     sortRow.cells[i].sTable = this;

  @     sortRow.cells[i].onclick = function () {
  @       this.sTable.sort(this);
  @       return false;
  @     }
  @   }
  @ }
  @ var t = new SortableTable(gebi("%s(zTableId)"));
  @ </script>
}


/*
** WEBPAGE: /rptview
**







>
>
>
>
>

|

|



>





|

















>
>
>
>
>
>
>
>













>






|







921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
** Output Javascript code that will enables sorting of the table with
** the id zTableId by clicking.
**
** The javascript is derived from:
**
**     http://www.webtoolkit.info/sortable-html-table.html
**
** This variation allows column types to be expressed using the second
** argument.  Each character of the second argument represent a column.
** "t" means sort as text.  "n" means sort numerically.  "x" means do not
** sort on this column.  If there are fewer characters in zColumnTypes[] than
** their are columns, the all extra columns assume type "t" (text).
*/
void output_table_sorting_javascript(const char *zTableId, const char *zColumnTypes){
  @ <script>
  @ function SortableTable(tableEl,columnTypes){
  @   this.tbody = tableEl.getElementsByTagName('tbody');
  @   this.sort = function (cell) {
  @     var column = cell.cellIndex;
  @     var sortFn = cell.sortType=="n" ? this.sortNumeric : this.sortText;
  @     this.sortIndex = column;
  @     var newRows = new Array();
  @     for (j = 0; j < this.tbody[0].rows.length; j++) {
  @        newRows[j] = this.tbody[0].rows[j];
  @     }
  @     newRows.sort(sortFn);
  @     if (cell.getAttribute("sortdir") == 'down') {
  @        newRows.reverse();
  @        cell.setAttribute('sortdir','up');
  @     } else {
  @        cell.setAttribute('sortdir','down');
  @     }
  @     for (i=0;i<newRows.length;i++) {
  @       this.tbody[0].appendChild(newRows[i]);
  @     }
  @   }
  @   this.sortText = function(a,b) {
  @     var i = thisObject.sortIndex;
  @     aa = a.cells[i].textContent.replace(/^\W+/,'').toLowerCase();
  @     bb = b.cells[i].textContent.replace(/^\W+/,'').toLowerCase();
  @     if(aa==bb) return 0;
  @     if(aa<bb) return -1;
  @     return 1;
  @   }
  @   this.sortNumeric = function(a,b) {
  @     var i = thisObject.sortIndex;
  @     aa = parseFloat(a.cells[i].textContent);
  @     if (isNaN(aa)) aa = 0;
  @     bb = parseFloat(b.cells[i].textContent);
  @     if (isNaN(bb)) bb = 0;
  @     return aa-bb;
  @   }
  @   var thisObject = this;
  @   var x = tableEl.getElementsByTagName('thead');
  @   if(!(this.tbody && this.tbody[0].rows && this.tbody[0].rows.length>0)){
  @     return;
  @   }
  @   if(x && x[0].rows && x[0].rows.length > 0) {
  @     var sortRow = x[0].rows[0];
  @   } else {
  @     return;
  @   }
  @   for (var i=0; i<sortRow.cells.length; i++) {
  @     sortRow.cells[i].sTable = this;
  @     sortRow.cells[i].sortType = columnTypes[i] || 't';
  @     sortRow.cells[i].onclick = function () {
  @       this.sTable.sort(this);
  @       return false;
  @     }
  @   }
  @ }
  @ var t = new SortableTable(gebi("%s(zTableId)"),"%s(zColumnTypes)");
  @ </script>
}


/*
** WEBPAGE: /rptview
**
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
    report_unrestrict_sql();
    @ </tbody></table>
    if( zErr1 ){
      @ <p class="reportError">Error: %h(zErr1)</p>
    }else if( zErr2 ){
      @ <p class="reportError">Error: %h(zErr2)</p>
    }
    output_table_sorting_javascript("reportTable");
    style_footer();
  }else{
    report_restrict_sql(&zErr1);
    sqlite3_exec_readonly(g.db, zSql, output_tab_separated, &count, &zErr2);
    report_unrestrict_sql();
    cgi_set_content_type("text/plain");
  }







|







1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
    report_unrestrict_sql();
    @ </tbody></table>
    if( zErr1 ){
      @ <p class="reportError">Error: %h(zErr1)</p>
    }else if( zErr2 ){
      @ <p class="reportError">Error: %h(zErr2)</p>
    }
    output_table_sorting_javascript("reportTable","");
    style_footer();
  }else{
    report_restrict_sql(&zErr1);
    sqlite3_exec_readonly(g.db, zSql, output_tab_separated, &count, &zErr2);
    report_unrestrict_sql();
    cgi_set_content_type("text/plain");
  }
Changes to src/timeline.c.
1935
1936
1937
1938
1939
1940
1941

1942
1943
1944
1945

1946
1947



1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
    rowClass = ++nRowNumber % 2;
    @ <tr class='row%d(rowClass)'>
    @ <td></td>
    @ <td colspan='2'>Yearly total: %d(nEventsPerYear)</td>
    @</tr>    
  }


  rowClass = ++nRowNumber % 2;
  @ <tr class='row%d(rowClass)'>
  @   <td colspan='3'>Total events: %d(nEventTotal)</td>
  @ </tr>

  @ </tbody></table>
  db_finalize(&query);



}

void stats_report_by_user(){
  Stmt query = empty_Stmt;
  int const nPixelsPerEvent = 1;     /* for sizing the "graph" part */
  int nRowNumber = 0;                /* current TR number */
  int nEventTotal = 0;               /* Total event count */
  int rowClass = 0;                  /* counter for alternating
                                        row colors */
  Blob sql = empty_blob;             /* SQL */
  blob_append(&sql,
               "SELECT user, "
               "COUNT(*) AS eventCount "
               "FROM event "
               "GROUP BY user ORDER BY user",
              -1);
  db_prepare(&query, blob_str(&sql));
  blob_reset(&sql);
  @ <h1>Timeline Events by User</h1>
  @ <table class='statistics-report-table-events' border='0'
  @ cellpadding='2' cellspacing='0' id='statsTable'>
  @ <thead><tr>







>




>


>
>
>














|







1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
    rowClass = ++nRowNumber % 2;
    @ <tr class='row%d(rowClass)'>
    @ <td></td>
    @ <td colspan='2'>Yearly total: %d(nEventsPerYear)</td>
    @</tr>    
  }

#if 0
  rowClass = ++nRowNumber % 2;
  @ <tr class='row%d(rowClass)'>
  @   <td colspan='3'>Total events: %d(nEventTotal)</td>
  @ </tr>
#endif
  @ </tbody></table>
  db_finalize(&query);
  if( !includeMonth ){
    output_table_sorting_javascript("statsTable","tnx");
  }
}

void stats_report_by_user(){
  Stmt query = empty_Stmt;
  int const nPixelsPerEvent = 1;     /* for sizing the "graph" part */
  int nRowNumber = 0;                /* current TR number */
  int nEventTotal = 0;               /* Total event count */
  int rowClass = 0;                  /* counter for alternating
                                        row colors */
  Blob sql = empty_blob;             /* SQL */
  blob_append(&sql,
               "SELECT user, "
               "COUNT(*) AS eventCount "
               "FROM event "
               "GROUP BY user ORDER BY user COLLATE nocase",
              -1);
  db_prepare(&query, blob_str(&sql));
  blob_reset(&sql);
  @ <h1>Timeline Events by User</h1>
  @ <table class='statistics-report-table-events' border='0'
  @ cellpadding='2' cellspacing='0' id='statsTable'>
  @ <thead><tr>
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
    @ </div></td>
    @</tr>
    /*
      Potential improvement: calculate the min/max event counts and
      use percent-based graph bars.
    */
  }

  rowClass = ++nRowNumber % 2;
  @ <tr class='row%d(rowClass)'>
  @   <td colspan='3'>Total events: %d(nEventTotal)</td>
  @ </tr>
  @ </tbody></table>
  db_finalize(&query);
  output_table_sorting_javascript("statsTable");
}

/*
** WEBPAGE: stats_report
**
** Shows activity reports for the repository.
**







<
<
<
<
<


|







1993
1994
1995
1996
1997
1998
1999





2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
    @ </div></td>
    @</tr>
    /*
      Potential improvement: calculate the min/max event counts and
      use percent-based graph bars.
    */
  }





  @ </tbody></table>
  db_finalize(&query);
  output_table_sorting_javascript("statsTable","tnx");
}

/*
** WEBPAGE: stats_report
**
** Shows activity reports for the repository.
**