finished user functionality, added favourite artists
This commit is contained in:
+4
-1
@@ -5,10 +5,13 @@ tmp/
|
||||
|
||||
Icon*
|
||||
.DS_Store
|
||||
dump.rdb
|
||||
Thumbs.db
|
||||
|
||||
/config/config.yml
|
||||
/config/sevendigital.yml
|
||||
|
||||
/public/images_old/
|
||||
/public/.sass-cache/
|
||||
/public/media/
|
||||
/public/assets/
|
||||
/public/cache/
|
||||
+11
-9
@@ -40,10 +40,11 @@ GEM
|
||||
bcrypt-ruby (2.1.4)
|
||||
bcrypt-ruby (2.1.4-x86-mingw32)
|
||||
builder (2.1.2)
|
||||
closure (1.2.701)
|
||||
closure (1.3.0)
|
||||
rack (>= 1.0.0)
|
||||
cocaine (0.1.0)
|
||||
daemons (1.0.10)
|
||||
devise (1.3.4)
|
||||
devise (1.4.0)
|
||||
bcrypt-ruby (~> 2.1.2)
|
||||
orm_adapter (~> 0.0.3)
|
||||
warden (~> 1.0.3)
|
||||
@@ -64,10 +65,10 @@ GEM
|
||||
i18n (0.6.0)
|
||||
jammit (0.6.3)
|
||||
yui-compressor (>= 0.9.3)
|
||||
jquery-rails (1.0.9)
|
||||
jquery-rails (1.0.12)
|
||||
railties (~> 3.0)
|
||||
thor (~> 0.14)
|
||||
json (1.5.1)
|
||||
json (1.5.3)
|
||||
mail (2.2.19)
|
||||
activesupport (>= 2.3.6)
|
||||
i18n (>= 0.4.0)
|
||||
@@ -94,15 +95,16 @@ GEM
|
||||
oa-core (= 0.2.6)
|
||||
rack-openid (~> 1.3.1)
|
||||
ruby-openid-apps-discovery (~> 1.2.0)
|
||||
oauth (0.4.4)
|
||||
oauth (0.4.5)
|
||||
oauth2 (0.4.1)
|
||||
faraday (~> 0.6.1)
|
||||
multi_json (>= 0.0.5)
|
||||
open4 (1.0.1)
|
||||
open4 (1.1.0)
|
||||
orm_adapter (0.0.5)
|
||||
paperclip (2.3.11)
|
||||
paperclip (2.3.12)
|
||||
activerecord (>= 2.3.0)
|
||||
activesupport (>= 2.3.2)
|
||||
cocaine (>= 0.0.2)
|
||||
peachy (0.4.1)
|
||||
polyglot (0.3.1)
|
||||
rack (1.2.3)
|
||||
@@ -135,7 +137,7 @@ GEM
|
||||
ruby-openid (>= 2.1.7)
|
||||
ruby_parser (2.0.6)
|
||||
sexp_processor (~> 3.0)
|
||||
sass (3.1.2)
|
||||
sass (3.1.3)
|
||||
sexp_processor (3.0.5)
|
||||
sqlite3 (1.3.3)
|
||||
sqlite3 (1.3.3-x86-mingw32)
|
||||
@@ -147,7 +149,7 @@ GEM
|
||||
typhoeus (0.2.4)
|
||||
mime-types
|
||||
mime-types
|
||||
tzinfo (0.3.27)
|
||||
tzinfo (0.3.29)
|
||||
warden (1.0.4)
|
||||
rack (>= 1.0)
|
||||
will_paginate (2.3.15)
|
||||
|
||||
@@ -2,4 +2,22 @@
|
||||
protect_from_forgery
|
||||
|
||||
before_filter { |c| @youtube_client = YouTubeIt::Client.new(:dev_key=>"AI39si600H1fRQ6HW1pHG89e-23Uxf44YHu5TsCJMhNf5hFaYWSSSyyrOIEcOX451sFeh_OZdbbA48_g6OInfTv042-Id163tg") }
|
||||
|
||||
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
|
||||
@@ -5,7 +5,7 @@ class ArtistsController < ApplicationController
|
||||
@@limit = { tracks: 10, albums: 4, similar: 6 }
|
||||
|
||||
def show
|
||||
artist = CGI.unescape params[:artist]
|
||||
artist = CGI.unescape params[:id]
|
||||
|
||||
@artist = LastFM::Artist.getInfo artist
|
||||
@tracks = LastFM::Artist.getTopTracks artist, @@limit[:tracks]
|
||||
@@ -44,12 +44,26 @@ class ArtistsController < ApplicationController
|
||||
end
|
||||
|
||||
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!
|
||||
|
||||
render :partial=>"album_info", :locals=>{:album=>@album}
|
||||
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
|
||||
params[:q] = CGI.unescape params[:q]
|
||||
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")
|
||||
set_flash_message(:notice, :signed_in) if is_navigational_format?
|
||||
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
|
||||
@@ -2,7 +2,7 @@ class HomeController < ApplicationController
|
||||
|
||||
def show
|
||||
@files = Dir.glob("public/images/startsite/*.jpg")
|
||||
render :partial=>"index"
|
||||
render :partial=>"index", :locals => {:files => @files}
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -6,7 +6,8 @@ class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
|
||||
|
||||
if @user.persisted?
|
||||
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
|
||||
session["devise.facebook_data"] = env["omniauth.auth"]
|
||||
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)
|
||||
if @user.persisted?
|
||||
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
|
||||
session["devise.open:id_data"] = env["openid.ext1"]
|
||||
redirect_to new_user_registration_url
|
||||
|
||||
@@ -1,12 +1,18 @@
|
||||
class UsersController < ApplicationController
|
||||
def show
|
||||
@user = User.find params[:user]
|
||||
@user = User.find params[:id]
|
||||
render :partial => "show", :locals => { :user => @user }
|
||||
end
|
||||
|
||||
def edit
|
||||
@user = User.find params[:user]
|
||||
@user = User.find params[:id]
|
||||
render :partial => "edit", :locals => { :user => @user }
|
||||
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
|
||||
|
||||
@@ -24,8 +24,12 @@ module ApplicationHelper
|
||||
end
|
||||
|
||||
def camelCaseString phrase
|
||||
phrase.gsub!(/^[a-z]|\s+[a-z]/) { |a| a.upcase }
|
||||
return phrase
|
||||
end
|
||||
phrase.gsub!(/^[a-z]|\s+[a-z]/) { |a| a.upcase }
|
||||
return phrase
|
||||
end
|
||||
|
||||
def async_link_to body, path, html_options = {}
|
||||
link_to body, "/#!" + path, html_options
|
||||
end
|
||||
|
||||
end
|
||||
@@ -1,7 +1,7 @@
|
||||
module UsersHelper
|
||||
|
||||
def validate_avatar_url url
|
||||
return url if url.present? and FileTest.exists? url
|
||||
def validate_avatar user, size = :original
|
||||
return user.avatar.url(size) if user.avatar?
|
||||
"examples/user-big.jpg"
|
||||
end
|
||||
|
||||
|
||||
+7
-1
@@ -8,7 +8,13 @@ class User < ActiveRecord::Base
|
||||
|
||||
# Setup accessible (or protected) attributes for your model
|
||||
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)
|
||||
super.tap do |user|
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
.tabs_js.information
|
||||
%h1
|
||||
= artist.name
|
||||
= link_to "", "#", :class=>"heart"
|
||||
%span.heart
|
||||
%ul.nav
|
||||
%li= image_tag "icons/artist-info.png"
|
||||
%li= image_tag "icons/artist-links.png"
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
<%- if controller_name != 'sessions' %>
|
||||
<%= link_to "Sign in", "/#!/login" %><br />
|
||||
<%= async_link_to "Login", new_user_session_path %><br />
|
||||
<% end -%>
|
||||
|
||||
<%- if devise_mapping.registerable? && controller_name != 'registrations' %>
|
||||
<%= link_to "Sign up", "/#!/register" %><br />
|
||||
<%= async_link_to "Register", new_user_registration_path %><br />
|
||||
<% end -%>
|
||||
|
||||
<%- if devise_mapping.recoverable? && controller_name != 'passwords' %>
|
||||
@@ -19,6 +19,6 @@
|
||||
<% end -%>
|
||||
|
||||
<%- if devise_mapping.omniauthable? %>
|
||||
<%= link_to "Sign in 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 Facebook", user_omniauth_authorize_path(:facebook) %><br />
|
||||
<%= link_to "Login with Google", user_omniauth_authorize_path(:open_id, :openid_url => 'https://www.google.com/accounts/o8/id') %><br />
|
||||
<% end -%>
|
||||
@@ -1,5 +1,5 @@
|
||||
%ul#top_artist
|
||||
- for file in @files
|
||||
- for file in files
|
||||
%li= image_tag "startsite/"+File.basename(file)
|
||||
%ul#top_artist_nav
|
||||
%li= link_to image_tag("startsite/small/beatles.jpg"),"", :class=>"ll dir"
|
||||
|
||||
@@ -1,4 +0,0 @@
|
||||
#white
|
||||
%br
|
||||
%br
|
||||
%br
|
||||
@@ -16,18 +16,17 @@
|
||||
#site
|
||||
#uuser{:style=>"display:block; color:#ddd;"}
|
||||
- if user_signed_in?
|
||||
=link_to "Profile", "/#!/users/#{current_user.id}"
|
||||
=link_to "Logout", "/#!/logout"
|
||||
- else
|
||||
=link_to "Login", "/#!/login"
|
||||
=link_to "Register", "/#!/register"
|
||||
=async_link_to "Logout", destroy_user_session_path
|
||||
#head
|
||||
%h1= link_to image_tag("nine-minutes.png"), "/#!/home"
|
||||
= render :partial=>"layouts/player"
|
||||
#navigation
|
||||
%li.active= link_to "home", "/#!/home"
|
||||
%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
|
||||
= form_tag '/search', :method => 'get', :id => "search_form", :remote=>true do
|
||||
= text_field_tag 'q', params[:q], :class => "text", :placeholder => "Search here ..."
|
||||
|
||||
@@ -1,12 +1,7 @@
|
||||
#user_left
|
||||
=image_tag validate_avatar_url(user.avatar.url), :class => "picture"
|
||||
.information
|
||||
%p{:style=>"display:block; color:#ddd;"}
|
||||
%h1{:style=>"color:#ddd;"}= current_user.username || current_user.email
|
||||
%br
|
||||
|
||||
.tabs.tabs_js.w02
|
||||
%ul.nav
|
||||
%li profile settings
|
||||
.content
|
||||
%div EDIT - bla bla bla
|
||||
EDIT - Settings
|
||||
= form_for user, :url => {:action=>"update"} do |f|
|
||||
=f.text_field :username
|
||||
=f.submit "Save"
|
||||
= form_for user, :url => {:action=>"update"}, :html => {:multipart=>true} do |f|
|
||||
=f.file_field :avatar
|
||||
=f.submit "Save"
|
||||
@@ -1,10 +1,7 @@
|
||||
#user_left
|
||||
=image_tag validate_avatar_url(user.avatar.url), :class => "picture"
|
||||
=image_tag validate_avatar(user), :class => "picture"
|
||||
.information
|
||||
%h1= user.username
|
||||
%p{:style=>"display:block; color:#ddd;"}
|
||||
=link_to "Profil editieren", "/#!/users/#{current_user.id}/edit"
|
||||
%br
|
||||
%h1= user.username || current_user.email
|
||||
%ul.nav
|
||||
%li=image_tag "icons/artist-info.png"
|
||||
%li=image_tag "icons/artist-links.png"
|
||||
@@ -14,7 +11,13 @@
|
||||
.tabs.tabs_js.w02
|
||||
%ul.nav
|
||||
%li profile
|
||||
%li playlist
|
||||
- if user == current_user
|
||||
%li settings
|
||||
.content
|
||||
%div SONGS
|
||||
%div ALBUMS
|
||||
%div
|
||||
- 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
@@ -1,7 +1,5 @@
|
||||
Nineminutes::Application.routes.draw do
|
||||
|
||||
get "charts/index"
|
||||
|
||||
devise_for :users,
|
||||
:controllers => { :omniauth_callbacks => "users/omniauth_callbacks", :registrations => "registrations", :sessions => "sessions" }
|
||||
devise_scope :user do
|
||||
@@ -14,27 +12,24 @@ Nineminutes::Application.routes.draw do
|
||||
end
|
||||
|
||||
get "tracks/index"
|
||||
match "/artists/:artist", :to => "artists#show"
|
||||
match "/more_tracks", :to => "artists#more_tracks"
|
||||
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 "/search_video", :to => "tracks#search_video"
|
||||
|
||||
#resources :artists, :constraints => { :id => /.*/ }
|
||||
resources :search, :constraints => { :id => /.*/ }
|
||||
#resources :users, :only => [ :show ]
|
||||
resources :artists, :only => [ :show ], :constraints => { :id => /.*/ }
|
||||
match "/more_tracks", :to => "artists#more_tracks"
|
||||
match "/more_albums", :to => "artists#more_albums"
|
||||
match "/album_info", :to => "artists#album_info"
|
||||
match "/favourize", :to => "artists#favourize"
|
||||
|
||||
get "home/", :to => "home#show"
|
||||
get "charts/", :to => "charts#index"
|
||||
resources :search, :only => [ :show ], :constraints => { :id => /.*/ }
|
||||
match "/more_artists", :to => "search#more_artists"
|
||||
match "/autocomplete", :to => "search#autocomplete"
|
||||
|
||||
match "/more_charts", :to => "charts#more"
|
||||
match "/charts", :to => "charts#index"
|
||||
|
||||
resources :users, :only => [ :show, :update, :edit, :create ]
|
||||
|
||||
get "/home", :to => "home#show"
|
||||
|
||||
root :to => "home#index"
|
||||
end
|
||||
|
||||
@@ -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
@@ -10,12 +10,13 @@
|
||||
#
|
||||
# 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|
|
||||
t.string "name"
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.string "img_url"
|
||||
end
|
||||
|
||||
create_table "artists_users", :id => false, :force => true do |t|
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
|
||||
});
|
||||
@@ -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){
|
||||
cacheResponse = cacheRequest(link+params);
|
||||
hide_flash(true);
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
$(document).ready(function(){
|
||||
|
||||
// Artist Show Page
|
||||
Path.map(hashbang+artist_path+":artist").to(function(){
|
||||
Path.map(hashbang+artist_path+":id").to(function(){
|
||||
show_flash(false);
|
||||
load_site_request(artist_path, this.params['artist']);
|
||||
load_site_request(artist_path, this.params['id']);
|
||||
});
|
||||
|
||||
// Home Page
|
||||
@@ -43,14 +43,9 @@ $(document).ready(function(){
|
||||
});
|
||||
|
||||
// User Show Page
|
||||
Path.map(hashbang+user_path+":user").to(function(){
|
||||
Path.map(hashbang+user_path+":id").to(function(){
|
||||
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");
|
||||
});
|
||||
});
|
||||
@@ -11,6 +11,7 @@ var user_path = "/users/";
|
||||
var register_path = "/register";
|
||||
var login_path = "/login";
|
||||
var logout_path = "/logout";
|
||||
var favourite_path = "/favourize";
|
||||
|
||||
$(document).ready(function(){
|
||||
// home path
|
||||
|
||||
Reference in New Issue
Block a user