Friday, May 15, 2009

Customizing the ASP.NET Issue Tracker

Microsoft's Issue Tracker (part of the ASP.NET Starter Kit package) is old code. But it's free, it works, it runs on IIS6, and it's open source. I probably could have gone with something fancier.

Anyways, right away I noticed that there were a number of usability tweaks that could be made to make the application quite a bit easier to use. Here's a good example...

When you create a new event, by default, the "Owned By" combo box is empty. To me, that doesn't make sense. The majority of the time the owner will also be the... creator! So why not just set the value to the current user automatically when a new event is being created?

If you look inside ~/Issues/IssueDetail.aspx you'll see that the type of control for choosing the Owner is . All of the data bound controls within Issue Tracker are regular Web Forms controls, wrapped in a custom UserControl. By default not all of the properties are exposed, so we'll need to first expose the list items collection by adding this code to ~/UserControls/PickSingleUser.aspx.cs

public ListItemCollection Items
{
get { return dropUsers.Items; }
}

Now that we can access the list items, let's write the code to actually find and select the user.

The most logical place to handle this is on the Page_Load event of ~/Issues/IssueDetail.aspx.cs There's already an if/then handler for if the item is new or not.

if (IssueId == 0)
{
BindOptions();
ctlCustomFields.DataSource = CustomField.GetCustomFieldsByProjectId(ProjectId);
}
else
{
BindValues();
ctlCustomFields.DataSource = CustomField.GetCustomFieldsByIssueId(IssueId);
}

Here's what we need to do: Get the current user's full name, find that name in the databound dropOwned list items, and then select that item.

Issue Tracker already includes a user manager type object built in, ITUser. We can pass it the current page's identity and get the user from the user database.

ITUser user = ITUser.GetUserByUsername(Page.User.Identity.Name);

From there, all we need to do is identify that user in the list item collection, and select it.
foreach (ListItem li in dropOwned.Items)
if (li.Text == user.DisplayName)
{
li.Selected = true;
break;
}
The current user should not automatically be selected as the Owner default when a new issue is created.

The complete code listing should look like this:
// Initialize for Adding or Editing
if (IssueId == 0)
{
BindOptions();
ctlCustomFields.DataSource = CustomField.GetCustomFieldsByProjectId(ProjectId);

// Choose defaults
ITUser user = ITUser.GetUserByUsername(Page.User.Identity.Name);
foreach (ListItem li in dropOwned.Items)
if (li.Text == user.DisplayName)
{
li.Selected = true;
break;
}

}
else
{
BindValues();
ctlCustomFields.DataSource = CustomField.GetCustomFieldsByIssueId(IssueId);
}

0 comments:

  © Blogger template 'Minimalist G' by Ourblogtemplates.com 2008

Back to TOP