Skip to content

Instantly share code, notes, and snippets.

@jun66j5
Created August 10, 2011 13:28
Show Gist options
  • Save jun66j5/1136796 to your computer and use it in GitHub Desktop.
Save jun66j5/1136796 to your computer and use it in GitHub Desktop.
SELECT
CASE tt.status WHEN 'closed' THEN 5 WHEN 'new' THEN 3 ELSE 1 END AS __color__,
(CASE tt.status
WHEN 'closed' THEN 'color: #777; background: #ddd; border-color: #ccc;'
ELSE
(CASE tt.owner WHEN $USER THEN 'font-weight: bold' END)
END) AS __style__,
tt.milestone AS __group__,
t.id AS id,
'' AS 'ストーリー',
tt.id AS ticket,
tt.summary AS 'タスク',
tt.owner AS '担当者',
tt.status AS '状態',
CASE WHEN st.child IS NULL THEN peh.value ELSE eh.value END AS '見積',
CASE WHEN st.child IS NULL THEN pth.value ELSE th.value END AS '作業時間',
'' AS description,
tt.id AS _id
FROM ticket t
LEFT JOIN subtickets st ON st.parent =t.id AND t.type='ストーリー'
LEFT JOIN ticket tt ON tt.id=st.child
LEFT JOIN milestone m ON t.milestone = m.name
LEFT JOIN ticket_custom eh ON eh.ticket = tt.id AND eh.name = 'estimatedhours'
LEFT JOIN ticket_custom th ON th.ticket = tt.id AND th.name = 'totalhours'
LEFT JOIN ticket_custom peh ON peh.ticket = t.id AND peh.name = 'estimatedhours'
LEFT JOIN ticket_custom pth ON pth.ticket = t.id AND pth.name = 'totalhours'
WHERE t.type='ストーリー' AND st.child IS NOT NULL AND t.status <> 'closed'
UNION
SELECT
4 AS __color__,
'color: black; font-weight: bold;' AS __style__,
t.milestone AS __group__,
t.id AS id,
t.summary AS 'ストーリー',
'',
'',
'',
'',
'',
'',
'[/newticket?type=タスク&parents='||t.id||'&milestone='||t.milestone||' タスク作成]' AS description,
t.id AS _id
FROM ticket t
WHERE t.type='ストーリー' AND t.status<>'closed'
UNION
SELECT
CASE t.status WHEN 'closed' THEN 5 WHEN 'new' THEN 3 ELSE 1 END AS __color__,
(CASE t.status
WHEN 'closed' THEN 'color: #777; background: #ddd; border-color: #ccc;'
ELSE
(CASE t.owner WHEN $USER THEN 'font-weight: bold' END)
END) AS __style__,
t.milestone AS __group__,
'-' AS id,
'その他:' ||t.type AS 'ストーリー',
t.id AS ticket,
t.summary as 'タスク',
t.owner AS '担当者',
t.status AS '状態',
eh.value AS '見積',
th.value AS '作業時間',
'',
NULL AS _id
FROM ticket as t
LEFT JOIN ticket_custom eh ON eh.ticket = t.id AND eh.name = 'estimatedhours'
LEFT JOIN ticket_custom th ON th.ticket = t.id AND th.name = 'totalhours'
WHERE NOT t.type IN ('ストーリー') AND
NOT EXISTS (SELECT * from subtickets WHERE subtickets.child = t.id)
ORDER BY __group__ DESC, id, ticket DESC
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment