Skip to content

Instantly share code, notes, and snippets.

@tota
Created October 21, 2011 14:47
Show Gist options
  • Save tota/1304025 to your computer and use it in GitHub Desktop.
Save tota/1304025 to your computer and use it in GitHub Desktop.
patch to display owner's name at gantt chart on Trac Lightning
ganttcalendar/templates/gantt.html | 20 +++++++++++---------
ganttcalendar/ticketgantt.py | 14 ++++++++------
2 files changed, 19 insertions(+), 15 deletions(-)
diff --git a/ganttcalendar/templates/gantt.html b/ganttcalendar/templates/gantt.html
index a4c6c02..3c5ced8 100644
--- a/ganttcalendar/templates/gantt.html
+++ b/ganttcalendar/templates/gantt.html
@@ -2,7 +2,7 @@
xmlns:py="http://genshi.edgewall.org/"
xmlns:i18n="http://genshi.edgewall.org/i18n"
xmlns:xi="http://www.w3.org/2001/XInclude"
- py:with="px_ti=30;px_hd=46;px_dw=36/zoom;px_ch=10;maxtic=len(tickets);px_left=3;px_top=13;px_height=px_top+px_ch;">
+ py:with="px_ti=25+ti_mrgn;px_hd=46;px_dw=36/zoom;px_ch=10;maxtic=len(tickets);px_left=3;px_top=13;px_height=px_top+px_ch;">
<xi:include href="layout.html" />
<xi:include href="macros.html" />
<head>
@@ -46,7 +46,7 @@
.bdy {position: absolute;background-color: #fff;text-align: left;top:${px_hd}px;height:${maxtic*px_ti+px_height}px;}
.bdy_elem {position: absolute;font-size: 10px;left:1px;height:${px_ti-2}px;}
.tic_summary {position: absolute;font-size: 10px;color: #000; background-color: #fff; height: 11px; line-height: 11px; white-space:nowrap;}
- .stripe {position: absolute; overflow: hidden; background: #e8f0f8;}
+ .stripe {position: absolute; overflow: hidden; background: #f7f7f7;}
.tip {position: static;}
.tip span.popup{position: absolute;visibility: hidden;background-color: #ffe;color: black;border: 1px solid #555;left: 20px;top: 30px;padding: 3px;
/*IE6 Hack*/ min-width: 400px; width: auto; _width: 400px;
@@ -283,7 +283,7 @@
<!-- gantt -->
<div style="position:relative;left:1px;top:1px;width:100%;height:${maxtic*px_ti+px_hd+1+40+px_height}px;">
<!-- right side -->
- <div style="overflow:auto;margin-left:384px;margin-right:4px;position:relative;left:0px;top:1px;height:${maxtic*px_ti+px_hd+1+30+px_height}px;">
+ <div style="overflow:auto;margin-left:331px;margin-right:4px;position:relative;left:0px;top:1px;height:${maxtic*px_ti+px_hd+1+30+px_height}px;">
<div class="border_line" style="left:0px;top:1px;width:${px_dw*days_term+1}px;height:${maxtic*px_ti+px_hd+1+px_height}px;">
<!-- head and sun,sta,holiday -->
<div class="bdy" style="position:relative;left:1px;top:${px_hd}px;width:${px_dw*days_term-1}px;height:${maxtic*px_ti+px_height}px;"/>
@@ -337,7 +337,7 @@
</a>
</div>
<div py:if="show_ticket_status == 'on'" py:attrs="{'title':tic_tip}" py:choose="" class="tic_summary" style="left:${int(e*px_dw)+5}px;top:${px_ti*cnt+px_hd+(px_ti-px_ch)/2+(ti_mrgn/2-1)+px_top}px;">
- ${t['status']}<span py:when="t['status']!='closed'"> ${t['complete']}%</span><span py:otherwise="">: ${t['resolution']}</span><span py:if="t['estimatedhours']!=None"> ${t['totalhours']}h</span> ${t['owner']}
+ ${t['status']}<span py:when="t['status']!='closed'"> ${t['complete']}%</span><span py:otherwise="">: ${t['resolution']}</span><span py:if="t['estimatedhours']!=None"> ${t['totalhours']}h</span>
</div>
</py:with>
</py:if>
@@ -367,13 +367,14 @@
</div>
</div>
<!-- left side -->
- <div style="position:absolute;background-color:gray;left:1px;top:1px;width:380px;height:${maxtic*px_ti+px_hd+1+px_height}px;">
+ <div style="position:absolute;background-color:gray;left:1px;top:1px;width:327px;height:${maxtic*px_ti+px_hd+1+px_height}px;">
<div py:choose="" class="hdr" style="left:1px;top:1px;width: 89px;height:${px_hd-2}px;">
<span class="hdr_title" style="top:${(px_hd-2-16)/2}px;font-size:12px;">
<span py:when="sorted_field=='milestone'">${_('Milestone')}</span><span py:otherwise="">${_('Component')}</span>
</span>
</div>
- <div class="hdr" style="left:91px;top:1px;width:288px;height:${px_hd-2}px;"><span class="hdr_title" style="top:${(px_hd-2-16)/2}px;font-size:12px;">${_('Ticket')}</span></div>
+ <div class="hdr" style="left:91px;top:1px;width:104px;height:${px_hd-2}px;"><span class="hdr_title" style="top:${(px_hd-2-16)/2}px;font-size:12px;">${_('Ticket')}</span></div>
+ <div class="hdr" style="left:196px;top:1px;width:130px;height:${px_hd-2}px;"><span class="hdr_title" style="top:${(px_hd-2-16)/2}px;font-size:12px;">${_('Owner')}</span></div>
<py:def function="print_field(px_x,px_w,ticket_col,dupchk=False)">
<div class="bdy" style="left:${px_x}px;width:${px_w}px;">
@@ -384,10 +385,10 @@
<div class="stripe" style="top: ${cnt*px_ti+px_top}px;width: ${px_w}px; height: ${px_ti}px;"></div>
</py:if>
<div class="bdy_elem" style="top: ${cnt*px_ti+px_top}px;left: ${px_left-1}px;width: ${px_w-2}px;">
- <a class="tip" href="${req.href.ticket()}/${t['id']}">${t['type']} <s py:strip="t['status']!='closed'">#${t['id']}</s>: ${t['summary'][0:32]}<span py:if="len(t['summary'])>32">...</span>
+ <a class="tip" href="${req.href.ticket()}/${t['id']}"><s py:strip="t['status']!='closed'">#${t['id']}</s>:${t['summary'][0:14]}<span py:if="len(t['summary'])>14">...</span>
<span class="popup">
<br/>
- <s py:strip="t['status']!='closed'"> ${t['type']} #${t['id']}</s>: ${t['summary']}<br/>
+ <s py:strip="t['status']!='closed'"> ${t['type']}#${t['id']}</s>: ${t['summary']}<br/>
<br/>
<strong>${_('Start date')}</strong>:
${t['due_assign'].strftime(dateFormat)}
@@ -442,7 +443,8 @@
</div>
</py:def>
- ${print_field( 91,288,'ticket')}
+ ${print_field( 196,130,'owner')}
+ ${print_field( 91,104,'ticket')}
${print_field( 1, 89,sorted_field,dupchk=True)}
</div>
diff --git a/ganttcalendar/ticketgantt.py b/ganttcalendar/ticketgantt.py
index 00bcfc1..3a24fd5 100644
--- a/ganttcalendar/ticketgantt.py
+++ b/ganttcalendar/ticketgantt.py
@@ -13,6 +13,7 @@ from trac.ticket.api import TicketSystem
#from trac.util.translation import _
from trac.config import IntOption, BoolOption, Option
from trac import __version__
+from trac.util.compat import any
from trac.util.translation import domain_functions
@@ -203,7 +204,7 @@ class TicketGanttChartPlugin(Component):
show_ticket_status = req.args.get('show_ticket_status')
ts = TicketSystem(self.env)
- if not 'complete' in ts.get_custom_fields():
+ if not any(f['name'] == 'complete' for f in ts.get_custom_fields()):
add_warning(req, _("'complete' field is not defined. Please define it."))
normal_mode = req.args.get('normal')
current_mode = req.args.get('zoom')
@@ -237,7 +238,7 @@ class TicketGanttChartPlugin(Component):
show_ticket_summary = None
if show_ticket_summary:
- ticket_margin = 12
+ ticket_margin = 5
else:
ticket_margin = 0
@@ -503,11 +504,12 @@ class TicketGanttChartPlugin(Component):
if clauses:
condition = "WHERE " + (" OR ".join('(%s)' % c for c in clauses))
- sql = ("SELECT id, type, summary, owner, t.description, status, resolution, priority, a.value, c.value, cmp.value, est.value, tot.value, milestone, component "
+ sql = ("SELECT id, type, summary, (CASE owner WHEN 'somebody' THEN '未割当' ELSE sa.value END), t.description, status, resolution, priority, a.value, c.value, cmp.value, est.value, tot.value, milestone, component "
"FROM ticket t "
- "JOIN ticket_custom a ON a.ticket = t.id AND a.name = 'due_assign' "
- "JOIN ticket_custom c ON c.ticket = t.id AND c.name = 'due_close' "
- "JOIN ticket_custom cmp ON cmp.ticket = t.id AND cmp.name = 'complete' "
+ "LEFT OUTER JOIN session_attribute sa ON sa.sid = owner AND sa.name = 'name' "
+ "LEFT OUTER JOIN ticket_custom a ON a.ticket = t.id AND a.name = 'due_assign' "
+ "LEFT OUTER JOIN ticket_custom c ON c.ticket = t.id AND c.name = 'due_close' "
+ "LEFT OUTER JOIN ticket_custom cmp ON cmp.ticket = t.id AND cmp.name = 'complete' "
"LEFT OUTER JOIN ticket_custom est ON est.ticket = t.id AND est.name = 'estimatedhours' "
"LEFT OUTER JOIN ticket_custom tot ON tot.ticket = t.id AND tot.name = 'totalhours' "
"%s %s ORDER by %s , a.value ") % (custom_join, condition, sorted_field)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment