Fossil SCM

Improvements to search dialog boxes. On the /search menu, allow restricting the search to a specific category of document. Add a search submenu item on the timeline page.

drh 2015-02-05 15:48 UTC form-submenu
Commit 49a990b6fdba3faa875aea83b5c237604c52adf1
+1 -1
--- src/doc.c
+++ src/doc.c
@@ -785,8 +785,8 @@
785785
** Search for documents that match a user-supplied pattern.
786786
*/
787787
void doc_search_page(void){
788788
login_check_credentials();
789789
style_header("Document Search");
790
- search_screen(SRCH_DOC, "docsrch");
790
+ search_screen(SRCH_DOC, 0);
791791
style_footer();
792792
}
793793
--- src/doc.c
+++ src/doc.c
@@ -785,8 +785,8 @@
785 ** Search for documents that match a user-supplied pattern.
786 */
787 void doc_search_page(void){
788 login_check_credentials();
789 style_header("Document Search");
790 search_screen(SRCH_DOC, "docsrch");
791 style_footer();
792 }
793
--- src/doc.c
+++ src/doc.c
@@ -785,8 +785,8 @@
785 ** Search for documents that match a user-supplied pattern.
786 */
787 void doc_search_page(void){
788 login_check_credentials();
789 style_header("Document Search");
790 search_screen(SRCH_DOC, 0);
791 style_footer();
792 }
793
+37 -17
--- src/search.c
+++ src/search.c
@@ -882,46 +882,75 @@
882882
/*
883883
** Generate some HTML for doing search. At a minimum include the
884884
** Search-Text entry form. If the "s" query parameter is present, also
885885
** show search results.
886886
**
887
-** The srchFlags parameter is used to customize some of the text of the
888
-** form and the results. srchFlags should be either a single search
889
-** category or all categories. Any srchFlags with two or more bits set
887
+** The srchFlags parameter restricts the set of documents to be searched.
888
+** srchFlags should normally be either a single search category or all
889
+** categories. Any srchFlags with two or more bits set
890890
** is treated like SRCH_ALL for display purposes.
891891
**
892
-** The entry box is shown disabled if srchFlags is 0.
892
+** This routine automatically restricts srchFlag according to user
893
+** permissions and the server configuration. The entry box is shown
894
+** disabled if srchFlags is 0 after these restrictions are applied.
895
+**
896
+** If useYparam is true, then this routine also looks at the y= query
897
+** parameter for further search restrictions.
893898
*/
894
-void search_screen(unsigned srchFlags, const char *zAction){
899
+void search_screen(unsigned srchFlags, int useYparam){
895900
const char *zType = 0;
896901
const char *zClass = 0;
897902
const char *zDisable1;
898903
const char *zDisable2;
899904
const char *zPattern;
905
+ srchFlags = search_restrict(srchFlags);
900906
switch( srchFlags ){
901907
case SRCH_CKIN: zType = " Check-ins"; zClass = "Ckin"; break;
902908
case SRCH_DOC: zType = " Docs"; zClass = "Doc"; break;
903909
case SRCH_TKT: zType = " Tickets"; zClass = "Tkt"; break;
904910
case SRCH_WIKI: zType = " Wiki"; zClass = "Wiki"; break;
905911
}
906
- srchFlags = search_restrict(srchFlags);
907912
if( srchFlags==0 ){
908913
zDisable1 = " disabled";
909914
zDisable2 = " disabled";
910915
zPattern = "";
911916
}else{
912917
zDisable1 = " autofocus";
913918
zDisable2 = "";
914919
zPattern = PD("s","");
915920
}
916
- @ <form method='GET' action='%s(zAction)'>
921
+ @ <form method='GET' action='%R/%t(g.zPath)'>
917922
if( zClass ){
918923
@ <div class='searchForm searchForm%s(zClass)'>
919924
}else{
920925
@ <div class='searchForm'>
921926
}
922927
@ <input type="text" name="s" size="40" value="%h(zPattern)"%s(zDisable1)>
928
+ if( useYparam && (srchFlags & (srchFlags-1))!=0 && useYparam ){
929
+ static const struct { char *z; char *zNm; unsigned m; } aY[] = {
930
+ { "all", "All", SRCH_ALL },
931
+ { "c", "Check-ins", SRCH_CKIN },
932
+ { "d", "Docs", SRCH_DOC },
933
+ { "t", "Tickets", SRCH_TKT },
934
+ { "w", "Wiki", SRCH_WIKI },
935
+ };
936
+ const char *zY = PD("y","all");
937
+ unsigned newFlags = srchFlags;
938
+ int i;
939
+ @ <select size='1' name='y'>
940
+ for(i=0; i<ArraySize(aY); i++){
941
+ if( (aY[i].m & srchFlags)==0 ) continue;
942
+ cgi_printf("<option value='%s'", aY[i].z);
943
+ if( fossil_strcmp(zY,aY[i].z)==0 ){
944
+ newFlags &= aY[i].m;
945
+ cgi_printf(" selected");
946
+ }
947
+ cgi_printf(">%s</option>\n", aY[i].zNm);
948
+ }
949
+ @ </select>
950
+ srchFlags = newFlags;
951
+ }
923952
@ <input type="submit" value="Search%s(zType)"%s(zDisable2)>
924953
if( srchFlags==0 ){
925954
@ <p class="generalError">Search is disabled</p>
926955
}
927956
@ </div></form>
@@ -944,22 +973,13 @@
944973
**
945974
** Search for check-in comments, documents, tickets, or wiki that
946975
** match a user-supplied pattern.
947976
*/
948977
void search_page(void){
949
- unsigned srchFlags = SRCH_ALL;
950
- const char *zOnly = P("only");
951
-
952978
login_check_credentials();
953
- if( zOnly ){
954
- if( strchr(zOnly,'c') ) srchFlags &= SRCH_CKIN;
955
- if( strchr(zOnly,'d') ) srchFlags &= SRCH_DOC;
956
- if( strchr(zOnly,'t') ) srchFlags &= SRCH_TKT;
957
- if( strchr(zOnly,'w') ) srchFlags &= SRCH_WIKI;
958
- }
959979
style_header("Search");
960
- search_screen(srchFlags, "search");
980
+ search_screen(SRCH_ALL, 1);
961981
style_footer();
962982
}
963983
964984
965985
/*
966986
--- src/search.c
+++ src/search.c
@@ -882,46 +882,75 @@
882 /*
883 ** Generate some HTML for doing search. At a minimum include the
884 ** Search-Text entry form. If the "s" query parameter is present, also
885 ** show search results.
886 **
887 ** The srchFlags parameter is used to customize some of the text of the
888 ** form and the results. srchFlags should be either a single search
889 ** category or all categories. Any srchFlags with two or more bits set
890 ** is treated like SRCH_ALL for display purposes.
891 **
892 ** The entry box is shown disabled if srchFlags is 0.
 
 
 
 
 
893 */
894 void search_screen(unsigned srchFlags, const char *zAction){
895 const char *zType = 0;
896 const char *zClass = 0;
897 const char *zDisable1;
898 const char *zDisable2;
899 const char *zPattern;
 
900 switch( srchFlags ){
901 case SRCH_CKIN: zType = " Check-ins"; zClass = "Ckin"; break;
902 case SRCH_DOC: zType = " Docs"; zClass = "Doc"; break;
903 case SRCH_TKT: zType = " Tickets"; zClass = "Tkt"; break;
904 case SRCH_WIKI: zType = " Wiki"; zClass = "Wiki"; break;
905 }
906 srchFlags = search_restrict(srchFlags);
907 if( srchFlags==0 ){
908 zDisable1 = " disabled";
909 zDisable2 = " disabled";
910 zPattern = "";
911 }else{
912 zDisable1 = " autofocus";
913 zDisable2 = "";
914 zPattern = PD("s","");
915 }
916 @ <form method='GET' action='%s(zAction)'>
917 if( zClass ){
918 @ <div class='searchForm searchForm%s(zClass)'>
919 }else{
920 @ <div class='searchForm'>
921 }
922 @ <input type="text" name="s" size="40" value="%h(zPattern)"%s(zDisable1)>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
923 @ <input type="submit" value="Search%s(zType)"%s(zDisable2)>
924 if( srchFlags==0 ){
925 @ <p class="generalError">Search is disabled</p>
926 }
927 @ </div></form>
@@ -944,22 +973,13 @@
944 **
945 ** Search for check-in comments, documents, tickets, or wiki that
946 ** match a user-supplied pattern.
947 */
948 void search_page(void){
949 unsigned srchFlags = SRCH_ALL;
950 const char *zOnly = P("only");
951
952 login_check_credentials();
953 if( zOnly ){
954 if( strchr(zOnly,'c') ) srchFlags &= SRCH_CKIN;
955 if( strchr(zOnly,'d') ) srchFlags &= SRCH_DOC;
956 if( strchr(zOnly,'t') ) srchFlags &= SRCH_TKT;
957 if( strchr(zOnly,'w') ) srchFlags &= SRCH_WIKI;
958 }
959 style_header("Search");
960 search_screen(srchFlags, "search");
961 style_footer();
962 }
963
964
965 /*
966
--- src/search.c
+++ src/search.c
@@ -882,46 +882,75 @@
882 /*
883 ** Generate some HTML for doing search. At a minimum include the
884 ** Search-Text entry form. If the "s" query parameter is present, also
885 ** show search results.
886 **
887 ** The srchFlags parameter restricts the set of documents to be searched.
888 ** srchFlags should normally be either a single search category or all
889 ** categories. Any srchFlags with two or more bits set
890 ** is treated like SRCH_ALL for display purposes.
891 **
892 ** This routine automatically restricts srchFlag according to user
893 ** permissions and the server configuration. The entry box is shown
894 ** disabled if srchFlags is 0 after these restrictions are applied.
895 **
896 ** If useYparam is true, then this routine also looks at the y= query
897 ** parameter for further search restrictions.
898 */
899 void search_screen(unsigned srchFlags, int useYparam){
900 const char *zType = 0;
901 const char *zClass = 0;
902 const char *zDisable1;
903 const char *zDisable2;
904 const char *zPattern;
905 srchFlags = search_restrict(srchFlags);
906 switch( srchFlags ){
907 case SRCH_CKIN: zType = " Check-ins"; zClass = "Ckin"; break;
908 case SRCH_DOC: zType = " Docs"; zClass = "Doc"; break;
909 case SRCH_TKT: zType = " Tickets"; zClass = "Tkt"; break;
910 case SRCH_WIKI: zType = " Wiki"; zClass = "Wiki"; break;
911 }
 
912 if( srchFlags==0 ){
913 zDisable1 = " disabled";
914 zDisable2 = " disabled";
915 zPattern = "";
916 }else{
917 zDisable1 = " autofocus";
918 zDisable2 = "";
919 zPattern = PD("s","");
920 }
921 @ <form method='GET' action='%R/%t(g.zPath)'>
922 if( zClass ){
923 @ <div class='searchForm searchForm%s(zClass)'>
924 }else{
925 @ <div class='searchForm'>
926 }
927 @ <input type="text" name="s" size="40" value="%h(zPattern)"%s(zDisable1)>
928 if( useYparam && (srchFlags & (srchFlags-1))!=0 && useYparam ){
929 static const struct { char *z; char *zNm; unsigned m; } aY[] = {
930 { "all", "All", SRCH_ALL },
931 { "c", "Check-ins", SRCH_CKIN },
932 { "d", "Docs", SRCH_DOC },
933 { "t", "Tickets", SRCH_TKT },
934 { "w", "Wiki", SRCH_WIKI },
935 };
936 const char *zY = PD("y","all");
937 unsigned newFlags = srchFlags;
938 int i;
939 @ <select size='1' name='y'>
940 for(i=0; i<ArraySize(aY); i++){
941 if( (aY[i].m & srchFlags)==0 ) continue;
942 cgi_printf("<option value='%s'", aY[i].z);
943 if( fossil_strcmp(zY,aY[i].z)==0 ){
944 newFlags &= aY[i].m;
945 cgi_printf(" selected");
946 }
947 cgi_printf(">%s</option>\n", aY[i].zNm);
948 }
949 @ </select>
950 srchFlags = newFlags;
951 }
952 @ <input type="submit" value="Search%s(zType)"%s(zDisable2)>
953 if( srchFlags==0 ){
954 @ <p class="generalError">Search is disabled</p>
955 }
956 @ </div></form>
@@ -944,22 +973,13 @@
973 **
974 ** Search for check-in comments, documents, tickets, or wiki that
975 ** match a user-supplied pattern.
976 */
977 void search_page(void){
 
 
 
978 login_check_credentials();
 
 
 
 
 
 
979 style_header("Search");
980 search_screen(SRCH_ALL, 1);
981 style_footer();
982 }
983
984
985 /*
986
--- src/timeline.c
+++ src/timeline.c
@@ -1565,10 +1565,11 @@
15651565
}
15661566
}
15671567
if( P("showsql") ){
15681568
@ <blockquote>%h(blob_sql_text(&sql))</blockquote>
15691569
}
1570
+ style_submenu_element("Search", 0, "/search?y=c");
15701571
if( P("showid") ) tmFlags |= TIMELINE_SHOWRID;
15711572
blob_zero(&sql);
15721573
db_prepare(&q, "SELECT * FROM timeline ORDER BY sortby DESC /*scan*/");
15731574
@ <h2>%b(&desc)</h2>
15741575
blob_reset(&desc);
15751576
--- src/timeline.c
+++ src/timeline.c
@@ -1565,10 +1565,11 @@
1565 }
1566 }
1567 if( P("showsql") ){
1568 @ <blockquote>%h(blob_sql_text(&sql))</blockquote>
1569 }
 
1570 if( P("showid") ) tmFlags |= TIMELINE_SHOWRID;
1571 blob_zero(&sql);
1572 db_prepare(&q, "SELECT * FROM timeline ORDER BY sortby DESC /*scan*/");
1573 @ <h2>%b(&desc)</h2>
1574 blob_reset(&desc);
1575
--- src/timeline.c
+++ src/timeline.c
@@ -1565,10 +1565,11 @@
1565 }
1566 }
1567 if( P("showsql") ){
1568 @ <blockquote>%h(blob_sql_text(&sql))</blockquote>
1569 }
1570 style_submenu_element("Search", 0, "/search?y=c");
1571 if( P("showid") ) tmFlags |= TIMELINE_SHOWRID;
1572 blob_zero(&sql);
1573 db_prepare(&q, "SELECT * FROM timeline ORDER BY sortby DESC /*scan*/");
1574 @ <h2>%b(&desc)</h2>
1575 blob_reset(&desc);
1576
+1 -1
--- src/tkt.c
+++ src/tkt.c
@@ -1434,8 +1434,8 @@
14341434
*/
14351435
void tkt_srchpage(void){
14361436
login_check_credentials();
14371437
style_header("Ticket Search");
14381438
ticket_standard_submenu(T_ALL_BUT(T_SRCH));
1439
- search_screen(SRCH_TKT, "tktsrch");
1439
+ search_screen(SRCH_TKT, 0);
14401440
style_footer();
14411441
}
14421442
--- src/tkt.c
+++ src/tkt.c
@@ -1434,8 +1434,8 @@
1434 */
1435 void tkt_srchpage(void){
1436 login_check_credentials();
1437 style_header("Ticket Search");
1438 ticket_standard_submenu(T_ALL_BUT(T_SRCH));
1439 search_screen(SRCH_TKT, "tktsrch");
1440 style_footer();
1441 }
1442
--- src/tkt.c
+++ src/tkt.c
@@ -1434,8 +1434,8 @@
1434 */
1435 void tkt_srchpage(void){
1436 login_check_credentials();
1437 style_header("Ticket Search");
1438 ticket_standard_submenu(T_ALL_BUT(T_SRCH));
1439 search_screen(SRCH_TKT, 0);
1440 style_footer();
1441 }
1442
+1 -1
--- src/wiki.c
+++ src/wiki.c
@@ -291,11 +291,11 @@
291291
*/
292292
void wiki_srchpage(void){
293293
login_check_credentials();
294294
style_header("Wiki Search");
295295
wiki_standard_submenu(W_HELP|W_LIST|W_SANDBOX);
296
- search_screen(SRCH_WIKI, "wikisrch");
296
+ search_screen(SRCH_WIKI, 0);
297297
style_footer();
298298
}
299299
300300
/*
301301
** WEBPAGE: wiki
302302
--- src/wiki.c
+++ src/wiki.c
@@ -291,11 +291,11 @@
291 */
292 void wiki_srchpage(void){
293 login_check_credentials();
294 style_header("Wiki Search");
295 wiki_standard_submenu(W_HELP|W_LIST|W_SANDBOX);
296 search_screen(SRCH_WIKI, "wikisrch");
297 style_footer();
298 }
299
300 /*
301 ** WEBPAGE: wiki
302
--- src/wiki.c
+++ src/wiki.c
@@ -291,11 +291,11 @@
291 */
292 void wiki_srchpage(void){
293 login_check_credentials();
294 style_header("Wiki Search");
295 wiki_standard_submenu(W_HELP|W_LIST|W_SANDBOX);
296 search_screen(SRCH_WIKI, 0);
297 style_footer();
298 }
299
300 /*
301 ** WEBPAGE: wiki
302

Keyboard Shortcuts

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