Fossil SCM

Add the /thisdayinhistory page.

drh 2019-05-10 16:19 trunk
Commit e7103eeb63b8e40c57f3112a0d35e74c1dd88e25dae29b5f8f9686b65fa877f6
1 file changed +64
--- src/timeline.c
+++ src/timeline.c
@@ -2783,10 +2783,74 @@
27832783
db_prepare_blob(&q, &sql);
27842784
blob_reset(&sql);
27852785
print_timeline(&q, n, width, verboseFlag);
27862786
db_finalize(&q);
27872787
}
2788
+
2789
+/*
2790
+** WEBPAGE: thisdayinhistory
2791
+**
2792
+** Generate a vanity page that shows project activity for the current
2793
+** day of the year for various years in the history of the project.
2794
+**
2795
+** Query parameters:
2796
+**
2797
+** today=DATE Use DATE as today's date
2798
+*/
2799
+void thisdayinhistory_page(void){
2800
+ static int aYearsAgo[] = { 1, 2, 3, 4, 5, 10, 15, 20, 30, 40, 50, 75, 100 };
2801
+ const char *zToday;
2802
+ char *zStartOfProject;
2803
+ int i;
2804
+ Stmt q;
2805
+
2806
+ login_check_credentials();
2807
+ if( (!g.perm.Read && !g.perm.RdTkt && !g.perm.RdWiki && !g.perm.RdForum) ){
2808
+ login_needed(g.anon.Read && g.anon.RdTkt && g.anon.RdWiki);
2809
+ return;
2810
+ }
2811
+ style_header("Today In History");
2812
+ zToday = (char*)P("today");
2813
+ if( zToday ){
2814
+ zToday = timeline_expand_datetime(zToday);
2815
+ if( !fossil_isdate(zToday) ) zToday = 0;
2816
+ }
2817
+ if( zToday==0 ){
2818
+ zToday = db_text(0, "SELECT date('now',toLocal())");
2819
+ }
2820
+ @ <h1>This Day In History For %h(zToday)</h1>
2821
+ zStartOfProject = db_text(0,
2822
+ "SELECT datetime(min(mtime),toLocal()) FROM event;"
2823
+ );
2824
+ timeline_temp_table();
2825
+ db_prepare(&q, "SELECT * FROM timeline ORDER BY sortby DESC /*scan*/");
2826
+ for(i=0; i<sizeof(aYearsAgo)/sizeof(aYearsAgo[0]); i++){
2827
+ int iAgo = aYearsAgo[i];
2828
+ char *zThis = db_text(0, "SELECT date(%Q,'-%d years')", zToday, iAgo);
2829
+ Blob sql;
2830
+ if( strcmp(zThis, zStartOfProject)<0 ) break;
2831
+ blob_init(&sql, 0, 0);
2832
+ blob_append(&sql, "INSERT OR IGNORE INTO timeline ", -1);
2833
+ blob_append(&sql, timeline_query_for_www(), -1);
2834
+ blob_append_sql(&sql,
2835
+ " AND %Q=date(event.mtime,toLocal()) "
2836
+ " AND event.mtime BETWEEN julianday(%Q,'-1 day')"
2837
+ " AND julianday(%Q,'+2 days')",
2838
+ zThis, zThis, zThis
2839
+ );
2840
+ db_multi_exec("DELETE FROM timeline; %s;", blob_sql_text(&sql));
2841
+ blob_reset(&sql);
2842
+ if( db_int(0, "SELECT count(*) FROM timeline")==0 ){
2843
+ continue;
2844
+ }
2845
+ @ <h2>%d(iAgo) Year%s(iAgo>1?"s":"") Ago
2846
+ @ <small>%z(href("%R/timeline?c=%s",zThis))(more context)</a></small></h2>
2847
+ www_print_timeline(&q, TIMELINE_GRAPH|TIMELINE_DISJOINT, 0, 0, 0, 0);
2848
+ }
2849
+ db_finalize(&q);
2850
+ style_footer();
2851
+}
27882852
27892853
27902854
/*
27912855
** COMMAND: test-timewarp-list
27922856
**
27932857
--- src/timeline.c
+++ src/timeline.c
@@ -2783,10 +2783,74 @@
2783 db_prepare_blob(&q, &sql);
2784 blob_reset(&sql);
2785 print_timeline(&q, n, width, verboseFlag);
2786 db_finalize(&q);
2787 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2788
2789
2790 /*
2791 ** COMMAND: test-timewarp-list
2792 **
2793
--- src/timeline.c
+++ src/timeline.c
@@ -2783,10 +2783,74 @@
2783 db_prepare_blob(&q, &sql);
2784 blob_reset(&sql);
2785 print_timeline(&q, n, width, verboseFlag);
2786 db_finalize(&q);
2787 }
2788
2789 /*
2790 ** WEBPAGE: thisdayinhistory
2791 **
2792 ** Generate a vanity page that shows project activity for the current
2793 ** day of the year for various years in the history of the project.
2794 **
2795 ** Query parameters:
2796 **
2797 ** today=DATE Use DATE as today's date
2798 */
2799 void thisdayinhistory_page(void){
2800 static int aYearsAgo[] = { 1, 2, 3, 4, 5, 10, 15, 20, 30, 40, 50, 75, 100 };
2801 const char *zToday;
2802 char *zStartOfProject;
2803 int i;
2804 Stmt q;
2805
2806 login_check_credentials();
2807 if( (!g.perm.Read && !g.perm.RdTkt && !g.perm.RdWiki && !g.perm.RdForum) ){
2808 login_needed(g.anon.Read && g.anon.RdTkt && g.anon.RdWiki);
2809 return;
2810 }
2811 style_header("Today In History");
2812 zToday = (char*)P("today");
2813 if( zToday ){
2814 zToday = timeline_expand_datetime(zToday);
2815 if( !fossil_isdate(zToday) ) zToday = 0;
2816 }
2817 if( zToday==0 ){
2818 zToday = db_text(0, "SELECT date('now',toLocal())");
2819 }
2820 @ <h1>This Day In History For %h(zToday)</h1>
2821 zStartOfProject = db_text(0,
2822 "SELECT datetime(min(mtime),toLocal()) FROM event;"
2823 );
2824 timeline_temp_table();
2825 db_prepare(&q, "SELECT * FROM timeline ORDER BY sortby DESC /*scan*/");
2826 for(i=0; i<sizeof(aYearsAgo)/sizeof(aYearsAgo[0]); i++){
2827 int iAgo = aYearsAgo[i];
2828 char *zThis = db_text(0, "SELECT date(%Q,'-%d years')", zToday, iAgo);
2829 Blob sql;
2830 if( strcmp(zThis, zStartOfProject)<0 ) break;
2831 blob_init(&sql, 0, 0);
2832 blob_append(&sql, "INSERT OR IGNORE INTO timeline ", -1);
2833 blob_append(&sql, timeline_query_for_www(), -1);
2834 blob_append_sql(&sql,
2835 " AND %Q=date(event.mtime,toLocal()) "
2836 " AND event.mtime BETWEEN julianday(%Q,'-1 day')"
2837 " AND julianday(%Q,'+2 days')",
2838 zThis, zThis, zThis
2839 );
2840 db_multi_exec("DELETE FROM timeline; %s;", blob_sql_text(&sql));
2841 blob_reset(&sql);
2842 if( db_int(0, "SELECT count(*) FROM timeline")==0 ){
2843 continue;
2844 }
2845 @ <h2>%d(iAgo) Year%s(iAgo>1?"s":"") Ago
2846 @ <small>%z(href("%R/timeline?c=%s",zThis))(more context)</a></small></h2>
2847 www_print_timeline(&q, TIMELINE_GRAPH|TIMELINE_DISJOINT, 0, 0, 0, 0);
2848 }
2849 db_finalize(&q);
2850 style_footer();
2851 }
2852
2853
2854 /*
2855 ** COMMAND: test-timewarp-list
2856 **
2857

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button