Browse files

added forms etc

  • Loading branch information...
1 parent 6f758aa commit d9692f5abc1323715d70a0ec763c90d3bccd1191 @pedro pedro committed Apr 12, 2012
Showing with 67 additions and 32 deletions.
  1. +1 −0 Gemfile
  2. +12 −0 Gemfile.lock
  3. +12 −1 lib/ranked/api.rb
  4. +9 −7 views/index.haml
  5. +2 −4 views/layout.haml
  6. +5 −2 views/navbar.haml
  7. +7 −7 views/players.haml
  8. +19 −11 views/results.haml
View
1 Gemfile
@@ -1,5 +1,6 @@
source :rubygems
+gem "buckshot"
gem "pg"
gem "sequel"
gem "unicorn"
View
12 Gemfile.lock
@@ -1,6 +1,11 @@
GEM
remote: http://rubygems.org/
specs:
+ buckshot (0.2.0)
+ shotgun
+ thin
+ daemons (1.1.8)
+ eventmachine (0.12.10)
haml (3.1.2)
hashie (1.2.0)
kgio (2.7.4)
@@ -20,12 +25,18 @@ GEM
raindrops (0.8.0)
ruby-openid (2.1.8)
sequel (3.34.1)
+ shotgun (0.9)
+ rack (>= 1.0)
sinatra (1.3.2)
rack (~> 1.3, >= 1.3.6)
rack-protection (~> 1.2)
tilt (~> 1.3, >= 1.3.3)
sinatra-google-auth (0.0.3)
omniauth-openid
+ thin (1.3.1)
+ daemons (>= 1.0.9)
+ eventmachine (>= 0.12.6)
+ rack (>= 1.0.0)
tilt (1.3.3)
unicorn (4.2.1)
kgio (~> 2.6)
@@ -36,6 +47,7 @@ PLATFORMS
ruby
DEPENDENCIES
+ buckshot
haml
pg
sequel
View
13 lib/ranked/api.rb
@@ -18,10 +18,16 @@ class Api < Sinatra::Base
def data
@data ||= JSON.parse(request.body.read)
end
+
+ def link_class(path)
+ return "active" if request.path_info == path
+ end
end
before do
- @user = session['user']
+ if user = session['user']
+ @user = Player.find_or_create(:user => user)
+ end
end
get "/" do
@@ -42,6 +48,11 @@ def data
haml :results
end
+ post "/results" do
+ Result.create(:winner_id => params[:winner_id], :loser_id => @user.id, :at => Time.now)
+ redirect "/"
+ end
+
error do
puts env['sinatra.error']
500
View
16 views/index.haml
@@ -1,10 +1,12 @@
.container
-%table.table.table-condensed.table-striped
- %thead
- %tr
- %th User
- %tbody
- - @players.each do |player|
+ %table.table.table-condensed.table-striped
+ %thead
%tr
- %td= player.user
+ %td Rank
+ %th User
+ %tbody
+ - @players.each_with_index do |player, i|
+ %tr
+ %td= "##{i+1}"
+ %td= player.user
View
6 views/layout.haml
@@ -4,20 +4,18 @@
%title Ranked
%link{ :href => "/bootstrap/css/bootstrap.css", :type => "text/css", :rel => "stylesheet" }
-
%link{ :href => "/css/styles.css", :type => "text/css", :rel => "stylesheet" }
-
%link{ :href => "/bootstrap/css/bootstrap-responsive.css", :type => "text/css", :rel => "stylesheet" }
%link{ rel: "apple-touch-icon", href: "/bootstrap/images/apple-touch-icon.png"}
%link{ rel: "shortcut icon", href: "/bootstrap/images/favicon.ico"}
%link{ rel: "apple-touch-icon", sizes: "72x72", href: "/bootstrap/images/apple-touch-icon-72x72.png"}
%link{ rel: "apple-touch-icon", sizes: "114x114", href: "/bootstrap/images/apple-touch-icon-114x114.png"}
-
+
+ %meta{:name=>"viewport", :content=>"width=device-width", "initial-scale"=>"1.0"}
%body
%div= haml :navbar
-
%div= yield
%div= haml :footer
View
7 views/navbar.haml
@@ -8,7 +8,10 @@
%a.brand{:href => '/'} Ranked
.nav-collapse
%ul.nav
- %li
+ %li{:class => link_class("/players")}
%a{:href => '/players'}Players
- %li
+ %li{:class => link_class("/results")}
%a{:href => '/results'}Results
+ %ul.nav.pull-right
+ %li
+ %a= @user.user
View
14 views/players.haml
@@ -1,10 +1,10 @@
.container
-%table.table.table-condensed.table-striped
- %thead
- %tr
- %th User
- %tbody
- - @players.each do |player|
+ %table.table.table-condensed.table-striped
+ %thead
%tr
- %td= player.user
+ %th User
+ %tbody
+ - @players.each do |player|
+ %tr
+ %td= player.user
View
30 views/results.haml
@@ -1,14 +1,22 @@
.container
-%table.table.table-condensed.table-striped
- %thead
- %tr
- %th At
- %th Winner
- %th Loser
- %tbody
- - @results.each do |result|
+ %form.form-inline{:method=>"post", :action=>"/results"}
+ %select{:name=>"winner_id"}
+ - Ranked::Player.all.each do |player|
+ - next if player == @user
+ %option{:value=>player.id}= player.user
+
+ %input.btn.btn-primary{:type=>"submit", :value=>"Beat me"}
+
+ %table.table.table-condensed.table-striped
+ %thead
%tr
- %td= result.at
- %td= result.winner_user
- %td= result.loser_user
+ %th At
+ %th Winner
+ %th Loser
+ %tbody
+ - @results.each do |result|
+ %tr
+ %td= result.at
+ %td= result.winner_user
+ %td= result.loser_user

0 comments on commit d9692f5

Please sign in to comment.