Permalink
Browse files

New Quiz: Movie Soundtracks

  • Loading branch information...
1 parent cb05678 commit 3834a3a6be7f94681f9b012c09db60cc01004db0 @luizbranco committed Nov 11, 2011
Showing with 92 additions and 72 deletions.
  1. +17 −8 app/assets/javascripts/challenges.js.coffee
  2. +11 −13 app/assets/stylesheets/challenges.css.scss
  3. +9 −14 app/controllers/songs_controller.rb
  4. +14 −2 app/models/challenge.rb
  5. +2 −1 app/views/aliases/index.html.haml
  6. +13 −9 app/views/challenges/new.html.haml
  7. +4 −1 app/views/songs/_form.html.haml
  8. +1 −1 app/views/songs/edit.html.haml
  9. +5 −4 app/views/songs/index.html.haml
  10. +1 −1 app/views/songs/new.html.haml
  11. +2 −2 app/views/songs/show.html.haml
  12. +1 −1 app/views/tracks/_form.html.haml
  13. +1 −1 app/views/tracks/index.html.haml
  14. +3 −3 config/facebook.yml
  15. +3 −6 config/routes.rb
  16. +0 −1 public/assets/application-90fa0d0a9621033be224cd698ab3999f.css
  17. BIN public/assets/application-90fa0d0a9621033be224cd698ab3999f.css.gz
  18. +2 −2 ...pplication-7d1dc14d88d9a11a5e0947608e09c396.js → application-a82322d16477a304aed089372087b078.js}
  19. BIN ...tion-7d1dc14d88d9a11a5e0947608e09c396.js.gz → application-a82322d16477a304aed089372087b078.js.gz}
  20. +1 −0 public/assets/application-eb0dc5032bac7a322ee80a93d03feb2d.css
  21. BIN public/assets/application-eb0dc5032bac7a322ee80a93d03feb2d.css.gz
  22. BIN public/assets/jquery-ui.min-2b432ef5545e6620f94e7638b7574058.js.gz
  23. BIN public/assets/jquery.min-ac6382033c1c5e27ebbc5a5a0597ccb9.js.gz
  24. +2 −2 public/assets/manifest.yml
  25. BIN public/audio/031.mp3
  26. BIN public/audio/031.ogg
  27. BIN public/audio/032.mp3
  28. BIN public/audio/032.ogg
  29. BIN public/audio/033.mp3
  30. BIN public/audio/033.ogg
  31. BIN public/audio/034.mp3
  32. BIN public/audio/034.ogg
  33. BIN public/audio/035.mp3
  34. BIN public/audio/035.ogg
  35. BIN public/audio/036.mp3
  36. BIN public/audio/036.ogg
  37. BIN public/audio/037.mp3
  38. BIN public/audio/037.ogg
  39. BIN public/audio/038.mp3
  40. BIN public/audio/038.ogg
  41. BIN public/audio/039.mp3
  42. BIN public/audio/039.ogg
  43. BIN public/audio/040.mp3
  44. BIN public/audio/040.ogg
  45. BIN public/audio/041.mp3
  46. BIN public/audio/041.ogg
  47. BIN public/audio/042.mp3
  48. BIN public/audio/042.ogg
  49. BIN public/audio/043.mp3
  50. BIN public/audio/043.ogg
  51. BIN public/audio/044.mp3
  52. BIN public/audio/044.ogg
  53. BIN public/audio/045.mp3
  54. BIN public/audio/045.ogg
  55. BIN public/audio/046.mp3
  56. BIN public/audio/046.ogg
  57. BIN public/audio/047.mp3
  58. BIN public/audio/047.ogg
  59. BIN public/audio/048.mp3
  60. BIN public/audio/048.ogg
  61. BIN public/audio/049.mp3
  62. BIN public/audio/049.ogg
  63. BIN public/audio/050.mp3
  64. BIN public/audio/050.ogg
  65. BIN public/audio/051.mp3
  66. BIN public/audio/051.ogg
  67. BIN public/audio/052.mp3
  68. BIN public/audio/052.ogg
  69. BIN public/audio/053.mp3
  70. BIN public/audio/053.ogg
  71. BIN public/audio/054.mp3
  72. BIN public/audio/054.ogg
  73. BIN public/audio/055.mp3
  74. BIN public/audio/055.ogg
  75. BIN public/audio/056.mp3
  76. BIN public/audio/056.ogg
  77. BIN public/audio/057.mp3
  78. BIN public/audio/057.ogg
  79. BIN public/audio/058.mp3
  80. BIN public/audio/058.ogg
  81. BIN public/audio/059.mp3
  82. BIN public/audio/059.ogg
  83. BIN public/audio/060.mp3
  84. BIN public/audio/060.ogg
@@ -2,17 +2,16 @@ trim = (str) ->
trimmed = str.replace(/^\s+|\s+$/g,"")
escape(trimmed)
-inputListener = ->
- if document.getElementById('challenge_tracks')
- tracks = document.getElementById('challenge_tracks')
- track_inputs = tracks.getElementsByTagName('input')
+$ inputListener = ->
+ if $('#challenge_tracks').length
+ track_inputs = $('.song_item > input')
for i in track_inputs
i.onkeydown = ->
valueCheck this
valueCheck = (e) ->
e.className = ""
- if e.value.length > 1
+ if e.value.length > 0
clearTimeout t
e.className = "thinking"
t = setTimeout((=> requestValue(e)), 2000)
@@ -27,6 +26,15 @@ requestValue = (e) ->
success: ->
e.className = "right"
+stopMusic = ->
+ audio_tags = $('audio')
+ for i in audio_tags
+ i.pause()
+ i.currentTime = 0;
+
+playNextMusic = ->
+ $('#track_active > .track_player > audio')[0].play()
+
hideControllers = ->
if $('#track_controllers').length
track_items = $('.track_item')
@@ -55,6 +63,8 @@ $ trackControllers = ->
$(item).next().fadeIn()
$(item).next().attr('id','track_active')
hideControllers()
+ stopMusic()
+ playNextMusic()
false
$(prev).click ->
item = $("#track_active")
@@ -63,7 +73,6 @@ $ trackControllers = ->
$(item).prev().attr('id','track_active')
$(item).prev().fadeIn()
hideControllers()
+ stopMusic()
+ playNextMusic()
false
-
-window.onload = ->
- inputListener()
@@ -11,7 +11,7 @@ div.wrapper {
width: 700px;
margin: 0 auto;
padding: 20px;
- background: white;
+ background: #FFF;
border: 1px solid #CCC;
-moz-box-shadow: 0 3px 4px #CCC;
-webkit-box-shadow: 0 3px 4px #CCC;
@@ -97,7 +97,7 @@ div#flash_notice{
color: #97AA4F;
font-weight: bold;
padding: 5px;
- width: 200px;
+ width: 400px;
margin: 10px 0;
}
@@ -114,35 +114,33 @@ div#flash_error{
ul#challenge_list{
list-style-type: none;
- & li{
+ li{
border-bottom: 1px solid #EBEBEB;
padding-bottom: 10px;
- & div.theme_scores{
+ div.theme_scores{
float: right;
width: 130px;
margin: 40px 5px 0 5px;
background-color: #F3F3F3;
border: 1px solid #EBEBEB;
padding: 10px;
- & h3{
+ h3{
font-size: 16px;
text-align: center;
}
- & div.theme_avg_score{
+ div.theme_avg_score{
margin-top: 10px;
color: #5FA400;
font-size: 30px;
font-weight: bold;
text-align: center;
- & div.theme_user_score{
+ div.theme_user_score{
margin-top: 10px;
font-size: 15px;
font-weight: normal;
}
}
}
- & h2{
- }
}
}
@@ -151,13 +149,13 @@ div#challenge_tracks{
width: 300px;
margin: 0 auto;
margin-bottom: 20px;
- & div.track_player{
+ div.track_player{
margin-bottom: 10px;
}
- & label{
+ label{
font-weight: bold;
}
- & input {
+ input {
border: 1px solid #ccc;
padding: 5px;
margin: 5px 0;
@@ -172,7 +170,7 @@ div#challenge_tracks{
background: url(asset_path("track_thinking.gif", image)) no-repeat 190px 50%;
}
}
- & div#track_controllers{
+ div#track_controllers{
width: 300px;
margin: 0 auto;
margin-top: 20px;
@@ -8,40 +8,35 @@ def index
end
def show
- @artist = Artist.find(params[:artist_id])
- @song = @artist.songs.find(params[:id])
+ @song = Song.find(params[:id])
@aliases = @song.aliases
end
def new
- @artist = Artist.find(params[:artist_id])
- @song = @artist.songs.build
+ @song = Song.new
end
def create
- @artist = Artist.find(params[:artist_id])
- @song = @artist.songs.build(params[:song])
+ @song = Song.new(params[:song])
if @song.save
flash[:notice] = 'Song created!'
- respond_with(@song, :location => artist_path(@artist))
+ respond_with(@song, :location => song_path(@song))
else
- redirect_to artist_path(@artist), :error => 'An error has occured!'
+ redirect_to songs_path, :error => 'An error has occured!'
end
end
def edit
- @artist = Artist.find(params[:artist_id])
- @song = @artist.songs.find(params[:id])
+ @song = Song.find(params[:id])
end
def update
- @artist = Artist.find(params[:artist_id])
- @song = @artist.songs.find(params[:id])
+ @song = Song.find(params[:id])
if @song.update_attributes(params[:song])
flash[:notice] = 'Song updated!'
- respond_with(@song, :location => artist_path(@artist))
+ respond_with(@song, :location => song_path(@song))
else
- redirect_to artist_path(@artist), :error => 'An error has occured!'
+ redirect_to song_path, :error => 'An error has occured!'
end
end
View
@@ -18,10 +18,22 @@ def create_score
private
def calculate_score
- tracks = ((theme.tracks.count)*2).to_f # Each track has one song and one artist
+ tracks_total
correct_answers = (answers.where("correct = ?", true).count).to_f
- ratio = ((correct_answers/tracks)*100).round
+ ratio = ((correct_answers/tracks_total.to_f)*100).round
self.score = ratio
end
+ def tracks_total
+ tracks = theme.tracks
+ tracks_total = 0
+ tracks.each do |track|
+ if track.song.artist.nil?
+ tracks_total = tracks_total + 1
+ else
+ tracks_total = tracks_total + 2
+ end
+ end
+ tracks_total
+ end
end
@@ -6,4 +6,5 @@
- @aliases.each do |alternative|
%li
= alternative.name
- = alternative.id
+ = link_to 'Edit', edit_song_alias_path(alternative.aliasable,alternative) if alternative.aliasable.class == Song
+ = link_to 'Edit', edit_artist_alias_path(alternative.aliasable,alternative) if alternative.aliasable.class == Artist
@@ -4,7 +4,7 @@
= f.hidden_field :user_id, :value => @user.id
- @tracks.each_with_index do |track, i|
%div.track_item{:style => 'display:none'}
- %h3= "##{i+1} Track:"
+ %h3= "##{i+1} of #{@tracks.count} Tracks:"
%div.track_player
%audio{:controls => "controls"}
%source{:src => "#{track.song.file_path}.ogg", :type => "audio/ogg"}
@@ -16,14 +16,18 @@
= f.fields_for :answers do |builder|
= builder.hidden_field :answerable_id, :value => track.song.id
= builder.hidden_field :answerable_type, :value => track.song.class
- = builder.label :name, 'Song:'
- = builder.text_field :name,'data-url' => check_artist_song_url(track.song.artist,track.song)
- %div.artist_item
- = f.fields_for :answers do |builder|
- = builder.hidden_field :answerable_id, :value => track.song.artist.id
- = builder.hidden_field :answerable_type, :value => track.song.artist.class
- = builder.label :name, 'Artist:'
- = builder.text_field :name,'data-url' => check_artist_url(track.song.artist)
+ - if track.song.artist.nil?
+ = builder.label :name, 'Movie:'
+ - else
+ = builder.label :name, 'Song:'
+ = builder.text_field :name,'data-url' => check_song_url(track.song)
+ - unless track.song.artist.nil?
+ %div.artist_item
+ = f.fields_for :answers do |builder|
+ = builder.hidden_field :answerable_id, :value => track.song.artist.id
+ = builder.hidden_field :answerable_type, :value => track.song.artist.class
+ = builder.label :name, 'Artist:'
+ = builder.text_field :name,'data-url' => check_artist_url(track.song.artist)
%div#track_controllers
=link_to '<< Prev', "#", :id => "prev_track", :class => "button"
=link_to 'Next >>', "#", :id => "next_track", :class => "button"
@@ -1,4 +1,7 @@
-=form_for([@artist, @song]) do |f|
+=form_for @song do |f|
+ %div
+ =f.label :artist_id, 'Artist:'
+ =f.select(:artist_id, Artist.all.collect {|p| [ p.name, p.id ] }, { :include_blank => 'None' })
%div
=f.label :name, 'Name:'
=f.text_field :name, :autofocus => true
@@ -1,2 +1,2 @@
-%h2= "Edit Song for #{@artist.name}"
+%h2 Edit Song
=render :partial => 'form'
@@ -5,7 +5,8 @@
%ol
- @songs.each do |song|
%li
- = link_to song.name, artist_song_path(@artist,song)
- = link_to 'Edit', edit_artist_song_path(@artist,song)
- = link_to 'Delete', artist_song_path(@artist,song), :confirm => 'Are you sure?', :method => :delete
-= link_to 'New Song', new_artist_song_path(@artist)
+ = link_to song.name, song_path(song)
+ = song.artist.name unless song.artist.nil?
+ = link_to 'Edit', edit_song_path(song)
+ = link_to 'Delete', song_path(song), :confirm => 'Are you sure?', :method => :delete
+= link_to 'New Song', new_song_path
@@ -1,2 +1,2 @@
-%h2= "New Song for #{@artist.name}"
+%h2 New Song
=render :partial => 'form'
@@ -1,3 +1,3 @@
-%h2= "#{@song.name} by #{@song.artist.name}"
+%h2= @song.name
=render :template => 'aliases/index', :collection => @aliases
-=link_to 'New Alias', new_artist_song_alias_path(@artist, @song)
+=link_to 'New Alias', new_song_alias_path(@song)
@@ -1,5 +1,5 @@
=form_for([@theme, @track]) do |f|
%div
=f.label :song, 'Song name:'
- =f.grouped_collection_select(:song_id, @artists, :songs, :name, :id, :name)
+ =f.select(:song_id, Song.all.collect {|p| [ p.name, p.id ] }, { :prompt => 'Select one' })
=f.submit
@@ -6,5 +6,5 @@
%audio{:controls => "controls", :src => "#{track.song.file_path}.mp3"}
= track.song.name
\ -
- = track.song.artist.name
+ = track.song.artist.name unless track.song.artist.nil?
= link_to 'Edit', edit_theme_track_path(@theme,track)
View
@@ -1,8 +1,8 @@
development: &defaults
- client_id: 160926967336434
- client_secret: 17d31f21f2417788ad53e2e84f2c3a4a
+ client_id: 145425388892883
+ client_secret: 644fff9eaa2d9cdeb0c9341afa515954
scope: user_about_me,email,publish_stream
- canvas_url: https://apps.facebook.com/musicquiz_mp/
+ canvas_url: https://apps.facebook.com/music_quiz_dev/
test:
<<: *defaults
View
@@ -17,15 +17,12 @@
get 'check'
end
resources :aliases
- resources :songs, :except => :index do
- member do
- get 'check'
- end
- resources :aliases
- end
end
resources :songs do
+ member do
+ get 'check'
+ end
resources :aliases
end

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

Large diffs are not rendered by default.

Oops, something went wrong.

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -5,5 +5,5 @@ track_wrong.png: track_wrong-2340a99260b3a639c42e628a82ce6453.png
vinyl.png: vinyl-991f08006859e3e092b1981326452c6e.png
jquery-ui.min.js: jquery-ui.min-2b432ef5545e6620f94e7638b7574058.js
jquery.min.js: jquery.min-ac6382033c1c5e27ebbc5a5a0597ccb9.js
-application.js: application-7d1dc14d88d9a11a5e0947608e09c396.js
-application.css: application-90fa0d0a9621033be224cd698ab3999f.css
+application.js: application-a82322d16477a304aed089372087b078.js
+application.css: application-eb0dc5032bac7a322ee80a93d03feb2d.css
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.

0 comments on commit 3834a3a

Please sign in to comment.