<!--                                                                  -->
<!--  Copyright (C) 2006 RoyaltyShare, Inc.   All Rights Reserved     -->
<!--                                                                  -->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

<xsl:include href="/app/tools/support/templates/job_queue/queue_util.xsl" />

	<xsl:template match="Root">
		<xsl:call-template name="jobsFinishedSection" />
	</xsl:template>

	<xsl:template name="jobsFinishedSection">
		<xsl:variable name="jobsFinished" select="JobQueue/Jobs[EndDate != '0000-00-00 00:00:00']" />
        <xsl:variable name="totalJobCount" select="QueuedJobCount" />
        <xsl:variable name="displayJobCount" select="/Root/JobQueue/Jobs/@size" />
		<fieldset>
			<legend>Completed</legend>
			<xsl:choose>
				<xsl:when test="$jobsFinished">
                    <p class="emptyMessage">(Displaying last <xsl:value-of select="$displayJobCount" /> matching completed jobs)</p>
					<table class="textChart">
						<tr>
							<th>Job ID</th>
							<th>Host</th>
							<th>Client</th>
							<th>Class</th>
							<th>Subclass</th>
							<th class="right">Run ID</th>
							<th>Start Date</th>
							<th>End Date</th>
							<th class="right">
								Duration <img src="/production/images/icons/16x16/info.gif" title="HH:MM:SS" alt="HH:MM:SS" />
							</th>
							<th>Exit Code</th>
						</tr>
						<xsl:for-each select="$jobsFinished">
							<xsl:sort select="EndDate" order="descending" />
							<xsl:call-template name="jobFinishedRow" />
						</xsl:for-each>
					</table>
				</xsl:when>
				<xsl:otherwise>
					<p class="emptyMessage">No jobs have been completed in the selected time frame.</p>
					<br />
				</xsl:otherwise>
			</xsl:choose>
		</fieldset>
		<br />
	</xsl:template>

	<xsl:template name="jobFinishedRow">
		<tr>
			<xsl:attribute name="class">
				row<xsl:value-of select="position() mod 2" />
				<xsl:if test="normalize-space(ExitCode) and ExitCode != 0"> error</xsl:if>
			</xsl:attribute>
			<td>
              <xsl:call-template name="jobDetailLink">
                <xsl:with-param name="job_id" select = "JobID" />
			  </xsl:call-template>
            </td>
			<td><xsl:value-of select="RunHostName" /></td>
            <td>
				<xsl:call-template name="clientIDToName">
					<xsl:with-param name="clientID" select="ClientID" />
				</xsl:call-template>
            </td>
			<td><xsl:value-of select="Class" /></td>
			<td><xsl:value-of select="Subclass" /></td>
			<td class="right"><xsl:value-of select="RunID" /></td>
			<td>
				<xsl:attribute name="title">Queued <xsl:value-of select="QueueDate" /></xsl:attribute>
				<xsl:value-of select="StartDate" />
			</td>
			<td><xsl:value-of select="EndDate" /></td>
			<td class="right">
				<xsl:value-of select="Duration" />
			</td>
			<td>
				<xsl:choose>
					<xsl:when test="normalize-space(ExitCode)">
						<xsl:value-of select="ExitCode" />
					</xsl:when>
					<xsl:otherwise>Aborted</xsl:otherwise>
				</xsl:choose>
			</td>
		</tr>
	</xsl:template>

</xsl:stylesheet>
