
Bonus exercise
Need more practice? Here are a few more things you can implement to make this app better.
Attendees
(Use git checkout 10.bonus1
to catch up with the class)
Open up lib/fawkes_web/templates/talk/show.html.eex
. Scroll down to line 55 where it shows the list of attendees. Note that all these attendees are fake. In this exercise, you will retreive the users who added this talk to their agendas.
- Open up
lib/fawkes/agenda/agenda.ex
. Add a function to retrieve the user given a talk id. Preload the user profile. - Open up
lib/fawkes_web/controller/talk_controller.ex
, in thedef show(conn, %{"id" => id})
function, call agenda to retrieve the users. Add that to the render function. - Open up
lib/fawkes_web/templates/talk/show.html.eex
, change the for loop to get the user<%= for user <- @users do %>
. Add a wrapper around the image to only show it if there is a profile. Then change the hardcode image to the user image. Add a wrapper around the github and twitter handle to only show it if there is a profile. Here is the result from the for loop.
<%= for user <- @users do %>
<div class="card col-sm-3">
<div class="card-body">
<%= if user.profile do %>
<img src="<%= Fawkes.Uploader.Image.url({user.profile.image, user.profile}) %>" class="rounded-circle">
<% end %>
<i class="fas fa-check-circle attendee__check"></i>
<h4><%= user.username %></h4>
<%= if user.profile do %>
<div class="speaker__handle">
<i class="fab fa-github"></i> <%= user.profile.github %>
</div>
<div class="speaker__handle">
<i class="fab fa-twitter"></i> <%= user.profile.twitter %>
</div>
<% end %>
</div>
</div>
<% end %>
See the answer on Github
Agenda by day
(Use git checkout 10.bonus2
to catch up with the class)
In this exercise we’ll filter the talks by the day. Notice if you click on any of the date, it hits schedule_slots
with the date param (http://localhost:4000/schedule_slots?date=2018-09-07).
- Open
lib/fawkes_web/controller/slot_controller.ex
, edit theindex
function to pass the params date toSchedule.list_schedule_slots
. Open uplib/fawkes/schedule/schedule.ex
, change thelist_schedule_slots
function to take in a date. Parse the date, get the beginning of the day and end of the day. Then filter to return the slot within the given time frame. Here is some code to help you with the parsing.
parsed_date = Timex.parse!(date, "%Y-%m-%d", :strftime)
beginning_of_day = Timex.beginning_of_day(parsed_date)
end_of_day = Timex.end_of_day(parsed_date)
See the answer on Github