Fossil SCM

Add a selection widget for status filtering. Now how to make the setting sticky?

stephan 2026-05-26 17:08 UTC forum-statuses
Commit 4c87c5690c18cfb527535fefb1aa02d89f9fa6ad4f1dc4634a081e61bfc03e9a
1 file changed +36 -4
+36 -4
--- src/forum.c
+++ src/forum.c
@@ -2417,10 +2417,36 @@
24172417
@ </form>
24182418
}
24192419
24202420
style_finish_page();
24212421
}
2422
+
2423
+/*
2424
+** If the forum-statuses setting is active and has 2 or more entries,
2425
+** this adds a submenu for selecting the status filter, else it emits
2426
+** nothing.
2427
+*/
2428
+static void forum_status_submenu(void){
2429
+ const ForumStatusList * const fss = forum_statuses();
2430
+ static int i = 0;
2431
+ static const char **az;
2432
+ if( i==0 && fss->n>1 ){
2433
+ unsigned j;
2434
+ az = fossil_malloc(sizeof(az[0]) * ((1 + fss->n) * 2));
2435
+ az[i++] = "*";
2436
+ az[i++] = "Any status";
2437
+ for( j = 0; j < fss->n; ++j ){
2438
+ const ForumStatus * fs = &fss->aStatus[j];
2439
+ az[i++] = fs->zValue;
2440
+ az[i++] = fs->zLabel;
2441
+ }
2442
+ //assert( i==(1+fss->n)*2 );
2443
+ }
2444
+ if( i ){
2445
+ style_submenu_multichoice("status", i/2, az, 0);
2446
+ }
2447
+}
24222448
24232449
/*
24242450
** WEBPAGE: forummain
24252451
** WEBPAGE: forum
24262452
**
@@ -2439,10 +2465,11 @@
24392465
int iLimit = 0, iOfst, iCnt;
24402466
int srchFlags;
24412467
const int isSearch = P("s")!=0;
24422468
const char *zStatusFilter = P("status");
24432469
char const *zLimit = 0;
2470
+ const int bHasStatus = forum_statuses()->n>1;
24442471
24452472
login_check_credentials();
24462473
srchFlags = search_restrict(SRCH_FORUM);
24472474
if( !g.perm.RdForum ){
24482475
login_needed(g.anon.RdForum);
@@ -2484,15 +2511,18 @@
24842511
cgi_replace_query_parameter("n", fossil_strdup("25"))
24852512
/*for the sake of Max, below*/;
24862513
iLimit = 25;
24872514
}
24882515
style_submenu_entry("n","Max:",4,0);
2516
+ forum_status_submenu();
24892517
iOfst = atoi(PD("x","0"));
24902518
iCnt = 0;
2491
- if( zStatusFilter && !*zStatusFilter ) zStatusFilter = 0;
2519
+ if( zStatusFilter &&
2520
+ (!*zStatusFilter || 0==fossil_strcmp("*",zStatusFilter)) ){
2521
+ zStatusFilter = 0;
2522
+ }
24922523
if( db_table_exists("repository","forumpost") ){
2493
- const int bHasStatus = forum_statuses()->n>1;
24942524
db_prepare(&q,
24952525
"WITH "
24962526
"root(id,pinned,status,statlbl) AS ("
24972527
/* FIXME: the status/statlbl columns are running the same query
24982528
** to get two adjacent columns. Certainly this query can be
@@ -2500,10 +2530,11 @@
25002530
" SELECT froot id,"
25012531
" (SELECT 1 FROM tagxref ref, tag t"
25022532
" WHERE ref.rid=x.fpid AND ref.tagtype>0"
25032533
" AND ref.tagid=t.tagid"
25042534
" AND t.tagname='pinned') pinned,"
2535
+ /* Status value: */
25052536
" CASE WHEN %d /*bHasStatus*/ THEN coalesce("
25062537
" (SELECT ref.value FROM tagxref ref, tag t, forumstatus fs"
25072538
" WHERE ref.rid=x.froot AND ref.tagtype>0"
25082539
" AND ref.tagid=t.tagid"
25092540
" AND t.tagname='status'"
@@ -2510,10 +2541,11 @@
25102541
" AND ref.value=fs.value"
25112542
" ORDER BY ref.mtime desc"
25122543
" ),"
25132544
" (SELECT value FROM forumstatus WHERE ord=1)"
25142545
" ) ELSE NULL END status,"
2546
+ /* Status label: */
25152547
" CASE WHEN %d /*bHasStatus*/ THEN coalesce("
25162548
" (SELECT fs.label FROM tagxref ref, tag t, forumstatus fs"
25172549
" WHERE ref.rid=x.froot AND ref.tagtype>0"
25182550
" AND ref.tagid=t.tagid"
25192551
" AND t.tagname='status'"
@@ -2520,11 +2552,11 @@
25202552
" AND ref.value=fs.value"
25212553
" ORDER BY ref.mtime desc"
25222554
" ),"
25232555
" (SELECT label FROM forumstatus WHERE ord=1)"
25242556
" ) ELSE NULL END statlbl"
2525
- " FROM forumpost x WHERE firt IS NULL AND fprev IS NULL"
2557
+ " FROM forumpost x WHERE firt IS NULL" /*??? AND fprev IS NULL*/
25262558
"),"
25272559
" thread(age,duration,cnt,root,last,pinned,status,statlbl)"
25282560
" AS ("
25292561
" SELECT"
25302562
" julianday('now') - max(fmtime),"
@@ -2552,11 +2584,11 @@
25522584
" thread.status," /* 7 */
25532585
" thread.statlbl" /* 8 */
25542586
" FROM thread, blob, event"
25552587
" WHERE blob.rid=thread.last"
25562588
" AND event.objid=thread.last"
2557
- " ORDER BY 7 DESC, 1;",
2589
+ " ORDER BY 7/*pinned*/ DESC, 1;",
25582590
bHasStatus, bHasStatus,
25592591
g.perm.ModForum ? "" : "AND y.fpid NOT IN private" /*safe-for-%s*/,
25602592
g.perm.ModForum ? "true" : "fpid NOT IN private" /*safe-for-%s*/,
25612593
!!zStatusFilter, zStatusFilter,
25622594
iLimit+1, iOfst
25632595
--- src/forum.c
+++ src/forum.c
@@ -2417,10 +2417,36 @@
2417 @ </form>
2418 }
2419
2420 style_finish_page();
2421 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2422
2423 /*
2424 ** WEBPAGE: forummain
2425 ** WEBPAGE: forum
2426 **
@@ -2439,10 +2465,11 @@
2439 int iLimit = 0, iOfst, iCnt;
2440 int srchFlags;
2441 const int isSearch = P("s")!=0;
2442 const char *zStatusFilter = P("status");
2443 char const *zLimit = 0;
 
2444
2445 login_check_credentials();
2446 srchFlags = search_restrict(SRCH_FORUM);
2447 if( !g.perm.RdForum ){
2448 login_needed(g.anon.RdForum);
@@ -2484,15 +2511,18 @@
2484 cgi_replace_query_parameter("n", fossil_strdup("25"))
2485 /*for the sake of Max, below*/;
2486 iLimit = 25;
2487 }
2488 style_submenu_entry("n","Max:",4,0);
 
2489 iOfst = atoi(PD("x","0"));
2490 iCnt = 0;
2491 if( zStatusFilter && !*zStatusFilter ) zStatusFilter = 0;
 
 
 
2492 if( db_table_exists("repository","forumpost") ){
2493 const int bHasStatus = forum_statuses()->n>1;
2494 db_prepare(&q,
2495 "WITH "
2496 "root(id,pinned,status,statlbl) AS ("
2497 /* FIXME: the status/statlbl columns are running the same query
2498 ** to get two adjacent columns. Certainly this query can be
@@ -2500,10 +2530,11 @@
2500 " SELECT froot id,"
2501 " (SELECT 1 FROM tagxref ref, tag t"
2502 " WHERE ref.rid=x.fpid AND ref.tagtype>0"
2503 " AND ref.tagid=t.tagid"
2504 " AND t.tagname='pinned') pinned,"
 
2505 " CASE WHEN %d /*bHasStatus*/ THEN coalesce("
2506 " (SELECT ref.value FROM tagxref ref, tag t, forumstatus fs"
2507 " WHERE ref.rid=x.froot AND ref.tagtype>0"
2508 " AND ref.tagid=t.tagid"
2509 " AND t.tagname='status'"
@@ -2510,10 +2541,11 @@
2510 " AND ref.value=fs.value"
2511 " ORDER BY ref.mtime desc"
2512 " ),"
2513 " (SELECT value FROM forumstatus WHERE ord=1)"
2514 " ) ELSE NULL END status,"
 
2515 " CASE WHEN %d /*bHasStatus*/ THEN coalesce("
2516 " (SELECT fs.label FROM tagxref ref, tag t, forumstatus fs"
2517 " WHERE ref.rid=x.froot AND ref.tagtype>0"
2518 " AND ref.tagid=t.tagid"
2519 " AND t.tagname='status'"
@@ -2520,11 +2552,11 @@
2520 " AND ref.value=fs.value"
2521 " ORDER BY ref.mtime desc"
2522 " ),"
2523 " (SELECT label FROM forumstatus WHERE ord=1)"
2524 " ) ELSE NULL END statlbl"
2525 " FROM forumpost x WHERE firt IS NULL AND fprev IS NULL"
2526 "),"
2527 " thread(age,duration,cnt,root,last,pinned,status,statlbl)"
2528 " AS ("
2529 " SELECT"
2530 " julianday('now') - max(fmtime),"
@@ -2552,11 +2584,11 @@
2552 " thread.status," /* 7 */
2553 " thread.statlbl" /* 8 */
2554 " FROM thread, blob, event"
2555 " WHERE blob.rid=thread.last"
2556 " AND event.objid=thread.last"
2557 " ORDER BY 7 DESC, 1;",
2558 bHasStatus, bHasStatus,
2559 g.perm.ModForum ? "" : "AND y.fpid NOT IN private" /*safe-for-%s*/,
2560 g.perm.ModForum ? "true" : "fpid NOT IN private" /*safe-for-%s*/,
2561 !!zStatusFilter, zStatusFilter,
2562 iLimit+1, iOfst
2563
--- src/forum.c
+++ src/forum.c
@@ -2417,10 +2417,36 @@
2417 @ </form>
2418 }
2419
2420 style_finish_page();
2421 }
2422
2423 /*
2424 ** If the forum-statuses setting is active and has 2 or more entries,
2425 ** this adds a submenu for selecting the status filter, else it emits
2426 ** nothing.
2427 */
2428 static void forum_status_submenu(void){
2429 const ForumStatusList * const fss = forum_statuses();
2430 static int i = 0;
2431 static const char **az;
2432 if( i==0 && fss->n>1 ){
2433 unsigned j;
2434 az = fossil_malloc(sizeof(az[0]) * ((1 + fss->n) * 2));
2435 az[i++] = "*";
2436 az[i++] = "Any status";
2437 for( j = 0; j < fss->n; ++j ){
2438 const ForumStatus * fs = &fss->aStatus[j];
2439 az[i++] = fs->zValue;
2440 az[i++] = fs->zLabel;
2441 }
2442 //assert( i==(1+fss->n)*2 );
2443 }
2444 if( i ){
2445 style_submenu_multichoice("status", i/2, az, 0);
2446 }
2447 }
2448
2449 /*
2450 ** WEBPAGE: forummain
2451 ** WEBPAGE: forum
2452 **
@@ -2439,10 +2465,11 @@
2465 int iLimit = 0, iOfst, iCnt;
2466 int srchFlags;
2467 const int isSearch = P("s")!=0;
2468 const char *zStatusFilter = P("status");
2469 char const *zLimit = 0;
2470 const int bHasStatus = forum_statuses()->n>1;
2471
2472 login_check_credentials();
2473 srchFlags = search_restrict(SRCH_FORUM);
2474 if( !g.perm.RdForum ){
2475 login_needed(g.anon.RdForum);
@@ -2484,15 +2511,18 @@
2511 cgi_replace_query_parameter("n", fossil_strdup("25"))
2512 /*for the sake of Max, below*/;
2513 iLimit = 25;
2514 }
2515 style_submenu_entry("n","Max:",4,0);
2516 forum_status_submenu();
2517 iOfst = atoi(PD("x","0"));
2518 iCnt = 0;
2519 if( zStatusFilter &&
2520 (!*zStatusFilter || 0==fossil_strcmp("*",zStatusFilter)) ){
2521 zStatusFilter = 0;
2522 }
2523 if( db_table_exists("repository","forumpost") ){
 
2524 db_prepare(&q,
2525 "WITH "
2526 "root(id,pinned,status,statlbl) AS ("
2527 /* FIXME: the status/statlbl columns are running the same query
2528 ** to get two adjacent columns. Certainly this query can be
@@ -2500,10 +2530,11 @@
2530 " SELECT froot id,"
2531 " (SELECT 1 FROM tagxref ref, tag t"
2532 " WHERE ref.rid=x.fpid AND ref.tagtype>0"
2533 " AND ref.tagid=t.tagid"
2534 " AND t.tagname='pinned') pinned,"
2535 /* Status value: */
2536 " CASE WHEN %d /*bHasStatus*/ THEN coalesce("
2537 " (SELECT ref.value FROM tagxref ref, tag t, forumstatus fs"
2538 " WHERE ref.rid=x.froot AND ref.tagtype>0"
2539 " AND ref.tagid=t.tagid"
2540 " AND t.tagname='status'"
@@ -2510,10 +2541,11 @@
2541 " AND ref.value=fs.value"
2542 " ORDER BY ref.mtime desc"
2543 " ),"
2544 " (SELECT value FROM forumstatus WHERE ord=1)"
2545 " ) ELSE NULL END status,"
2546 /* Status label: */
2547 " CASE WHEN %d /*bHasStatus*/ THEN coalesce("
2548 " (SELECT fs.label FROM tagxref ref, tag t, forumstatus fs"
2549 " WHERE ref.rid=x.froot AND ref.tagtype>0"
2550 " AND ref.tagid=t.tagid"
2551 " AND t.tagname='status'"
@@ -2520,11 +2552,11 @@
2552 " AND ref.value=fs.value"
2553 " ORDER BY ref.mtime desc"
2554 " ),"
2555 " (SELECT label FROM forumstatus WHERE ord=1)"
2556 " ) ELSE NULL END statlbl"
2557 " FROM forumpost x WHERE firt IS NULL" /*??? AND fprev IS NULL*/
2558 "),"
2559 " thread(age,duration,cnt,root,last,pinned,status,statlbl)"
2560 " AS ("
2561 " SELECT"
2562 " julianday('now') - max(fmtime),"
@@ -2552,11 +2584,11 @@
2584 " thread.status," /* 7 */
2585 " thread.statlbl" /* 8 */
2586 " FROM thread, blob, event"
2587 " WHERE blob.rid=thread.last"
2588 " AND event.objid=thread.last"
2589 " ORDER BY 7/*pinned*/ DESC, 1;",
2590 bHasStatus, bHasStatus,
2591 g.perm.ModForum ? "" : "AND y.fpid NOT IN private" /*safe-for-%s*/,
2592 g.perm.ModForum ? "true" : "fpid NOT IN private" /*safe-for-%s*/,
2593 !!zStatusFilter, zStatusFilter,
2594 iLimit+1, iOfst
2595

Keyboard Shortcuts

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