Fossil SCM

Unify the search screen generator code. Provide class marks to support CSS customization.

drh 2015-02-03 13:17 trunk
Commit bb4a13012143affd0d88412d5654f19fbacc2f59
+1 -25
--- src/doc.c
+++ src/doc.c
@@ -783,34 +783,10 @@
783783
** WEBPAGE: /docsrch
784784
**
785785
** Search for documents that match a user-supplied pattern.
786786
*/
787787
void doc_search_page(void){
788
- const char *zPattern = PD("s","");
789
- unsigned srchFlags = 0;
790
- const char *zDisable;
791
-
792788
login_check_credentials();
793
- srchFlags = search_restrict(SRCH_DOC);
794
- if( srchFlags==0 ){
795
- zDisable = " disabled";
796
- zPattern = "";
797
- }else{
798
- zDisable = "";
799
- zPattern = PD("s","");
800
- }
801789
style_header("Document Search");
802
- @ <form method="GET" action="docsrch"><center>
803
- @ <input type="text" name="s" size="40" value="%h(zPattern)"%s(zDisable)>
804
- @ <input type="submit" value="Search Docs"%s(zDisable)>
805
- if( srchFlags==0 ){
806
- @ <p class="generalError">Document search is disabled</p>
807
- }
808
- @ </center></form>
809
- while( fossil_isspace(zPattern[0]) ) zPattern++;
810
- if( zPattern[0] ){
811
- if( search_run_and_output(zPattern, srchFlags)==0 ){
812
- @ <p><i>No matches for: "%h(zPattern)"</i></p>
813
- }
814
- }
790
+ search_screen(SRCH_DOC, "docsrch");
815791
style_footer();
816792
}
817793
--- src/doc.c
+++ src/doc.c
@@ -783,34 +783,10 @@
783 ** WEBPAGE: /docsrch
784 **
785 ** Search for documents that match a user-supplied pattern.
786 */
787 void doc_search_page(void){
788 const char *zPattern = PD("s","");
789 unsigned srchFlags = 0;
790 const char *zDisable;
791
792 login_check_credentials();
793 srchFlags = search_restrict(SRCH_DOC);
794 if( srchFlags==0 ){
795 zDisable = " disabled";
796 zPattern = "";
797 }else{
798 zDisable = "";
799 zPattern = PD("s","");
800 }
801 style_header("Document Search");
802 @ <form method="GET" action="docsrch"><center>
803 @ <input type="text" name="s" size="40" value="%h(zPattern)"%s(zDisable)>
804 @ <input type="submit" value="Search Docs"%s(zDisable)>
805 if( srchFlags==0 ){
806 @ <p class="generalError">Document search is disabled</p>
807 }
808 @ </center></form>
809 while( fossil_isspace(zPattern[0]) ) zPattern++;
810 if( zPattern[0] ){
811 if( search_run_and_output(zPattern, srchFlags)==0 ){
812 @ <p><i>No matches for: "%h(zPattern)"</i></p>
813 }
814 }
815 style_footer();
816 }
817
--- src/doc.c
+++ src/doc.c
@@ -783,34 +783,10 @@
783 ** WEBPAGE: /docsrch
784 **
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
+56 -22
--- src/search.c
+++ src/search.c
@@ -570,11 +570,10 @@
570570
*/
571571
unsigned int search_restrict(unsigned int srchFlags){
572572
if( g.perm.Read==0 ) srchFlags &= ~(SRCH_CKIN|SRCH_DOC);
573573
if( g.perm.RdTkt==0 ) srchFlags &= ~(SRCH_TKT);
574574
if( g.perm.RdWiki==0 ) srchFlags &= ~(SRCH_WIKI);
575
- if( search_index_exists() ) return srchFlags;
576575
if( (srchFlags & SRCH_CKIN)!=0 && db_get_boolean("search-ci",0)==0 ){
577576
srchFlags &= ~SRCH_CKIN;
578577
}
579578
if( (srchFlags & SRCH_DOC)!=0 && db_get_boolean("search-doc",0)==0 ){
580579
srchFlags &= ~SRCH_DOC;
@@ -824,50 +823,85 @@
824823
}
825824
return nRow;
826825
}
827826
828827
/*
829
-** WEBPAGE: /search
828
+** Generate some HTML for doing search. At a minimum include the
829
+** Search-Text entry form. If the "s" query parameter is present, also
830
+** show search results.
831
+**
832
+** The srchFlags parameter is used to customize some of the text of the
833
+** form and the results. srchFlags should be either a single search
834
+** category or all categories. Any srchFlags with two or more bits set
835
+** is treated like SRCH_ALL for display purposes.
830836
**
831
-** Search for check-in comments, documents, tickets, or wiki that
832
-** match a user-supplied pattern.
837
+** The entry box is shown disabled if srchFlags is 0.
833838
*/
834
-void search_page(void){
835
- const char *zPattern = PD("s","");
836
- unsigned srchFlags = 0;
839
+void search_screen(unsigned srchFlags, const char *zAction){
840
+ const char *zType = 0;
841
+ const char *zClass = 0;
837842
const char *zDisable;
838
- const char *zOnly = P("only");
839
-
840
- login_check_credentials();
841
- srchFlags = search_restrict(SRCH_ALL);
842
- if( zOnly ){
843
- if( strchr(zOnly,'c') ) srchFlags &= SRCH_CKIN;
844
- if( strchr(zOnly,'d') ) srchFlags &= SRCH_DOC;
845
- if( strchr(zOnly,'t') ) srchFlags &= SRCH_TKT;
846
- if( strchr(zOnly,'w') ) srchFlags &= SRCH_WIKI;
847
- }
843
+ const char *zPattern;
844
+ switch( srchFlags ){
845
+ case SRCH_CKIN: zType = " Check-ins"; zClass = "Ckin"; break;
846
+ case SRCH_DOC: zType = " Docs"; zClass = "Doc"; break;
847
+ case SRCH_TKT: zType = " Tickets"; zClass = "Tkt"; break;
848
+ case SRCH_WIKI: zType = " Wiki"; zClass = "Wiki"; break;
849
+ }
850
+ srchFlags = search_restrict(srchFlags);
848851
if( srchFlags==0 ){
849852
zDisable = " disabled";
850853
zPattern = "";
851854
}else{
852855
zDisable = "";
853856
zPattern = PD("s","");
854857
}
855
- style_header("Search");
856
- @ <form method="GET" action="search"><center>
858
+ @ <form method='GET' action='%s(zAction)'>
859
+ if( zClass ){
860
+ @ <div class='searchForm searchForm%s(zClass)'>
861
+ }else{
862
+ @ <div class='searchForm'>
863
+ }
857864
@ <input type="text" name="s" size="40" value="%h(zPattern)"%s(zDisable)>
858
- @ <input type="submit" value="Search"%s(zDisable)>
865
+ @ <input type="submit" value="Search%s(zType)"%s(zDisable)>
859866
if( srchFlags==0 ){
860867
@ <p class="generalError">Search is disabled</p>
861868
}
862
- @ </center></form>
869
+ @ </div></form>
863870
while( fossil_isspace(zPattern[0]) ) zPattern++;
864871
if( zPattern[0] ){
872
+ if( zClass ){
873
+ @ <div class='searchResult searchResult%s(zClass)'>
874
+ }else{
875
+ @ <div class='searchResult'>
876
+ }
865877
if( search_run_and_output(zPattern, srchFlags)==0 ){
866
- @ <p><i>No matches for: "%h(zPattern)"</i></p>
878
+ @ <p class='searchEmpty'>No matches for: <span>%h(zPattern)</span></p>
867879
}
880
+ @ </div>
881
+ }
882
+}
883
+
884
+/*
885
+** WEBPAGE: /search
886
+**
887
+** Search for check-in comments, documents, tickets, or wiki that
888
+** match a user-supplied pattern.
889
+*/
890
+void search_page(void){
891
+ unsigned srchFlags = SRCH_ALL;
892
+ const char *zOnly = P("only");
893
+
894
+ login_check_credentials();
895
+ if( zOnly ){
896
+ if( strchr(zOnly,'c') ) srchFlags &= SRCH_CKIN;
897
+ if( strchr(zOnly,'d') ) srchFlags &= SRCH_DOC;
898
+ if( strchr(zOnly,'t') ) srchFlags &= SRCH_TKT;
899
+ if( strchr(zOnly,'w') ) srchFlags &= SRCH_WIKI;
868900
}
901
+ style_header("Search");
902
+ search_screen(srchFlags, "search");
869903
style_footer();
870904
}
871905
872906
873907
/*
874908
--- src/search.c
+++ src/search.c
@@ -570,11 +570,10 @@
570 */
571 unsigned int search_restrict(unsigned int srchFlags){
572 if( g.perm.Read==0 ) srchFlags &= ~(SRCH_CKIN|SRCH_DOC);
573 if( g.perm.RdTkt==0 ) srchFlags &= ~(SRCH_TKT);
574 if( g.perm.RdWiki==0 ) srchFlags &= ~(SRCH_WIKI);
575 if( search_index_exists() ) return srchFlags;
576 if( (srchFlags & SRCH_CKIN)!=0 && db_get_boolean("search-ci",0)==0 ){
577 srchFlags &= ~SRCH_CKIN;
578 }
579 if( (srchFlags & SRCH_DOC)!=0 && db_get_boolean("search-doc",0)==0 ){
580 srchFlags &= ~SRCH_DOC;
@@ -824,50 +823,85 @@
824 }
825 return nRow;
826 }
827
828 /*
829 ** WEBPAGE: /search
 
 
 
 
 
 
 
830 **
831 ** Search for check-in comments, documents, tickets, or wiki that
832 ** match a user-supplied pattern.
833 */
834 void search_page(void){
835 const char *zPattern = PD("s","");
836 unsigned srchFlags = 0;
837 const char *zDisable;
838 const char *zOnly = P("only");
839
840 login_check_credentials();
841 srchFlags = search_restrict(SRCH_ALL);
842 if( zOnly ){
843 if( strchr(zOnly,'c') ) srchFlags &= SRCH_CKIN;
844 if( strchr(zOnly,'d') ) srchFlags &= SRCH_DOC;
845 if( strchr(zOnly,'t') ) srchFlags &= SRCH_TKT;
846 if( strchr(zOnly,'w') ) srchFlags &= SRCH_WIKI;
847 }
848 if( srchFlags==0 ){
849 zDisable = " disabled";
850 zPattern = "";
851 }else{
852 zDisable = "";
853 zPattern = PD("s","");
854 }
855 style_header("Search");
856 @ <form method="GET" action="search"><center>
 
 
 
 
857 @ <input type="text" name="s" size="40" value="%h(zPattern)"%s(zDisable)>
858 @ <input type="submit" value="Search"%s(zDisable)>
859 if( srchFlags==0 ){
860 @ <p class="generalError">Search is disabled</p>
861 }
862 @ </center></form>
863 while( fossil_isspace(zPattern[0]) ) zPattern++;
864 if( zPattern[0] ){
 
 
 
 
 
865 if( search_run_and_output(zPattern, srchFlags)==0 ){
866 @ <p><i>No matches for: "%h(zPattern)"</i></p>
867 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
868 }
 
 
869 style_footer();
870 }
871
872
873 /*
874
--- src/search.c
+++ src/search.c
@@ -570,11 +570,10 @@
570 */
571 unsigned int search_restrict(unsigned int srchFlags){
572 if( g.perm.Read==0 ) srchFlags &= ~(SRCH_CKIN|SRCH_DOC);
573 if( g.perm.RdTkt==0 ) srchFlags &= ~(SRCH_TKT);
574 if( g.perm.RdWiki==0 ) srchFlags &= ~(SRCH_WIKI);
 
575 if( (srchFlags & SRCH_CKIN)!=0 && db_get_boolean("search-ci",0)==0 ){
576 srchFlags &= ~SRCH_CKIN;
577 }
578 if( (srchFlags & SRCH_DOC)!=0 && db_get_boolean("search-doc",0)==0 ){
579 srchFlags &= ~SRCH_DOC;
@@ -824,50 +823,85 @@
823 }
824 return nRow;
825 }
826
827 /*
828 ** Generate some HTML for doing search. At a minimum include the
829 ** Search-Text entry form. If the "s" query parameter is present, also
830 ** show search results.
831 **
832 ** The srchFlags parameter is used to customize some of the text of the
833 ** form and the results. srchFlags should be either a single search
834 ** category or all categories. Any srchFlags with two or more bits set
835 ** is treated like SRCH_ALL for display purposes.
836 **
837 ** The entry box is shown disabled if srchFlags is 0.
 
838 */
839 void search_screen(unsigned srchFlags, const char *zAction){
840 const char *zType = 0;
841 const char *zClass = 0;
842 const char *zDisable;
843 const char *zPattern;
844 switch( srchFlags ){
845 case SRCH_CKIN: zType = " Check-ins"; zClass = "Ckin"; break;
846 case SRCH_DOC: zType = " Docs"; zClass = "Doc"; break;
847 case SRCH_TKT: zType = " Tickets"; zClass = "Tkt"; break;
848 case SRCH_WIKI: zType = " Wiki"; zClass = "Wiki"; break;
849 }
850 srchFlags = search_restrict(srchFlags);
 
 
851 if( srchFlags==0 ){
852 zDisable = " disabled";
853 zPattern = "";
854 }else{
855 zDisable = "";
856 zPattern = PD("s","");
857 }
858 @ <form method='GET' action='%s(zAction)'>
859 if( zClass ){
860 @ <div class='searchForm searchForm%s(zClass)'>
861 }else{
862 @ <div class='searchForm'>
863 }
864 @ <input type="text" name="s" size="40" value="%h(zPattern)"%s(zDisable)>
865 @ <input type="submit" value="Search%s(zType)"%s(zDisable)>
866 if( srchFlags==0 ){
867 @ <p class="generalError">Search is disabled</p>
868 }
869 @ </div></form>
870 while( fossil_isspace(zPattern[0]) ) zPattern++;
871 if( zPattern[0] ){
872 if( zClass ){
873 @ <div class='searchResult searchResult%s(zClass)'>
874 }else{
875 @ <div class='searchResult'>
876 }
877 if( search_run_and_output(zPattern, srchFlags)==0 ){
878 @ <p class='searchEmpty'>No matches for: <span>%h(zPattern)</span></p>
879 }
880 @ </div>
881 }
882 }
883
884 /*
885 ** WEBPAGE: /search
886 **
887 ** Search for check-in comments, documents, tickets, or wiki that
888 ** match a user-supplied pattern.
889 */
890 void search_page(void){
891 unsigned srchFlags = SRCH_ALL;
892 const char *zOnly = P("only");
893
894 login_check_credentials();
895 if( zOnly ){
896 if( strchr(zOnly,'c') ) srchFlags &= SRCH_CKIN;
897 if( strchr(zOnly,'d') ) srchFlags &= SRCH_DOC;
898 if( strchr(zOnly,'t') ) srchFlags &= SRCH_TKT;
899 if( strchr(zOnly,'w') ) srchFlags &= SRCH_WIKI;
900 }
901 style_header("Search");
902 search_screen(srchFlags, "search");
903 style_footer();
904 }
905
906
907 /*
908
--- src/style.c
+++ src/style.c
@@ -1130,10 +1130,18 @@
11301130
{ "span.snippet>mark",
11311131
"Search markup",
11321132
@ background-color: inherit;
11331133
@ font-weight: bold;
11341134
},
1135
+ { "div.searchForm",
1136
+ "Container for the search terms entry box",
1137
+ @ text-align: center;
1138
+ },
1139
+ { "p.searchEmpty",
1140
+ "Message explaining that there are no search results",
1141
+ @ font-style: italic;
1142
+ },
11351143
{ 0,
11361144
0,
11371145
0
11381146
}
11391147
};
11401148
--- src/style.c
+++ src/style.c
@@ -1130,10 +1130,18 @@
1130 { "span.snippet>mark",
1131 "Search markup",
1132 @ background-color: inherit;
1133 @ font-weight: bold;
1134 },
 
 
 
 
 
 
 
 
1135 { 0,
1136 0,
1137 0
1138 }
1139 };
1140
--- src/style.c
+++ src/style.c
@@ -1130,10 +1130,18 @@
1130 { "span.snippet>mark",
1131 "Search markup",
1132 @ background-color: inherit;
1133 @ font-weight: bold;
1134 },
1135 { "div.searchForm",
1136 "Container for the search terms entry box",
1137 @ text-align: center;
1138 },
1139 { "p.searchEmpty",
1140 "Message explaining that there are no search results",
1141 @ font-style: italic;
1142 },
1143 { 0,
1144 0,
1145 0
1146 }
1147 };
1148
+1 -25
--- src/tkt.c
+++ src/tkt.c
@@ -1431,35 +1431,11 @@
14311431
** Usage: /tktsrch?s=PATTERN
14321432
**
14331433
** Full-text search of all current tickets
14341434
*/
14351435
void tkt_srchpage(void){
1436
- const char *zPattern = PD("s","");
1437
- unsigned srchFlags = 0;
1438
- const char *zDisable;
1439
-
14401436
login_check_credentials();
1441
- srchFlags = search_restrict(SRCH_TKT);
1442
- if( srchFlags==0 ){
1443
- zDisable = " disabled";
1444
- zPattern = "";
1445
- }else{
1446
- zDisable = "";
1447
- zPattern = PD("s","");
1448
- }
14491437
style_header("Ticket Search");
14501438
ticket_standard_submenu(T_ALL_BUT(T_SRCH));
1451
- @ <form method="GET" action="tktsrch"><center>
1452
- @ <input type="text" name="s" size="40" value="%h(zPattern)"%s(zDisable)>
1453
- @ <input type="submit" value="Search Tickets"%s(zDisable)>
1454
- if( srchFlags==0 ){
1455
- @ <p class="generalError">Ticket search is disabled</p>
1456
- }
1457
- @ </center></form>
1458
- while( fossil_isspace(zPattern[0]) ) zPattern++;
1459
- if( zPattern[0] ){
1460
- if( search_run_and_output(zPattern, srchFlags)==0 ){
1461
- @ <p><i>No matches for: "%h(zPattern)"</i></p>
1462
- }
1463
- }
1439
+ search_screen(SRCH_TKT, "tktsrch");
14641440
style_footer();
14651441
}
14661442
--- src/tkt.c
+++ src/tkt.c
@@ -1431,35 +1431,11 @@
1431 ** Usage: /tktsrch?s=PATTERN
1432 **
1433 ** Full-text search of all current tickets
1434 */
1435 void tkt_srchpage(void){
1436 const char *zPattern = PD("s","");
1437 unsigned srchFlags = 0;
1438 const char *zDisable;
1439
1440 login_check_credentials();
1441 srchFlags = search_restrict(SRCH_TKT);
1442 if( srchFlags==0 ){
1443 zDisable = " disabled";
1444 zPattern = "";
1445 }else{
1446 zDisable = "";
1447 zPattern = PD("s","");
1448 }
1449 style_header("Ticket Search");
1450 ticket_standard_submenu(T_ALL_BUT(T_SRCH));
1451 @ <form method="GET" action="tktsrch"><center>
1452 @ <input type="text" name="s" size="40" value="%h(zPattern)"%s(zDisable)>
1453 @ <input type="submit" value="Search Tickets"%s(zDisable)>
1454 if( srchFlags==0 ){
1455 @ <p class="generalError">Ticket search is disabled</p>
1456 }
1457 @ </center></form>
1458 while( fossil_isspace(zPattern[0]) ) zPattern++;
1459 if( zPattern[0] ){
1460 if( search_run_and_output(zPattern, srchFlags)==0 ){
1461 @ <p><i>No matches for: "%h(zPattern)"</i></p>
1462 }
1463 }
1464 style_footer();
1465 }
1466
--- src/tkt.c
+++ src/tkt.c
@@ -1431,35 +1431,11 @@
1431 ** Usage: /tktsrch?s=PATTERN
1432 **
1433 ** Full-text search of all current tickets
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
+1 -25
--- src/wiki.c
+++ src/wiki.c
@@ -288,38 +288,14 @@
288288
** Usage: /wikisrch?s=PATTERN
289289
**
290290
** Full-text search of all current wiki text
291291
*/
292292
void wiki_srchpage(void){
293
- const char *zPattern = PD("s","");
294
- unsigned srchFlags = 0;
295
- const char *zDisable;
296
-
297293
login_check_credentials();
298
- srchFlags = search_restrict(SRCH_WIKI);
299
- if( srchFlags==0 ){
300
- zDisable = " disabled";
301
- zPattern = "";
302
- }else{
303
- zDisable = "";
304
- zPattern = PD("s","");
305
- }
306294
style_header("Wiki Search");
307295
wiki_standard_submenu(W_HELP|W_LIST|W_SANDBOX);
308
- @ <form method="GET" action="wikisrch"><center>
309
- @ <input type="text" name="s" size="40" value="%h(zPattern)"%s(zDisable)>
310
- @ <input type="submit" value="Search Wiki"%s(zDisable)>
311
- if( srchFlags==0 ){
312
- @ <p class="generalError">Wiki search is disabled</p>
313
- }
314
- @ </center></form>
315
- while( fossil_isspace(zPattern[0]) ) zPattern++;
316
- if( zPattern[0] ){
317
- if( search_run_and_output(zPattern, srchFlags)==0 ){
318
- @ <p><i>No matches for: "%h(zPattern)"</i></p>
319
- }
320
- }
296
+ search_screen(SRCH_WIKI, "wikisrch");
321297
style_footer();
322298
}
323299
324300
/*
325301
** WEBPAGE: wiki
326302
--- src/wiki.c
+++ src/wiki.c
@@ -288,38 +288,14 @@
288 ** Usage: /wikisrch?s=PATTERN
289 **
290 ** Full-text search of all current wiki text
291 */
292 void wiki_srchpage(void){
293 const char *zPattern = PD("s","");
294 unsigned srchFlags = 0;
295 const char *zDisable;
296
297 login_check_credentials();
298 srchFlags = search_restrict(SRCH_WIKI);
299 if( srchFlags==0 ){
300 zDisable = " disabled";
301 zPattern = "";
302 }else{
303 zDisable = "";
304 zPattern = PD("s","");
305 }
306 style_header("Wiki Search");
307 wiki_standard_submenu(W_HELP|W_LIST|W_SANDBOX);
308 @ <form method="GET" action="wikisrch"><center>
309 @ <input type="text" name="s" size="40" value="%h(zPattern)"%s(zDisable)>
310 @ <input type="submit" value="Search Wiki"%s(zDisable)>
311 if( srchFlags==0 ){
312 @ <p class="generalError">Wiki search is disabled</p>
313 }
314 @ </center></form>
315 while( fossil_isspace(zPattern[0]) ) zPattern++;
316 if( zPattern[0] ){
317 if( search_run_and_output(zPattern, srchFlags)==0 ){
318 @ <p><i>No matches for: "%h(zPattern)"</i></p>
319 }
320 }
321 style_footer();
322 }
323
324 /*
325 ** WEBPAGE: wiki
326
--- src/wiki.c
+++ src/wiki.c
@@ -288,38 +288,14 @@
288 ** Usage: /wikisrch?s=PATTERN
289 **
290 ** Full-text search of all current wiki text
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

Keyboard Shortcuts

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