finished user functionality, added favourite artists

This commit is contained in:
Thomas Buchöster
2011-06-30 06:38:27 +02:00
parent e6974e61fa
commit 09b44f0e6e
26 changed files with 175 additions and 134 deletions
+5 -2
View File
@@ -5,10 +5,13 @@ tmp/
Icon* Icon*
.DS_Store .DS_Store
dump.rdb
Thumbs.db Thumbs.db
/config/config.yml /config/config.yml
/config/sevendigital.yml
/public/images_old/ /public/images_old/
/public/.sass-cache/ /public/.sass-cache/
/public/media/
/public/assets/
/public/cache/
+11 -9
View File
@@ -40,10 +40,11 @@ GEM
bcrypt-ruby (2.1.4) bcrypt-ruby (2.1.4)
bcrypt-ruby (2.1.4-x86-mingw32) bcrypt-ruby (2.1.4-x86-mingw32)
builder (2.1.2) builder (2.1.2)
closure (1.2.701) closure (1.3.0)
rack (>= 1.0.0) rack (>= 1.0.0)
cocaine (0.1.0)
daemons (1.0.10) daemons (1.0.10)
devise (1.3.4) devise (1.4.0)
bcrypt-ruby (~> 2.1.2) bcrypt-ruby (~> 2.1.2)
orm_adapter (~> 0.0.3) orm_adapter (~> 0.0.3)
warden (~> 1.0.3) warden (~> 1.0.3)
@@ -64,10 +65,10 @@ GEM
i18n (0.6.0) i18n (0.6.0)
jammit (0.6.3) jammit (0.6.3)
yui-compressor (>= 0.9.3) yui-compressor (>= 0.9.3)
jquery-rails (1.0.9) jquery-rails (1.0.12)
railties (~> 3.0) railties (~> 3.0)
thor (~> 0.14) thor (~> 0.14)
json (1.5.1) json (1.5.3)
mail (2.2.19) mail (2.2.19)
activesupport (>= 2.3.6) activesupport (>= 2.3.6)
i18n (>= 0.4.0) i18n (>= 0.4.0)
@@ -94,15 +95,16 @@ GEM
oa-core (= 0.2.6) oa-core (= 0.2.6)
rack-openid (~> 1.3.1) rack-openid (~> 1.3.1)
ruby-openid-apps-discovery (~> 1.2.0) ruby-openid-apps-discovery (~> 1.2.0)
oauth (0.4.4) oauth (0.4.5)
oauth2 (0.4.1) oauth2 (0.4.1)
faraday (~> 0.6.1) faraday (~> 0.6.1)
multi_json (>= 0.0.5) multi_json (>= 0.0.5)
open4 (1.0.1) open4 (1.1.0)
orm_adapter (0.0.5) orm_adapter (0.0.5)
paperclip (2.3.11) paperclip (2.3.12)
activerecord (>= 2.3.0) activerecord (>= 2.3.0)
activesupport (>= 2.3.2) activesupport (>= 2.3.2)
cocaine (>= 0.0.2)
peachy (0.4.1) peachy (0.4.1)
polyglot (0.3.1) polyglot (0.3.1)
rack (1.2.3) rack (1.2.3)
@@ -135,7 +137,7 @@ GEM
ruby-openid (>= 2.1.7) ruby-openid (>= 2.1.7)
ruby_parser (2.0.6) ruby_parser (2.0.6)
sexp_processor (~> 3.0) sexp_processor (~> 3.0)
sass (3.1.2) sass (3.1.3)
sexp_processor (3.0.5) sexp_processor (3.0.5)
sqlite3 (1.3.3) sqlite3 (1.3.3)
sqlite3 (1.3.3-x86-mingw32) sqlite3 (1.3.3-x86-mingw32)
@@ -147,7 +149,7 @@ GEM
typhoeus (0.2.4) typhoeus (0.2.4)
mime-types mime-types
mime-types mime-types
tzinfo (0.3.27) tzinfo (0.3.29)
warden (1.0.4) warden (1.0.4)
rack (>= 1.0) rack (>= 1.0)
will_paginate (2.3.15) will_paginate (2.3.15)
+19 -1
View File
@@ -2,4 +2,22 @@
protect_from_forgery protect_from_forgery
before_filter { |c| @youtube_client = YouTubeIt::Client.new(:dev_key=>"AI39si600H1fRQ6HW1pHG89e-23Uxf44YHu5TsCJMhNf5hFaYWSSSyyrOIEcOX451sFeh_OZdbbA48_g6OInfTv042-Id163tg") } before_filter { |c| @youtube_client = YouTubeIt::Client.new(:dev_key=>"AI39si600H1fRQ6HW1pHG89e-23Uxf44YHu5TsCJMhNf5hFaYWSSSyyrOIEcOX451sFeh_OZdbbA48_g6OInfTv042-Id163tg") }
end
def async_redirect_to path
redirect_to "/#!" + path
end
def validate_img_url image, type, size
@attr = (type=="gallery") ? "name" : "size"
image.each do |img|
if img[@attr] == size.to_s
if img["#text"].blank?
return "/images/placeholder/#{type.to_s}.png"
end
return img["#text"]
end
end
end
end
+16 -2
View File
@@ -5,7 +5,7 @@ class ArtistsController < ApplicationController
@@limit = { tracks: 10, albums: 4, similar: 6 } @@limit = { tracks: 10, albums: 4, similar: 6 }
def show def show
artist = CGI.unescape params[:artist] artist = CGI.unescape params[:id]
@artist = LastFM::Artist.getInfo artist @artist = LastFM::Artist.getInfo artist
@tracks = LastFM::Artist.getTopTracks artist, @@limit[:tracks] @tracks = LastFM::Artist.getTopTracks artist, @@limit[:tracks]
@@ -44,12 +44,26 @@ class ArtistsController < ApplicationController
end end
def album_info def album_info
@album = LastFM::Album.getInfo CGI.unescape(params[:album]), CGI.unescape(params[:artist]) @album = LastFM::Album.getInfo CGI.unescape(params[:album]), CGI.unescape(params[:id])
LastFM::Request.run_queue! LastFM::Request.run_queue!
render :partial=>"album_info", :locals=>{:album=>@album} render :partial=>"album_info", :locals=>{:album=>@album}
end end
def favourize
puts params.inspect
artist = CGI.unescape params[:id]
@artist = LastFM::Artist.getInfo artist
LastFM::Request.run_queue!
@artist = Artist.new(:name => @artist.name, :img_url => validate_img_url(@artist.image, "artist", :extralarge))
unless current_user.artists.include? @artist
current_user.artists << @artist if @artist.save
end
render :nothing => true
end
private
def prepare params def prepare params
params[:q] = CGI.unescape params[:q] params[:q] = CGI.unescape params[:q]
params[:size] = params[:size].to_i params[:size] = params[:size].to_i
@@ -10,6 +10,13 @@ class DeviseAuth::SessionsController < Devise::SessionsController
resource = warden.authenticate!(:scope => resource_name, :recall => "#{controller_path}#new") resource = warden.authenticate!(:scope => resource_name, :recall => "#{controller_path}#new")
set_flash_message(:notice, :signed_in) if is_navigational_format? set_flash_message(:notice, :signed_in) if is_navigational_format?
sign_in(resource_name, resource) sign_in(resource_name, resource)
redirect_to "/#!/home", :partial => "devise/registrations/new" aysnc_redirect_to new_user_registration_path
end
def destroy
signed_in = signed_in?(resource_name)
Devise.sign_out_all_scopes ? sign_out : sign_out(resource_name)
async_redirect_to charts_path
end end
end end
+2 -2
View File
@@ -1,8 +1,8 @@
class HomeController < ApplicationController class HomeController < ApplicationController
def show def show
@files = Dir.glob("public/images/startsite/*.jpg") @files = Dir.glob("public/images/startsite/*.jpg")
render :partial=>"index" render :partial=>"index", :locals => {:files => @files}
end end
end end
@@ -6,7 +6,8 @@ class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
if @user.persisted? if @user.persisted?
flash[:notice] = I18n.t "devise.omniauth_callbacks.success", :kind => "Facebook" flash[:notice] = I18n.t "devise.omniauth_callbacks.success", :kind => "Facebook"
sign_in_and_redirect @user, :event => :authentication sign_in @user
async_redirect_to user_path(@user)
else else
session["devise.facebook_data"] = env["omniauth.auth"] session["devise.facebook_data"] = env["omniauth.auth"]
redirect_to new_user_registration_url redirect_to new_user_registration_url
@@ -18,7 +19,8 @@ class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
@user = User.find_for_open_id(env["omniauth.auth"], current_user) @user = User.find_for_open_id(env["omniauth.auth"], current_user)
if @user.persisted? if @user.persisted?
flash[:notice] = I18n.t "devise.omniauth_callbacks.success", :kind => "Google" flash[:notice] = I18n.t "devise.omniauth_callbacks.success", :kind => "Google"
sign_in_and_redirect @user, :event => :authentication sign_in @user
async_redirect_to user_path(@user)
else else
session["devise.open:id_data"] = env["openid.ext1"] session["devise.open:id_data"] = env["openid.ext1"]
redirect_to new_user_registration_url redirect_to new_user_registration_url
+8 -2
View File
@@ -1,12 +1,18 @@
class UsersController < ApplicationController class UsersController < ApplicationController
def show def show
@user = User.find params[:user] @user = User.find params[:id]
render :partial => "show", :locals => { :user => @user } render :partial => "show", :locals => { :user => @user }
end end
def edit def edit
@user = User.find params[:user] @user = User.find params[:id]
render :partial => "edit", :locals => { :user => @user } render :partial => "edit", :locals => { :user => @user }
end end
def update
current_user.update_attribute(:avatar, params[:user][:avatar]) if params[:user] and params[:user][:avatar]
current_user.update_attribute(:username, params[:user][:username]) if params[:user] and params[:user][:username]
async_redirect_to user_path(current_user)
end
end end
+7 -3
View File
@@ -24,8 +24,12 @@ module ApplicationHelper
end end
def camelCaseString phrase def camelCaseString phrase
phrase.gsub!(/^[a-z]|\s+[a-z]/) { |a| a.upcase } phrase.gsub!(/^[a-z]|\s+[a-z]/) { |a| a.upcase }
return phrase return phrase
end end
def async_link_to body, path, html_options = {}
link_to body, "/#!" + path, html_options
end
end end
+3 -3
View File
@@ -1,7 +1,7 @@
module UsersHelper module UsersHelper
def validate_avatar_url url def validate_avatar user, size = :original
return url if url.present? and FileTest.exists? url return user.avatar.url(size) if user.avatar?
"examples/user-big.jpg" "examples/user-big.jpg"
end end
+8 -2
View File
@@ -8,8 +8,14 @@ class User < ActiveRecord::Base
# Setup accessible (or protected) attributes for your model # Setup accessible (or protected) attributes for your model
attr_accessible :username, :email, :password, :password_confirmation, :remember_me attr_accessible :username, :email, :password, :password_confirmation, :remember_me
has_attached_file :avatar, :styles => { :original => "200x200>", :thumb => "60x60>" } has_attached_file :avatar,
:styles => {
:original => "200x200#",
:thumb => "60x60#"
},
:url => "/media/avatars/:style/:id_:filename",
:path => ":rails_root/public/media/avatars/:style/:id_:filename"
def self.new_with_session(params, session) def self.new_with_session(params, session)
super.tap do |user| super.tap do |user|
if data = session["devise.facebook_data"] && session["devise.facebook_data"]["extra"]["user_hash"] if data = session["devise.facebook_data"] && session["devise.facebook_data"]["extra"]["user_hash"]
+1 -1
View File
@@ -4,7 +4,7 @@
.tabs_js.information .tabs_js.information
%h1 %h1
= artist.name = artist.name
= link_to "", "#", :class=>"heart" %span.heart
%ul.nav %ul.nav
%li= image_tag "icons/artist-info.png" %li= image_tag "icons/artist-info.png"
%li= image_tag "icons/artist-links.png" %li= image_tag "icons/artist-links.png"
+4 -4
View File
@@ -1,9 +1,9 @@
<%- if controller_name != 'sessions' %> <%- if controller_name != 'sessions' %>
<%= link_to "Sign in", "/#!/login" %><br /> <%= async_link_to "Login", new_user_session_path %><br />
<% end -%> <% end -%>
<%- if devise_mapping.registerable? && controller_name != 'registrations' %> <%- if devise_mapping.registerable? && controller_name != 'registrations' %>
<%= link_to "Sign up", "/#!/register" %><br /> <%= async_link_to "Register", new_user_registration_path %><br />
<% end -%> <% end -%>
<%- if devise_mapping.recoverable? && controller_name != 'passwords' %> <%- if devise_mapping.recoverable? && controller_name != 'passwords' %>
@@ -19,6 +19,6 @@
<% end -%> <% end -%>
<%- if devise_mapping.omniauthable? %> <%- if devise_mapping.omniauthable? %>
<%= link_to "Sign in with Facebook", user_omniauth_authorize_path(:facebook) %><br /> <%= link_to "Login with Facebook", user_omniauth_authorize_path(:facebook) %><br />
<%= link_to "Sign in with Google", user_omniauth_authorize_path(:open_id, :openid_url => 'https://www.google.com/accounts/o8/id') %><br /> <%= link_to "Login with Google", user_omniauth_authorize_path(:open_id, :openid_url => 'https://www.google.com/accounts/o8/id') %><br />
<% end -%> <% end -%>
+1 -1
View File
@@ -1,5 +1,5 @@
%ul#top_artist %ul#top_artist
- for file in @files - for file in files
%li= image_tag "startsite/"+File.basename(file) %li= image_tag "startsite/"+File.basename(file)
%ul#top_artist_nav %ul#top_artist_nav
%li= link_to image_tag("startsite/small/beatles.jpg"),"", :class=>"ll dir" %li= link_to image_tag("startsite/small/beatles.jpg"),"", :class=>"ll dir"
-4
View File
@@ -1,4 +0,0 @@
#white
%br
%br
%br
+5 -6
View File
@@ -16,18 +16,17 @@
#site #site
#uuser{:style=>"display:block; color:#ddd;"} #uuser{:style=>"display:block; color:#ddd;"}
- if user_signed_in? - if user_signed_in?
=link_to "Profile", "/#!/users/#{current_user.id}" =async_link_to "Logout", destroy_user_session_path
=link_to "Logout", "/#!/logout"
- else
=link_to "Login", "/#!/login"
=link_to "Register", "/#!/register"
#head #head
%h1= link_to image_tag("nine-minutes.png"), "/#!/home" %h1= link_to image_tag("nine-minutes.png"), "/#!/home"
= render :partial=>"layouts/player" = render :partial=>"layouts/player"
#navigation #navigation
%li.active= link_to "home", "/#!/home" %li.active= link_to "home", "/#!/home"
%li= link_to "charts", "/#!/charts" %li= link_to "charts", "/#!/charts"
%li= link_to "register", "/#!/register" - if signed_in?
%li= async_link_to "profile", user_path(current_user)
- else
%li= async_link_to "register", new_user_registration_path
%li.search %li.search
= form_tag '/search', :method => 'get', :id => "search_form", :remote=>true do = form_tag '/search', :method => 'get', :id => "search_form", :remote=>true do
= text_field_tag 'q', params[:q], :class => "text", :placeholder => "Search here ..." = text_field_tag 'q', params[:q], :class => "text", :placeholder => "Search here ..."
+7 -12
View File
@@ -1,12 +1,7 @@
#user_left EDIT - Settings
=image_tag validate_avatar_url(user.avatar.url), :class => "picture" = form_for user, :url => {:action=>"update"} do |f|
.information =f.text_field :username
%p{:style=>"display:block; color:#ddd;"} =f.submit "Save"
%h1{:style=>"color:#ddd;"}= current_user.username || current_user.email = form_for user, :url => {:action=>"update"}, :html => {:multipart=>true} do |f|
%br =f.file_field :avatar
=f.submit "Save"
.tabs.tabs_js.w02
%ul.nav
%li profile settings
.content
%div EDIT - bla bla bla
+11 -8
View File
@@ -1,10 +1,7 @@
#user_left #user_left
=image_tag validate_avatar_url(user.avatar.url), :class => "picture" =image_tag validate_avatar(user), :class => "picture"
.information .information
%h1= user.username %h1= user.username || current_user.email
%p{:style=>"display:block; color:#ddd;"}
=link_to "Profil editieren", "/#!/users/#{current_user.id}/edit"
%br
%ul.nav %ul.nav
%li=image_tag "icons/artist-info.png" %li=image_tag "icons/artist-info.png"
%li=image_tag "icons/artist-links.png" %li=image_tag "icons/artist-links.png"
@@ -14,7 +11,13 @@
.tabs.tabs_js.w02 .tabs.tabs_js.w02
%ul.nav %ul.nav
%li profile %li profile
%li playlist - if user == current_user
%li settings
.content .content
%div SONGS %div
%div ALBUMS - user.artists.each do |artist|
%p
=artist.name
=image_tag artist.img_url
- if user == current_user
%div=render :partial => "edit", :locals => { :user => current_user }
+15 -20
View File
@@ -1,7 +1,5 @@
Nineminutes::Application.routes.draw do Nineminutes::Application.routes.draw do
get "charts/index"
devise_for :users, devise_for :users,
:controllers => { :omniauth_callbacks => "users/omniauth_callbacks", :registrations => "registrations", :sessions => "sessions" } :controllers => { :omniauth_callbacks => "users/omniauth_callbacks", :registrations => "registrations", :sessions => "sessions" }
devise_scope :user do devise_scope :user do
@@ -14,27 +12,24 @@ Nineminutes::Application.routes.draw do
end end
get "tracks/index" get "tracks/index"
match "/artists/:artist", :to => "artists#show" match "/search_video", :to => "tracks#search_video"
resources :artists, :only => [ :show ], :constraints => { :id => /.*/ }
match "/more_tracks", :to => "artists#more_tracks" match "/more_tracks", :to => "artists#more_tracks"
match "/more_albums", :to => "artists#more_albums" match "/more_albums", :to => "artists#more_albums"
match "/more_artists", :to => "search#more_artists"
match "/more_charts", :to => "charts#more"
#get "artists/", :to => "artists#index"
match "/users/:user", :to => "users#show"
match "/users/:user/edit", :to => "users#edit"
match "/autocomplete", :to => "search#autocomplete"
match "/album_info", :to => "artists#album_info" match "/album_info", :to => "artists#album_info"
match "/search_video", :to => "tracks#search_video" match "/favourize", :to => "artists#favourize"
#resources :artists, :constraints => { :id => /.*/ } resources :search, :only => [ :show ], :constraints => { :id => /.*/ }
resources :search, :constraints => { :id => /.*/ } match "/more_artists", :to => "search#more_artists"
#resources :users, :only => [ :show ] match "/autocomplete", :to => "search#autocomplete"
get "home/", :to => "home#show" match "/more_charts", :to => "charts#more"
get "charts/", :to => "charts#index" match "/charts", :to => "charts#index"
resources :users, :only => [ :show, :update, :edit, :create ]
get "/home", :to => "home#show"
root :to => "home#index" root :to => "home#index"
end end
-39
View File
@@ -1,39 +0,0 @@
#Your API access key and secret
oauth_consumer_key: "7d7gfjmr2r"
oauth_consumer_secret: "qhb5jq2pwycc7yhz"
#Your website/application name & version
#this information will be appended to user-agent HTTP headers for all API requests
app_name: 9minutes
app_version: 0.0.1
#automatically populate properties
lazy_load: true
#raise SevendigitalError if lazy loading a property fails?
#true - the error is ignored and the property remains unpopulated
#false - the original error is raised
ignorant_lazy_load: false
#what information to log
#false or nil - (default) don't log anything
#true or verbose - log basic info
#very_verbose - include full request & api responses in the log
#verbose: true
## default settings for common API parameters ##
#if any of the bellow parameters is specified here it will be appended to all API requests
#they can always be overridden for each individual API query
#e.g.:
# @client = Sevendigital::Client.new(:country => 'GB', :page_size => 20)
# @client.release.search("radiohead", :country => 'ES', :page_size => 5) -> will return 5 results from spanish catalogue
#end user's location
#country: GB
##size of images returned by API responses (for valid size please see the 7digital API documentation)
#image_size: 50
#number of items returned in API responses
#page_size: 20
@@ -0,0 +1,9 @@
class AddImageUrlToArtist < ActiveRecord::Migration
def self.up
add_column :artists, :img_url, :string
end
def self.down
remove_column :artists, :img_url
end
end
+2 -1
View File
@@ -10,12 +10,13 @@
# #
# It's strongly recommended to check this file into your version control system. # It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20110606000240) do ActiveRecord::Schema.define(:version => 20110630033512) do
create_table "artists", :force => true do |t| create_table "artists", :force => true do |t|
t.string "name" t.string "name"
t.datetime "created_at" t.datetime "created_at"
t.datetime "updated_at" t.datetime "updated_at"
t.string "img_url"
end end
create_table "artists_users", :id => false, :force => true do |t| create_table "artists_users", :id => false, :force => true do |t|
+8
View File
@@ -0,0 +1,8 @@
$(document).ready(function(){
$('.heart').live("click", function(){
var params = "id="+$('#content .tabs .content').attr('q');
alert(params);
favourite_request(favourite_path, params);
});
});
+16
View File
@@ -26,6 +26,22 @@
} }
} }
function favourite_request(link, params){
$.ajax({
type: "GET",
dataType: "html",
url: link,
data: params,
error: function(){
hide_flash(false);
show_flash(true);
},
success: function(data){
$('#content .heart').addClass('loved');
}
});
}
function load_site_request(link, params){ function load_site_request(link, params){
cacheResponse = cacheRequest(link+params); cacheResponse = cacheRequest(link+params);
hide_flash(true); hide_flash(true);
+4 -9
View File
@@ -1,9 +1,9 @@
$(document).ready(function(){ $(document).ready(function(){
// Artist Show Page // Artist Show Page
Path.map(hashbang+artist_path+":artist").to(function(){ Path.map(hashbang+artist_path+":id").to(function(){
show_flash(false); show_flash(false);
load_site_request(artist_path, this.params['artist']); load_site_request(artist_path, this.params['id']);
}); });
// Home Page // Home Page
@@ -43,14 +43,9 @@ $(document).ready(function(){
}); });
// User Show Page // User Show Page
Path.map(hashbang+user_path+":user").to(function(){ Path.map(hashbang+user_path+":id").to(function(){
show_flash(false); show_flash(false);
load_site_request(user_path, this.params['user']); load_site_request(user_path, this.params['id']);
}); });
// User Edit Page
Path.map(hashbang+user_path+":user/edit").to(function(){
show_flash(false);
load_site_request(user_path, this.params['user'] + "/edit");
});
}); });
+1
View File
@@ -11,6 +11,7 @@ var user_path = "/users/";
var register_path = "/register"; var register_path = "/register";
var login_path = "/login"; var login_path = "/login";
var logout_path = "/logout"; var logout_path = "/logout";
var favourite_path = "/favourize";
$(document).ready(function(){ $(document).ready(function(){
// home path // home path