Saturday, February 9, 2008

DvdFriend - User Review Page

In the other blog, Chris requested a page that shows all of the reviews he has written. I estimated it would take 14 seconds. It took 50 minutes to build and deploy.

Example: http://www.dvdfriend.us/UserReviews.aspx?un=DVDFriend

1 - Create a page Called UserReviews.aspx. It uses the normal site master page. Loaded this page into the browser passing it ?un=DvdFriend. The page loaded without any content.

2 - Created a stored procedure called DFGetUserBlogs(@userName). There's an existing view, DFvwBlogEntries, that already has all of the information I need. The stored procedure queries some fields for that where UserName=@userName

3 - Expose the query as a method in one of the business objects. There's an existing class called BlogFactory that has lots of similar methods. I created the new method:


public static DataTable GetUserBlogs(string userName)
{
const string STORED_PROCEDURE = "DFGetUserBlogs";
return AWDatabase.GetReadonly().ExecuteDataSet(STORED_PROCEDURE, userName).Tables[0];
}

4 - Added an object data source to the new page. Pointed it to the new method. Added a query string parameter for un.

5 - Added a datagrid to the page. Wired it up to the object data source. Loaded the page.. it's good!

6 - Tweaked the grid. Shut off AUTO GENERATE COLUMNS, then added the fields in the order I wanted. Formatted the date field.

7 - Added the SortExpression for each of the columns.

8 - Added a server-side H1 to the page. Assigned its value from the UserName property, which returns the value of Request.Querystring["un"];

9 - Changed Default.aspx and P.aspx: converted the USERNAME display fields to hyperlinks for the new page.

10 - Tested

11 - Deployed

Using out-of-the-box asp.net controls, and a little custom code, I was able to create this page pretty quick, but there's a lot more that can be done.

The page is a dump of everything the user has. Currently, DVFriend is the worse-case-scenario, wich isn't so bad. Once the list reaches a certain unknown size, it will be time to add paging.

Adding paging is easy enough; just have to enable it in the grid. However, the problem is that even if you're only showing one page of data, it would still query for all of the rows. I wouldn't be able to sleep if I did that (other than as, maybe, a transitional step).

I had a problem with the sort description. I set the Rating column to Rating,ProductName. I thought that would work, but it didn't. It always sorted by rating ASC. DESC wouldn't work, so I took off product name for now. The sorts will have to be revisited.

Other TO DOs
- I'd also like to add a summary grid and some filters on the top. IE: Pick a particular rating, and or date range; and/or reviews only. The summary would show how many ratings and reviews the user has, how long they have been active, etc.

- Show a list of other users on the right side so you can browser all reviews from all users. As long as the active user list is short, that will work... i can drop it in quick. Once the site conquers the world and the list is bigger, it won't hold.

- Put the grid in an asp.net update panel. I would've done this to begin with if I thought of it at the time.

So, the asp.net controls are pretty powerful; quick and easy. I'm not a huge fan of the final result, though. Its super quick and easy, but each SORT operation is a post back. I'd rather use the querystring so that you can bookmark the page and get back to it in the same state you left it. As is, you can bookmark it, but it will go to its original state.

Prior to asp.net, I created a ton of reports in JTS that needed this functionality. It was all done by adding attributes to the html tags, and javascript would create the new url and request it. In the end, I ended up with one generic ASP page and a bunch of XLSTs and data sources. To sort, you'd add a SORT="" attribute to the corresponding TH. There'd be some notation for asc, desc, etc (I forget the details). That worked out pretty well.

2 comments:

Mike said...

One thing...how do i get to the page from the home page?

Jay Allard said...

The AUTHOR name is now a hyperlink. That's new.

Also, if you click a product, you get a list of all of the existing reviews and the authors. The authors there are links too.