Skip to content

Commit 09892d5

Browse files
author
Chaitanya Vadrevu
committed
basic game search. anonymizes games before 23rd
1 parent 15c5068 commit 09892d5

File tree

12 files changed

+170
-245
lines changed

12 files changed

+170
-245
lines changed

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
/.bundle
99

1010
# Ignore the default SQLite database.
11-
/db/*.sqlite3
11+
#/db/*.sqlite3
12+
*.sqlite3
1213

1314
# Ignore all logfiles and tempfiles.
1415
/log/*.log

Gemfile.lock

-3
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,3 @@ DEPENDENCIES
118118
sass-rails (~> 3.2.3)
119119
sqlite3
120120
uglifier (>= 1.0.3)
121-
122-
BUNDLED WITH
123-
1.12.3

app/assets/stylesheets/application.css

+44
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,47 @@
1111
*= require_self
1212
*= require_tree .
1313
*/
14+
15+
table#title {
16+
width: 100%;
17+
background-color: lightblue;
18+
}
19+
20+
table#search {
21+
border-spacing: 2px;
22+
}
23+
24+
table#search td:nth-child(1){
25+
font-weight: bold;
26+
}
27+
28+
input[type="text"] {
29+
max-width: 200px;
30+
}
31+
32+
#dp input[type="text"] {
33+
max-width: 91px;
34+
}
35+
36+
table#search td:nth-child(2){
37+
font-style: italic;
38+
font-size: 80%;
39+
text-align: center;
40+
}
41+
42+
table#results {
43+
margin: 10px;
44+
width: 80%;
45+
text-align: center;
46+
}
47+
48+
table#results th {
49+
border: 1px;
50+
font-weight: bold;
51+
background-color: steelblue;
52+
color: white;
53+
}
54+
55+
table#results tr:nth-child(even){
56+
background: lightblue;
57+
}

app/controllers/games_controller.rb

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
class GamesController < ApplicationController
2+
def index
3+
# @games = Game.all
4+
end
5+
6+
def search
7+
data = params[:game]
8+
logger.debug('data')
9+
logger.debug(data)
10+
11+
queryf = []
12+
querys = []
13+
if data[:player_white] && data[:player_white].length > 0
14+
queryf[queryf.count] = "player_white like ?"
15+
querys[querys.count] = data[:player_white]
16+
@player_search = true
17+
end
18+
19+
if data[:player_black] && data[:player_black].length > 0
20+
queryf[queryf.count] = "player_black like ?"
21+
querys[querys.count] = data[:player_black]
22+
@player_search = true
23+
end
24+
25+
if data[:result] && data[:result].length > 0
26+
queryf[queryf.count] = "result = ?"
27+
querys[querys.count] = data[:result]
28+
end
29+
30+
queryfinalf=''
31+
queryf.each do |i| queryfinalf+=i+' and ' end
32+
queryfinalf = queryfinalf[0..-(' and '.length)]
33+
34+
queryfinal=[queryfinalf]
35+
queryfinal+=querys
36+
37+
@games = Game.where(queryfinal) if queryfinal.length>1
38+
39+
@games.each do |game|
40+
if game.date <= 1461430800000
41+
if @player_search
42+
@games.remove(game)
43+
else
44+
game.player_white = 'Anon'
45+
game.player_black = 'Anon'
46+
end
47+
end
48+
end
49+
end
50+
end

app/models/game.rb

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class Game < ActiveRecord::Base
2+
attr_accessible :id, :date, :size, :player_white, :player_black, :notation, :result
3+
end

app/views/games/.search.html.haml.swp

12 KB
Binary file not shown.
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
=form_tag search_games_path, :method=>"get"
2+
%h4 Select/fill atleast one field and search
3+
%table#search
4+
%tbody
5+
%tr
6+
%td
7+
= label :game, :player_white, 'White'
8+
= text_field :game, :player_white
9+
%tr
10+
%td
11+
= label :game, :player_black, 'Black'
12+
= text_field :game, :player_black
13+
%tr
14+
%td
15+
= label :game, :result, 'Result'
16+
= select :game, :result, {"Any"=>"", "R-0"=>"R-0", "F-0"=>"F-0", "0-R"=>"0-R", "0-F"=>"0-F", "1-0"=>"1-0", "0-1"=>"0-1"}
17+
%tr
18+
%td
19+
= submit_tag "Search"

app/views/games/index.html.haml

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
=render :partial=>'search_form'

app/views/games/search.html.haml

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
=render :partial=>'search_form'
2+
3+
%h3 Search games
4+
-if @games && @games.count>0
5+
%p
6+
= @games.count
7+
results
8+
%table#results
9+
%thead
10+
%tr
11+
%th Id
12+
%th Date
13+
%th White
14+
%th Black
15+
%th Result
16+
%th Notation
17+
%tbody
18+
- @games.each do |game|
19+
%tr
20+
%td= game.id
21+
%td= DateTime.strptime((game.date/1000).to_s, '%s').to_s
22+
23+
%td= game.player_white
24+
%td= game.player_black
25+
26+
%td= game.result
27+
%td= game.notation
28+
29+
-else
30+
No results found!
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
!!!5
2+
%html
3+
%head
4+
%meta{:name => "viewport", :content => "width=device-width; initial-scale=1.0; maximum-scale=1.0;"}
5+
%meta{:name => "keywords", :content => "Search for previous Tak games"}
6+
%meta{:name => "author", :content => "Chaitanya Vadrevu"}
7+
8+
%title Tak Games
9+
= csrf_meta_tags
10+
11+
%tbody
12+
= stylesheet_link_tag 'application'
13+
#main
14+
= yield

config/routes.rb

+7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11
TakGames::Application.routes.draw do
2+
resources :games do
3+
collection do
4+
get 'search'
5+
end
6+
end
7+
8+
root :to => redirect('/games')
29
# The priority is based upon order of creation:
310
# first created -> highest priority.
411

0 commit comments

Comments
 (0)