From ebb5a26fedf4aa30cfd38f6575054a020ea82467 Mon Sep 17 00:00:00 2001 From: Bryan Larsen Date: Mon, 3 Jun 2013 16:38:23 +0200 Subject: [PATCH] add-task-summary-to-user-page ## Add a task summary to the user's home page Now that each task provides links to the assigned users, the user's page is not looking great. Rapid has rendered cards for the task-assignments but there's no meaningful content in them. What we'd like to see there is a list of all the tasks the user has been assigned to. Having them grouped by story would be helpful too. To achieve this we want to create a custom template for `users/show`. If you look in `app/views/users` you'll see that it's empty. When a page template is missing, Hobo tries to fall back on a defined tag. For a 'show' page, that tag is ``. The Rapid library provides a definition of ``, so that's what we're seeing at the moment. As soon as we create `app/views/users/show.dryml`, that file will take over from the generic `` tag. Try creating that file and just throw "Hello!" in there for now. You should see that the user's show page now displays just "Hello!" and has lost all of the page styling. If you now edit `show.dryml` to read "``" you'll see we're back where we started. The `` tag is just being called explicitly instead of by convention. Rapid has generated a custom definition of ``. You can find this in `app/views/taglibs/auto/rapid/pages.dryml`. Don't edit this file! Your changes will be overwritten. Instead use this file as a reference so you can see what the page provides, and what parameters there are (the `param` attributes). You'll see:
{: .dryml} That means you can change that part of the page entirely, like this: Hello! {: .dryml} Edit show.dryml to look like that. The "Hello!" message is back, but now it's embedded in the properly marked-up page. Now let's get the content we're after - the user's assigned tasks, grouped by story. It's only five lines of markup: SHOW_PATCH Again - lots of new stuff there. Let's quickly run over what's going on * The `` tag is a handy little gadget. It outputs "Your" if the context is the current user, otherwise it outputs the user's name. You'll see "Your Assigned Tasks" when looking at yourself, and "Fred's Assigned Tasks" when looking at Fred. * We're using `` again, but this time we're setting the context to the result of a Ruby expression (`with="&...expr..."`). The expression `@user.tasks.group_by(&:story)` gives us the grouped tasks. * We're repeating on a hash this time. Inside the repeat `this` (the implicit context) will be an array of tasks, and `this_key` will be the story. So `` gives us a link to the story. * `` is used to render a collection of anything in a `