Silver Arrow Systems

DWP: Project Progress Bars

Get a dynamically-updating collapsible display of your team's tasks sorted by project and resource with this web part. It utilizes three custom lists, with the help of lookup columns to link the data together - all you need to do is set up the necessary lists and columns, then enter the relevant names into the DWP Builder. You can also (optionally) filter projects by a priority indicator.
SharePoint 2007 and 2013 support coming soon.
<div id="CEWP_ProgressBars_Wrapper" style="font-family: 'Times New Roman'; color: #000000;">Please wait, projects are loading...</div>
<script type="text/javascript">
//Global declarations
var resources = [],
projects = [],
allresources = [],
groups = [],
attempts = 3,
done = false,
listnames = {
resources: "Resources",
projects: "Projects",
tasks: "Tasks"
},
columns = {
resource_name: "Title",
project_name: "Title",
project_progress: "Progress",
project_resource: "Resource",
project_priority: "Priority",
task_name: "Title",
task_progress: "Progress",
task_project: "Project"
},
priorityfilter = 1;

function toggleGroupFct(b){var a=document.getElementById("expandbutton-"+b).innerHTML==="+";if(a){document.getElementById("expandbutton-"+b).innerHTML="-";document.getElementById("bar-group-"+b).style.display="block"}else{document.getElementById("expandbutton-"+b).innerHTML="+";document.getElementById("bar-group-"+b).style.display="none"}}function barDefaultsFct(a){a.caption=a.caption||"";a.progress=a.progress||"100";a.showpercentage=a.showpercentage||true;a.width=a.width||"500";a.border=a.border||"2px solid #000000";a.padding=a.padding||"0";a.open=a.open||false;a.bgcolor=a.bgcolor||"#FFFFFF";a.fgcolor=a.fgcolor||"#000000";a.textcolor=a.textcolor||"#FFFFFF";a.indent=a.indent||"10";a.fontsize=a.fontsize||"20";if(a.bracket!==false){a.bracket=a.bracket||"5"}return a}function generateBarFct(a,d){var c="";if(d){c+="<div class='bar-caption' style='font-size: "+a.fontsize+"px; margin-top: 5px; cursor: pointer;' onclick='toggleGroupFct(\""+d+"\")'>";c+="<span class='expandbutton' id='expandbutton-"+d+"' style='font-family: monospace;'>";if(a.open){c+="-"}else{c+="+"}c+="</span>"}else{c+="<div class='bar-caption' style='font-size: "+a.fontsize+"px; margin-top: 5px;'>"}c+="<span class='bar-name'>&nbsp;"+a.caption+"</span>";c+="<span class='bar-percentage' style='font-weight: bold;'>&nbsp;("+a.progress+"%)</span>";c+="</div>";c+="<div class='bar-background' style='width: "+a.width+"px; background-color: "+a.bgcolor+"; padding: "+a.padding+"px; margin-bottom: 2px; margin-left: "+a.indent+"px; border: "+a.border+";'>";c+="<div class='bar-foreground' style='width: "+a.progress+"%; background-color: "+a.fgcolor+"; color: "+a.textcolor+"; font-size: "+a.fontsize+"px; padding: 3px 0px;'></div>";c+="</div>";return c}function leftBracketFct(a){var b="";b+=" border-left: 2px solid #000000;";b+=" -webkit-border-top-left-radius: "+a+"px;";b+=" -webkit-border-bottom-left-radius: "+a+"px;";b+=" -moz-border-radius-topleft: "+a+"px;";b+=" -moz-border-radius-bottomleft: "+a+"px;";b+=" border-top-left-radius: "+a+"px;";b+=" border-bottom-left-radius: "+a+"px;";return b}function writeHTMLFct(){var d="",h,l,b,a,c;for(var g=0;g<groups.length;g++){l=barDefaultsFct(groups[g]);projects=l.projects;d+="<div class='group' id='group-"+g+"' style='font-size: "+l.fontsize+"px; font-weight: bold;'>";if(l.projects.length>0){d+="<div class='group-caption' style='cursor: pointer;' onclick='toggleGroupFct(\""+g+"\")'>";d+="<span class='expandbutton' id='expandbutton-"+g+"' style='font-family: monospace;'>";if(l.open){d+="-"}else{d+="+"}d+="</span>";d+="<span class='group-name'>&nbsp;"+l.caption+"</span>";d+="</div>"}else{d+="<div class='group-caption'>";d+="<span class='group-name' style='padding-left: 0.85em;'>"+l.caption+" (no projects)</span>";d+="</div>"}if(l.projects.length>0){if(l.open){d+="<div class='bar-group' id='bar-group-"+g+"' style='margin-top: -10px; margin-left: "+l.indent+"px;'>"}else{d+="<div class='bar-group' id='bar-group-"+g+"' style='margin-top: -10px; margin-left: "+l.indent+"px; display: none;'>"}for(var f=0;f<l.projects.length;f++){h=barDefaultsFct(l.projects[f]);b=g+"-"+f;d+=generateBarFct(h,b);h.indent=parseInt(h.indent,10)*1.5;if(h.bracket){a=leftBracketFct(h.bracket)}else{a=""}if(h.open){d+="<div class='bar-group' id='bar-group-"+b+"' style='margin-top: -5px; margin-left: "+h.indent+"px;"+a+"'>"}else{d+="<div class='bar-group' id='bar-group-"+b+"' style='margin-top: -5px; margin-left: "+h.indent+"px; display: none;"+a+"'>"}for(var e=0;e<h.tasks.length;e++){c=barDefaultsFct(h.tasks[e]);if(h.bracket){c.width=parseInt(c.width,10)-h.indent-2}else{c.width=parseInt(c.width,10)-h.indent}d+=generateBarFct(c)}d+="</div>"}d+="</div>"}d+="</div>"}document.getElementById("CEWP_ProgressBars_Wrapper").innerHTML=d;console.log("Completed project progress bars web part.")}function getListFct(f,g){var d=new SP.ClientContext.get_current(),e=d.get_web().get_lists(),a=new SP.CamlQuery(),b,c;if(priorityfilter!==-1&&f===listnames.projects){a.set_viewXml("<View><Query><Where><Eq><FieldRef Name='"+columns.project_priority+"'/><Value Type='Number'>"+priorityfilter+"</Value></Eq></Where></Query></View>")}c=e.getByTitle(f).getItems(a);d.load(c);d.executeQueryAsync(Function.createDelegate(this,function(i,h){b=c.getEnumerator();while(b.moveNext()){g(b.get_current())}g(false)}),Function.createDelegate(this,function(i,h){if(attempts!==0){document.getElementById("CEWP_ProgressBars_Wrapper").innerHTML="Loading is taking a little longer than usual...";console.error("Project progress bars web part list query failed. The error was:\n"+h.get_message()+"\nThe stack trace (if any) was:\n"+h.get_stackTrace());attempts-=1;if(attempts===0){console.debug("Error is still present. Giving up.")}else{console.debug("Trying to reload the web part in 5 ms. Giving up after "+attempts+" more tries.")}setTimeout(function(){getListFct(listnames.resources,getResourcesFct)},5)}else{if(h.get_message()==="Access denied. You do not have permission to perform this action or access this resource."){console.debug("It appears that you're getting an insufficient permission error. This is a known bug - the only fix right now is to refresh your page.");document.getElementById("CEWP_ProgressBars_Wrapper").innerHTML="Sorry, something went wrong with your browser. Try refreshing your page to fix it."}else{console.debug("There seems to be a permanent error with the web part. Check to make sure you're actually running on a SharePoint site and your list name is right.")}}}))}function percent(a){return(parseFloat(a,10)*100)+""}function getResourcesFct(a){if(!a){getListFct(listnames.projects,getProjectsFct);return false}resources[a.get_item(columns.resource_name)]=[];allresources.push(a.get_item(columns.resource_name))}function getProjectsFct(a){var b;if(!a){getListFct(listnames.tasks,getTasksFct);return false}b=a.get_item(columns.project_resource).get_lookupValue();if(resources[b]){resources[b].push(a.get_item(columns.project_name));projects[a.get_item(columns.project_name)]={caption:a.get_item(columns.project_name),progress:percent(a.get_item(columns.project_progress)),tasks:[]}}}function getTasksFct(b){var a;if(!b){assembleDataFct();return false}a=b.get_item(columns.task_project).get_lookupValue();if(projects[a]){projects[a].tasks.push({caption:b.get_item(columns.task_name),progress:percent(b.get_item(columns.task_progress))})}}function assembleDataFct(){var c,e,d;for(var b=0;b<allresources.length;b++){c=allresources[b];d={caption:c,projects:[]};for(var a=0;a<resources[c].length;a++){e=projects[resources[c][a]];d.projects.push(e)}groups.push(d)}writeHTMLFct()}document.getElementById("CEWP_ProgressBars_Wrapper").innerHTML="Please wait, projects are loading...";setTimeout(function(){console.log("Initiated project progress bars web part.");SP.SOD.executeFunc("sp.js","SP.ClientContext",function(){done=true;console.log("Processing project progress bars web part.");getListFct(listnames.resources,getResourcesFct)});setTimeout(function(){SP.SOD.executeFunc("sp.js","SP.ClientContext",function(){if(!done){console.log("Reprocessing project progress bars web part.");document.getElementById("CEWP_ProgressBars_Wrapper").innerHTML="Loading is taking a little longer than usual...";getListFct(listnames.resources,getResourcesFct)}})},2000)},1);
</script>

<!-- Progress Bar Web Part v4.3.0 -->
<!-- All code copyright © 2013 Silver Arrow Systems. All rights reserved. -->
<!-- Usage and redistribution of this web part is restricted to individuals with permission expressly granted by Silver Arrow Systems (hereafter referred to as Licensed Users). -->
<!-- Licensed Users may use, modify, and redistribute this web part without any restrictions. -->
<!-- Individuals without permission expressly granted by Silver Arrow Systems (hereafter referred to as Unlicensed Users) may use and redistribute, but not modify this web part. -->
<!-- Unlicensed Users must keep this copyright notice intact in all usages or redistributions of this web part. -->
<!-- No user may hold Silver Arrow Systems responsible for any damages incurred by or because of this web part, its contents, or its usage. -->
<!-- http://www.silverarrowsystems.com -->
How to use this web part:
Setup:
- Create a list for your resources. This needs a column for the resource name.
- Create a list for your projects. This needs columns for the project name and the project progress (a number column displayed as a percentage).
- Create a lookup column in your projects list, pointed at the resource name column in your resources list.
- Create a list for your tasks. This needs columns for the task name and the task progress (a number column displayed as a percentage).
- Create a lookup column in your tasks list, pointed at the project name column in your projects list.
- OPTIONAL: Create a priority column in your projects list. This needs to be a number column, but can hold any values you want.
Install options:
- Copy and paste this code, then save as a .dwp file (file will use default options).
- Download as a .dwp file (file will use default options).
- NEW! Use our custom DWP builder to set all your own options.
Don't know how to install a DWP?
Check out our tutorial for SharePoint 2010 (SharePoint 2007 and 2013 tutorials coming soon.)
X

Silver Arrow Systems Custom DWP Builder

Step 1: Set your options. All fields are required unless otherwise noted.

Step 2: Click the button.

Generate custom DWP
All fields are required unless otherwise noted.

Step 3: Copy and paste this text, then save as a .dwp file.