Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
SharePoint 2010 Project Tasks list dashbaord
<?xml version="1.0" encoding="UTF-8"?>
<!--
Date: 03-Oct-2014
Purpose: Show project plans in customized way to be presented on dashboard
-->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0"
xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime">
<xsl:include href="/_layouts/xsl/main.xsl"/>
<xsl:variable name="nbsp" select="'&amp;nbsp;'" />
<xsl:variable name="apos">&apos;</xsl:variable>
<xsl:template match="/">
<!-- store rows in variable -->
<xsl:variable name="Rows" select="/dsQueryResponse/Rows/Row" />
<!-- count number of plans -->
<xsl:variable name="totalPlans" select="count($Rows)"/>
<xsl:choose>
<!-- show no message if not plans -->
<xsl:when test="$totalPlans = 0">
<xsl:call-template name="noplans"/>
</xsl:when>
<!-- show plans -->
<xsl:otherwise>
<!-- output required css and javascript -->
<xsl:call-template name="style"/>
<xsl:call-template name="js"/>
<xsl:call-template name="overallCompletion">
<xsl:with-param name="Rows" select="$Rows"></xsl:with-param>
</xsl:call-template>
<xsl:call-template name="showPlans">
<xsl:with-param name="Rows" select="$Rows"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!-- Show overall completion -->
<xsl:template name="overallCompletion">
<xsl:param name="Rows"/>
<!-- total no of tasks -->
<xsl:variable name="totalTasks" select='count($Rows)'/>
<!-- sum of tasks completion -->
<xsl:variable name="sumComplete" select="sum($Rows[@PercentComplete != '']/@PercentComplete.)"/>
<xsl:variable name="complete" select="format-number(($sumComplete div $totalTasks) * 100,'00')"></xsl:variable>
<xsl:variable name="completeFormatted" select="concat($complete,'%')"></xsl:variable>
<h1>
Project Completion: <xsl:value-of select="$completeFormatted"/>
<xsl:value-of disable-output-escaping="yes" select="$nbsp"/>
<span style='height:20px;' class='pgbar'>
<span style="border:0;height:20px; width:{$completeFormatted}" class='scale'>
</span>
</span>
</h1>
</xsl:template>
<!-- Show plans -->
<xsl:template name="showPlans">
<xsl:param name="Rows"/>
<!-- output header -->
<table class="plandb">
<thead>
<tr>
<th class="left">Title</th>
<th>Start Date</th>
<th>Due Date</th>
<th>Completion</th>
</tr>
</thead>
<!-- output each plan -->
<xsl:for-each select="$Rows">
<tr>
<td><xsl:call-template name="titleLinked"/></td>
<td><xsl:value-of select="@StartDate"/></td>
<td><xsl:value-of select="@DueDate"/></td>
<td>
<xsl:if test="@PercentComplete != ''">
<table>
<tr>
<td>
<xsl:value-of select="@PercentComplete"/>
</td>
<td>
<span class='pgbar'>
<span style="width:{translate(@PercentComplete,' ' , '')}" class='scale'>
</span>
</span>
</td>
</tr>
</table>
</xsl:if>
</td>
</tr>
</xsl:for-each>
<!-- output footer -->
</table>
</xsl:template>
<!-- No plans message -->
<xsl:template name="noplans">
<p>No plans yet!</p>
</xsl:template>
<xsl:template name="style">
<style>
.plandb .right{
text-align:right;
}
.plandb th, .plandb td{
padding:0.5em;
padding-right:0.8em;
text-align:left;
}
.plandb th{
border-top:solid 2px #d9d9d9;
border-bottom:solid 2px #d9d9d9
}
.plandb td{
border-bottom:solid 1px #D9D9D9;
}
.plandb table td{
border:0;
}
.pgbar, .pgbar .scale{
height:15px;
display:inline-block;
}
.pgbar{
border:solid 1px #173677;
width:200px;
}
.pgbar .scale{
background-color:#3A71B4
}
</style>
</xsl:template>
<xsl:template name="titleLinked">
<xsl:variable name="itemurl" select="concat($FORM_DISPLAY,'&amp;ID=',@ID)"/>
<a href="{$itemurl}">
<xsl:attribute name="onclick">
<xsl:value-of select="concat('javascript:xslHelper_2502aee57bb3450c81bf121948fd8dd7(', $apos, $itemurl, $apos,');return false;')"/>
</xsl:attribute>
<xsl:value-of select="@Title"/>
</a>
</xsl:template>
<xsl:template name="js">
<script type="text/javascript">
function xslHelper_2502aee57bb3450c81bf121948fd8dd7(url) {
var options = {
url: url,
dialogReturnValueCallback: referesh
}
function referesh() {
document.forms[0].submit();
}
SP.UI.ModalDialog.showModalDialog(options);
}
</script>
</xsl:template>
</xsl:stylesheet>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment