root/tracunreadplugin/0.11/trac7_with_unread.sql

Revision 3534, 1.4 kB (checked in by vnaum, 1 week ago)

Initial import

Line 
1 -- My Tickets (with read / unread marks)
2 -- This is basically same as report:7, but with "unread" column
3 -- Of course, you must be logged in to use it (just like report:7).
4
5 SELECT p.value AS __color__,
6    (CASE status WHEN 'assigned' THEN 'Assigned' ELSE 'Owned' END) AS __group__,
7    t.id AS ticket, summary, component,
8    priority, time AS _created,
9    changetime AS modified,
10    reporter AS _reporter
11    , CASE
12     WHEN u.last_read_on IS NULL OR u.last_read_on < t.time
13     THEN '[ticket:' || t.id || ' new ticket]'
14     WHEN u.last_read_on > t.changetime
15     THEN 'no unread'
16     ELSE '[comment:ticket:' || t.id || ':' || (
17         -- fetch unread comment number
18         SELECT
19           CASE
20             -- Thanks for recording parent.child relationship, guys!
21             WHEN position('.' in oldvalue) != 0 THEN split_part(oldvalue, '.', 2)
22             ELSE oldvalue
23           END
24         FROM ticket_change tc
25         WHERE field = 'comment'
26           AND ticket = t.id
27           AND time > u.last_read_on
28         ORDER BY time
29         LIMIT 1
30       ) || ' unread comment]'
31     END
32     AS description
33
34   FROM ticket t
35   LEFT JOIN enum p ON p.name = t.priority AND p.type = 'priority'
36   LEFT JOIN trac_unread u ON (u.id=t.id
37     AND u.type = 'ticket'
38     AND u.username = '$USER'
39   )
40   WHERE t.status IN ('new', 'assigned', 'reopened') AND owner = '$USER'
41   ORDER BY (status = 'assigned') DESC, CAST(p.value AS integer), milestone, t.type, time
Note: See TracBrowser for help on using the browser.