From 47f5c77e1abf7f979f885be45a1f2fea2ffcdacf Mon Sep 17 00:00:00 2001 From: maxwell Date: Mon, 26 Jul 2010 15:09:02 -0700 Subject: [PATCH] kinda prettied up the albums page --- app/controllers/albums_controller.rb | 2 +- app/helpers/albums_helper.rb | 26 ++++++++++++++++++++++++++ app/models/album.rb | 8 ++++++++ app/views/albums/_album.html.haml | 5 +++++ app/views/albums/index.html.haml | 10 +++++++--- 5 files changed, 47 insertions(+), 4 deletions(-) create mode 100644 app/helpers/albums_helper.rb diff --git a/app/controllers/albums_controller.rb b/app/controllers/albums_controller.rb index 716bcd002..7b4ed0a6d 100644 --- a/app/controllers/albums_controller.rb +++ b/app/controllers/albums_controller.rb @@ -2,7 +2,7 @@ class AlbumsController < ApplicationController before_filter :authenticate_user! def index - @albums = Album.paginate :page => params[:page], :order => 'created_at DESC' + @albums = Album.mine_or_friends(params[:friends], current_user).paginate :page => params[:page], :order => 'created_at DESC' end def create diff --git a/app/helpers/albums_helper.rb b/app/helpers/albums_helper.rb new file mode 100644 index 000000000..a21735e45 --- /dev/null +++ b/app/helpers/albums_helper.rb @@ -0,0 +1,26 @@ +module AlbumsHelper + def friends_albums_link + if params[:friends] + "friends albums" + else + link_to 'friends albums', albums_path({:friends => true}) + end + end + + def your_albums_link + if params[:friends] + link_to 'your albums', albums_path + else + 'your albums' + end + end + + def album_person(album) + person = album.person + if album.person_id == current_user.id + link_to "you", user_path(current_user) + else + link_to person.real_name, person_path(person) + end + end +end \ No newline at end of file diff --git a/app/models/album.rb b/app/models/album.rb index 1307cfd2c..14aa95778 100644 --- a/app/models/album.rb +++ b/app/models/album.rb @@ -20,6 +20,14 @@ class Album after_save :notify_people before_destroy :propagate_retraction + def self.mine_or_friends(friend_param, current_user) + if friend_param + Album.where(:person_id.ne => current_user.id) + else + Album.where(:person_id => current_user.id) + end + end + def prev_photo(photo) n_photo = self.photos.where(:created_at.lt => photo.created_at).sort(:created_at.desc).first n_photo ? n_photo : self.photos.sort(:created_at.desc).first diff --git a/app/views/albums/_album.html.haml b/app/views/albums/_album.html.haml index e30c4b4c6..0043c0fd6 100644 --- a/app/views/albums/_album.html.haml +++ b/app/views/albums/_album.html.haml @@ -2,8 +2,13 @@ %div.name = link_to post.name, object_path(post) + %div.time + by: + = album_person(post) + %br = link_to(how_long_ago(post), object_path(post)) + %div.image_cycle - for photo in post.photos = image_tag photo.image.url(:thumb_large) diff --git a/app/views/albums/index.html.haml b/app/views/albums/index.html.haml index 47f11bd0b..ee4cd4c09 100644 --- a/app/views/albums/index.html.haml +++ b/app/views/albums/index.html.haml @@ -1,7 +1,9 @@ -%h1.big_text albums +%h1.big_text + = friends_albums_link + \/ + =your_albums_link + %span= link_to ' + ', new_album_path -%h3 - = link_to "make a new album", new_album_path %ul#stream - for album in @albums @@ -9,3 +11,5 @@ #pagination = will_paginate @albums +%h3 + = link_to "make a new album", new_album_path unless params[:friends]