comparison bug-list.xsl @ 5:d2efec56373f

working buglist transform and bugs fetching
author cin
date Tue, 01 Sep 2015 19:47:30 +0300
parents f8f966388b68
children 2a5f38eb25a9
comparison
equal deleted inserted replaced
4:f8f966388b68 5:d2efec56373f
2 <xsl:stylesheet version="1.0" 2 <xsl:stylesheet version="1.0"
3 xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:exsl="http://exslt.org/common" 3 xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:exsl="http://exslt.org/common"
4 extension-element-prefixes="exsl"> 4 extension-element-prefixes="exsl">
5 <xsl:output method="text" indent="yes" /> 5 <xsl:output method="text" indent="yes" />
6 6
7 <!-- PARAMETERS -->
8
9 <!-- chargeset - название аккаунта, на который вести расходы -->
10 <xsl:param name="chargeset" />
11
12 <!-- root_task_id - id корневой задачи, в которую будут организованы все
13 задачи -->
14 <xsl:param name="root_task_id" />
15
16 <!-- root_task - описание корневой задачи -->
17 <xsl:param name="root_task" />
18
19 <!-- GLOBAL VARIABLES -->
7 <xsl:variable name="resources" 20 <xsl:variable name="resources"
8 select="document('resources.xml')/resources/resource" /> 21 select="document('resources.xml')/resources/resource" />
9 22
10 <xsl:variable name="bugs" select="/bugzilla/bug" /> 23 <xsl:variable name="bugs" select="/bugzilla/bug" />
11 24
20 33
21 <xsl:template match="bug" mode="tree"> 34 <xsl:template match="bug" mode="tree">
22 <xsl:element name="bug"> 35 <xsl:element name="bug">
23 <xsl:attribute name="id"><xsl:value-of select="bug_id" /></xsl:attribute> 36 <xsl:attribute name="id"><xsl:value-of select="bug_id" /></xsl:attribute>
24 <xsl:if test="component = 'product' or not(number(estimated_time))"> 37 <xsl:if test="component = 'product' or not(number(estimated_time))">
25 <xsl:attribute name="product"><xsl:value-of select="boolean(1)" /></xsl:attribute> 38 <xsl:attribute name="group"><xsl:value-of select="boolean(1)" /></xsl:attribute>
26 </xsl:if> 39 </xsl:if>
27 <xsl:for-each select="dependson"> 40 <xsl:for-each select="dependson">
28 <xsl:apply-templates mode="tree" select="key('bugid', .)" /> 41 <xsl:apply-templates mode="tree" select="key('bugid', .)" />
29 </xsl:for-each> 42 </xsl:for-each>
30 </xsl:element> 43 </xsl:element>
46 59
47 <xsl:template match="bug" mode="traverse-relations"> 60 <xsl:template match="bug" mode="traverse-relations">
48 <xsl:variable name="bugid" select="@id" /> 61 <xsl:variable name="bugid" select="@id" />
49 <xsl:variable name="path" select="ancestor::bug" /> 62 <xsl:variable name="path" select="ancestor::bug" />
50 <xsl:variable name="level" select="count($path)" /> 63 <xsl:variable name="level" select="count($path)" />
51 <xsl:for-each select="$path[@product]"> 64 <xsl:for-each select="$path[@group]">
52 <xsl:variable name="pos" select="position()" /> 65 <xsl:variable name="pos" select="position()" />
53 <xsl:variable name="rank" select="$level - $pos" /> 66 <xsl:variable name="rank" select="$level - $pos" />
54 <rel container="{@id}" rank="{$rank}" level="{$level}"> 67 <rel container="{@id}" rank="{$rank}" level="{$level}">
55 <xsl:for-each select="$path[position() >= $pos and @product]"> 68 <xsl:for-each select="$path[position() >= $pos and @group]">
56 <bug id="{@id}" /> 69 <bug id="{@id}" />
57 </xsl:for-each> 70 </xsl:for-each>
58 </rel> 71 </rel>
59 </xsl:for-each> 72 </xsl:for-each>
60 </xsl:template> 73 </xsl:template>
72 <bug id="{@id}" parent="{$parent/@container}" rank="{$parent/@rank}" 85 <bug id="{@id}" parent="{$parent/@container}" rank="{$parent/@rank}"
73 level="{$parent/@level}" /> 86 level="{$parent/@level}" />
74 </xsl:template> 87 </xsl:template>
75 88
76 <xsl:variable name="structure"> 89 <xsl:variable name="structure">
77 <xsl:apply-templates select="$roots" mode="structure" /> 90 <xsl:choose>
91 <xsl:when test="$root_task">
92 <bug id="_root" desc="{$root_task}" group="true">
93 <xsl:apply-templates select="$roots" mode="structure"/>
94 </bug>
95 </xsl:when>
96 <xsl:otherwise>
97 <xsl:apply-templates select="$roots" mode="structure"/>
98 </xsl:otherwise>
99 </xsl:choose>
78 </xsl:variable> 100 </xsl:variable>
79 101
80 <xsl:template match="bug" mode="structure"> 102 <xsl:template match="bug" mode="structure">
81 <xsl:variable name="id" select="string(bug_id)" /> 103 <xsl:variable name="id" select="string(bug_id)" />
82 <xsl:variable name="self" select="." /> 104 <xsl:variable name="self" select="." />
83 <bug id="{$id}"> 105 <xsl:variable name="children"
84 <xsl:for-each select="exsl:node-set($parents)/bug[@parent = $id]"> 106 select="exsl:node-set($parents)/bug[@parent = $id]" />
85 <xsl:variable name="child" select="@id" /> 107 <xsl:element name="bug">
86 <xsl:apply-templates select="$bugs[bug_id = $child]" 108 <xsl:attribute name="id"><xsl:value-of select="$id" /></xsl:attribute>
87 mode="structure" /> 109 <xsl:attribute name="desc"><xsl:value-of select="short_desc" /></xsl:attribute>
88 </xsl:for-each> 110
111 <xsl:if test="$children">
112 <xsl:attribute name="group"><xsl:value-of select="boolean($children)" /></xsl:attribute>
113
114 <xsl:for-each select="$children">
115 <xsl:variable name="child" select="@id" />
116 <xsl:apply-templates select="$bugs[bug_id = $child]"
117 mode="structure" />
118 </xsl:for-each>
119
120 </xsl:if>
121
122 <!-- filter out dependencies -->
89 <xsl:variable name="dependencies" 123 <xsl:variable name="dependencies"
90 select="dependson[not(text() = exsl:node-set($parents)/bug[@parent = $id]/@id)]" /> 124 select="dependson[not(text() = exsl:node-set($parents)/bug[@parent = $id]/@id)]" />
91 <xsl:if test="$dependencies"> 125 <xsl:for-each select="$dependencies">
92 <depends> 126 <dependency id="{.}" />
93 <xsl:for-each select="$dependencies"> 127 </xsl:for-each>
94 <bug id="{.}" /> 128 </xsl:element>
95 </xsl:for-each>
96 </depends>
97 </xsl:if>
98 </bug>
99 </xsl:template> 129 </xsl:template>
100 130
101 <!-- output --> 131 <!-- output -->
102 <xsl:template match="/"> 132 <xsl:template match="/">
103 <xsl:apply-templates select="exsl:node-set($structure)/bug"> 133 <xsl:apply-templates select="exsl:node-set($structure)/bug">
104 <xsl:with-param name="indent" select="0" /> 134 <xsl:with-param name="indent" select="0" />
135 <xsl:with-param name="chargeset" select="$chargeset"/>
105 </xsl:apply-templates> 136 </xsl:apply-templates>
106 </xsl:template> 137 </xsl:template>
107 138
108 <xsl:template match="bug"> 139 <xsl:template match="bug">
109 <xsl:param name="indent" select="0" /> 140 <xsl:param name="indent" select="0" />
141 <xsl:param name="chargeset" />
110 <xsl:variable name="id" select="@id" /> 142 <xsl:variable name="id" select="@id" />
111 <xsl:variable name="details" select="$bugs[bug_id = $id]" /> 143 <xsl:variable name="details" select="$bugs[bug_id = $id]" />
144
145 <!-- task header -->
112 <xsl:call-template name="start-task"> 146 <xsl:call-template name="start-task">
113 <xsl:with-param name="indent" select="$indent" /> 147 <xsl:with-param name="indent" select="$indent" />
114 <xsl:with-param name="id" select="@id" /> 148 <xsl:with-param name="id">
115 <xsl:with-param name="desc" select="$details/short_desc" /> 149 <xsl:call-template name="bug-local-name">
116 </xsl:call-template> 150 <xsl:with-param name="id" select="@id" />
117 151 </xsl:call-template>
118 <xsl:for-each select="$details/*"> 152 </xsl:with-param>
119 <xsl:variable name="directive"> 153 <xsl:with-param name="desc" select="@desc" />
120 <xsl:apply-templates select="." mode="task-details" /> 154 </xsl:call-template>
121 </xsl:variable> 155
122 <xsl:if test="string($directive)"> 156 <xsl:if test="$chargeset">
123 <xsl:call-template name="begin-line"> 157 <xsl:call-template name="println">
158 <xsl:with-param name="indent" select="$indent + 1"/>
159 <xsl:with-param name="text" select="concat('chargeset ', $chargeset)"/>
160 </xsl:call-template>
161 </xsl:if>
162
163 <!-- task details -->
164 <xsl:choose>
165 <xsl:when test="@group">
166 <!-- DEBUG -->
167 <xsl:call-template name="comment">
124 <xsl:with-param name="indent" select="$indent + 1" /> 168 <xsl:with-param name="indent" select="$indent + 1" />
169 <xsl:with-param name="comment" select="'group'" />
125 </xsl:call-template> 170 </xsl:call-template>
126 <xsl:value-of select="$directive" /> 171
127 <xsl:call-template name="end-line" /> 172
128 </xsl:if> 173 <xsl:apply-templates select="$details/node()"
129 </xsl:for-each> 174 mode="group-details">
130 175 <xsl:with-param name="indent" select="$indent + 1" />
176 </xsl:apply-templates>
177
178 <xsl:if
179 test="number($details/estimated_time) or number($details/actual_time) or number($details/remaining_time)">
180 <xsl:call-template name="start-task">
181 <xsl:with-param name="indent" select="$indent + 1" />
182 <xsl:with-param name="id" select="'manage'" />
183 <xsl:with-param name="desc" select="@desc" />
184 </xsl:call-template>
185 <xsl:apply-templates
186 select="$details/estimated_time | $details/actual_time | $details/remaining_time | $details/assigned_to"
187 mode="task-details">
188 <xsl:with-param name="indent" select="$indent + 2" />
189 </xsl:apply-templates>
190 <xsl:call-template name="end-task">
191 <xsl:with-param name="indent" select="$indent + 1" />
192 </xsl:call-template>
193 </xsl:if>
194 </xsl:when>
195 <xsl:otherwise>
196 <xsl:apply-templates select="$details/node()"
197 mode="task-details">
198 <xsl:with-param name="indent" select="$indent + 1" />
199 </xsl:apply-templates>
200 </xsl:otherwise>
201 </xsl:choose>
202
203 <!-- subtasks and dependencies -->
131 <xsl:apply-templates> 204 <xsl:apply-templates>
132 <xsl:with-param name="indent" select="$indent + 1" /> 205 <xsl:with-param name="indent" select="$indent + 1" />
206 <xsl:with-param name="referer" select="." />
133 </xsl:apply-templates> 207 </xsl:apply-templates>
134 208
135 <xsl:call-template name="end-task"> 209 <xsl:call-template name="end-task">
136 <xsl:with-param name="indent" select="$indent" /> 210 <xsl:with-param name="indent" select="$indent" />
137 </xsl:call-template> 211 </xsl:call-template>
138 </xsl:template> 212 </xsl:template>
139 213
214 <xsl:template match="dependency">
215 <xsl:param name="indent" />
216 <xsl:param name="referer" />
217 <xsl:call-template name="println">
218 <xsl:with-param name="indent" select="$indent" />
219 <xsl:with-param name="text">
220 <xsl:text>depends </xsl:text>
221 <xsl:call-template name="bug-reference">
222 <xsl:with-param name="id" select="@id" />
223 <xsl:with-param name="referer" select="$referer" />
224 </xsl:call-template>
225 </xsl:with-param>
226 </xsl:call-template>
227 </xsl:template>
228
229
230 <xsl:template match="text()" />
231
232 <!-- TASK ATTRIBUTES -->
233
140 <xsl:template match="estimated_time" mode="task-details"> 234 <xsl:template match="estimated_time" mode="task-details">
235 <xsl:param name="indent" />
141 <xsl:if test="number(.)"> 236 <xsl:if test="number(.)">
142 <xsl:value-of select="concat('effort ', .,'h')" /> 237 <xsl:call-template name="println">
238 <xsl:with-param name="indent" select="$indent" />
239 <xsl:with-param name="text" select="concat('effort ', .,'h')" />
240 </xsl:call-template>
143 </xsl:if> 241 </xsl:if>
144 </xsl:template> 242 </xsl:template>
145 243
146 <xsl:template match="assigned_to" mode="task-details"> 244 <xsl:template match="assigned_to" mode="task-details">
245 <xsl:param name="indent" />
147 <xsl:variable name="email" select="string(.)" /> 246 <xsl:variable name="email" select="string(.)" />
148 <xsl:variable name="resource" select="$resources[@email = $email]/@id" /> 247 <xsl:variable name="resource" select="$resources[@email = $email]/@id" />
149 <xsl:if test="$resource"> 248 <xsl:if test="$resource">
150 <xsl:value-of select="concat('allocate ', $resource)" /> 249 <xsl:call-template name="println">
250 <xsl:with-param name="indent" select="$indent" />
251 <xsl:with-param name="text" select="concat('allocate ', $resource)" />
252 </xsl:call-template>
151 </xsl:if> 253 </xsl:if>
152 </xsl:template> 254 </xsl:template>
153 <xsl:template match="text()" mode="task-details"> 255 <xsl:template match="text()" mode="task-details">
154 </xsl:template> 256 </xsl:template>
155 257
156 <xsl:template match="depends"> 258 <xsl:template match="assigned_to" mode="group-details">
157 <xsl:param name="indent" select="0" /> 259 <xsl:param name="indent" />
158 <xsl:call-template name="begin-line"> 260 <xsl:variable name="email" select="string(.)" />
159 <xsl:with-param name="indent" select="$indent" /> 261 <xsl:variable name="resource" select="$resources[@email = $email]/@id" />
160 </xsl:call-template> 262 <xsl:if test="$resource">
161 <xsl:text>depends </xsl:text> 263 <xsl:call-template name="println">
162 <xsl:apply-templates> 264 <xsl:with-param name="indent" select="$indent" />
163 <xsl:with-param name="referer" select=".." /> 265 <xsl:with-param name="text"
164 </xsl:apply-templates> 266 select="concat('responsible ', $resource)" />
165 <xsl:call-template name="end-line" /> 267 </xsl:call-template>
166 </xsl:template> 268 </xsl:if>
167 269 </xsl:template>
168 <xsl:template match="depends/bug"> 270 <xsl:template match="text()" mode="group-details">
169 <xsl:param name="referer" /> 271 </xsl:template>
170 <xsl:call-template name="bug-reference"> 272
171 <xsl:with-param name="id" select="@id" /> 273 <!-- PRIMITIVES -->
172 <xsl:with-param name="referer" select="$referer" />
173 </xsl:call-template>
174 <xsl:if test="position() != last()">
175 <xsl:text>, </xsl:text>
176 </xsl:if>
177 </xsl:template>
178
179
180 <xsl:template match="text()" />
181 274
182 275
183 276
184 <xsl:template name="bug-local-name"> 277 <xsl:template name="bug-local-name">
185 <xsl:param name="id" /> 278 <xsl:param name="id" />
198 </xsl:for-each> 291 </xsl:for-each>
199 </xsl:variable> 292 </xsl:variable>
200 <xsl:variable name="targetPathFragment"> 293 <xsl:variable name="targetPathFragment">
201 <bug id="#root" /> 294 <bug id="#root" />
202 <xsl:for-each 295 <xsl:for-each
203 select="exsl:node-set($structure)//bug[local-name(..) != 'depends' and @id = $id]/ancestor-or-self::bug"> 296 select="exsl:node-set($structure)//bug[@id = $id]/ancestor-or-self::bug">
204 <bug id="{@id}" /> 297 <bug id="{@id}" />
205 </xsl:for-each> 298 </xsl:for-each>
206 </xsl:variable> 299 </xsl:variable>
207 <xsl:variable name="path" 300 <xsl:variable name="path"
208 select="exsl:node-set($refererPathFragment)/bug" /> 301 select="exsl:node-set($refererPathFragment)/bug" />
248 <xsl:param name="desc" /> 341 <xsl:param name="desc" />
249 <xsl:call-template name="begin-line"> 342 <xsl:call-template name="begin-line">
250 <xsl:with-param name="indent" select="$indent" /> 343 <xsl:with-param name="indent" select="$indent" />
251 </xsl:call-template> 344 </xsl:call-template>
252 <xsl:text>task </xsl:text> 345 <xsl:text>task </xsl:text>
253 <xsl:call-template name="bug-local-name"> 346 <xsl:value-of select="$id" />
254 <xsl:with-param name="id" select="$id" />
255 </xsl:call-template>
256 <xsl:value-of select="concat(' &quot;',$desc,'&quot; {')" /> 347 <xsl:value-of select="concat(' &quot;',$desc,'&quot; {')" />
257 <xsl:call-template name="end-line" /> 348 <xsl:call-template name="end-line" />
258 </xsl:template> 349 </xsl:template>
259 350
260 <xsl:template name="end-task"> 351 <xsl:template name="end-task">
273 <xsl:call-template name="begin-line"> 364 <xsl:call-template name="begin-line">
274 <xsl:with-param name="indent" select="$indent - 1" /> 365 <xsl:with-param name="indent" select="$indent - 1" />
275 </xsl:call-template> 366 </xsl:call-template>
276 </xsl:if> 367 </xsl:if>
277 </xsl:template> 368 </xsl:template>
369
278 <xsl:template name="end-line"> 370 <xsl:template name="end-line">
279 <xsl:text>&#xa;</xsl:text> 371 <xsl:text>&#xa;</xsl:text>
280 </xsl:template> 372 </xsl:template>
281 373
282 <xsl:template name="repeat"> 374 <xsl:template name="repeat">
289 <xsl:with-param name="value" select="$value" /> 381 <xsl:with-param name="value" select="$value" />
290 <xsl:with-param name="count" select="$count - 1" /> 382 <xsl:with-param name="count" select="$count - 1" />
291 </xsl:call-template> 383 </xsl:call-template>
292 </xsl:if> 384 </xsl:if>
293 </xsl:template> 385 </xsl:template>
386
387 <xsl:template name="comment">
388 <xsl:param name="indent" />
389 <xsl:param name="comment" />
390 <xsl:call-template name="println">
391 <xsl:with-param name="indent" select="$indent" />
392 <xsl:with-param name="text">
393 <xsl:text># </xsl:text>
394 <xsl:value-of select="$comment" />
395 </xsl:with-param>
396 </xsl:call-template>
397 </xsl:template>
398
399 <xsl:template name="println">
400 <xsl:param name="indent" />
401 <xsl:param name="text" />
402 <xsl:call-template name="begin-line">
403 <xsl:with-param name="indent" select="$indent" />
404 </xsl:call-template>
405 <xsl:value-of select="$text" />
406 <xsl:call-template name="end-line" />
407 </xsl:template>
294 </xsl:stylesheet> 408 </xsl:stylesheet>