| | @@ -2437,10 +2437,11 @@ |
| 2437 | 2437 | void forum_main_page(void){ |
| 2438 | 2438 | Stmt q; |
| 2439 | 2439 | int iLimit = 0, iOfst, iCnt; |
| 2440 | 2440 | int srchFlags; |
| 2441 | 2441 | const int isSearch = P("s")!=0; |
| 2442 | + const char *zStatus = P("status"); |
| 2442 | 2443 | char const *zLimit = 0; |
| 2443 | 2444 | |
| 2444 | 2445 | login_check_credentials(); |
| 2445 | 2446 | srchFlags = search_restrict(SRCH_FORUM); |
| 2446 | 2447 | if( !g.perm.RdForum ){ |
| | @@ -2488,42 +2489,55 @@ |
| 2488 | 2489 | iOfst = atoi(PD("x","0")); |
| 2489 | 2490 | iCnt = 0; |
| 2490 | 2491 | if( db_table_exists("repository","forumpost") ){ |
| 2491 | 2492 | const int bHasStatus = forum_statuses()->n>1; |
| 2492 | 2493 | db_prepare(&q, |
| 2493 | | - "WITH thread(age,duration,cnt,root,last,pinned,status) AS (" |
| 2494 | + "WITH " |
| 2495 | + "root(id,pinned,status,statlbl) AS (" |
| 2496 | + /* FIXME: the status/statlbl columns are running the same query |
| 2497 | + ** to get two adjacent columns. Certainly this query can be |
| 2498 | + ** restructured to avoid the duplicated lookup? */ |
| 2499 | + " SELECT froot id," |
| 2500 | + " (SELECT 1 FROM tagxref ref, tag t" |
| 2501 | + " WHERE ref.rid=x.fpid AND ref.tagtype>0" |
| 2502 | + " AND ref.tagid=t.tagid" |
| 2503 | + " AND t.tagname='pinned') pinned," |
| 2504 | + " CASE WHEN %d /*bHasStatus*/ THEN coalesce(" |
| 2505 | + " (SELECT ref.value FROM tagxref ref, tag t, forumstatus fs" |
| 2506 | + " WHERE ref.rid=x.froot AND ref.tagtype>0" |
| 2507 | + " AND ref.tagid=t.tagid" |
| 2508 | + " AND t.tagname='status'" |
| 2509 | + " AND ref.value=fs.value" |
| 2510 | + " ORDER BY ref.mtime desc" |
| 2511 | + " )," |
| 2512 | + " (SELECT value FROM forumstatus WHERE ord=1)" |
| 2513 | + " ) ELSE NULL END status," |
| 2514 | + " CASE WHEN %d /*bHasStatus*/ THEN coalesce(" |
| 2515 | + " (SELECT fs.label FROM tagxref ref, tag t, forumstatus fs" |
| 2516 | + " WHERE ref.rid=x.froot AND ref.tagtype>0" |
| 2517 | + " AND ref.tagid=t.tagid" |
| 2518 | + " AND t.tagname='status'" |
| 2519 | + " AND ref.value=fs.value" |
| 2520 | + " ORDER BY ref.mtime desc" |
| 2521 | + " )," |
| 2522 | + " (SELECT label FROM forumstatus WHERE ord=1)" |
| 2523 | + " ) ELSE NULL END statlbl" |
| 2524 | + " FROM forumpost x WHERE firt IS NULL" |
| 2525 | + ")," |
| 2526 | + " thread(age,duration,cnt,root,last,pinned,status,statlbl)" |
| 2527 | + " AS (" |
| 2494 | 2528 | " SELECT" |
| 2495 | 2529 | " julianday('now') - max(fmtime)," |
| 2496 | 2530 | " max(fmtime) - min(fmtime)," |
| 2497 | 2531 | " sum(fprev IS NULL)," |
| 2498 | | - " froot," |
| 2532 | + " root.id," |
| 2499 | 2533 | " (SELECT fpid FROM forumpost AS y" |
| 2500 | | - " WHERE y.froot=x.froot %s" |
| 2534 | + " WHERE y.froot=root.id %s" |
| 2501 | 2535 | " ORDER BY y.fmtime DESC LIMIT 1)," |
| 2502 | | - " (firt IS NULL AND" |
| 2503 | | - " (SELECT 1 FROM tagxref ref, tag t" |
| 2504 | | - " WHERE ref.rid=x.fpid AND ref.tagtype>0" |
| 2505 | | - " AND ref.tagid=t.tagid" |
| 2506 | | - " AND t.tagname='pinned'))," |
| 2507 | | -#if 0 |
| 2508 | | - " (SELECT ref.value FROM tagxref ref, tag t" |
| 2509 | | - " WHERE ref.rid=x.froot AND ref.tagtype>0" |
| 2510 | | - " AND ref.tagid=t.tagid" |
| 2511 | | - " AND t.tagname='status'" |
| 2512 | | - " UNION ALL" |
| 2513 | | - " SELECT value FROM forumstatus WHERE ord=1)" |
| 2514 | | -#else |
| 2515 | | - " (SELECT fs.label FROM tagxref ref, tag t, forumstatus fs" |
| 2516 | | - " WHERE ref.rid=x.froot AND ref.tagtype>0" |
| 2517 | | - " AND ref.tagid=t.tagid" |
| 2518 | | - " AND t.tagname='status'" |
| 2519 | | - " AND fs.value=ref.value" |
| 2520 | | - " UNION ALL" |
| 2521 | | - " SELECT label FROM forumstatus WHERE ord=1)" |
| 2522 | | -#endif |
| 2523 | | - " FROM forumpost AS x" |
| 2524 | | - " WHERE %s" |
| 2536 | + " root.pinned, root.status, root.statlbl" |
| 2537 | + " FROM forumpost, root" |
| 2538 | + " WHERE root.id=froot AND %s" |
| 2525 | 2539 | " GROUP BY froot" |
| 2526 | 2540 | " ORDER BY 6 DESC, 1 LIMIT %d OFFSET %d" |
| 2527 | 2541 | ")" |
| 2528 | 2542 | "SELECT" |
| 2529 | 2543 | " thread.age," /* 0 */ |
| | @@ -2531,15 +2545,17 @@ |
| 2531 | 2545 | " thread.cnt," /* 2 */ |
| 2532 | 2546 | " blob.uuid," /* 3 */ |
| 2533 | 2547 | " substr(event.comment,instr(event.comment,':')+1)," /* 4 */ |
| 2534 | 2548 | " thread.last," /* 5 */ |
| 2535 | 2549 | " thread.pinned," /* 6 */ |
| 2536 | | - " thread.status" /* 7 */ |
| 2550 | + " thread.status," /* 7 */ |
| 2551 | + " thread.statlbl" /* 8 */ |
| 2537 | 2552 | " FROM thread, blob, event" |
| 2538 | 2553 | " WHERE blob.rid=thread.last" |
| 2539 | 2554 | " AND event.objid=thread.last" |
| 2540 | 2555 | " ORDER BY 7 DESC, 1;", |
| 2556 | + bHasStatus, bHasStatus, |
| 2541 | 2557 | g.perm.ModForum ? "" : "AND y.fpid NOT IN private" /*safe-for-%s*/, |
| 2542 | 2558 | g.perm.ModForum ? "true" : "fpid NOT IN private" /*safe-for-%s*/, |
| 2543 | 2559 | iLimit+1, iOfst |
| 2544 | 2560 | ); |
| 2545 | 2561 | while( db_step(&q)==SQLITE_ROW ){ |
| | @@ -2547,10 +2563,11 @@ |
| 2547 | 2563 | int nMsg = db_column_int(&q, 2); |
| 2548 | 2564 | int bPinned = db_column_int(&q, 6); |
| 2549 | 2565 | const char *zUuid = db_column_text(&q, 3); |
| 2550 | 2566 | const char *zTitle = db_column_text(&q, 4); |
| 2551 | 2567 | const char *zStatus = bHasStatus ? db_column_text(&q, 7) : NULL; |
| 2568 | + const char *zStatusLbl = bHasStatus ? db_column_text(&q, 8) : NULL; |
| 2552 | 2569 | if( iCnt==0 ){ |
| 2553 | 2570 | if( iOfst>0 ){ |
| 2554 | 2571 | @ <h1>Threads at least %s(zAge) old</h1> |
| 2555 | 2572 | }else{ |
| 2556 | 2573 | @ <h1>Most recent threads</h1> |
| | @@ -2573,11 +2590,15 @@ |
| 2573 | 2590 | @ %z(href("%R/forum?x=%d&n=%d",iOfst+iLimit,iLimit))\ |
| 2574 | 2591 | @ ↓ Older...</a></td></tr> |
| 2575 | 2592 | fossil_free(zAge); |
| 2576 | 2593 | break; |
| 2577 | 2594 | } |
| 2578 | | - @ <tr%s(bPinned ? " class='pinned'" : "")><td>%h(zAge) ago</td> |
| 2595 | + @ <tr%s(bPinned ? " class='pinned'" : "") |
| 2596 | + if( bHasStatus ){ |
| 2597 | + @ data-status="%h(zStatus)"\ |
| 2598 | + } |
| 2599 | + @ ><td>%h(zAge) ago</td> |
| 2579 | 2600 | @ <td class='subject'>%z(href("%R/forumpost/%S",zUuid))%h(zTitle)</a>\ |
| 2580 | 2601 | @ </td><td>\ |
| 2581 | 2602 | if( g.perm.ModForum && moderation_pending(db_column_int(&q,5)) ){ |
| 2582 | 2603 | @ <span class="modpending">\ |
| 2583 | 2604 | @ Awaiting Moderator Approval</span><br> |
| | @@ -2588,12 +2609,12 @@ |
| 2588 | 2609 | char *zDuration = human_readable_age(db_column_double(&q,1)); |
| 2589 | 2610 | @ %d(nMsg) posts spanning %h(zDuration)\ |
| 2590 | 2611 | fossil_free(zDuration); |
| 2591 | 2612 | } |
| 2592 | 2613 | @ </td>\ |
| 2593 | | - if( zStatus ){ |
| 2594 | | - @ <td>%h(zStatus)</td>\ |
| 2614 | + if( bHasStatus ){ |
| 2615 | + @ <td class='status'>%h(zStatusLbl)</td>\ |
| 2595 | 2616 | } |
| 2596 | 2617 | @</tr> |
| 2597 | 2618 | fossil_free(zAge); |
| 2598 | 2619 | } |
| 2599 | 2620 | db_finalize(&q); |
| 2600 | 2621 | |