From ecef4973baed5580e3b2500ce0a65def1132d172 Mon Sep 17 00:00:00 2001 From: guntasgrewal Date: Tue, 25 Mar 2014 16:12:18 -0400 Subject: Changes to generate.sh --- app/models/game_option.rb | 2 -- app/models/game_setting.rb | 3 +++ db/migrate/20140307052327_create_servers.rb | 8 -------- db/migrate/20140307052331_create_matches.rb | 11 ----------- db/migrate/20140307052334_create_teams.rb | 9 --------- db/migrate/20140307052338_create_alerts.rb | 10 ---------- db/migrate/20140307052342_create_pms.rb | 11 ----------- db/migrate/20140307052346_create_tournaments.rb | 16 ---------------- db/migrate/20140307052350_create_games.rb | 15 --------------- db/migrate/20140307052354_create_users.rb | 13 ------------- db/migrate/20140307052358_create_sessions.rb | 9 --------- db/migrate/20140307052402_create_server_settings.rb | 8 -------- .../20140307052405_create_tournament_options.rb | 12 ------------ db/migrate/20140307052409_create_game_options.rb | 11 ----------- db/migrate/20140307052413_create_scores.rb | 11 ----------- ...0307052417_create_tournament_players_join_table.rb | 8 -------- ...140307052421_create_tournament_hosts_join_table.rb | 8 -------- .../20140307052424_create_team_user_join_table.rb | 8 -------- .../20140307052428_create_match_team_join_table.rb | 8 -------- db/migrate/20140307052443_add_hidden_attrs_to_user.rb | 8 -------- db/migrate/20140325201020_create_servers.rb | 8 ++++++++ db/migrate/20140325201022_create_matches.rb | 11 +++++++++++ db/migrate/20140325201025_create_teams.rb | 9 +++++++++ db/migrate/20140325201027_create_alerts.rb | 10 ++++++++++ db/migrate/20140325201030_create_pms.rb | 11 +++++++++++ db/migrate/20140325201033_create_tournaments.rb | 16 ++++++++++++++++ db/migrate/20140325201035_create_games.rb | 15 +++++++++++++++ db/migrate/20140325201038_create_users.rb | 13 +++++++++++++ db/migrate/20140325201040_create_sessions.rb | 9 +++++++++ db/migrate/20140325201043_create_server_settings.rb | 8 ++++++++ .../20140325201045_create_tournament_options.rb | 12 ++++++++++++ db/migrate/20140325201047_create_game_settings.rb | 15 +++++++++++++++ db/migrate/20140325201050_create_scores.rb | 11 +++++++++++ ...0325201052_create_tournament_players_join_table.rb | 8 ++++++++ ...140325201055_create_tournament_hosts_join_table.rb | 8 ++++++++ .../20140325201057_create_team_user_join_table.rb | 8 ++++++++ .../20140325201059_create_match_team_join_table.rb | 8 ++++++++ db/migrate/20140325201109_add_hidden_attrs_to_user.rb | 8 ++++++++ db/schema.rb | 12 +++++++++--- generate.sh | 2 +- test/fixtures/game_options.yml | 11 ----------- test/fixtures/game_settings.yml | 19 +++++++++++++++++++ test/models/game_option_test.rb | 7 ------- test/models/game_setting_test.rb | 7 +++++++ 44 files changed, 227 insertions(+), 208 deletions(-) delete mode 100644 app/models/game_option.rb create mode 100644 app/models/game_setting.rb delete mode 100644 db/migrate/20140307052327_create_servers.rb delete mode 100644 db/migrate/20140307052331_create_matches.rb delete mode 100644 db/migrate/20140307052334_create_teams.rb delete mode 100644 db/migrate/20140307052338_create_alerts.rb delete mode 100644 db/migrate/20140307052342_create_pms.rb delete mode 100644 db/migrate/20140307052346_create_tournaments.rb delete mode 100644 db/migrate/20140307052350_create_games.rb delete mode 100644 db/migrate/20140307052354_create_users.rb delete mode 100644 db/migrate/20140307052358_create_sessions.rb delete mode 100644 db/migrate/20140307052402_create_server_settings.rb delete mode 100644 db/migrate/20140307052405_create_tournament_options.rb delete mode 100644 db/migrate/20140307052409_create_game_options.rb delete mode 100644 db/migrate/20140307052413_create_scores.rb delete mode 100644 db/migrate/20140307052417_create_tournament_players_join_table.rb delete mode 100644 db/migrate/20140307052421_create_tournament_hosts_join_table.rb delete mode 100644 db/migrate/20140307052424_create_team_user_join_table.rb delete mode 100644 db/migrate/20140307052428_create_match_team_join_table.rb delete mode 100644 db/migrate/20140307052443_add_hidden_attrs_to_user.rb create mode 100644 db/migrate/20140325201020_create_servers.rb create mode 100644 db/migrate/20140325201022_create_matches.rb create mode 100644 db/migrate/20140325201025_create_teams.rb create mode 100644 db/migrate/20140325201027_create_alerts.rb create mode 100644 db/migrate/20140325201030_create_pms.rb create mode 100644 db/migrate/20140325201033_create_tournaments.rb create mode 100644 db/migrate/20140325201035_create_games.rb create mode 100644 db/migrate/20140325201038_create_users.rb create mode 100644 db/migrate/20140325201040_create_sessions.rb create mode 100644 db/migrate/20140325201043_create_server_settings.rb create mode 100644 db/migrate/20140325201045_create_tournament_options.rb create mode 100644 db/migrate/20140325201047_create_game_settings.rb create mode 100644 db/migrate/20140325201050_create_scores.rb create mode 100644 db/migrate/20140325201052_create_tournament_players_join_table.rb create mode 100644 db/migrate/20140325201055_create_tournament_hosts_join_table.rb create mode 100644 db/migrate/20140325201057_create_team_user_join_table.rb create mode 100644 db/migrate/20140325201059_create_match_team_join_table.rb create mode 100644 db/migrate/20140325201109_add_hidden_attrs_to_user.rb delete mode 100644 test/fixtures/game_options.yml create mode 100644 test/fixtures/game_settings.yml delete mode 100644 test/models/game_option_test.rb create mode 100644 test/models/game_setting_test.rb diff --git a/app/models/game_option.rb b/app/models/game_option.rb deleted file mode 100644 index bdc5560..0000000 --- a/app/models/game_option.rb +++ /dev/null @@ -1,2 +0,0 @@ -class GameOption < ActiveRecord::Base -end diff --git a/app/models/game_setting.rb b/app/models/game_setting.rb new file mode 100644 index 0000000..e147b15 --- /dev/null +++ b/app/models/game_setting.rb @@ -0,0 +1,3 @@ +class GameSetting < ActiveRecord::Base + belongs_to :game +end diff --git a/db/migrate/20140307052327_create_servers.rb b/db/migrate/20140307052327_create_servers.rb deleted file mode 100644 index f33241a..0000000 --- a/db/migrate/20140307052327_create_servers.rb +++ /dev/null @@ -1,8 +0,0 @@ -class CreateServers < ActiveRecord::Migration - def change - create_table :servers do |t| - - t.timestamps - end - end -end diff --git a/db/migrate/20140307052331_create_matches.rb b/db/migrate/20140307052331_create_matches.rb deleted file mode 100644 index 67a5b7b..0000000 --- a/db/migrate/20140307052331_create_matches.rb +++ /dev/null @@ -1,11 +0,0 @@ -class CreateMatches < ActiveRecord::Migration - def change - create_table :matches do |t| - t.references :tournament, index: true - t.string :name - t.references :winner, index: true - - t.timestamps - end - end -end diff --git a/db/migrate/20140307052334_create_teams.rb b/db/migrate/20140307052334_create_teams.rb deleted file mode 100644 index fdf9a68..0000000 --- a/db/migrate/20140307052334_create_teams.rb +++ /dev/null @@ -1,9 +0,0 @@ -class CreateTeams < ActiveRecord::Migration - def change - create_table :teams do |t| - t.references :match, index: true - - t.timestamps - end - end -end diff --git a/db/migrate/20140307052338_create_alerts.rb b/db/migrate/20140307052338_create_alerts.rb deleted file mode 100644 index 68a8e10..0000000 --- a/db/migrate/20140307052338_create_alerts.rb +++ /dev/null @@ -1,10 +0,0 @@ -class CreateAlerts < ActiveRecord::Migration - def change - create_table :alerts do |t| - t.references :author, index: true - t.text :message - - t.timestamps - end - end -end diff --git a/db/migrate/20140307052342_create_pms.rb b/db/migrate/20140307052342_create_pms.rb deleted file mode 100644 index 93bb5c6..0000000 --- a/db/migrate/20140307052342_create_pms.rb +++ /dev/null @@ -1,11 +0,0 @@ -class CreatePms < ActiveRecord::Migration - def change - create_table :pms do |t| - t.references :author, index: true - t.references :recipient, index: true - t.text :message - - t.timestamps - end - end -end diff --git a/db/migrate/20140307052346_create_tournaments.rb b/db/migrate/20140307052346_create_tournaments.rb deleted file mode 100644 index 545e603..0000000 --- a/db/migrate/20140307052346_create_tournaments.rb +++ /dev/null @@ -1,16 +0,0 @@ -class CreateTournaments < ActiveRecord::Migration - def change - create_table :tournaments do |t| - t.references :game, index: true - t.integer :status - t.integer :min_players_per_team - t.integer :max_players_per_team - t.integer :min_teams_per_match - t.integer :max_teams_per_match - t.integer :set_rounds - t.boolean :randomized_teams - - t.timestamps - end - end -end diff --git a/db/migrate/20140307052350_create_games.rb b/db/migrate/20140307052350_create_games.rb deleted file mode 100644 index 5e4f56f..0000000 --- a/db/migrate/20140307052350_create_games.rb +++ /dev/null @@ -1,15 +0,0 @@ -class CreateGames < ActiveRecord::Migration - def change - create_table :games do |t| - t.text :name - t.integer :min_players_per_team - t.integer :max_players_per_team - t.integer :min_teams_per_match - t.integer :max_teams_per_match - t.integer :set_rounds - t.boolean :randomized_teams - - t.timestamps - end - end -end diff --git a/db/migrate/20140307052354_create_users.rb b/db/migrate/20140307052354_create_users.rb deleted file mode 100644 index 8032870..0000000 --- a/db/migrate/20140307052354_create_users.rb +++ /dev/null @@ -1,13 +0,0 @@ -class CreateUsers < ActiveRecord::Migration - def change - create_table :users do |t| - t.string :name - t.string :email - t.string :user_name - - t.timestamps - end - add_index :users, :email, unique: true - add_index :users, :user_name, unique: true - end -end diff --git a/db/migrate/20140307052358_create_sessions.rb b/db/migrate/20140307052358_create_sessions.rb deleted file mode 100644 index fe25bf2..0000000 --- a/db/migrate/20140307052358_create_sessions.rb +++ /dev/null @@ -1,9 +0,0 @@ -class CreateSessions < ActiveRecord::Migration - def change - create_table :sessions do |t| - t.references :user, index: true - - t.timestamps - end - end -end diff --git a/db/migrate/20140307052402_create_server_settings.rb b/db/migrate/20140307052402_create_server_settings.rb deleted file mode 100644 index dfdd91b..0000000 --- a/db/migrate/20140307052402_create_server_settings.rb +++ /dev/null @@ -1,8 +0,0 @@ -class CreateServerSettings < ActiveRecord::Migration - def change - create_table :server_settings do |t| - - t.timestamps - end - end -end diff --git a/db/migrate/20140307052405_create_tournament_options.rb b/db/migrate/20140307052405_create_tournament_options.rb deleted file mode 100644 index 53b601c..0000000 --- a/db/migrate/20140307052405_create_tournament_options.rb +++ /dev/null @@ -1,12 +0,0 @@ -class CreateTournamentOptions < ActiveRecord::Migration - def change - create_table :tournament_options do |t| - t.references :tournament, index: true - t.integer :vartype - t.string :name - t.text :value - - t.timestamps - end - end -end diff --git a/db/migrate/20140307052409_create_game_options.rb b/db/migrate/20140307052409_create_game_options.rb deleted file mode 100644 index 2f62ef7..0000000 --- a/db/migrate/20140307052409_create_game_options.rb +++ /dev/null @@ -1,11 +0,0 @@ -class CreateGameOptions < ActiveRecord::Migration - def change - create_table :game_options do |t| - t.integer :vartype - t.string :name - t.text :default - - t.timestamps - end - end -end diff --git a/db/migrate/20140307052413_create_scores.rb b/db/migrate/20140307052413_create_scores.rb deleted file mode 100644 index 4ca0b0b..0000000 --- a/db/migrate/20140307052413_create_scores.rb +++ /dev/null @@ -1,11 +0,0 @@ -class CreateScores < ActiveRecord::Migration - def change - create_table :scores do |t| - t.references :user, index: true - t.references :match, index: true - t.integer :value - - t.timestamps - end - end -end diff --git a/db/migrate/20140307052417_create_tournament_players_join_table.rb b/db/migrate/20140307052417_create_tournament_players_join_table.rb deleted file mode 100644 index be240e8..0000000 --- a/db/migrate/20140307052417_create_tournament_players_join_table.rb +++ /dev/null @@ -1,8 +0,0 @@ -class CreateTournamentPlayersJoinTable < ActiveRecord::Migration - def change - create_join_table :players, :tournaments do |t| - # t.index [:player_id, :tournament_id] - # t.index [:tournament_id, :player_id] - end - end -end diff --git a/db/migrate/20140307052421_create_tournament_hosts_join_table.rb b/db/migrate/20140307052421_create_tournament_hosts_join_table.rb deleted file mode 100644 index 7521d89..0000000 --- a/db/migrate/20140307052421_create_tournament_hosts_join_table.rb +++ /dev/null @@ -1,8 +0,0 @@ -class CreateTournamentHostsJoinTable < ActiveRecord::Migration - def change - create_join_table :hosts, :tournaments do |t| - # t.index [:host_id, :tournament_id] - # t.index [:tournament_id, :host_id] - end - end -end diff --git a/db/migrate/20140307052424_create_team_user_join_table.rb b/db/migrate/20140307052424_create_team_user_join_table.rb deleted file mode 100644 index f3b57fc..0000000 --- a/db/migrate/20140307052424_create_team_user_join_table.rb +++ /dev/null @@ -1,8 +0,0 @@ -class CreateTeamUserJoinTable < ActiveRecord::Migration - def change - create_join_table :teams, :users do |t| - # t.index [:team_id, :user_id] - # t.index [:user_id, :team_id] - end - end -end diff --git a/db/migrate/20140307052428_create_match_team_join_table.rb b/db/migrate/20140307052428_create_match_team_join_table.rb deleted file mode 100644 index c2ed1b7..0000000 --- a/db/migrate/20140307052428_create_match_team_join_table.rb +++ /dev/null @@ -1,8 +0,0 @@ -class CreateMatchTeamJoinTable < ActiveRecord::Migration - def change - create_join_table :matches, :teams do |t| - # t.index [:match_id, :team_id] - # t.index [:team_id, :match_id] - end - end -end diff --git a/db/migrate/20140307052443_add_hidden_attrs_to_user.rb b/db/migrate/20140307052443_add_hidden_attrs_to_user.rb deleted file mode 100644 index 2f1b0b2..0000000 --- a/db/migrate/20140307052443_add_hidden_attrs_to_user.rb +++ /dev/null @@ -1,8 +0,0 @@ -class AddHiddenAttrsToUser < ActiveRecord::Migration - def change - add_column :users, :password_digest, :string - add_column :users, :remember_token, :string - add_index :users, :remember_token, unique: true - add_column :users, :groups, :integer - end -end diff --git a/db/migrate/20140325201020_create_servers.rb b/db/migrate/20140325201020_create_servers.rb new file mode 100644 index 0000000..f33241a --- /dev/null +++ b/db/migrate/20140325201020_create_servers.rb @@ -0,0 +1,8 @@ +class CreateServers < ActiveRecord::Migration + def change + create_table :servers do |t| + + t.timestamps + end + end +end diff --git a/db/migrate/20140325201022_create_matches.rb b/db/migrate/20140325201022_create_matches.rb new file mode 100644 index 0000000..67a5b7b --- /dev/null +++ b/db/migrate/20140325201022_create_matches.rb @@ -0,0 +1,11 @@ +class CreateMatches < ActiveRecord::Migration + def change + create_table :matches do |t| + t.references :tournament, index: true + t.string :name + t.references :winner, index: true + + t.timestamps + end + end +end diff --git a/db/migrate/20140325201025_create_teams.rb b/db/migrate/20140325201025_create_teams.rb new file mode 100644 index 0000000..fdf9a68 --- /dev/null +++ b/db/migrate/20140325201025_create_teams.rb @@ -0,0 +1,9 @@ +class CreateTeams < ActiveRecord::Migration + def change + create_table :teams do |t| + t.references :match, index: true + + t.timestamps + end + end +end diff --git a/db/migrate/20140325201027_create_alerts.rb b/db/migrate/20140325201027_create_alerts.rb new file mode 100644 index 0000000..68a8e10 --- /dev/null +++ b/db/migrate/20140325201027_create_alerts.rb @@ -0,0 +1,10 @@ +class CreateAlerts < ActiveRecord::Migration + def change + create_table :alerts do |t| + t.references :author, index: true + t.text :message + + t.timestamps + end + end +end diff --git a/db/migrate/20140325201030_create_pms.rb b/db/migrate/20140325201030_create_pms.rb new file mode 100644 index 0000000..93bb5c6 --- /dev/null +++ b/db/migrate/20140325201030_create_pms.rb @@ -0,0 +1,11 @@ +class CreatePms < ActiveRecord::Migration + def change + create_table :pms do |t| + t.references :author, index: true + t.references :recipient, index: true + t.text :message + + t.timestamps + end + end +end diff --git a/db/migrate/20140325201033_create_tournaments.rb b/db/migrate/20140325201033_create_tournaments.rb new file mode 100644 index 0000000..545e603 --- /dev/null +++ b/db/migrate/20140325201033_create_tournaments.rb @@ -0,0 +1,16 @@ +class CreateTournaments < ActiveRecord::Migration + def change + create_table :tournaments do |t| + t.references :game, index: true + t.integer :status + t.integer :min_players_per_team + t.integer :max_players_per_team + t.integer :min_teams_per_match + t.integer :max_teams_per_match + t.integer :set_rounds + t.boolean :randomized_teams + + t.timestamps + end + end +end diff --git a/db/migrate/20140325201035_create_games.rb b/db/migrate/20140325201035_create_games.rb new file mode 100644 index 0000000..5e4f56f --- /dev/null +++ b/db/migrate/20140325201035_create_games.rb @@ -0,0 +1,15 @@ +class CreateGames < ActiveRecord::Migration + def change + create_table :games do |t| + t.text :name + t.integer :min_players_per_team + t.integer :max_players_per_team + t.integer :min_teams_per_match + t.integer :max_teams_per_match + t.integer :set_rounds + t.boolean :randomized_teams + + t.timestamps + end + end +end diff --git a/db/migrate/20140325201038_create_users.rb b/db/migrate/20140325201038_create_users.rb new file mode 100644 index 0000000..8032870 --- /dev/null +++ b/db/migrate/20140325201038_create_users.rb @@ -0,0 +1,13 @@ +class CreateUsers < ActiveRecord::Migration + def change + create_table :users do |t| + t.string :name + t.string :email + t.string :user_name + + t.timestamps + end + add_index :users, :email, unique: true + add_index :users, :user_name, unique: true + end +end diff --git a/db/migrate/20140325201040_create_sessions.rb b/db/migrate/20140325201040_create_sessions.rb new file mode 100644 index 0000000..fe25bf2 --- /dev/null +++ b/db/migrate/20140325201040_create_sessions.rb @@ -0,0 +1,9 @@ +class CreateSessions < ActiveRecord::Migration + def change + create_table :sessions do |t| + t.references :user, index: true + + t.timestamps + end + end +end diff --git a/db/migrate/20140325201043_create_server_settings.rb b/db/migrate/20140325201043_create_server_settings.rb new file mode 100644 index 0000000..dfdd91b --- /dev/null +++ b/db/migrate/20140325201043_create_server_settings.rb @@ -0,0 +1,8 @@ +class CreateServerSettings < ActiveRecord::Migration + def change + create_table :server_settings do |t| + + t.timestamps + end + end +end diff --git a/db/migrate/20140325201045_create_tournament_options.rb b/db/migrate/20140325201045_create_tournament_options.rb new file mode 100644 index 0000000..53b601c --- /dev/null +++ b/db/migrate/20140325201045_create_tournament_options.rb @@ -0,0 +1,12 @@ +class CreateTournamentOptions < ActiveRecord::Migration + def change + create_table :tournament_options do |t| + t.references :tournament, index: true + t.integer :vartype + t.string :name + t.text :value + + t.timestamps + end + end +end diff --git a/db/migrate/20140325201047_create_game_settings.rb b/db/migrate/20140325201047_create_game_settings.rb new file mode 100644 index 0000000..0ebbf18 --- /dev/null +++ b/db/migrate/20140325201047_create_game_settings.rb @@ -0,0 +1,15 @@ +class CreateGameSettings < ActiveRecord::Migration + def change + create_table :game_settings do |t| + t.references :game, index: true + t.integer :type + t.string :name + t.text :default + t.text :discription + t.text :type_opt + t.integer :display_order + + t.timestamps + end + end +end diff --git a/db/migrate/20140325201050_create_scores.rb b/db/migrate/20140325201050_create_scores.rb new file mode 100644 index 0000000..4ca0b0b --- /dev/null +++ b/db/migrate/20140325201050_create_scores.rb @@ -0,0 +1,11 @@ +class CreateScores < ActiveRecord::Migration + def change + create_table :scores do |t| + t.references :user, index: true + t.references :match, index: true + t.integer :value + + t.timestamps + end + end +end diff --git a/db/migrate/20140325201052_create_tournament_players_join_table.rb b/db/migrate/20140325201052_create_tournament_players_join_table.rb new file mode 100644 index 0000000..be240e8 --- /dev/null +++ b/db/migrate/20140325201052_create_tournament_players_join_table.rb @@ -0,0 +1,8 @@ +class CreateTournamentPlayersJoinTable < ActiveRecord::Migration + def change + create_join_table :players, :tournaments do |t| + # t.index [:player_id, :tournament_id] + # t.index [:tournament_id, :player_id] + end + end +end diff --git a/db/migrate/20140325201055_create_tournament_hosts_join_table.rb b/db/migrate/20140325201055_create_tournament_hosts_join_table.rb new file mode 100644 index 0000000..7521d89 --- /dev/null +++ b/db/migrate/20140325201055_create_tournament_hosts_join_table.rb @@ -0,0 +1,8 @@ +class CreateTournamentHostsJoinTable < ActiveRecord::Migration + def change + create_join_table :hosts, :tournaments do |t| + # t.index [:host_id, :tournament_id] + # t.index [:tournament_id, :host_id] + end + end +end diff --git a/db/migrate/20140325201057_create_team_user_join_table.rb b/db/migrate/20140325201057_create_team_user_join_table.rb new file mode 100644 index 0000000..f3b57fc --- /dev/null +++ b/db/migrate/20140325201057_create_team_user_join_table.rb @@ -0,0 +1,8 @@ +class CreateTeamUserJoinTable < ActiveRecord::Migration + def change + create_join_table :teams, :users do |t| + # t.index [:team_id, :user_id] + # t.index [:user_id, :team_id] + end + end +end diff --git a/db/migrate/20140325201059_create_match_team_join_table.rb b/db/migrate/20140325201059_create_match_team_join_table.rb new file mode 100644 index 0000000..c2ed1b7 --- /dev/null +++ b/db/migrate/20140325201059_create_match_team_join_table.rb @@ -0,0 +1,8 @@ +class CreateMatchTeamJoinTable < ActiveRecord::Migration + def change + create_join_table :matches, :teams do |t| + # t.index [:match_id, :team_id] + # t.index [:team_id, :match_id] + end + end +end diff --git a/db/migrate/20140325201109_add_hidden_attrs_to_user.rb b/db/migrate/20140325201109_add_hidden_attrs_to_user.rb new file mode 100644 index 0000000..2f1b0b2 --- /dev/null +++ b/db/migrate/20140325201109_add_hidden_attrs_to_user.rb @@ -0,0 +1,8 @@ +class AddHiddenAttrsToUser < ActiveRecord::Migration + def change + add_column :users, :password_digest, :string + add_column :users, :remember_token, :string + add_index :users, :remember_token, unique: true + add_column :users, :groups, :integer + end +end diff --git a/db/schema.rb b/db/schema.rb index 55f4046..0394946 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20140307052443) do +ActiveRecord::Schema.define(version: 20140325201109) do create_table "alerts", force: true do |t| t.integer "author_id" @@ -22,14 +22,20 @@ ActiveRecord::Schema.define(version: 20140307052443) do add_index "alerts", ["author_id"], name: "index_alerts_on_author_id" - create_table "game_options", force: true do |t| - t.integer "vartype" + create_table "game_settings", force: true do |t| + t.integer "game_id" + t.integer "type" t.string "name" t.text "default" + t.text "discription" + t.text "type_opt" + t.integer "display_order" t.datetime "created_at" t.datetime "updated_at" end + add_index "game_settings", ["game_id"], name: "index_game_settings_on_game_id" + create_table "games", force: true do |t| t.text "name" t.integer "min_players_per_team" diff --git a/generate.sh b/generate.sh index 45a8ab6..5079abd 100755 --- a/generate.sh +++ b/generate.sh @@ -37,7 +37,7 @@ bundle exec rails generate scaffold session user:references # Just models bundle exec rails generate model server_settings $NOTEST bundle exec rails generate model tournament_option tournament:references vartype:integer name:string value:text $NOTEST -bundle exec rails generate model game_option vartype:integer name:string default:text $NOTEST +bundle exec rails generate model game_setting game:references type:integer name:string default:text discription:text type_opt:text display_order:integer $NOTEST bundle exec rails generate model score user:references match:references value:integer $NOTEST # Join tables diff --git a/test/fixtures/game_options.yml b/test/fixtures/game_options.yml deleted file mode 100644 index eb4760a..0000000 --- a/test/fixtures/game_options.yml +++ /dev/null @@ -1,11 +0,0 @@ -# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html - -one: - vartype: 1 - name: MyString - default: MyText - -two: - vartype: 1 - name: MyString - default: MyText diff --git a/test/fixtures/game_settings.yml b/test/fixtures/game_settings.yml new file mode 100644 index 0000000..5626c97 --- /dev/null +++ b/test/fixtures/game_settings.yml @@ -0,0 +1,19 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + game_id: + type: 1 + name: MyString + default: MyText + discription: MyText + type_opt: MyText + display_order: 1 + +two: + game_id: + type: 1 + name: MyString + default: MyText + discription: MyText + type_opt: MyText + display_order: 1 diff --git a/test/models/game_option_test.rb b/test/models/game_option_test.rb deleted file mode 100644 index 1ae5701..0000000 --- a/test/models/game_option_test.rb +++ /dev/null @@ -1,7 +0,0 @@ -require 'test_helper' - -class GameOptionTest < ActiveSupport::TestCase - # test "the truth" do - # assert true - # end -end diff --git a/test/models/game_setting_test.rb b/test/models/game_setting_test.rb new file mode 100644 index 0000000..8ab8bcf --- /dev/null +++ b/test/models/game_setting_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class GameSettingTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end -- cgit v1.2.3-54-g00ecf From 4e754e04d6bd04267e5a55011aa9f4f2a2fc7859 Mon Sep 17 00:00:00 2001 From: guntasgrewal Date: Tue, 25 Mar 2014 16:30:13 -0400 Subject: Tournament has a NAME now --- app/controllers/tournaments_controller.rb | 2 +- app/views/tournaments/_form.html.erb | 4 ++++ app/views/tournaments/index.html.erb | 2 ++ app/views/tournaments/index.json.jbuilder | 2 +- app/views/tournaments/show.html.erb | 5 +++++ app/views/tournaments/show.json.jbuilder | 2 +- db/migrate/20140325201020_create_servers.rb | 8 -------- db/migrate/20140325201022_create_matches.rb | 11 ----------- db/migrate/20140325201025_create_teams.rb | 9 --------- db/migrate/20140325201027_create_alerts.rb | 10 ---------- db/migrate/20140325201030_create_pms.rb | 11 ----------- db/migrate/20140325201033_create_tournaments.rb | 16 ---------------- db/migrate/20140325201035_create_games.rb | 15 --------------- db/migrate/20140325201038_create_users.rb | 13 ------------- db/migrate/20140325201040_create_sessions.rb | 9 --------- db/migrate/20140325201043_create_server_settings.rb | 8 -------- db/migrate/20140325201045_create_tournament_options.rb | 12 ------------ db/migrate/20140325201047_create_game_settings.rb | 15 --------------- db/migrate/20140325201050_create_scores.rb | 11 ----------- ...140325201052_create_tournament_players_join_table.rb | 8 -------- ...20140325201055_create_tournament_hosts_join_table.rb | 8 -------- .../20140325201057_create_team_user_join_table.rb | 8 -------- .../20140325201059_create_match_team_join_table.rb | 8 -------- db/migrate/20140325201109_add_hidden_attrs_to_user.rb | 8 -------- db/migrate/20140325202820_create_servers.rb | 8 ++++++++ db/migrate/20140325202823_create_matches.rb | 11 +++++++++++ db/migrate/20140325202826_create_teams.rb | 9 +++++++++ db/migrate/20140325202828_create_alerts.rb | 10 ++++++++++ db/migrate/20140325202831_create_pms.rb | 11 +++++++++++ db/migrate/20140325202833_create_tournaments.rb | 17 +++++++++++++++++ db/migrate/20140325202836_create_games.rb | 15 +++++++++++++++ db/migrate/20140325202838_create_users.rb | 13 +++++++++++++ db/migrate/20140325202841_create_sessions.rb | 9 +++++++++ db/migrate/20140325202843_create_server_settings.rb | 8 ++++++++ db/migrate/20140325202846_create_tournament_options.rb | 12 ++++++++++++ db/migrate/20140325202848_create_game_settings.rb | 15 +++++++++++++++ db/migrate/20140325202850_create_scores.rb | 11 +++++++++++ ...140325202853_create_tournament_players_join_table.rb | 8 ++++++++ ...20140325202855_create_tournament_hosts_join_table.rb | 8 ++++++++ .../20140325202858_create_team_user_join_table.rb | 8 ++++++++ .../20140325202900_create_match_team_join_table.rb | 8 ++++++++ db/migrate/20140325202910_add_hidden_attrs_to_user.rb | 8 ++++++++ db/schema.rb | 3 ++- generate.sh | 2 +- test/controllers/tournaments_controller_test.rb | 4 ++-- test/fixtures/tournaments.yml | 2 ++ 46 files changed, 210 insertions(+), 195 deletions(-) delete mode 100644 db/migrate/20140325201020_create_servers.rb delete mode 100644 db/migrate/20140325201022_create_matches.rb delete mode 100644 db/migrate/20140325201025_create_teams.rb delete mode 100644 db/migrate/20140325201027_create_alerts.rb delete mode 100644 db/migrate/20140325201030_create_pms.rb delete mode 100644 db/migrate/20140325201033_create_tournaments.rb delete mode 100644 db/migrate/20140325201035_create_games.rb delete mode 100644 db/migrate/20140325201038_create_users.rb delete mode 100644 db/migrate/20140325201040_create_sessions.rb delete mode 100644 db/migrate/20140325201043_create_server_settings.rb delete mode 100644 db/migrate/20140325201045_create_tournament_options.rb delete mode 100644 db/migrate/20140325201047_create_game_settings.rb delete mode 100644 db/migrate/20140325201050_create_scores.rb delete mode 100644 db/migrate/20140325201052_create_tournament_players_join_table.rb delete mode 100644 db/migrate/20140325201055_create_tournament_hosts_join_table.rb delete mode 100644 db/migrate/20140325201057_create_team_user_join_table.rb delete mode 100644 db/migrate/20140325201059_create_match_team_join_table.rb delete mode 100644 db/migrate/20140325201109_add_hidden_attrs_to_user.rb create mode 100644 db/migrate/20140325202820_create_servers.rb create mode 100644 db/migrate/20140325202823_create_matches.rb create mode 100644 db/migrate/20140325202826_create_teams.rb create mode 100644 db/migrate/20140325202828_create_alerts.rb create mode 100644 db/migrate/20140325202831_create_pms.rb create mode 100644 db/migrate/20140325202833_create_tournaments.rb create mode 100644 db/migrate/20140325202836_create_games.rb create mode 100644 db/migrate/20140325202838_create_users.rb create mode 100644 db/migrate/20140325202841_create_sessions.rb create mode 100644 db/migrate/20140325202843_create_server_settings.rb create mode 100644 db/migrate/20140325202846_create_tournament_options.rb create mode 100644 db/migrate/20140325202848_create_game_settings.rb create mode 100644 db/migrate/20140325202850_create_scores.rb create mode 100644 db/migrate/20140325202853_create_tournament_players_join_table.rb create mode 100644 db/migrate/20140325202855_create_tournament_hosts_join_table.rb create mode 100644 db/migrate/20140325202858_create_team_user_join_table.rb create mode 100644 db/migrate/20140325202900_create_match_team_join_table.rb create mode 100644 db/migrate/20140325202910_add_hidden_attrs_to_user.rb diff --git a/app/controllers/tournaments_controller.rb b/app/controllers/tournaments_controller.rb index 571203c..d7db632 100644 --- a/app/controllers/tournaments_controller.rb +++ b/app/controllers/tournaments_controller.rb @@ -69,6 +69,6 @@ class TournamentsController < ApplicationController # Never trust parameters from the scary internet, only allow the white list through. def tournament_params - params.require(:tournament).permit(:game_id, :status, :min_players_per_team, :max_players_per_team, :min_teams_per_match, :max_teams_per_match, :set_rounds, :randomized_teams) + params.require(:tournament).permit(:name, :game_id, :status, :min_players_per_team, :max_players_per_team, :min_teams_per_match, :max_teams_per_match, :set_rounds, :randomized_teams) end end diff --git a/app/views/tournaments/_form.html.erb b/app/views/tournaments/_form.html.erb index d098cbb..38855a0 100644 --- a/app/views/tournaments/_form.html.erb +++ b/app/views/tournaments/_form.html.erb @@ -11,6 +11,10 @@ <% end %> +
+ <%= f.label :name %>
+ <%= f.text_field :name %> +
<%= f.label :game_id %>
<%= f.text_field :game_id %> diff --git a/app/views/tournaments/index.html.erb b/app/views/tournaments/index.html.erb index fb8b381..f8f21e7 100644 --- a/app/views/tournaments/index.html.erb +++ b/app/views/tournaments/index.html.erb @@ -3,6 +3,7 @@ + @@ -20,6 +21,7 @@ <% @tournaments.each do |tournament| %> + diff --git a/app/views/tournaments/index.json.jbuilder b/app/views/tournaments/index.json.jbuilder index e95c6a7..4038f04 100644 --- a/app/views/tournaments/index.json.jbuilder +++ b/app/views/tournaments/index.json.jbuilder @@ -1,4 +1,4 @@ json.array!(@tournaments) do |tournament| - json.extract! tournament, :id, :game_id, :status, :min_players_per_team, :max_players_per_team, :min_teams_per_match, :max_teams_per_match, :set_rounds, :randomized_teams + json.extract! tournament, :id, :name, :game_id, :status, :min_players_per_team, :max_players_per_team, :min_teams_per_match, :max_teams_per_match, :set_rounds, :randomized_teams json.url tournament_url(tournament, format: :json) end diff --git a/app/views/tournaments/show.html.erb b/app/views/tournaments/show.html.erb index 208c6f4..3cb6179 100644 --- a/app/views/tournaments/show.html.erb +++ b/app/views/tournaments/show.html.erb @@ -1,5 +1,10 @@

<%= notice %>

+

+ Name: + <%= @tournament.name %> +

+

Game: <%= @tournament.game %> diff --git a/app/views/tournaments/show.json.jbuilder b/app/views/tournaments/show.json.jbuilder index de2fbe0..27fd5c0 100644 --- a/app/views/tournaments/show.json.jbuilder +++ b/app/views/tournaments/show.json.jbuilder @@ -1 +1 @@ -json.extract! @tournament, :id, :game_id, :status, :min_players_per_team, :max_players_per_team, :min_teams_per_match, :max_teams_per_match, :set_rounds, :randomized_teams, :created_at, :updated_at +json.extract! @tournament, :id, :name, :game_id, :status, :min_players_per_team, :max_players_per_team, :min_teams_per_match, :max_teams_per_match, :set_rounds, :randomized_teams, :created_at, :updated_at diff --git a/db/migrate/20140325201020_create_servers.rb b/db/migrate/20140325201020_create_servers.rb deleted file mode 100644 index f33241a..0000000 --- a/db/migrate/20140325201020_create_servers.rb +++ /dev/null @@ -1,8 +0,0 @@ -class CreateServers < ActiveRecord::Migration - def change - create_table :servers do |t| - - t.timestamps - end - end -end diff --git a/db/migrate/20140325201022_create_matches.rb b/db/migrate/20140325201022_create_matches.rb deleted file mode 100644 index 67a5b7b..0000000 --- a/db/migrate/20140325201022_create_matches.rb +++ /dev/null @@ -1,11 +0,0 @@ -class CreateMatches < ActiveRecord::Migration - def change - create_table :matches do |t| - t.references :tournament, index: true - t.string :name - t.references :winner, index: true - - t.timestamps - end - end -end diff --git a/db/migrate/20140325201025_create_teams.rb b/db/migrate/20140325201025_create_teams.rb deleted file mode 100644 index fdf9a68..0000000 --- a/db/migrate/20140325201025_create_teams.rb +++ /dev/null @@ -1,9 +0,0 @@ -class CreateTeams < ActiveRecord::Migration - def change - create_table :teams do |t| - t.references :match, index: true - - t.timestamps - end - end -end diff --git a/db/migrate/20140325201027_create_alerts.rb b/db/migrate/20140325201027_create_alerts.rb deleted file mode 100644 index 68a8e10..0000000 --- a/db/migrate/20140325201027_create_alerts.rb +++ /dev/null @@ -1,10 +0,0 @@ -class CreateAlerts < ActiveRecord::Migration - def change - create_table :alerts do |t| - t.references :author, index: true - t.text :message - - t.timestamps - end - end -end diff --git a/db/migrate/20140325201030_create_pms.rb b/db/migrate/20140325201030_create_pms.rb deleted file mode 100644 index 93bb5c6..0000000 --- a/db/migrate/20140325201030_create_pms.rb +++ /dev/null @@ -1,11 +0,0 @@ -class CreatePms < ActiveRecord::Migration - def change - create_table :pms do |t| - t.references :author, index: true - t.references :recipient, index: true - t.text :message - - t.timestamps - end - end -end diff --git a/db/migrate/20140325201033_create_tournaments.rb b/db/migrate/20140325201033_create_tournaments.rb deleted file mode 100644 index 545e603..0000000 --- a/db/migrate/20140325201033_create_tournaments.rb +++ /dev/null @@ -1,16 +0,0 @@ -class CreateTournaments < ActiveRecord::Migration - def change - create_table :tournaments do |t| - t.references :game, index: true - t.integer :status - t.integer :min_players_per_team - t.integer :max_players_per_team - t.integer :min_teams_per_match - t.integer :max_teams_per_match - t.integer :set_rounds - t.boolean :randomized_teams - - t.timestamps - end - end -end diff --git a/db/migrate/20140325201035_create_games.rb b/db/migrate/20140325201035_create_games.rb deleted file mode 100644 index 5e4f56f..0000000 --- a/db/migrate/20140325201035_create_games.rb +++ /dev/null @@ -1,15 +0,0 @@ -class CreateGames < ActiveRecord::Migration - def change - create_table :games do |t| - t.text :name - t.integer :min_players_per_team - t.integer :max_players_per_team - t.integer :min_teams_per_match - t.integer :max_teams_per_match - t.integer :set_rounds - t.boolean :randomized_teams - - t.timestamps - end - end -end diff --git a/db/migrate/20140325201038_create_users.rb b/db/migrate/20140325201038_create_users.rb deleted file mode 100644 index 8032870..0000000 --- a/db/migrate/20140325201038_create_users.rb +++ /dev/null @@ -1,13 +0,0 @@ -class CreateUsers < ActiveRecord::Migration - def change - create_table :users do |t| - t.string :name - t.string :email - t.string :user_name - - t.timestamps - end - add_index :users, :email, unique: true - add_index :users, :user_name, unique: true - end -end diff --git a/db/migrate/20140325201040_create_sessions.rb b/db/migrate/20140325201040_create_sessions.rb deleted file mode 100644 index fe25bf2..0000000 --- a/db/migrate/20140325201040_create_sessions.rb +++ /dev/null @@ -1,9 +0,0 @@ -class CreateSessions < ActiveRecord::Migration - def change - create_table :sessions do |t| - t.references :user, index: true - - t.timestamps - end - end -end diff --git a/db/migrate/20140325201043_create_server_settings.rb b/db/migrate/20140325201043_create_server_settings.rb deleted file mode 100644 index dfdd91b..0000000 --- a/db/migrate/20140325201043_create_server_settings.rb +++ /dev/null @@ -1,8 +0,0 @@ -class CreateServerSettings < ActiveRecord::Migration - def change - create_table :server_settings do |t| - - t.timestamps - end - end -end diff --git a/db/migrate/20140325201045_create_tournament_options.rb b/db/migrate/20140325201045_create_tournament_options.rb deleted file mode 100644 index 53b601c..0000000 --- a/db/migrate/20140325201045_create_tournament_options.rb +++ /dev/null @@ -1,12 +0,0 @@ -class CreateTournamentOptions < ActiveRecord::Migration - def change - create_table :tournament_options do |t| - t.references :tournament, index: true - t.integer :vartype - t.string :name - t.text :value - - t.timestamps - end - end -end diff --git a/db/migrate/20140325201047_create_game_settings.rb b/db/migrate/20140325201047_create_game_settings.rb deleted file mode 100644 index 0ebbf18..0000000 --- a/db/migrate/20140325201047_create_game_settings.rb +++ /dev/null @@ -1,15 +0,0 @@ -class CreateGameSettings < ActiveRecord::Migration - def change - create_table :game_settings do |t| - t.references :game, index: true - t.integer :type - t.string :name - t.text :default - t.text :discription - t.text :type_opt - t.integer :display_order - - t.timestamps - end - end -end diff --git a/db/migrate/20140325201050_create_scores.rb b/db/migrate/20140325201050_create_scores.rb deleted file mode 100644 index 4ca0b0b..0000000 --- a/db/migrate/20140325201050_create_scores.rb +++ /dev/null @@ -1,11 +0,0 @@ -class CreateScores < ActiveRecord::Migration - def change - create_table :scores do |t| - t.references :user, index: true - t.references :match, index: true - t.integer :value - - t.timestamps - end - end -end diff --git a/db/migrate/20140325201052_create_tournament_players_join_table.rb b/db/migrate/20140325201052_create_tournament_players_join_table.rb deleted file mode 100644 index be240e8..0000000 --- a/db/migrate/20140325201052_create_tournament_players_join_table.rb +++ /dev/null @@ -1,8 +0,0 @@ -class CreateTournamentPlayersJoinTable < ActiveRecord::Migration - def change - create_join_table :players, :tournaments do |t| - # t.index [:player_id, :tournament_id] - # t.index [:tournament_id, :player_id] - end - end -end diff --git a/db/migrate/20140325201055_create_tournament_hosts_join_table.rb b/db/migrate/20140325201055_create_tournament_hosts_join_table.rb deleted file mode 100644 index 7521d89..0000000 --- a/db/migrate/20140325201055_create_tournament_hosts_join_table.rb +++ /dev/null @@ -1,8 +0,0 @@ -class CreateTournamentHostsJoinTable < ActiveRecord::Migration - def change - create_join_table :hosts, :tournaments do |t| - # t.index [:host_id, :tournament_id] - # t.index [:tournament_id, :host_id] - end - end -end diff --git a/db/migrate/20140325201057_create_team_user_join_table.rb b/db/migrate/20140325201057_create_team_user_join_table.rb deleted file mode 100644 index f3b57fc..0000000 --- a/db/migrate/20140325201057_create_team_user_join_table.rb +++ /dev/null @@ -1,8 +0,0 @@ -class CreateTeamUserJoinTable < ActiveRecord::Migration - def change - create_join_table :teams, :users do |t| - # t.index [:team_id, :user_id] - # t.index [:user_id, :team_id] - end - end -end diff --git a/db/migrate/20140325201059_create_match_team_join_table.rb b/db/migrate/20140325201059_create_match_team_join_table.rb deleted file mode 100644 index c2ed1b7..0000000 --- a/db/migrate/20140325201059_create_match_team_join_table.rb +++ /dev/null @@ -1,8 +0,0 @@ -class CreateMatchTeamJoinTable < ActiveRecord::Migration - def change - create_join_table :matches, :teams do |t| - # t.index [:match_id, :team_id] - # t.index [:team_id, :match_id] - end - end -end diff --git a/db/migrate/20140325201109_add_hidden_attrs_to_user.rb b/db/migrate/20140325201109_add_hidden_attrs_to_user.rb deleted file mode 100644 index 2f1b0b2..0000000 --- a/db/migrate/20140325201109_add_hidden_attrs_to_user.rb +++ /dev/null @@ -1,8 +0,0 @@ -class AddHiddenAttrsToUser < ActiveRecord::Migration - def change - add_column :users, :password_digest, :string - add_column :users, :remember_token, :string - add_index :users, :remember_token, unique: true - add_column :users, :groups, :integer - end -end diff --git a/db/migrate/20140325202820_create_servers.rb b/db/migrate/20140325202820_create_servers.rb new file mode 100644 index 0000000..f33241a --- /dev/null +++ b/db/migrate/20140325202820_create_servers.rb @@ -0,0 +1,8 @@ +class CreateServers < ActiveRecord::Migration + def change + create_table :servers do |t| + + t.timestamps + end + end +end diff --git a/db/migrate/20140325202823_create_matches.rb b/db/migrate/20140325202823_create_matches.rb new file mode 100644 index 0000000..67a5b7b --- /dev/null +++ b/db/migrate/20140325202823_create_matches.rb @@ -0,0 +1,11 @@ +class CreateMatches < ActiveRecord::Migration + def change + create_table :matches do |t| + t.references :tournament, index: true + t.string :name + t.references :winner, index: true + + t.timestamps + end + end +end diff --git a/db/migrate/20140325202826_create_teams.rb b/db/migrate/20140325202826_create_teams.rb new file mode 100644 index 0000000..fdf9a68 --- /dev/null +++ b/db/migrate/20140325202826_create_teams.rb @@ -0,0 +1,9 @@ +class CreateTeams < ActiveRecord::Migration + def change + create_table :teams do |t| + t.references :match, index: true + + t.timestamps + end + end +end diff --git a/db/migrate/20140325202828_create_alerts.rb b/db/migrate/20140325202828_create_alerts.rb new file mode 100644 index 0000000..68a8e10 --- /dev/null +++ b/db/migrate/20140325202828_create_alerts.rb @@ -0,0 +1,10 @@ +class CreateAlerts < ActiveRecord::Migration + def change + create_table :alerts do |t| + t.references :author, index: true + t.text :message + + t.timestamps + end + end +end diff --git a/db/migrate/20140325202831_create_pms.rb b/db/migrate/20140325202831_create_pms.rb new file mode 100644 index 0000000..93bb5c6 --- /dev/null +++ b/db/migrate/20140325202831_create_pms.rb @@ -0,0 +1,11 @@ +class CreatePms < ActiveRecord::Migration + def change + create_table :pms do |t| + t.references :author, index: true + t.references :recipient, index: true + t.text :message + + t.timestamps + end + end +end diff --git a/db/migrate/20140325202833_create_tournaments.rb b/db/migrate/20140325202833_create_tournaments.rb new file mode 100644 index 0000000..c0d8929 --- /dev/null +++ b/db/migrate/20140325202833_create_tournaments.rb @@ -0,0 +1,17 @@ +class CreateTournaments < ActiveRecord::Migration + def change + create_table :tournaments do |t| + t.string :name + t.references :game, index: true + t.integer :status + t.integer :min_players_per_team + t.integer :max_players_per_team + t.integer :min_teams_per_match + t.integer :max_teams_per_match + t.integer :set_rounds + t.boolean :randomized_teams + + t.timestamps + end + end +end diff --git a/db/migrate/20140325202836_create_games.rb b/db/migrate/20140325202836_create_games.rb new file mode 100644 index 0000000..5e4f56f --- /dev/null +++ b/db/migrate/20140325202836_create_games.rb @@ -0,0 +1,15 @@ +class CreateGames < ActiveRecord::Migration + def change + create_table :games do |t| + t.text :name + t.integer :min_players_per_team + t.integer :max_players_per_team + t.integer :min_teams_per_match + t.integer :max_teams_per_match + t.integer :set_rounds + t.boolean :randomized_teams + + t.timestamps + end + end +end diff --git a/db/migrate/20140325202838_create_users.rb b/db/migrate/20140325202838_create_users.rb new file mode 100644 index 0000000..8032870 --- /dev/null +++ b/db/migrate/20140325202838_create_users.rb @@ -0,0 +1,13 @@ +class CreateUsers < ActiveRecord::Migration + def change + create_table :users do |t| + t.string :name + t.string :email + t.string :user_name + + t.timestamps + end + add_index :users, :email, unique: true + add_index :users, :user_name, unique: true + end +end diff --git a/db/migrate/20140325202841_create_sessions.rb b/db/migrate/20140325202841_create_sessions.rb new file mode 100644 index 0000000..fe25bf2 --- /dev/null +++ b/db/migrate/20140325202841_create_sessions.rb @@ -0,0 +1,9 @@ +class CreateSessions < ActiveRecord::Migration + def change + create_table :sessions do |t| + t.references :user, index: true + + t.timestamps + end + end +end diff --git a/db/migrate/20140325202843_create_server_settings.rb b/db/migrate/20140325202843_create_server_settings.rb new file mode 100644 index 0000000..dfdd91b --- /dev/null +++ b/db/migrate/20140325202843_create_server_settings.rb @@ -0,0 +1,8 @@ +class CreateServerSettings < ActiveRecord::Migration + def change + create_table :server_settings do |t| + + t.timestamps + end + end +end diff --git a/db/migrate/20140325202846_create_tournament_options.rb b/db/migrate/20140325202846_create_tournament_options.rb new file mode 100644 index 0000000..53b601c --- /dev/null +++ b/db/migrate/20140325202846_create_tournament_options.rb @@ -0,0 +1,12 @@ +class CreateTournamentOptions < ActiveRecord::Migration + def change + create_table :tournament_options do |t| + t.references :tournament, index: true + t.integer :vartype + t.string :name + t.text :value + + t.timestamps + end + end +end diff --git a/db/migrate/20140325202848_create_game_settings.rb b/db/migrate/20140325202848_create_game_settings.rb new file mode 100644 index 0000000..0ebbf18 --- /dev/null +++ b/db/migrate/20140325202848_create_game_settings.rb @@ -0,0 +1,15 @@ +class CreateGameSettings < ActiveRecord::Migration + def change + create_table :game_settings do |t| + t.references :game, index: true + t.integer :type + t.string :name + t.text :default + t.text :discription + t.text :type_opt + t.integer :display_order + + t.timestamps + end + end +end diff --git a/db/migrate/20140325202850_create_scores.rb b/db/migrate/20140325202850_create_scores.rb new file mode 100644 index 0000000..4ca0b0b --- /dev/null +++ b/db/migrate/20140325202850_create_scores.rb @@ -0,0 +1,11 @@ +class CreateScores < ActiveRecord::Migration + def change + create_table :scores do |t| + t.references :user, index: true + t.references :match, index: true + t.integer :value + + t.timestamps + end + end +end diff --git a/db/migrate/20140325202853_create_tournament_players_join_table.rb b/db/migrate/20140325202853_create_tournament_players_join_table.rb new file mode 100644 index 0000000..be240e8 --- /dev/null +++ b/db/migrate/20140325202853_create_tournament_players_join_table.rb @@ -0,0 +1,8 @@ +class CreateTournamentPlayersJoinTable < ActiveRecord::Migration + def change + create_join_table :players, :tournaments do |t| + # t.index [:player_id, :tournament_id] + # t.index [:tournament_id, :player_id] + end + end +end diff --git a/db/migrate/20140325202855_create_tournament_hosts_join_table.rb b/db/migrate/20140325202855_create_tournament_hosts_join_table.rb new file mode 100644 index 0000000..7521d89 --- /dev/null +++ b/db/migrate/20140325202855_create_tournament_hosts_join_table.rb @@ -0,0 +1,8 @@ +class CreateTournamentHostsJoinTable < ActiveRecord::Migration + def change + create_join_table :hosts, :tournaments do |t| + # t.index [:host_id, :tournament_id] + # t.index [:tournament_id, :host_id] + end + end +end diff --git a/db/migrate/20140325202858_create_team_user_join_table.rb b/db/migrate/20140325202858_create_team_user_join_table.rb new file mode 100644 index 0000000..f3b57fc --- /dev/null +++ b/db/migrate/20140325202858_create_team_user_join_table.rb @@ -0,0 +1,8 @@ +class CreateTeamUserJoinTable < ActiveRecord::Migration + def change + create_join_table :teams, :users do |t| + # t.index [:team_id, :user_id] + # t.index [:user_id, :team_id] + end + end +end diff --git a/db/migrate/20140325202900_create_match_team_join_table.rb b/db/migrate/20140325202900_create_match_team_join_table.rb new file mode 100644 index 0000000..c2ed1b7 --- /dev/null +++ b/db/migrate/20140325202900_create_match_team_join_table.rb @@ -0,0 +1,8 @@ +class CreateMatchTeamJoinTable < ActiveRecord::Migration + def change + create_join_table :matches, :teams do |t| + # t.index [:match_id, :team_id] + # t.index [:team_id, :match_id] + end + end +end diff --git a/db/migrate/20140325202910_add_hidden_attrs_to_user.rb b/db/migrate/20140325202910_add_hidden_attrs_to_user.rb new file mode 100644 index 0000000..2f1b0b2 --- /dev/null +++ b/db/migrate/20140325202910_add_hidden_attrs_to_user.rb @@ -0,0 +1,8 @@ +class AddHiddenAttrsToUser < ActiveRecord::Migration + def change + add_column :users, :password_digest, :string + add_column :users, :remember_token, :string + add_index :users, :remember_token, unique: true + add_column :users, :groups, :integer + end +end diff --git a/db/schema.rb b/db/schema.rb index 0394946..952cb26 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20140325201109) do +ActiveRecord::Schema.define(version: 20140325202910) do create_table "alerts", force: true do |t| t.integer "author_id" @@ -139,6 +139,7 @@ ActiveRecord::Schema.define(version: 20140325201109) do add_index "tournament_options", ["tournament_id"], name: "index_tournament_options_on_tournament_id" create_table "tournaments", force: true do |t| + t.string "name" t.integer "game_id" t.integer "status" t.integer "min_players_per_team" diff --git a/generate.sh b/generate.sh index 5079abd..1ff486f 100755 --- a/generate.sh +++ b/generate.sh @@ -22,7 +22,7 @@ bundle exec rails generate scaffold match tournament:references name:string winn bundle exec rails generate scaffold team match:references $NOTEST bundle exec rails generate scaffold alert author:references message:text $NOTEST bundle exec rails generate scaffold pm author:references recipient:references message:text $NOTEST -bundle exec rails generate scaffold tournament game:references status:integer \ +bundle exec rails generate scaffold tournament name:string:unique game:references status:integer \ min_players_per_team:integer max_players_per_team:integer \ min_teams_per_match:integer max_teams_per_match:integer \ set_rounds:integer randomized_teams:boolean diff --git a/test/controllers/tournaments_controller_test.rb b/test/controllers/tournaments_controller_test.rb index 02e578a..d5ab2af 100644 --- a/test/controllers/tournaments_controller_test.rb +++ b/test/controllers/tournaments_controller_test.rb @@ -18,7 +18,7 @@ class TournamentsControllerTest < ActionController::TestCase test "should create tournament" do assert_difference('Tournament.count') do - post :create, tournament: { game_id: @tournament.game_id, max_players_per_team: @tournament.max_players_per_team, max_teams_per_match: @tournament.max_teams_per_match, min_players_per_team: @tournament.min_players_per_team, min_teams_per_match: @tournament.min_teams_per_match, randomized_teams: @tournament.randomized_teams, set_rounds: @tournament.set_rounds, status: @tournament.status } + post :create, tournament: { game_id: @tournament.game_id, max_players_per_team: @tournament.max_players_per_team, max_teams_per_match: @tournament.max_teams_per_match, min_players_per_team: @tournament.min_players_per_team, min_teams_per_match: @tournament.min_teams_per_match, name: @tournament.name, randomized_teams: @tournament.randomized_teams, set_rounds: @tournament.set_rounds, status: @tournament.status } end assert_redirected_to tournament_path(assigns(:tournament)) @@ -35,7 +35,7 @@ class TournamentsControllerTest < ActionController::TestCase end test "should update tournament" do - patch :update, id: @tournament, tournament: { game_id: @tournament.game_id, max_players_per_team: @tournament.max_players_per_team, max_teams_per_match: @tournament.max_teams_per_match, min_players_per_team: @tournament.min_players_per_team, min_teams_per_match: @tournament.min_teams_per_match, randomized_teams: @tournament.randomized_teams, set_rounds: @tournament.set_rounds, status: @tournament.status } + patch :update, id: @tournament, tournament: { game_id: @tournament.game_id, max_players_per_team: @tournament.max_players_per_team, max_teams_per_match: @tournament.max_teams_per_match, min_players_per_team: @tournament.min_players_per_team, min_teams_per_match: @tournament.min_teams_per_match, name: @tournament.name, randomized_teams: @tournament.randomized_teams, set_rounds: @tournament.set_rounds, status: @tournament.status } assert_redirected_to tournament_path(assigns(:tournament)) end diff --git a/test/fixtures/tournaments.yml b/test/fixtures/tournaments.yml index 27c92f9..89edc9f 100644 --- a/test/fixtures/tournaments.yml +++ b/test/fixtures/tournaments.yml @@ -1,6 +1,7 @@ # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html one: + name: MyString game_id: status: 1 min_players_per_team: 1 @@ -11,6 +12,7 @@ one: randomized_teams: false two: + name: MyString game_id: status: 1 min_players_per_team: 1 -- cgit v1.2.3-54-g00ecf From 0c22c4bd9a0b4a0b0ff5840c1af41c0b320e3529 Mon Sep 17 00:00:00 2001 From: guntasgrewal Date: Tue, 25 Mar 2014 17:30:10 -0400 Subject: added match status --- app/assets/javascripts/ajax.js | 19 --- app/assets/stylesheets/application.css | 12 -- app/assets/stylesheets/custom.css.scss | 53 -------- app/assets/stylesheets/scaffolds.css.scss | 40 +----- app/assets/stylesheets/static.css.scss | 9 -- app/assets/stylesheets/tournaments.css.scss | 9 -- app/controllers/alerts_controller.rb | 10 -- app/controllers/application_controller.rb | 3 - app/controllers/matches_controller.rb | 25 ++-- app/controllers/servers_controller.rb | 10 -- app/controllers/sessions_controller.rb | 122 ++++++++++------- app/controllers/static_controller.rb | 2 - app/controllers/tournaments_controller.rb | 77 ++--------- app/controllers/users_controller.rb | 30 +---- app/helpers/sessions_helper.rb | 71 ---------- app/models/match.rb | 6 +- app/models/team.rb | 2 - app/models/tournament.rb | 41 +----- app/models/user.rb | 149 --------------------- app/views/alerts/show.html.erb | 2 + app/views/application/permission_denied.html.erb | 1 - app/views/common/_error_messages.html.erb | 11 -- app/views/games/index.html.erb | 6 +- app/views/games/show.html.erb | 2 + app/views/layouts/application.html.erb | 28 +--- app/views/matches/_form.html.erb | 23 +++- app/views/matches/index.html.erb | 14 +- app/views/matches/index.json.jbuilder | 2 +- app/views/matches/new.html.erb | 2 + app/views/matches/show.html.erb | 34 ++--- app/views/matches/show.json.jbuilder | 2 +- app/views/pms/show.html.erb | 2 + app/views/servers/show.html.erb | 2 + app/views/sessions/_form.html.erb | 21 +++ app/views/sessions/edit.html.erb | 6 + app/views/sessions/index.html.erb | 27 ++++ app/views/sessions/index.json.jbuilder | 4 + app/views/sessions/new.html.erb | 24 +--- app/views/sessions/show.html.erb | 9 ++ app/views/sessions/show.json.jbuilder | 1 + app/views/static/homepage.html.erb | 18 --- app/views/tournaments/_selected.html.erb | 21 --- app/views/tournaments/index.html.erb | 47 +++---- app/views/tournaments/join.html.erb | 2 - app/views/tournaments/new.html.erb | 15 +-- app/views/tournaments/show.html.erb | 35 +---- app/views/users/already_signed_in.html.erb | 1 - app/views/users/index.html.erb | 6 +- app/views/users/new.html.erb | 33 +---- app/views/users/show.html.erb | 2 + config/routes.rb | 14 +- db/migrate/20140325202820_create_servers.rb | 8 -- db/migrate/20140325202823_create_matches.rb | 11 -- db/migrate/20140325202826_create_teams.rb | 9 -- db/migrate/20140325202828_create_alerts.rb | 10 -- db/migrate/20140325202831_create_pms.rb | 11 -- db/migrate/20140325202833_create_tournaments.rb | 17 --- db/migrate/20140325202836_create_games.rb | 15 --- db/migrate/20140325202838_create_users.rb | 13 -- db/migrate/20140325202841_create_sessions.rb | 9 -- .../20140325202843_create_server_settings.rb | 8 -- .../20140325202846_create_tournament_options.rb | 12 -- db/migrate/20140325202848_create_game_settings.rb | 15 --- db/migrate/20140325202850_create_scores.rb | 11 -- ...5202853_create_tournament_players_join_table.rb | 8 -- ...325202855_create_tournament_hosts_join_table.rb | 8 -- .../20140325202858_create_team_user_join_table.rb | 8 -- .../20140325202900_create_match_team_join_table.rb | 8 -- .../20140325202910_add_hidden_attrs_to_user.rb | 8 -- db/migrate/20140325212820_create_servers.rb | 8 ++ db/migrate/20140325212823_create_matches.rb | 12 ++ db/migrate/20140325212826_create_teams.rb | 9 ++ db/migrate/20140325212828_create_alerts.rb | 10 ++ db/migrate/20140325212831_create_pms.rb | 11 ++ db/migrate/20140325212833_create_tournaments.rb | 17 +++ db/migrate/20140325212835_create_games.rb | 15 +++ db/migrate/20140325212838_create_users.rb | 13 ++ db/migrate/20140325212841_create_sessions.rb | 9 ++ .../20140325212844_create_server_settings.rb | 8 ++ .../20140325212846_create_tournament_options.rb | 12 ++ db/migrate/20140325212849_create_game_settings.rb | 15 +++ db/migrate/20140325212851_create_scores.rb | 11 ++ ...5212854_create_tournament_players_join_table.rb | 8 ++ ...325212855_create_tournament_hosts_join_table.rb | 8 ++ .../20140325212857_create_team_user_join_table.rb | 8 ++ .../20140325212859_create_match_team_join_table.rb | 8 ++ .../20140325212906_add_hidden_attrs_to_user.rb | 8 ++ db/schema.rb | 3 +- generate.sh | 2 +- test/controllers/matches_controller_test.rb | 4 +- test/fixtures/matches.yml | 2 + 91 files changed, 462 insertions(+), 1035 deletions(-) delete mode 100644 app/assets/javascripts/ajax.js delete mode 100644 app/assets/stylesheets/custom.css.scss delete mode 100644 app/views/application/permission_denied.html.erb delete mode 100644 app/views/common/_error_messages.html.erb create mode 100644 app/views/sessions/_form.html.erb create mode 100644 app/views/sessions/edit.html.erb create mode 100644 app/views/sessions/index.html.erb create mode 100644 app/views/sessions/index.json.jbuilder create mode 100644 app/views/sessions/show.html.erb create mode 100644 app/views/sessions/show.json.jbuilder delete mode 100644 app/views/static/homepage.html.erb delete mode 100644 app/views/tournaments/_selected.html.erb delete mode 100644 app/views/tournaments/join.html.erb delete mode 100644 app/views/users/already_signed_in.html.erb delete mode 100644 db/migrate/20140325202820_create_servers.rb delete mode 100644 db/migrate/20140325202823_create_matches.rb delete mode 100644 db/migrate/20140325202826_create_teams.rb delete mode 100644 db/migrate/20140325202828_create_alerts.rb delete mode 100644 db/migrate/20140325202831_create_pms.rb delete mode 100644 db/migrate/20140325202833_create_tournaments.rb delete mode 100644 db/migrate/20140325202836_create_games.rb delete mode 100644 db/migrate/20140325202838_create_users.rb delete mode 100644 db/migrate/20140325202841_create_sessions.rb delete mode 100644 db/migrate/20140325202843_create_server_settings.rb delete mode 100644 db/migrate/20140325202846_create_tournament_options.rb delete mode 100644 db/migrate/20140325202848_create_game_settings.rb delete mode 100644 db/migrate/20140325202850_create_scores.rb delete mode 100644 db/migrate/20140325202853_create_tournament_players_join_table.rb delete mode 100644 db/migrate/20140325202855_create_tournament_hosts_join_table.rb delete mode 100644 db/migrate/20140325202858_create_team_user_join_table.rb delete mode 100644 db/migrate/20140325202900_create_match_team_join_table.rb delete mode 100644 db/migrate/20140325202910_add_hidden_attrs_to_user.rb create mode 100644 db/migrate/20140325212820_create_servers.rb create mode 100644 db/migrate/20140325212823_create_matches.rb create mode 100644 db/migrate/20140325212826_create_teams.rb create mode 100644 db/migrate/20140325212828_create_alerts.rb create mode 100644 db/migrate/20140325212831_create_pms.rb create mode 100644 db/migrate/20140325212833_create_tournaments.rb create mode 100644 db/migrate/20140325212835_create_games.rb create mode 100644 db/migrate/20140325212838_create_users.rb create mode 100644 db/migrate/20140325212841_create_sessions.rb create mode 100644 db/migrate/20140325212844_create_server_settings.rb create mode 100644 db/migrate/20140325212846_create_tournament_options.rb create mode 100644 db/migrate/20140325212849_create_game_settings.rb create mode 100644 db/migrate/20140325212851_create_scores.rb create mode 100644 db/migrate/20140325212854_create_tournament_players_join_table.rb create mode 100644 db/migrate/20140325212855_create_tournament_hosts_join_table.rb create mode 100644 db/migrate/20140325212857_create_team_user_join_table.rb create mode 100644 db/migrate/20140325212859_create_match_team_join_table.rb create mode 100644 db/migrate/20140325212906_add_hidden_attrs_to_user.rb diff --git a/app/assets/javascripts/ajax.js b/app/assets/javascripts/ajax.js deleted file mode 100644 index 040c100..0000000 --- a/app/assets/javascripts/ajax.js +++ /dev/null @@ -1,19 +0,0 @@ -function populate() { - //populate optionArray - //make a form element - var e = document.getElementById("tournament_id"); - var gameType = e.options[e.selectedIndex].text; - if (gameType != "Select a Game Type") { - alert(gameType + " was Selected!"); - //populate optionArray via AJAX - //select * from tournament_settings where gametype = GameType - for(var option in optionArray){ - //identify the number of - ; - } - }; - -//$.ajax(url: "/selected").done (html) -> $("#ajax-form").append html - -} - diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css index b3f5d46..3192ec8 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.css @@ -11,15 +11,3 @@ *= require_self *= require_tree . */ - -#query{ - background-color: white; - border: 2px solid #ED9C28; - border-radius: 5px; - color: #FFF; - font-weight: bold; - height: 30px; -} -.navbar{ - background-color: white; -} diff --git a/app/assets/stylesheets/custom.css.scss b/app/assets/stylesheets/custom.css.scss deleted file mode 100644 index 1a9b09a..0000000 --- a/app/assets/stylesheets/custom.css.scss +++ /dev/null @@ -1,53 +0,0 @@ -@import "bootstrap"; - -header > nav { - @extend .navbar; - @extend .navbar-inverse; - color: white; - - #log-buttons { - margin-top: 8px; - form { display: inline; } - } - form.search { - @extend .navbar-form; - @extend .navbar-right; - input[type="submit"] { - @extend .btn-warning; margin-top: -3px; margin-right: 8px; - } - } -} - -a, input[type="submit"] { - @extend .btn; - &.user { @extend .btn-info; } - &.signup { @extend .btn-success; } - &.signin { @extend .btn-info; } - &.signout { @extend .btn-danger; } -} - -p.errors { - background-color: #FCF8C7; - color: red; - border-radius: 7px; - padding: 10px; -} - -#errorExplanation { - h2 { - font-size: 1em; - color: red; - font-weight: bold; - } - li { - font-size: 1em; - color: red; - font-style: italic; - } - -} - -#notice { - text-align: center; - font-weight: bold; -} \ No newline at end of file diff --git a/app/assets/stylesheets/scaffolds.css.scss b/app/assets/stylesheets/scaffolds.css.scss index 6700fef..6ec6a8f 100644 --- a/app/assets/stylesheets/scaffolds.css.scss +++ b/app/assets/stylesheets/scaffolds.css.scss @@ -1,5 +1,3 @@ -@import "bootstrap"; - body { background-color: #fff; color: #333; @@ -8,10 +6,6 @@ body { line-height: 18px; } -h1, h2, h3, h4, h5{ - color: #0f0f0f; -} - p, ol, ul, td { font-family: verdana, arial, helvetica, sans-serif; font-size: 13px; @@ -27,11 +21,11 @@ pre { a { color: #000; &:visited { - color: #000; + color: #666; } &:hover { - color: green; - text-decoration: none; + color: #fff; + background-color: #000; } } @@ -46,9 +40,8 @@ div { } .field_with_errors { - padding: 1px; - background-color: #FF4C4C; - box-shadow: 0px 0px 5px red; + padding: 2px; + background-color: red; display: table; } @@ -74,26 +67,3 @@ div { list-style: square; } } - -.navbar-brand { - @extend .no-dec; - a{ - color: white; - &:hover, &:active, &:focus { - color: white; - font-weight: normal; - text-decoration: none; - } - } -} - -footer { - text-align: center; - border-top: solid 1px #999999; - padding-top: 18px; - margin-top: 18px; -} - -button, input[type="submit"] { - @extend .btn; -} diff --git a/app/assets/stylesheets/static.css.scss b/app/assets/stylesheets/static.css.scss index d73e77d..5a803c8 100644 --- a/app/assets/stylesheets/static.css.scss +++ b/app/assets/stylesheets/static.css.scss @@ -1,12 +1,3 @@ // Place all the styles related to the static controller here. // They will automatically be included in application.css. // You can use Sass (SCSS) here: http://sass-lang.com/ - -.jumbotron { - background-color: #FFF; - - p { - line-height: 1.5em; - } - -} diff --git a/app/assets/stylesheets/tournaments.css.scss b/app/assets/stylesheets/tournaments.css.scss index 458897e..e372b90 100644 --- a/app/assets/stylesheets/tournaments.css.scss +++ b/app/assets/stylesheets/tournaments.css.scss @@ -1,12 +1,3 @@ // Place all the styles related to the tournaments controller here. // They will automatically be included in application.css. // You can use Sass (SCSS) here: http://sass-lang.com/ - -p.default-field { - display: inline; -} - -span.default-explanation { - color: gray; - font-style: italic; -} diff --git a/app/controllers/alerts_controller.rb b/app/controllers/alerts_controller.rb index ac11854..873e9b7 100644 --- a/app/controllers/alerts_controller.rb +++ b/app/controllers/alerts_controller.rb @@ -1,6 +1,5 @@ class AlertsController < ApplicationController before_action :set_alert, only: [:show, :edit, :update, :destroy] - before_action :check_perms, only: [:new, :create, :edit, :update, :destroy] # GET /alerts # GET /alerts.json @@ -68,15 +67,6 @@ class AlertsController < ApplicationController @alert = Alert.find(params[:id]) end - def check_perms - unless (signed_in? and (current_user.in_group?(:admin) or current_user.in_group?(:host))) - respond_to do |format| - format.html { render action: 'permission_denied', status: :forbidden } - format.json { render json: "Permission denied", status: :forbidden } - end - end - end - # Never trust parameters from the scary internet, only allow the white list through. def alert_params params.require(:alert).permit(:author_id, :message) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 7487f87..d83690e 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -2,7 +2,4 @@ class ApplicationController < ActionController::Base # Prevent CSRF attacks by raising an exception. # For APIs, you may want to use :null_session instead. protect_from_forgery with: :exception - - #include sessionhelper for the session controller and view - include SessionsHelper end diff --git a/app/controllers/matches_controller.rb b/app/controllers/matches_controller.rb index 1f0d964..d79a7fc 100644 --- a/app/controllers/matches_controller.rb +++ b/app/controllers/matches_controller.rb @@ -1,10 +1,10 @@ class MatchesController < ApplicationController - before_action :set_tournament, only: [:index, :new, :create] before_action :set_match, only: [:show, :edit, :update, :destroy] + # GET /matches # GET /matches.json def index - @matches = @tournament.matches + @matches = Match.all end # GET /matches/1 @@ -14,7 +14,7 @@ class MatchesController < ApplicationController # GET /matches/new def new - + @match = Match.new end # GET /matches/1/edit @@ -24,11 +24,11 @@ class MatchesController < ApplicationController # POST /matches # POST /matches.json def create - @match = @tournament.matches.build(match_params) + @match = Match.new(match_params) respond_to do |format| if @match.save - format.html { redirect_to tournament_matches_path, notice: 'Match was successfully created.' } + format.html { redirect_to @match, notice: 'Match was successfully created.' } format.json { render action: 'show', status: :created, location: @match } else format.html { render action: 'new' } @@ -42,7 +42,7 @@ class MatchesController < ApplicationController def update respond_to do |format| if @match.update(match_params) - format.html { redirect_to [@tournament, @match], notice: 'Match was successfully updated.' } + format.html { redirect_to @match, notice: 'Match was successfully updated.' } format.json { head :no_content } else format.html { render action: 'edit' } @@ -54,24 +54,21 @@ class MatchesController < ApplicationController # DELETE /matches/1 # DELETE /matches/1.json def destroy - @match.destroy respond_to do |format| - format.html { redirect_to tournament_matches_path } + format.html { redirect_to matches_url } + format.json { head :no_content } end end private # Use callbacks to share common setup or constraints between actions. def set_match - @tournament = Tournament.find(params[:tournament_id]) - @match = @tournament.matches.find(params[:id]); - end - def set_tournament - @tournament = Tournament.find(params[:tournament_id]) + @match = Match.find(params[:id]) end + # Never trust parameters from the scary internet, only allow the white list through. def match_params - params.require(:match).permit(:tournament_id, :name, :winner_id) + params.require(:match).permit(:status, :tournament_id, :name, :winner_id) end end diff --git a/app/controllers/servers_controller.rb b/app/controllers/servers_controller.rb index bb5d5f7..7d54eb6 100644 --- a/app/controllers/servers_controller.rb +++ b/app/controllers/servers_controller.rb @@ -1,6 +1,5 @@ class ServersController < ApplicationController before_action :set_server, only: [:show, :edit, :update, :destroy] - before_action :check_perms # GET /servers # GET /servers.json @@ -68,15 +67,6 @@ class ServersController < ApplicationController @server = Server.find(params[:id]) end - def check_perms - unless (signed_in? and current_user.in_group?(:admin)) - respond_to do |format| - format.html { render action: 'permission_denied', status: :forbidden } - format.json { render json: "Permission denied", status: :forbidden } - end - end - end - # Never trust parameters from the scary internet, only allow the white list through. def server_params params[:server] diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb index 7cb16e8..2f72bf7 100644 --- a/app/controllers/sessions_controller.rb +++ b/app/controllers/sessions_controller.rb @@ -1,52 +1,74 @@ class SessionsController < ApplicationController - before_action :set_session, only: [:destroy] - - # GET /sessions/new - def new - @user = User.new - #@session = Session.new - end - - # POST /sessions - # POST /sessions.json - def create - # find the user... - @user = User.find_by_email(params[:session][:username_or_email]) || User.find_by_user_name(params[:session][:username_or_email]) - - #@session = Session.new(@user) - # ... and create a new session - respond_to do |format| - if @user && @user.authenticate(params[:session][:password]) - sign_in @user - format.html { redirect_to root_path } - #format.json { #TODO } - else - format.html { render action: 'new' } - format.json { render json: @user.errors, status: :unprocessable_entity } - end - end - end - - # DELETE /sessions/1 - # DELETE /sessions/1.json - def destroy - #@session.destroy - sign_out - respond_to do |format| - format.html { redirect_to root_path } - format.json { head :no_content } - end - end - - private - - # Use callbacks to share common setup or constraints between actions. - def set_session - #@session = Session.find(cookies[:remember_token]) - end - - # Never trust parameters from the scary internet, only allow the white list through. - def session_params - params.require(:session).permit(:session_email, :session_user_name, :session_password) - end + before_action :set_session, only: [:show, :edit, :update, :destroy] + + # GET /sessions + # GET /sessions.json + def index + @sessions = Session.all + end + + # GET /sessions/1 + # GET /sessions/1.json + def show + end + + # GET /sessions/new + def new + @session = Session.new + end + + # GET /sessions/1/edit + def edit + end + + # POST /sessions + # POST /sessions.json + def create + @session = Session.new(session_params) + + respond_to do |format| + if @session.save + format.html { redirect_to @session, notice: 'Session was successfully created.' } + format.json { render action: 'show', status: :created, location: @session } + else + format.html { render action: 'new' } + format.json { render json: @session.errors, status: :unprocessable_entity } + end + end + end + + # PATCH/PUT /sessions/1 + # PATCH/PUT /sessions/1.json + def update + respond_to do |format| + if @session.update(session_params) + format.html { redirect_to @session, notice: 'Session was successfully updated.' } + format.json { head :no_content } + else + format.html { render action: 'edit' } + format.json { render json: @session.errors, status: :unprocessable_entity } + end + end + end + + # DELETE /sessions/1 + # DELETE /sessions/1.json + def destroy + @session.destroy + respond_to do |format| + format.html { redirect_to sessions_url } + format.json { head :no_content } + end + end + + private + # Use callbacks to share common setup or constraints between actions. + def set_session + @session = Session.find(params[:id]) + end + + # Never trust parameters from the scary internet, only allow the white list through. + def session_params + params.require(:session).permit(:user_id) + end end diff --git a/app/controllers/static_controller.rb b/app/controllers/static_controller.rb index 6fc9490..c6df11e 100644 --- a/app/controllers/static_controller.rb +++ b/app/controllers/static_controller.rb @@ -1,4 +1,2 @@ class StaticController < ApplicationController - def homepage - end end diff --git a/app/controllers/tournaments_controller.rb b/app/controllers/tournaments_controller.rb index 8d90758..d7db632 100644 --- a/app/controllers/tournaments_controller.rb +++ b/app/controllers/tournaments_controller.rb @@ -1,6 +1,5 @@ class TournamentsController < ApplicationController - before_action :set_tournament, only: [:show, :edit, :update, :destroy, :join] - before_action :check_perms, only: [:new, :create, :edit, :destroy] + before_action :set_tournament, only: [:show, :edit, :update, :destroy] # GET /tournaments # GET /tournaments.json @@ -11,37 +10,24 @@ class TournamentsController < ApplicationController # GET /tournaments/1 # GET /tournaments/1.json def show - case @tournament.status - when 0 - when 1..2 - redirect_to "/tournaments/" + @tournament.id.to_s + "/matches" #tournament_matches_page(@tournament) - end end # GET /tournaments/new def new - @games = Game.all - @tournament = Tournament.new(game: Game.find_by_id(params[:game])) + @tournament = Tournament.new end # GET /tournaments/1/edit def edit - if params['close_action'] == 'close' - @tournament.status = 1 - @tournament.save - @tournament.setup(@tournament) - redirect_to "/tournaments" - end end # POST /tournaments # POST /tournaments.json def create @tournament = Tournament.new(tournament_params) - @tournament.status = 0 + respond_to do |format| if @tournament.save - @tournament.hosts.push(current_user) format.html { redirect_to @tournament, notice: 'Tournament was successfully created.' } format.json { render action: 'show', status: :created, location: @tournament } else @@ -54,45 +40,13 @@ class TournamentsController < ApplicationController # PATCH/PUT /tournaments/1 # PATCH/PUT /tournaments/1.json def update - - if params[:update_action].nil? - check_perms - respond_to do |format| - if @tournament.update(tournament_params) - format.html { redirect_to @tournament, notice: 'Tournament was successfully updated.' } - format.json { head :no_content } - else - format.html { render action: 'edit' } - format.json { render json: @tournament.errors, status: :unprocessable_entity } - end - end - else - case params[:update_action] - when "join" - respond_to do |format| - if @tournament.join(current_user) - format.html { render action: 'show', notice: 'You have joined this tournament.' } - format.json { head :no_content } - end - format.html { render action: 'permission_denied', status: :forbidden } - format.json { render json: "Permission denied", status: :forbidden } - end - when "open" - respond_to do |format| - if @tournament.setup - format.html { render action: 'show', notice: 'You have joined this tournament.' } - format.json { head :no_content } - end - format.html { render action: 'permission_denied', status: :forbidden } - format.json { render json: "Permission denied", status: :forbidden } - end - #when "close" - # TODO + respond_to do |format| + if @tournament.update(tournament_params) + format.html { redirect_to @tournament, notice: 'Tournament was successfully updated.' } + format.json { head :no_content } else - respond_to do |format| - format.html { render action: 'show', notice: "Invalid action", status: :unprocessable_entity } - format.json { render json: @tournament.errors, status: :unprocessable_entity } - end + format.html { render action: 'edit' } + format.json { render json: @tournament.errors, status: :unprocessable_entity } end end end @@ -113,19 +67,8 @@ class TournamentsController < ApplicationController @tournament = Tournament.find(params[:id]) end - def check_perms - unless (signed_in? and current_user.in_group?(:host)) - respond_to do |format| - format.html { render action: 'permission_denied', status: :forbidden } - format.json { render json: "Permission denied", status: :forbidden } - end - end - end - # Never trust parameters from the scary internet, only allow the white list through. def tournament_params - - params.require(:tournament).permit(:game, :name, :game_id, :status, :min_players_per_team, :max_players_per_team, :min_teams_per_match, :max_teams_per_match, :set_rounds, :randomized_teams) - + params.require(:tournament).permit(:name, :game_id, :status, :min_players_per_team, :max_players_per_team, :min_teams_per_match, :max_teams_per_match, :set_rounds, :randomized_teams) end end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 70facca..b18efed 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -1,7 +1,5 @@ class UsersController < ApplicationController before_action :set_user, only: [:show, :edit, :update, :destroy] - before_action :perms_edit, only: [:edit, :update, :destroy] - before_action :perms_create, only: [:new, :create] # GET /users # GET /users.json @@ -12,7 +10,6 @@ class UsersController < ApplicationController # GET /users/1 # GET /users/1.json def show - @user = User.find(params[:id]) end # GET /users/new @@ -28,14 +25,13 @@ class UsersController < ApplicationController # POST /users.json def create @user = User.new(user_params) - @user.groups = 0 + respond_to do |format| if @user.save - sign_in @user - format.html { redirect_to root_path, notice: 'User was successfully created.' } + format.html { redirect_to @user, notice: 'User was successfully created.' } format.json { render action: 'show', status: :created, location: @user } else - format.html { render action: 'new', status: :unprocessable_entity } + format.html { render action: 'new' } format.json { render json: @user.errors, status: :unprocessable_entity } end end @@ -71,26 +67,8 @@ class UsersController < ApplicationController @user = User.find(params[:id]) end - def perms_edit - unless (current_user == @user) or (signed_in? and current_user.in_group? :admin) - respond_to do |format| - format.html { render action: 'permission_denied', status: :forbidden } - format.json { render json: "Permission denied", status: :forbidden } - end - end - end - - def perms_create - if signed_in? - respond_to do |format| - format.html { render action: 'already_signed_in', status: :unprocessable_entity } - format.json { render json: "Already signed in", status: :unprocessable_entity } - end - end - end - # Never trust parameters from the scary internet, only allow the white list through. def user_params - params.require(:user).permit(:name, :email, :user_name, :password, :password_confirmation) + params.require(:user).permit(:name, :email, :user_name) end end diff --git a/app/helpers/sessions_helper.rb b/app/helpers/sessions_helper.rb index 046ca6f..309f8b2 100644 --- a/app/helpers/sessions_helper.rb +++ b/app/helpers/sessions_helper.rb @@ -1,73 +1,2 @@ module SessionsHelper - - def sign_in(user) - #create a new remember token - remember_token = User.new_remember_token - #place token inside of the browser - cookies.permanent[:remember_token] = remember_token - #save the hashed token to the database - user.update_attribute(:remember_token, - User.hash(remember_token)) - #set the current user to be the given user - self.current_user = user - end - -# The curret_user=(user) is the conversion of self.current_user = user - def current_user=(user) - @current_user = user - end - -# sets the @current_user instance virable to the user corresponding -# to the remember token, but only if @current_user is undefined -# since the remember token is hashed, we need to hash the cookie -# to find match the remember token - def current_user - remember_token = User.hash(cookies[:remember_token]) - @current_user ||= User.find_by(remember_token: remember_token) - end - - # checks if someone is currently signed in - def signed_in? - !current_user.nil? - end - - def sign_out - current_user.update_attribute(:remember_token, User.hash(User.new_remember_token)) - cookies.delete(:remember_token) - self.current_user = nil - end - -=begin - -This is for anyone that cares about how long a user is signed -in: - -Currently I have a user to be signed in forever unless they -log out (cookies.permanent....). - -If you want to change that, change line 7 to this: - -cookies[:remember_token] = { value: remember_token, - expires: 20.years.from_now.utc } - -which will expire the cookie in 20 years from its date of -creation. - -Oddly enough, this line above is equivalent to the: - -cookies.permanent - -This is just a short cut for this line since most people -create permanent cookies these days. - -Other times are: - -10.weeks.from_now - -5.days.ago - -etc... - -=end - end diff --git a/app/models/match.rb b/app/models/match.rb index 782dce8..bb814c1 100644 --- a/app/models/match.rb +++ b/app/models/match.rb @@ -1,8 +1,4 @@ class Match < ActiveRecord::Base belongs_to :tournament - - has_and_belongs_to_many :teams - - belongs_to :winner, class_name: "Team" - + belongs_to :winner end diff --git a/app/models/team.rb b/app/models/team.rb index 2348de5..9e71557 100644 --- a/app/models/team.rb +++ b/app/models/team.rb @@ -1,5 +1,3 @@ class Team < ActiveRecord::Base belongs_to :match - has_and_belongs_to_many :matches - has_and_belongs_to_many :users end diff --git a/app/models/tournament.rb b/app/models/tournament.rb index 69bedf5..cc915a0 100644 --- a/app/models/tournament.rb +++ b/app/models/tournament.rb @@ -1,42 +1,3 @@ class Tournament < ActiveRecord::Base - belongs_to :game - has_many :matches - has_and_belongs_to_many :players, class_name: "User", association_foreign_key: "player_id", join_table: "players_tournaments" - has_and_belongs_to_many :hosts, class_name: "User", association_foreign_key: "host_id", join_table: "hosts_tournaments" - - def open? - return true - end - - def joinable_by?(user) - return ((not user.nil?) and user.in_group?(:player) and open?) - end - - def join(user) - unless joinable_by?(user) - return false - end - players.push(user) - end - - def setup(tournament) - num_teams = (self.players.count/self.max_players_per_team).floor - num_matches = num_teams - 1 - for i in 1..num_matches - self.matches.create(name: "Match #{i}") - end - match_num = 0 - team_num = 0 - self.players.each_slice(tournament.max_players_per_team) do |players| - self.matches[match_num].teams.push(Team.create(users: players)) - if (team_num != 0 and team_num % tournament.max_teams_per_match == 0) - match_num += 1 - team_num = 0 - else - team_num += 1 - end - end - end - - + belongs_to :game end diff --git a/app/models/user.rb b/app/models/user.rb index 6e439fb..4a57cf0 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,151 +1,2 @@ class User < ActiveRecord::Base - has_and_belongs_to_many :tournaments_played, class_name: "Tournament", foreign_key: "player_id", join_table: "players_tournaments" - has_and_belongs_to_many :tournaments_hosted, class_name: "Tournament", foreign_key: "host_id", join_table: "hosts_tournaments" - has_and_belongs_to_many :teams - - before_save { self.email = email.downcase } - before_save { self.user_name = user_name } - - ## - # Rails looks for the create_remember_token and runs the method - # before anything else. - # - # This method cannot be called by a user since it is denoted - # as private. - before_create :create_remember_token - - def in_group?(group) - case group - when :admin - return ((groups & 2) != 0) - when :host - return true #((groups & 1) != 0) - when :player - return true - when :specator - return true - else - return false - end - end - - def join_groups(join=[]) - # FIXME: race condition - join.each do |group| - case group - when :admin - groups |= 2 - when :host - groups |= 1 - else - end - end - end - - def leave_groups(leave=[]) - # FIXME: race condition - leave.each do |group| - case group - when :admin - groups &= ~ 2 - when :host - groups &= ~ 1 - else - end - end - end - - ## - # VAILD_EMAIL is the regex used to validate a user given email. - VALID_EMAIL_REG = /\A\S+@\S+\.\S+\z/i - - ## - # VALID_USER_NAME checks to make sure a user's user_name - # is in the proper format. - VALID_USER_NAME_REG = /\A[a-zA-Z0-9\-]+\z/ - - ## - # The following lines put a user account through a series of - # validations in order to make sure all of their information - # is in the proper format. - # - # validates :symbol_to_be_validated - # - # - presence: determines whether or not a symbol is filled or not - # - length: ensures there is a length limit on the symbol - # - format: checks the format of given information to ensure - # validity - validates(:name, presence: true, length: { maximum: 50 }) - validates(:email, presence: true, format: {with: - VALID_EMAIL_REG}, - uniqueness: { case_sensitive: false }) - validates(:user_name, presence: true, length:{maximum: 50}, - format: {with: VALID_USER_NAME_REG }, - uniqueness: {case_sensitive: false }) - - ## - # Instead of adding password and password_confirmation - # attributes, requiring the presence of a password, - # requiring that pw and pw_com match, and add an authenticate - # method to compare an encrypted password to the - # password_digest to authenticate users, I can just add - # has_secure_password which does all of this for me. - has_secure_password - - validates :password, length: { minimum: 6 } - - ## - # Create a random remember token for the user. This will be - # changed every time the user creates a new session. - # - # By changing the cookie every new session, any hijacked sessions - # (where the attacker steals a cookie to sign in as a certain - # user) will expire the next time the user signs back in. - # - # The random string is of length 16 composed of A-Z, a-z, 0-9 - # This is the browser's cookie value. - def User.new_remember_token - SecureRandom.urlsafe_base64 - end - - ## - # Encrypt the remember token. - # This is the encrypted version of the cookie stored on - # the database. - # - # The reasoning for storing a hashed token is so that even if - # the database is compromised, the attacker won't be able to use - # the remember tokens to sign in. - def User.hash(token) - Digest::SHA1.hexdigest(token.to_s) - end - - ## - # SHA-1 (Secure Hash Algorithm) is a US engineered hash - # function that produces a 20 byte hash value which typically - # forms a hexadecimal number 40 digits long. - # The reason I am not using the Bcrypt algorithm is because - # SHA-1 is much faster and I will be calling this on - # every page a user accesses. - # - # https://en.wikipedia.org/wiki/SHA-1 - - - # Everything under private is hidden so you cannot call. - private - - ## - # Create_remember_token in order to ensure a user always has - # a remember token. - def create_remember_token - self.remember_token = User.hash(User.new_remember_token) - end - - ## - # In order to ensure that someone did not accidentally submit - # two accounts rapidly (which would throw off the validates - # for user_name and email), I added an index to the Users - # email and user_name in the database to ensure uniqueness - # This also gives and index to the user_name and email - # so finding a user SHOULD be easier for the database. end diff --git a/app/views/alerts/show.html.erb b/app/views/alerts/show.html.erb index 5dda2c9..eeab7f7 100644 --- a/app/views/alerts/show.html.erb +++ b/app/views/alerts/show.html.erb @@ -1,3 +1,5 @@ +

<%= notice %>

+

Author: <%= @alert.author %> diff --git a/app/views/application/permission_denied.html.erb b/app/views/application/permission_denied.html.erb deleted file mode 100644 index 1ef883c..0000000 --- a/app/views/application/permission_denied.html.erb +++ /dev/null @@ -1 +0,0 @@ -

Permission denied

diff --git a/app/views/common/_error_messages.html.erb b/app/views/common/_error_messages.html.erb deleted file mode 100644 index 731f62c..0000000 --- a/app/views/common/_error_messages.html.erb +++ /dev/null @@ -1,11 +0,0 @@ -<%# http://railscasts.com/episodes/211-validations-in-rails-3 %> -<% if target.errors.any? %> -
-

<%= pluralize(target.errors.count, "error") %> prohibited this form from being submitted:

-
    - <% target.errors.full_messages.each do |msg| %> -
  • <%= msg %>
  • - <% end %> -
-
-<% end %> diff --git a/app/views/games/index.html.erb b/app/views/games/index.html.erb index 79acd1e..27c5860 100644 --- a/app/views/games/index.html.erb +++ b/app/views/games/index.html.erb @@ -1,6 +1,6 @@

Listing games

-
Name Game Status Min players per team
<%= tournament.name %> <%= tournament.game %> <%= tournament.status %> <%= tournament.min_players_per_team %>
+
@@ -36,6 +36,4 @@
- -<%= link_to 'New Game', new_game_path, {:class => "btn btn-warning"} %> - +<%= link_to 'New Game', new_game_path %> diff --git a/app/views/games/show.html.erb b/app/views/games/show.html.erb index 39d4a97..1f1a154 100644 --- a/app/views/games/show.html.erb +++ b/app/views/games/show.html.erb @@ -1,3 +1,5 @@ +

<%= notice %>

+

Name: <%= @game.name %> diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 976ee85..cefd1be 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -5,36 +5,10 @@ <%= stylesheet_link_tag "application", media: "all", "data-turbolinks-track" => true %> <%= javascript_include_tag "application", "data-turbolinks-track" => true %> <%= csrf_meta_tags %> - <%= yield :head %> -

+<%= yield %> -<% if notice %>

<%= notice %>

<% end %> - -
<%= yield %>
- -
-

Leaguer © 2014, Tomer Kimia, Andrew Murrell, Luke Shumaker, Nathaniel Foy, Davis Webb, and Guntas Grewal

-
-<%= debug(params) if Rails.env.development? %> diff --git a/app/views/matches/_form.html.erb b/app/views/matches/_form.html.erb index 015aed0..727c002 100644 --- a/app/views/matches/_form.html.erb +++ b/app/views/matches/_form.html.erb @@ -1,5 +1,20 @@ -<%= form_for([@tournament, @tournament.matches.build]) do |f| %> - +<%= form_for(@match) do |f| %> + <% if @match.errors.any? %> +
+

<%= pluralize(@match.errors.count, "error") %> prohibited this match from being saved:

+ +
    + <% @match.errors.full_messages.each do |msg| %> +
  • <%= msg %>
  • + <% end %> +
+
+ <% end %> + +
+ <%= f.label :status %>
+ <%= f.number_field :status %> +
<%= f.label :tournament_id %>
<%= f.text_field :tournament_id %> @@ -8,6 +23,10 @@ <%= f.label :name %>
<%= f.text_field :name %>
+
+ <%= f.label :winner_id %>
+ <%= f.text_field :winner_id %> +
<%= f.submit %>
diff --git a/app/views/matches/index.html.erb b/app/views/matches/index.html.erb index 60df1b5..400efb4 100644 --- a/app/views/matches/index.html.erb +++ b/app/views/matches/index.html.erb @@ -3,6 +3,7 @@
Name
+ @@ -13,14 +14,15 @@ - <% @tournament.matches.each do |match| %> + <% @matches.each do |match| %> - + + - - - + + + <% end %> @@ -28,4 +30,4 @@
-<%= link_to 'New Match', new_tournament_match_path %> +<%= link_to 'New Match', new_match_path %> diff --git a/app/views/matches/index.json.jbuilder b/app/views/matches/index.json.jbuilder index 0b2bfcd..1a63f5f 100644 --- a/app/views/matches/index.json.jbuilder +++ b/app/views/matches/index.json.jbuilder @@ -1,4 +1,4 @@ json.array!(@matches) do |match| - json.extract! match, :id, :tournament_id, :name, :winner_id + json.extract! match, :id, :status, :tournament_id, :name, :winner_id json.url match_url(match, format: :json) end diff --git a/app/views/matches/new.html.erb b/app/views/matches/new.html.erb index 74e7e3a..bd4c78c 100644 --- a/app/views/matches/new.html.erb +++ b/app/views/matches/new.html.erb @@ -1,3 +1,5 @@

New match

<%= render 'form' %> + +<%= link_to 'Back', matches_path %> diff --git a/app/views/matches/show.html.erb b/app/views/matches/show.html.erb index b6930ea..f3fc822 100644 --- a/app/views/matches/show.html.erb +++ b/app/views/matches/show.html.erb @@ -1,6 +1,13 @@ +

<%= notice %>

+ +

+ Status: + <%= @match.status %> +

+

Tournament: - <%= @match.tournament.id %> + <%= @match.tournament %>

@@ -8,23 +15,10 @@ <%= @match.name %>

-<% if (@tournament.hosts.include?(current_user) and @match.winner.nil?) %> - <%= form_for([@tournament, @match], method: "put") do |f| %> -
    - <% @match.teams.each do |team| %> -
  • - <% end %> -
- <%= f.submit("Select winner") %> - <% end %> -<% end %> - -<% unless @match.winner.nil? %> -

- Winner: - <%= @match.winner.users.collect{|u| u.user_name}.join(", ") %> -

-<% end %> +

+ Winner: + <%= @match.winner %> +

-<%= link_to 'Back', tournament_matches_path %> +<%= link_to 'Edit', edit_match_path(@match) %> | +<%= link_to 'Back', matches_path %> diff --git a/app/views/matches/show.json.jbuilder b/app/views/matches/show.json.jbuilder index fe14010..a3ef588 100644 --- a/app/views/matches/show.json.jbuilder +++ b/app/views/matches/show.json.jbuilder @@ -1 +1 @@ -json.extract! @match, :id, :tournament_id, :name, :winner_id, :created_at, :updated_at +json.extract! @match, :id, :status, :tournament_id, :name, :winner_id, :created_at, :updated_at diff --git a/app/views/pms/show.html.erb b/app/views/pms/show.html.erb index 2a03716..5ee483f 100644 --- a/app/views/pms/show.html.erb +++ b/app/views/pms/show.html.erb @@ -1,3 +1,5 @@ +

<%= notice %>

+

Author: <%= @pm.author %> diff --git a/app/views/servers/show.html.erb b/app/views/servers/show.html.erb index 67f7647..039cd8f 100644 --- a/app/views/servers/show.html.erb +++ b/app/views/servers/show.html.erb @@ -1,2 +1,4 @@ +

<%= notice %>

+ <%= link_to 'Edit', edit_server_path(@server) %> | <%= link_to 'Back', servers_path %> diff --git a/app/views/sessions/_form.html.erb b/app/views/sessions/_form.html.erb new file mode 100644 index 0000000..1b94e77 --- /dev/null +++ b/app/views/sessions/_form.html.erb @@ -0,0 +1,21 @@ +<%= form_for(@session) do |f| %> + <% if @session.errors.any? %> +
+

<%= pluralize(@session.errors.count, "error") %> prohibited this session from being saved:

+ +
    + <% @session.errors.full_messages.each do |msg| %> +
  • <%= msg %>
  • + <% end %> +
+
+ <% end %> + +
+ <%= f.label :user_id %>
+ <%= f.text_field :user_id %> +
+
+ <%= f.submit %> +
+<% end %> diff --git a/app/views/sessions/edit.html.erb b/app/views/sessions/edit.html.erb new file mode 100644 index 0000000..bbd8407 --- /dev/null +++ b/app/views/sessions/edit.html.erb @@ -0,0 +1,6 @@ +

Editing session

+ +<%= render 'form' %> + +<%= link_to 'Show', @session %> | +<%= link_to 'Back', sessions_path %> diff --git a/app/views/sessions/index.html.erb b/app/views/sessions/index.html.erb new file mode 100644 index 0000000..707a47d --- /dev/null +++ b/app/views/sessions/index.html.erb @@ -0,0 +1,27 @@ +

Listing sessions

+ +
Status Tournament Name Winner
<%= match.tournament.id %><%= match.status %><%= match.tournament %> <%= match.name %> <%= match.winner %><%= link_to 'Show', tournament_match_path(@tournament, match) %><%= link_to 'Edit', edit_tournament_match_path(@tournament, match) %><%= link_to 'Destroy', tournament_match_path(@tournament, match), method: :delete, data: { confirm: 'Are you sure?' } %><%= link_to 'Show', match %><%= link_to 'Edit', edit_match_path(match) %><%= link_to 'Destroy', match, method: :delete, data: { confirm: 'Are you sure?' } %>
+ + + + + + + + + + + <% @sessions.each do |session| %> + + + + + + + <% end %> + +
User
<%= session.user %><%= link_to 'Show', session %><%= link_to 'Edit', edit_session_path(session) %><%= link_to 'Destroy', session, method: :delete, data: { confirm: 'Are you sure?' } %>
+ +
+ +<%= link_to 'New Session', new_session_path %> diff --git a/app/views/sessions/index.json.jbuilder b/app/views/sessions/index.json.jbuilder new file mode 100644 index 0000000..18fd4fa --- /dev/null +++ b/app/views/sessions/index.json.jbuilder @@ -0,0 +1,4 @@ +json.array!(@sessions) do |session| + json.extract! session, :id, :user_id + json.url session_url(session, format: :json) +end diff --git a/app/views/sessions/new.html.erb b/app/views/sessions/new.html.erb index b4acf77..55c9eca 100644 --- a/app/views/sessions/new.html.erb +++ b/app/views/sessions/new.html.erb @@ -1,23 +1,5 @@ -

Sign in

-<% if @user.nil? %> -

The email/username or password is incorrect. Verify that CAPS LOCK is not on, and then retype the current email/username and password.

-<% end %> +

New session

-
- <%= form_for(:session, url: sessions_path) do |f| %> -

- <%= f.label(:username_or_email, "Username/Email") %>
- <%= f.text_field :username_or_email%> -

-

- <%= f.label :password %>
- <%= f.password_field :password %> -

-

- <%= f.submit "Sign in", class: "btn btn-large btn-primary" %> -

- <% end %> - -

New user? <%= link_to("Sign up now!", new_user_path) %>

-
+<%= render 'form' %> +<%= link_to 'Back', sessions_path %> diff --git a/app/views/sessions/show.html.erb b/app/views/sessions/show.html.erb new file mode 100644 index 0000000..5176869 --- /dev/null +++ b/app/views/sessions/show.html.erb @@ -0,0 +1,9 @@ +

<%= notice %>

+ +

+ User: + <%= @session.user %> +

+ +<%= link_to 'Edit', edit_session_path(@session) %> | +<%= link_to 'Back', sessions_path %> diff --git a/app/views/sessions/show.json.jbuilder b/app/views/sessions/show.json.jbuilder new file mode 100644 index 0000000..4ebf936 --- /dev/null +++ b/app/views/sessions/show.json.jbuilder @@ -0,0 +1 @@ +json.extract! @session, :id, :user_id, :created_at, :updated_at diff --git a/app/views/static/homepage.html.erb b/app/views/static/homepage.html.erb deleted file mode 100644 index 3ca8176..0000000 --- a/app/views/static/homepage.html.erb +++ /dev/null @@ -1,18 +0,0 @@ -
- -
-

Welcome to Leaguer

-

This is a tournment management system designed to be used for any team sport. Our peer review system ensures that the best players move on to the next round! Try creating a new tournament and having people sign up for it.

-

- <% if !signed_in? %> - <%= link_to 'Log In', new_session_path, :class => "btn btn-warning btn-lg", :role => "button" %> - <%= link_to 'Sign Up', new_user_path, :class => "btn btn-warning btn-lg", :role => "button" %> - <% else %> - <%= link_to 'Start a Tournament', new_tournament_path, :class => "btn btn-warning btn-lg", :role => "button" %> - <% end %> - <%= link_to 'See Ongoing Tournaments', tournaments_path, :class => "btn btn-warning btn-lg", :role => "button" %> - -

-
- -
diff --git a/app/views/tournaments/_selected.html.erb b/app/views/tournaments/_selected.html.erb deleted file mode 100644 index 8734b14..0000000 --- a/app/views/tournaments/_selected.html.erb +++ /dev/null @@ -1,21 +0,0 @@ -<%= form_for(@tournament) do |f| %> - <%= render "common/error_messages", :target => @tournament %> - <%= f.hidden_field(:game_id) %> - - <% @chosen = Game.find_by(params[:game]) %> - <% @tournament.attributes.each do |name, value| %> - <% if (name == "id") or (name =~ /.*_at$/) or (name == "game_id") or (name == "status") %> - <% next %> - <% end %> -

- <%= f.label name %>
- <% if !@chosen.attributes[name].nil? %> - <%= f.text_field(name, :value => @chosen.attributes[name] ) %> - <% else %> - <%= f.text_field name %> - <% end %> -

- <% end %> - - <%= f.submit %> -<% end %> diff --git a/app/views/tournaments/index.html.erb b/app/views/tournaments/index.html.erb index 90c3d7a..f8f21e7 100644 --- a/app/views/tournaments/index.html.erb +++ b/app/views/tournaments/index.html.erb @@ -1,14 +1,16 @@ -

Listing Tournaments

+

Listing tournaments

-<% if @tournaments.length > 0 %> - +
- - + + + + + @@ -20,28 +22,13 @@ <% @tournaments.each do |tournament| %> - - - + + + + + + + @@ -50,9 +37,7 @@ <% end %>
Name Game StatusPlayers per teamTeams per matchMin players per teamMax players per teamMin teams per matchMax teams per matchSet rounds Randomized teams
<%= tournament.name %><% case tournament.status - when 0 %> - <%= form_tag(tournament_path(tournament), method: "put") do %> - - <%= submit_tag("Join") %> - <% end %> - <% when 1 %> - Ongoing - <% else %> - Closed - <%end %> - <%= tournament.min_players_per_team %> - <% if tournament.min_players_per_team != tournament.max_players_per_team %> - to <%= tournament.max_players_per_team %> - <% end %> - <%= tournament.min_teams_per_match %> - <% if tournament.min_teams_per_match != tournament.max_teams_per_match %> - to <%= tournament.max_teams_per_match %> - <% end %> - <%= tournament.game %><%= tournament.status %><%= tournament.min_players_per_team %><%= tournament.max_players_per_team %><%= tournament.min_teams_per_match %><%= tournament.max_teams_per_match %><%= tournament.set_rounds %> <%= tournament.randomized_teams %> <%= link_to 'Show', tournament %> <%= link_to 'Edit', edit_tournament_path(tournament) %>
-<% else %> -

No tournaments going on right now... Why not start your own?

-<% end %> +
-<%= link_to 'New Tournament', new_tournament_path, :class => "btn btn-warning btn-lg" %> +<%= link_to 'New Tournament', new_tournament_path %> diff --git a/app/views/tournaments/join.html.erb b/app/views/tournaments/join.html.erb deleted file mode 100644 index 1d38d68..0000000 --- a/app/views/tournaments/join.html.erb +++ /dev/null @@ -1,2 +0,0 @@ - <%= @user.name %> - diff --git a/app/views/tournaments/new.html.erb b/app/views/tournaments/new.html.erb index 8c74068..2a60539 100644 --- a/app/views/tournaments/new.html.erb +++ b/app/views/tournaments/new.html.erb @@ -1,16 +1,5 @@ -

New Tournament

+

New tournament

-<%= form_tag(new_tournament_path, method: "get") do %> - <%= select_tag('game', - options_from_collection_for_select(@games, 'id', 'name', @tournament.game.nil? || @tournament.game.id), - :prompt => "Select a Game Type") %> - <%= submit_tag("Select", :class => "btn btn-success btn-xs") %> -<% end %> - -
- <% if not @tournament.game.nil? %> - <%= render 'selected' %> - <% end %> -
+<%= render 'form' %> <%= link_to 'Back', tournaments_path %> diff --git a/app/views/tournaments/show.html.erb b/app/views/tournaments/show.html.erb index 3de0623..3cb6179 100644 --- a/app/views/tournaments/show.html.erb +++ b/app/views/tournaments/show.html.erb @@ -1,19 +1,5 @@ -<% if @tournament.joinable_by?(current_user) %> - <%= form_tag(tournament_path(@tournament), method: "put") do %> - - <%= current_user.name %><%= submit_tag("Join") %> - <% end %> -<% end %> +

<%= notice %>

- -
- <%= tag("div", {:class => "progress-bar progress-bar-warning", :style => "width: " +(@tournament.players.count * 100 / (@tournament.min_players_per_team * @tournament.min_teams_per_match)).to_s + "%", "aria-valuemax" => "100", "aria-valuemin" => "0", "aria-valuenow" => (@tournament.players.count * 100 / (@tournament.min_players_per_team * @tournament.min_teams_per_match)).to_s, "role" => "progressbar"}) %> - 60% Complete (warning) -
-
-

<%= @tournament.players.count %> have signed up. <%= @tournament.min_players_per_team * @tournament.min_teams_per_match %> needed.

- -<% if current_user.in_group?(:host) %>

Name: <%= @tournament.name %> @@ -21,7 +7,7 @@

Game: - <%= @tournament.id %> + <%= @tournament.game %>

@@ -59,22 +45,5 @@ <%= @tournament.randomized_teams %>

-

- Status: - <%= @tournament.status %> -

- -<%= form_tag(tournaments_path.to_s + "/" + @tournament.id.to_s + "/edit", method: "get") do %> - - <% if @tournament.players.count >= @tournament.min_players_per_team * @tournament.min_teams_per_match %> - <%= submit_tag("Close Tournament Registration") %> - <% else %> - <%= submit_tag("Close Tournament Registration", disabled: true) %> - <% end %> -<% end %> - <%= link_to 'Edit', edit_tournament_path(@tournament) %> | <%= link_to 'Back', tournaments_path %> - -<% end %> - diff --git a/app/views/users/already_signed_in.html.erb b/app/views/users/already_signed_in.html.erb deleted file mode 100644 index 04b4248..0000000 --- a/app/views/users/already_signed_in.html.erb +++ /dev/null @@ -1 +0,0 @@ -

You are currently signed in

diff --git a/app/views/users/index.html.erb b/app/views/users/index.html.erb index 89e369a..3692112 100644 --- a/app/views/users/index.html.erb +++ b/app/views/users/index.html.erb @@ -1,9 +1,8 @@

Listing users

- +
- @@ -16,9 +15,8 @@ <% @users.each do |user| %> - - + diff --git a/app/views/users/new.html.erb b/app/views/users/new.html.erb index c23f76d..efc0404 100644 --- a/app/views/users/new.html.erb +++ b/app/views/users/new.html.erb @@ -1,32 +1,5 @@ -

Sign Up

+

New user

-<%= form_for @user do |f| %> - <%= render "common/error_messages", :target => @user %> -

- <%= f.label :name %>
- <%= f.text_field :name %> -

-

- <%= f.label :email %>
- <%= f.text_field :email %> -

-

- <%= f.label :user_name %>
- <%= f.text_field :user_name %> -

-

- <%= f.label :password %>
- <%= f.password_field :password %> -

-

- <%= f.label(:password_confirmation, "Confirm Password") %>
- <%= f.password_field :password_confirmation %> -

-

- <%= f.submit("Be a Leaguer", :class => "signup") %> -

-<% end %> - - -<%= link_to 'Already Have an Account? Log in', new_session_path, :class => "signin" %> +<%= render 'form' %> +<%= link_to 'Back', users_path %> diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb index d8cc82b..9455a3c 100644 --- a/app/views/users/show.html.erb +++ b/app/views/users/show.html.erb @@ -1,3 +1,5 @@ +

<%= notice %>

+

Name: <%= @user.name %> diff --git a/config/routes.rb b/config/routes.rb index 5c5bece..97e82f8 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,25 +1,21 @@ Leaguer::Application.routes.draw do - - #creates sessions as a resource but limits it to these actions - resources :sessions, only: [:new, :create, :destroy] + resources :sessions resources :users resources :games + resources :tournaments + resources :pms resources :alerts - resource :server, only: [:show, :edit, :update] - resources :teams - resources :tournaments do - resources :matches - end + resources :matches - root to: 'static#homepage' + resources :servers # The priority is based upon order of creation: first created -> highest priority. # See how all your routes lay out with "rake routes". diff --git a/db/migrate/20140325202820_create_servers.rb b/db/migrate/20140325202820_create_servers.rb deleted file mode 100644 index f33241a..0000000 --- a/db/migrate/20140325202820_create_servers.rb +++ /dev/null @@ -1,8 +0,0 @@ -class CreateServers < ActiveRecord::Migration - def change - create_table :servers do |t| - - t.timestamps - end - end -end diff --git a/db/migrate/20140325202823_create_matches.rb b/db/migrate/20140325202823_create_matches.rb deleted file mode 100644 index 67a5b7b..0000000 --- a/db/migrate/20140325202823_create_matches.rb +++ /dev/null @@ -1,11 +0,0 @@ -class CreateMatches < ActiveRecord::Migration - def change - create_table :matches do |t| - t.references :tournament, index: true - t.string :name - t.references :winner, index: true - - t.timestamps - end - end -end diff --git a/db/migrate/20140325202826_create_teams.rb b/db/migrate/20140325202826_create_teams.rb deleted file mode 100644 index fdf9a68..0000000 --- a/db/migrate/20140325202826_create_teams.rb +++ /dev/null @@ -1,9 +0,0 @@ -class CreateTeams < ActiveRecord::Migration - def change - create_table :teams do |t| - t.references :match, index: true - - t.timestamps - end - end -end diff --git a/db/migrate/20140325202828_create_alerts.rb b/db/migrate/20140325202828_create_alerts.rb deleted file mode 100644 index 68a8e10..0000000 --- a/db/migrate/20140325202828_create_alerts.rb +++ /dev/null @@ -1,10 +0,0 @@ -class CreateAlerts < ActiveRecord::Migration - def change - create_table :alerts do |t| - t.references :author, index: true - t.text :message - - t.timestamps - end - end -end diff --git a/db/migrate/20140325202831_create_pms.rb b/db/migrate/20140325202831_create_pms.rb deleted file mode 100644 index 93bb5c6..0000000 --- a/db/migrate/20140325202831_create_pms.rb +++ /dev/null @@ -1,11 +0,0 @@ -class CreatePms < ActiveRecord::Migration - def change - create_table :pms do |t| - t.references :author, index: true - t.references :recipient, index: true - t.text :message - - t.timestamps - end - end -end diff --git a/db/migrate/20140325202833_create_tournaments.rb b/db/migrate/20140325202833_create_tournaments.rb deleted file mode 100644 index c0d8929..0000000 --- a/db/migrate/20140325202833_create_tournaments.rb +++ /dev/null @@ -1,17 +0,0 @@ -class CreateTournaments < ActiveRecord::Migration - def change - create_table :tournaments do |t| - t.string :name - t.references :game, index: true - t.integer :status - t.integer :min_players_per_team - t.integer :max_players_per_team - t.integer :min_teams_per_match - t.integer :max_teams_per_match - t.integer :set_rounds - t.boolean :randomized_teams - - t.timestamps - end - end -end diff --git a/db/migrate/20140325202836_create_games.rb b/db/migrate/20140325202836_create_games.rb deleted file mode 100644 index 5e4f56f..0000000 --- a/db/migrate/20140325202836_create_games.rb +++ /dev/null @@ -1,15 +0,0 @@ -class CreateGames < ActiveRecord::Migration - def change - create_table :games do |t| - t.text :name - t.integer :min_players_per_team - t.integer :max_players_per_team - t.integer :min_teams_per_match - t.integer :max_teams_per_match - t.integer :set_rounds - t.boolean :randomized_teams - - t.timestamps - end - end -end diff --git a/db/migrate/20140325202838_create_users.rb b/db/migrate/20140325202838_create_users.rb deleted file mode 100644 index 8032870..0000000 --- a/db/migrate/20140325202838_create_users.rb +++ /dev/null @@ -1,13 +0,0 @@ -class CreateUsers < ActiveRecord::Migration - def change - create_table :users do |t| - t.string :name - t.string :email - t.string :user_name - - t.timestamps - end - add_index :users, :email, unique: true - add_index :users, :user_name, unique: true - end -end diff --git a/db/migrate/20140325202841_create_sessions.rb b/db/migrate/20140325202841_create_sessions.rb deleted file mode 100644 index fe25bf2..0000000 --- a/db/migrate/20140325202841_create_sessions.rb +++ /dev/null @@ -1,9 +0,0 @@ -class CreateSessions < ActiveRecord::Migration - def change - create_table :sessions do |t| - t.references :user, index: true - - t.timestamps - end - end -end diff --git a/db/migrate/20140325202843_create_server_settings.rb b/db/migrate/20140325202843_create_server_settings.rb deleted file mode 100644 index dfdd91b..0000000 --- a/db/migrate/20140325202843_create_server_settings.rb +++ /dev/null @@ -1,8 +0,0 @@ -class CreateServerSettings < ActiveRecord::Migration - def change - create_table :server_settings do |t| - - t.timestamps - end - end -end diff --git a/db/migrate/20140325202846_create_tournament_options.rb b/db/migrate/20140325202846_create_tournament_options.rb deleted file mode 100644 index 53b601c..0000000 --- a/db/migrate/20140325202846_create_tournament_options.rb +++ /dev/null @@ -1,12 +0,0 @@ -class CreateTournamentOptions < ActiveRecord::Migration - def change - create_table :tournament_options do |t| - t.references :tournament, index: true - t.integer :vartype - t.string :name - t.text :value - - t.timestamps - end - end -end diff --git a/db/migrate/20140325202848_create_game_settings.rb b/db/migrate/20140325202848_create_game_settings.rb deleted file mode 100644 index 0ebbf18..0000000 --- a/db/migrate/20140325202848_create_game_settings.rb +++ /dev/null @@ -1,15 +0,0 @@ -class CreateGameSettings < ActiveRecord::Migration - def change - create_table :game_settings do |t| - t.references :game, index: true - t.integer :type - t.string :name - t.text :default - t.text :discription - t.text :type_opt - t.integer :display_order - - t.timestamps - end - end -end diff --git a/db/migrate/20140325202850_create_scores.rb b/db/migrate/20140325202850_create_scores.rb deleted file mode 100644 index 4ca0b0b..0000000 --- a/db/migrate/20140325202850_create_scores.rb +++ /dev/null @@ -1,11 +0,0 @@ -class CreateScores < ActiveRecord::Migration - def change - create_table :scores do |t| - t.references :user, index: true - t.references :match, index: true - t.integer :value - - t.timestamps - end - end -end diff --git a/db/migrate/20140325202853_create_tournament_players_join_table.rb b/db/migrate/20140325202853_create_tournament_players_join_table.rb deleted file mode 100644 index be240e8..0000000 --- a/db/migrate/20140325202853_create_tournament_players_join_table.rb +++ /dev/null @@ -1,8 +0,0 @@ -class CreateTournamentPlayersJoinTable < ActiveRecord::Migration - def change - create_join_table :players, :tournaments do |t| - # t.index [:player_id, :tournament_id] - # t.index [:tournament_id, :player_id] - end - end -end diff --git a/db/migrate/20140325202855_create_tournament_hosts_join_table.rb b/db/migrate/20140325202855_create_tournament_hosts_join_table.rb deleted file mode 100644 index 7521d89..0000000 --- a/db/migrate/20140325202855_create_tournament_hosts_join_table.rb +++ /dev/null @@ -1,8 +0,0 @@ -class CreateTournamentHostsJoinTable < ActiveRecord::Migration - def change - create_join_table :hosts, :tournaments do |t| - # t.index [:host_id, :tournament_id] - # t.index [:tournament_id, :host_id] - end - end -end diff --git a/db/migrate/20140325202858_create_team_user_join_table.rb b/db/migrate/20140325202858_create_team_user_join_table.rb deleted file mode 100644 index f3b57fc..0000000 --- a/db/migrate/20140325202858_create_team_user_join_table.rb +++ /dev/null @@ -1,8 +0,0 @@ -class CreateTeamUserJoinTable < ActiveRecord::Migration - def change - create_join_table :teams, :users do |t| - # t.index [:team_id, :user_id] - # t.index [:user_id, :team_id] - end - end -end diff --git a/db/migrate/20140325202900_create_match_team_join_table.rb b/db/migrate/20140325202900_create_match_team_join_table.rb deleted file mode 100644 index c2ed1b7..0000000 --- a/db/migrate/20140325202900_create_match_team_join_table.rb +++ /dev/null @@ -1,8 +0,0 @@ -class CreateMatchTeamJoinTable < ActiveRecord::Migration - def change - create_join_table :matches, :teams do |t| - # t.index [:match_id, :team_id] - # t.index [:team_id, :match_id] - end - end -end diff --git a/db/migrate/20140325202910_add_hidden_attrs_to_user.rb b/db/migrate/20140325202910_add_hidden_attrs_to_user.rb deleted file mode 100644 index 2f1b0b2..0000000 --- a/db/migrate/20140325202910_add_hidden_attrs_to_user.rb +++ /dev/null @@ -1,8 +0,0 @@ -class AddHiddenAttrsToUser < ActiveRecord::Migration - def change - add_column :users, :password_digest, :string - add_column :users, :remember_token, :string - add_index :users, :remember_token, unique: true - add_column :users, :groups, :integer - end -end diff --git a/db/migrate/20140325212820_create_servers.rb b/db/migrate/20140325212820_create_servers.rb new file mode 100644 index 0000000..f33241a --- /dev/null +++ b/db/migrate/20140325212820_create_servers.rb @@ -0,0 +1,8 @@ +class CreateServers < ActiveRecord::Migration + def change + create_table :servers do |t| + + t.timestamps + end + end +end diff --git a/db/migrate/20140325212823_create_matches.rb b/db/migrate/20140325212823_create_matches.rb new file mode 100644 index 0000000..30949a8 --- /dev/null +++ b/db/migrate/20140325212823_create_matches.rb @@ -0,0 +1,12 @@ +class CreateMatches < ActiveRecord::Migration + def change + create_table :matches do |t| + t.integer :status + t.references :tournament, index: true + t.string :name + t.references :winner, index: true + + t.timestamps + end + end +end diff --git a/db/migrate/20140325212826_create_teams.rb b/db/migrate/20140325212826_create_teams.rb new file mode 100644 index 0000000..fdf9a68 --- /dev/null +++ b/db/migrate/20140325212826_create_teams.rb @@ -0,0 +1,9 @@ +class CreateTeams < ActiveRecord::Migration + def change + create_table :teams do |t| + t.references :match, index: true + + t.timestamps + end + end +end diff --git a/db/migrate/20140325212828_create_alerts.rb b/db/migrate/20140325212828_create_alerts.rb new file mode 100644 index 0000000..68a8e10 --- /dev/null +++ b/db/migrate/20140325212828_create_alerts.rb @@ -0,0 +1,10 @@ +class CreateAlerts < ActiveRecord::Migration + def change + create_table :alerts do |t| + t.references :author, index: true + t.text :message + + t.timestamps + end + end +end diff --git a/db/migrate/20140325212831_create_pms.rb b/db/migrate/20140325212831_create_pms.rb new file mode 100644 index 0000000..93bb5c6 --- /dev/null +++ b/db/migrate/20140325212831_create_pms.rb @@ -0,0 +1,11 @@ +class CreatePms < ActiveRecord::Migration + def change + create_table :pms do |t| + t.references :author, index: true + t.references :recipient, index: true + t.text :message + + t.timestamps + end + end +end diff --git a/db/migrate/20140325212833_create_tournaments.rb b/db/migrate/20140325212833_create_tournaments.rb new file mode 100644 index 0000000..c0d8929 --- /dev/null +++ b/db/migrate/20140325212833_create_tournaments.rb @@ -0,0 +1,17 @@ +class CreateTournaments < ActiveRecord::Migration + def change + create_table :tournaments do |t| + t.string :name + t.references :game, index: true + t.integer :status + t.integer :min_players_per_team + t.integer :max_players_per_team + t.integer :min_teams_per_match + t.integer :max_teams_per_match + t.integer :set_rounds + t.boolean :randomized_teams + + t.timestamps + end + end +end diff --git a/db/migrate/20140325212835_create_games.rb b/db/migrate/20140325212835_create_games.rb new file mode 100644 index 0000000..5e4f56f --- /dev/null +++ b/db/migrate/20140325212835_create_games.rb @@ -0,0 +1,15 @@ +class CreateGames < ActiveRecord::Migration + def change + create_table :games do |t| + t.text :name + t.integer :min_players_per_team + t.integer :max_players_per_team + t.integer :min_teams_per_match + t.integer :max_teams_per_match + t.integer :set_rounds + t.boolean :randomized_teams + + t.timestamps + end + end +end diff --git a/db/migrate/20140325212838_create_users.rb b/db/migrate/20140325212838_create_users.rb new file mode 100644 index 0000000..8032870 --- /dev/null +++ b/db/migrate/20140325212838_create_users.rb @@ -0,0 +1,13 @@ +class CreateUsers < ActiveRecord::Migration + def change + create_table :users do |t| + t.string :name + t.string :email + t.string :user_name + + t.timestamps + end + add_index :users, :email, unique: true + add_index :users, :user_name, unique: true + end +end diff --git a/db/migrate/20140325212841_create_sessions.rb b/db/migrate/20140325212841_create_sessions.rb new file mode 100644 index 0000000..fe25bf2 --- /dev/null +++ b/db/migrate/20140325212841_create_sessions.rb @@ -0,0 +1,9 @@ +class CreateSessions < ActiveRecord::Migration + def change + create_table :sessions do |t| + t.references :user, index: true + + t.timestamps + end + end +end diff --git a/db/migrate/20140325212844_create_server_settings.rb b/db/migrate/20140325212844_create_server_settings.rb new file mode 100644 index 0000000..dfdd91b --- /dev/null +++ b/db/migrate/20140325212844_create_server_settings.rb @@ -0,0 +1,8 @@ +class CreateServerSettings < ActiveRecord::Migration + def change + create_table :server_settings do |t| + + t.timestamps + end + end +end diff --git a/db/migrate/20140325212846_create_tournament_options.rb b/db/migrate/20140325212846_create_tournament_options.rb new file mode 100644 index 0000000..53b601c --- /dev/null +++ b/db/migrate/20140325212846_create_tournament_options.rb @@ -0,0 +1,12 @@ +class CreateTournamentOptions < ActiveRecord::Migration + def change + create_table :tournament_options do |t| + t.references :tournament, index: true + t.integer :vartype + t.string :name + t.text :value + + t.timestamps + end + end +end diff --git a/db/migrate/20140325212849_create_game_settings.rb b/db/migrate/20140325212849_create_game_settings.rb new file mode 100644 index 0000000..0ebbf18 --- /dev/null +++ b/db/migrate/20140325212849_create_game_settings.rb @@ -0,0 +1,15 @@ +class CreateGameSettings < ActiveRecord::Migration + def change + create_table :game_settings do |t| + t.references :game, index: true + t.integer :type + t.string :name + t.text :default + t.text :discription + t.text :type_opt + t.integer :display_order + + t.timestamps + end + end +end diff --git a/db/migrate/20140325212851_create_scores.rb b/db/migrate/20140325212851_create_scores.rb new file mode 100644 index 0000000..4ca0b0b --- /dev/null +++ b/db/migrate/20140325212851_create_scores.rb @@ -0,0 +1,11 @@ +class CreateScores < ActiveRecord::Migration + def change + create_table :scores do |t| + t.references :user, index: true + t.references :match, index: true + t.integer :value + + t.timestamps + end + end +end diff --git a/db/migrate/20140325212854_create_tournament_players_join_table.rb b/db/migrate/20140325212854_create_tournament_players_join_table.rb new file mode 100644 index 0000000..be240e8 --- /dev/null +++ b/db/migrate/20140325212854_create_tournament_players_join_table.rb @@ -0,0 +1,8 @@ +class CreateTournamentPlayersJoinTable < ActiveRecord::Migration + def change + create_join_table :players, :tournaments do |t| + # t.index [:player_id, :tournament_id] + # t.index [:tournament_id, :player_id] + end + end +end diff --git a/db/migrate/20140325212855_create_tournament_hosts_join_table.rb b/db/migrate/20140325212855_create_tournament_hosts_join_table.rb new file mode 100644 index 0000000..7521d89 --- /dev/null +++ b/db/migrate/20140325212855_create_tournament_hosts_join_table.rb @@ -0,0 +1,8 @@ +class CreateTournamentHostsJoinTable < ActiveRecord::Migration + def change + create_join_table :hosts, :tournaments do |t| + # t.index [:host_id, :tournament_id] + # t.index [:tournament_id, :host_id] + end + end +end diff --git a/db/migrate/20140325212857_create_team_user_join_table.rb b/db/migrate/20140325212857_create_team_user_join_table.rb new file mode 100644 index 0000000..f3b57fc --- /dev/null +++ b/db/migrate/20140325212857_create_team_user_join_table.rb @@ -0,0 +1,8 @@ +class CreateTeamUserJoinTable < ActiveRecord::Migration + def change + create_join_table :teams, :users do |t| + # t.index [:team_id, :user_id] + # t.index [:user_id, :team_id] + end + end +end diff --git a/db/migrate/20140325212859_create_match_team_join_table.rb b/db/migrate/20140325212859_create_match_team_join_table.rb new file mode 100644 index 0000000..c2ed1b7 --- /dev/null +++ b/db/migrate/20140325212859_create_match_team_join_table.rb @@ -0,0 +1,8 @@ +class CreateMatchTeamJoinTable < ActiveRecord::Migration + def change + create_join_table :matches, :teams do |t| + # t.index [:match_id, :team_id] + # t.index [:team_id, :match_id] + end + end +end diff --git a/db/migrate/20140325212906_add_hidden_attrs_to_user.rb b/db/migrate/20140325212906_add_hidden_attrs_to_user.rb new file mode 100644 index 0000000..2f1b0b2 --- /dev/null +++ b/db/migrate/20140325212906_add_hidden_attrs_to_user.rb @@ -0,0 +1,8 @@ +class AddHiddenAttrsToUser < ActiveRecord::Migration + def change + add_column :users, :password_digest, :string + add_column :users, :remember_token, :string + add_index :users, :remember_token, unique: true + add_column :users, :groups, :integer + end +end diff --git a/db/schema.rb b/db/schema.rb index 952cb26..e7bb933 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20140325202910) do +ActiveRecord::Schema.define(version: 20140325212906) do create_table "alerts", force: true do |t| t.integer "author_id" @@ -54,6 +54,7 @@ ActiveRecord::Schema.define(version: 20140325202910) do end create_table "matches", force: true do |t| + t.integer "status" t.integer "tournament_id" t.string "name" t.integer "winner_id" diff --git a/generate.sh b/generate.sh index 1ff486f..2013703 100755 --- a/generate.sh +++ b/generate.sh @@ -18,7 +18,7 @@ git checkout clean-start -- app test config/routes.rb # The whole shebang, models, views, and controllers bundle exec rails generate scaffold server --force $NOTEST -bundle exec rails generate scaffold match tournament:references name:string winner:references --force $NOTEST +bundle exec rails generate scaffold match status:integer tournament:references name:string winner:references --force $NOTEST bundle exec rails generate scaffold team match:references $NOTEST bundle exec rails generate scaffold alert author:references message:text $NOTEST bundle exec rails generate scaffold pm author:references recipient:references message:text $NOTEST diff --git a/test/controllers/matches_controller_test.rb b/test/controllers/matches_controller_test.rb index 51b7f37..c3cc7a4 100644 --- a/test/controllers/matches_controller_test.rb +++ b/test/controllers/matches_controller_test.rb @@ -18,7 +18,7 @@ class MatchesControllerTest < ActionController::TestCase test "should create match" do assert_difference('Match.count') do - post :create, match: { name: @match.name, tournament_id: @match.tournament_id, winner_id: @match.winner_id } + post :create, match: { name: @match.name, status: @match.status, tournament_id: @match.tournament_id, winner_id: @match.winner_id } end assert_redirected_to match_path(assigns(:match)) @@ -35,7 +35,7 @@ class MatchesControllerTest < ActionController::TestCase end test "should update match" do - patch :update, id: @match, match: { name: @match.name, tournament_id: @match.tournament_id, winner_id: @match.winner_id } + patch :update, id: @match, match: { name: @match.name, status: @match.status, tournament_id: @match.tournament_id, winner_id: @match.winner_id } assert_redirected_to match_path(assigns(:match)) end diff --git a/test/fixtures/matches.yml b/test/fixtures/matches.yml index 956229c..00af9f5 100644 --- a/test/fixtures/matches.yml +++ b/test/fixtures/matches.yml @@ -1,11 +1,13 @@ # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html one: + status: 1 tournament_id: name: MyString winner_id: two: + status: 1 tournament_id: name: MyString winner_id: -- cgit v1.2.3-54-g00ecf From 53b4f8028fc987b0cf26a7a073fec7064b4b6d8a Mon Sep 17 00:00:00 2001 From: AndrewMurrell Date: Tue, 25 Mar 2014 17:38:38 -0400 Subject: revert Guntas --- app/assets/javascripts/ajax.js | 19 +++ app/assets/stylesheets/application.css | 12 ++ app/assets/stylesheets/custom.css.scss | 53 ++++++++ app/assets/stylesheets/scaffolds.css.scss | 40 +++++- app/assets/stylesheets/static.css.scss | 9 ++ app/assets/stylesheets/tournaments.css.scss | 9 ++ app/controllers/alerts_controller.rb | 10 ++ app/controllers/application_controller.rb | 3 + app/controllers/matches_controller.rb | 25 ++-- app/controllers/servers_controller.rb | 10 ++ app/controllers/sessions_controller.rb | 122 +++++++---------- app/controllers/static_controller.rb | 2 + app/controllers/tournaments_controller.rb | 77 +++++++++-- app/controllers/users_controller.rb | 30 ++++- app/helpers/sessions_helper.rb | 71 ++++++++++ app/models/match.rb | 6 +- app/models/team.rb | 2 + app/models/tournament.rb | 41 +++++- app/models/user.rb | 149 +++++++++++++++++++++ app/views/alerts/show.html.erb | 2 - app/views/application/permission_denied.html.erb | 1 + app/views/common/_error_messages.html.erb | 11 ++ app/views/games/index.html.erb | 6 +- app/views/games/show.html.erb | 2 - app/views/layouts/application.html.erb | 28 +++- app/views/matches/_form.html.erb | 23 +--- app/views/matches/index.html.erb | 14 +- app/views/matches/index.json.jbuilder | 2 +- app/views/matches/new.html.erb | 2 - app/views/matches/show.html.erb | 34 +++-- app/views/matches/show.json.jbuilder | 2 +- app/views/pms/show.html.erb | 2 - app/views/servers/show.html.erb | 2 - app/views/sessions/_form.html.erb | 21 --- app/views/sessions/edit.html.erb | 6 - app/views/sessions/index.html.erb | 27 ---- app/views/sessions/index.json.jbuilder | 4 - app/views/sessions/new.html.erb | 24 +++- app/views/sessions/show.html.erb | 9 -- app/views/sessions/show.json.jbuilder | 1 - app/views/static/homepage.html.erb | 18 +++ app/views/tournaments/_selected.html.erb | 21 +++ app/views/tournaments/index.html.erb | 47 ++++--- app/views/tournaments/join.html.erb | 2 + app/views/tournaments/new.html.erb | 15 ++- app/views/tournaments/show.html.erb | 35 ++++- app/views/users/already_signed_in.html.erb | 1 + app/views/users/index.html.erb | 6 +- app/views/users/new.html.erb | 33 ++++- app/views/users/show.html.erb | 2 - config/routes.rb | 14 +- db/migrate/20140325202820_create_servers.rb | 8 ++ db/migrate/20140325202823_create_matches.rb | 11 ++ db/migrate/20140325202826_create_teams.rb | 9 ++ db/migrate/20140325202828_create_alerts.rb | 10 ++ db/migrate/20140325202831_create_pms.rb | 11 ++ db/migrate/20140325202833_create_tournaments.rb | 17 +++ db/migrate/20140325202836_create_games.rb | 15 +++ db/migrate/20140325202838_create_users.rb | 13 ++ db/migrate/20140325202841_create_sessions.rb | 9 ++ .../20140325202843_create_server_settings.rb | 8 ++ .../20140325202846_create_tournament_options.rb | 12 ++ db/migrate/20140325202848_create_game_settings.rb | 15 +++ db/migrate/20140325202850_create_scores.rb | 11 ++ ...5202853_create_tournament_players_join_table.rb | 8 ++ ...325202855_create_tournament_hosts_join_table.rb | 8 ++ .../20140325202858_create_team_user_join_table.rb | 8 ++ .../20140325202900_create_match_team_join_table.rb | 8 ++ .../20140325202910_add_hidden_attrs_to_user.rb | 8 ++ db/migrate/20140325212820_create_servers.rb | 8 -- db/migrate/20140325212823_create_matches.rb | 12 -- db/migrate/20140325212826_create_teams.rb | 9 -- db/migrate/20140325212828_create_alerts.rb | 10 -- db/migrate/20140325212831_create_pms.rb | 11 -- db/migrate/20140325212833_create_tournaments.rb | 17 --- db/migrate/20140325212835_create_games.rb | 15 --- db/migrate/20140325212838_create_users.rb | 13 -- db/migrate/20140325212841_create_sessions.rb | 9 -- .../20140325212844_create_server_settings.rb | 8 -- .../20140325212846_create_tournament_options.rb | 12 -- db/migrate/20140325212849_create_game_settings.rb | 15 --- db/migrate/20140325212851_create_scores.rb | 11 -- ...5212854_create_tournament_players_join_table.rb | 8 -- ...325212855_create_tournament_hosts_join_table.rb | 8 -- .../20140325212857_create_team_user_join_table.rb | 8 -- .../20140325212859_create_match_team_join_table.rb | 8 -- .../20140325212906_add_hidden_attrs_to_user.rb | 8 -- db/schema.rb | 3 +- generate.sh | 2 +- test/controllers/matches_controller_test.rb | 4 +- test/fixtures/matches.yml | 2 - 91 files changed, 1035 insertions(+), 462 deletions(-) create mode 100644 app/assets/javascripts/ajax.js create mode 100644 app/assets/stylesheets/custom.css.scss create mode 100644 app/views/application/permission_denied.html.erb create mode 100644 app/views/common/_error_messages.html.erb delete mode 100644 app/views/sessions/_form.html.erb delete mode 100644 app/views/sessions/edit.html.erb delete mode 100644 app/views/sessions/index.html.erb delete mode 100644 app/views/sessions/index.json.jbuilder delete mode 100644 app/views/sessions/show.html.erb delete mode 100644 app/views/sessions/show.json.jbuilder create mode 100644 app/views/static/homepage.html.erb create mode 100644 app/views/tournaments/_selected.html.erb create mode 100644 app/views/tournaments/join.html.erb create mode 100644 app/views/users/already_signed_in.html.erb create mode 100644 db/migrate/20140325202820_create_servers.rb create mode 100644 db/migrate/20140325202823_create_matches.rb create mode 100644 db/migrate/20140325202826_create_teams.rb create mode 100644 db/migrate/20140325202828_create_alerts.rb create mode 100644 db/migrate/20140325202831_create_pms.rb create mode 100644 db/migrate/20140325202833_create_tournaments.rb create mode 100644 db/migrate/20140325202836_create_games.rb create mode 100644 db/migrate/20140325202838_create_users.rb create mode 100644 db/migrate/20140325202841_create_sessions.rb create mode 100644 db/migrate/20140325202843_create_server_settings.rb create mode 100644 db/migrate/20140325202846_create_tournament_options.rb create mode 100644 db/migrate/20140325202848_create_game_settings.rb create mode 100644 db/migrate/20140325202850_create_scores.rb create mode 100644 db/migrate/20140325202853_create_tournament_players_join_table.rb create mode 100644 db/migrate/20140325202855_create_tournament_hosts_join_table.rb create mode 100644 db/migrate/20140325202858_create_team_user_join_table.rb create mode 100644 db/migrate/20140325202900_create_match_team_join_table.rb create mode 100644 db/migrate/20140325202910_add_hidden_attrs_to_user.rb delete mode 100644 db/migrate/20140325212820_create_servers.rb delete mode 100644 db/migrate/20140325212823_create_matches.rb delete mode 100644 db/migrate/20140325212826_create_teams.rb delete mode 100644 db/migrate/20140325212828_create_alerts.rb delete mode 100644 db/migrate/20140325212831_create_pms.rb delete mode 100644 db/migrate/20140325212833_create_tournaments.rb delete mode 100644 db/migrate/20140325212835_create_games.rb delete mode 100644 db/migrate/20140325212838_create_users.rb delete mode 100644 db/migrate/20140325212841_create_sessions.rb delete mode 100644 db/migrate/20140325212844_create_server_settings.rb delete mode 100644 db/migrate/20140325212846_create_tournament_options.rb delete mode 100644 db/migrate/20140325212849_create_game_settings.rb delete mode 100644 db/migrate/20140325212851_create_scores.rb delete mode 100644 db/migrate/20140325212854_create_tournament_players_join_table.rb delete mode 100644 db/migrate/20140325212855_create_tournament_hosts_join_table.rb delete mode 100644 db/migrate/20140325212857_create_team_user_join_table.rb delete mode 100644 db/migrate/20140325212859_create_match_team_join_table.rb delete mode 100644 db/migrate/20140325212906_add_hidden_attrs_to_user.rb diff --git a/app/assets/javascripts/ajax.js b/app/assets/javascripts/ajax.js new file mode 100644 index 0000000..040c100 --- /dev/null +++ b/app/assets/javascripts/ajax.js @@ -0,0 +1,19 @@ +function populate() { + //populate optionArray + //make a form element + var e = document.getElementById("tournament_id"); + var gameType = e.options[e.selectedIndex].text; + if (gameType != "Select a Game Type") { + alert(gameType + " was Selected!"); + //populate optionArray via AJAX + //select * from tournament_settings where gametype = GameType + for(var option in optionArray){ + //identify the number of + ; + } + }; + +//$.ajax(url: "/selected").done (html) -> $("#ajax-form").append html + +} + diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css index 3192ec8..b3f5d46 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.css @@ -11,3 +11,15 @@ *= require_self *= require_tree . */ + +#query{ + background-color: white; + border: 2px solid #ED9C28; + border-radius: 5px; + color: #FFF; + font-weight: bold; + height: 30px; +} +.navbar{ + background-color: white; +} diff --git a/app/assets/stylesheets/custom.css.scss b/app/assets/stylesheets/custom.css.scss new file mode 100644 index 0000000..1a9b09a --- /dev/null +++ b/app/assets/stylesheets/custom.css.scss @@ -0,0 +1,53 @@ +@import "bootstrap"; + +header > nav { + @extend .navbar; + @extend .navbar-inverse; + color: white; + + #log-buttons { + margin-top: 8px; + form { display: inline; } + } + form.search { + @extend .navbar-form; + @extend .navbar-right; + input[type="submit"] { + @extend .btn-warning; margin-top: -3px; margin-right: 8px; + } + } +} + +a, input[type="submit"] { + @extend .btn; + &.user { @extend .btn-info; } + &.signup { @extend .btn-success; } + &.signin { @extend .btn-info; } + &.signout { @extend .btn-danger; } +} + +p.errors { + background-color: #FCF8C7; + color: red; + border-radius: 7px; + padding: 10px; +} + +#errorExplanation { + h2 { + font-size: 1em; + color: red; + font-weight: bold; + } + li { + font-size: 1em; + color: red; + font-style: italic; + } + +} + +#notice { + text-align: center; + font-weight: bold; +} \ No newline at end of file diff --git a/app/assets/stylesheets/scaffolds.css.scss b/app/assets/stylesheets/scaffolds.css.scss index 6ec6a8f..6700fef 100644 --- a/app/assets/stylesheets/scaffolds.css.scss +++ b/app/assets/stylesheets/scaffolds.css.scss @@ -1,3 +1,5 @@ +@import "bootstrap"; + body { background-color: #fff; color: #333; @@ -6,6 +8,10 @@ body { line-height: 18px; } +h1, h2, h3, h4, h5{ + color: #0f0f0f; +} + p, ol, ul, td { font-family: verdana, arial, helvetica, sans-serif; font-size: 13px; @@ -21,11 +27,11 @@ pre { a { color: #000; &:visited { - color: #666; + color: #000; } &:hover { - color: #fff; - background-color: #000; + color: green; + text-decoration: none; } } @@ -40,8 +46,9 @@ div { } .field_with_errors { - padding: 2px; - background-color: red; + padding: 1px; + background-color: #FF4C4C; + box-shadow: 0px 0px 5px red; display: table; } @@ -67,3 +74,26 @@ div { list-style: square; } } + +.navbar-brand { + @extend .no-dec; + a{ + color: white; + &:hover, &:active, &:focus { + color: white; + font-weight: normal; + text-decoration: none; + } + } +} + +footer { + text-align: center; + border-top: solid 1px #999999; + padding-top: 18px; + margin-top: 18px; +} + +button, input[type="submit"] { + @extend .btn; +} diff --git a/app/assets/stylesheets/static.css.scss b/app/assets/stylesheets/static.css.scss index 5a803c8..d73e77d 100644 --- a/app/assets/stylesheets/static.css.scss +++ b/app/assets/stylesheets/static.css.scss @@ -1,3 +1,12 @@ // Place all the styles related to the static controller here. // They will automatically be included in application.css. // You can use Sass (SCSS) here: http://sass-lang.com/ + +.jumbotron { + background-color: #FFF; + + p { + line-height: 1.5em; + } + +} diff --git a/app/assets/stylesheets/tournaments.css.scss b/app/assets/stylesheets/tournaments.css.scss index e372b90..458897e 100644 --- a/app/assets/stylesheets/tournaments.css.scss +++ b/app/assets/stylesheets/tournaments.css.scss @@ -1,3 +1,12 @@ // Place all the styles related to the tournaments controller here. // They will automatically be included in application.css. // You can use Sass (SCSS) here: http://sass-lang.com/ + +p.default-field { + display: inline; +} + +span.default-explanation { + color: gray; + font-style: italic; +} diff --git a/app/controllers/alerts_controller.rb b/app/controllers/alerts_controller.rb index 873e9b7..ac11854 100644 --- a/app/controllers/alerts_controller.rb +++ b/app/controllers/alerts_controller.rb @@ -1,5 +1,6 @@ class AlertsController < ApplicationController before_action :set_alert, only: [:show, :edit, :update, :destroy] + before_action :check_perms, only: [:new, :create, :edit, :update, :destroy] # GET /alerts # GET /alerts.json @@ -67,6 +68,15 @@ class AlertsController < ApplicationController @alert = Alert.find(params[:id]) end + def check_perms + unless (signed_in? and (current_user.in_group?(:admin) or current_user.in_group?(:host))) + respond_to do |format| + format.html { render action: 'permission_denied', status: :forbidden } + format.json { render json: "Permission denied", status: :forbidden } + end + end + end + # Never trust parameters from the scary internet, only allow the white list through. def alert_params params.require(:alert).permit(:author_id, :message) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index d83690e..7487f87 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -2,4 +2,7 @@ class ApplicationController < ActionController::Base # Prevent CSRF attacks by raising an exception. # For APIs, you may want to use :null_session instead. protect_from_forgery with: :exception + + #include sessionhelper for the session controller and view + include SessionsHelper end diff --git a/app/controllers/matches_controller.rb b/app/controllers/matches_controller.rb index d79a7fc..1f0d964 100644 --- a/app/controllers/matches_controller.rb +++ b/app/controllers/matches_controller.rb @@ -1,10 +1,10 @@ class MatchesController < ApplicationController + before_action :set_tournament, only: [:index, :new, :create] before_action :set_match, only: [:show, :edit, :update, :destroy] - # GET /matches # GET /matches.json def index - @matches = Match.all + @matches = @tournament.matches end # GET /matches/1 @@ -14,7 +14,7 @@ class MatchesController < ApplicationController # GET /matches/new def new - @match = Match.new + end # GET /matches/1/edit @@ -24,11 +24,11 @@ class MatchesController < ApplicationController # POST /matches # POST /matches.json def create - @match = Match.new(match_params) + @match = @tournament.matches.build(match_params) respond_to do |format| if @match.save - format.html { redirect_to @match, notice: 'Match was successfully created.' } + format.html { redirect_to tournament_matches_path, notice: 'Match was successfully created.' } format.json { render action: 'show', status: :created, location: @match } else format.html { render action: 'new' } @@ -42,7 +42,7 @@ class MatchesController < ApplicationController def update respond_to do |format| if @match.update(match_params) - format.html { redirect_to @match, notice: 'Match was successfully updated.' } + format.html { redirect_to [@tournament, @match], notice: 'Match was successfully updated.' } format.json { head :no_content } else format.html { render action: 'edit' } @@ -54,21 +54,24 @@ class MatchesController < ApplicationController # DELETE /matches/1 # DELETE /matches/1.json def destroy + @match.destroy respond_to do |format| - format.html { redirect_to matches_url } - format.json { head :no_content } + format.html { redirect_to tournament_matches_path } end end private # Use callbacks to share common setup or constraints between actions. def set_match - @match = Match.find(params[:id]) + @tournament = Tournament.find(params[:tournament_id]) + @match = @tournament.matches.find(params[:id]); + end + def set_tournament + @tournament = Tournament.find(params[:tournament_id]) end - # Never trust parameters from the scary internet, only allow the white list through. def match_params - params.require(:match).permit(:status, :tournament_id, :name, :winner_id) + params.require(:match).permit(:tournament_id, :name, :winner_id) end end diff --git a/app/controllers/servers_controller.rb b/app/controllers/servers_controller.rb index 7d54eb6..bb5d5f7 100644 --- a/app/controllers/servers_controller.rb +++ b/app/controllers/servers_controller.rb @@ -1,5 +1,6 @@ class ServersController < ApplicationController before_action :set_server, only: [:show, :edit, :update, :destroy] + before_action :check_perms # GET /servers # GET /servers.json @@ -67,6 +68,15 @@ class ServersController < ApplicationController @server = Server.find(params[:id]) end + def check_perms + unless (signed_in? and current_user.in_group?(:admin)) + respond_to do |format| + format.html { render action: 'permission_denied', status: :forbidden } + format.json { render json: "Permission denied", status: :forbidden } + end + end + end + # Never trust parameters from the scary internet, only allow the white list through. def server_params params[:server] diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb index 2f72bf7..7cb16e8 100644 --- a/app/controllers/sessions_controller.rb +++ b/app/controllers/sessions_controller.rb @@ -1,74 +1,52 @@ class SessionsController < ApplicationController - before_action :set_session, only: [:show, :edit, :update, :destroy] - - # GET /sessions - # GET /sessions.json - def index - @sessions = Session.all - end - - # GET /sessions/1 - # GET /sessions/1.json - def show - end - - # GET /sessions/new - def new - @session = Session.new - end - - # GET /sessions/1/edit - def edit - end - - # POST /sessions - # POST /sessions.json - def create - @session = Session.new(session_params) - - respond_to do |format| - if @session.save - format.html { redirect_to @session, notice: 'Session was successfully created.' } - format.json { render action: 'show', status: :created, location: @session } - else - format.html { render action: 'new' } - format.json { render json: @session.errors, status: :unprocessable_entity } - end - end - end - - # PATCH/PUT /sessions/1 - # PATCH/PUT /sessions/1.json - def update - respond_to do |format| - if @session.update(session_params) - format.html { redirect_to @session, notice: 'Session was successfully updated.' } - format.json { head :no_content } - else - format.html { render action: 'edit' } - format.json { render json: @session.errors, status: :unprocessable_entity } - end - end - end - - # DELETE /sessions/1 - # DELETE /sessions/1.json - def destroy - @session.destroy - respond_to do |format| - format.html { redirect_to sessions_url } - format.json { head :no_content } - end - end - - private - # Use callbacks to share common setup or constraints between actions. - def set_session - @session = Session.find(params[:id]) - end - - # Never trust parameters from the scary internet, only allow the white list through. - def session_params - params.require(:session).permit(:user_id) - end + before_action :set_session, only: [:destroy] + + # GET /sessions/new + def new + @user = User.new + #@session = Session.new + end + + # POST /sessions + # POST /sessions.json + def create + # find the user... + @user = User.find_by_email(params[:session][:username_or_email]) || User.find_by_user_name(params[:session][:username_or_email]) + + #@session = Session.new(@user) + # ... and create a new session + respond_to do |format| + if @user && @user.authenticate(params[:session][:password]) + sign_in @user + format.html { redirect_to root_path } + #format.json { #TODO } + else + format.html { render action: 'new' } + format.json { render json: @user.errors, status: :unprocessable_entity } + end + end + end + + # DELETE /sessions/1 + # DELETE /sessions/1.json + def destroy + #@session.destroy + sign_out + respond_to do |format| + format.html { redirect_to root_path } + format.json { head :no_content } + end + end + + private + + # Use callbacks to share common setup or constraints between actions. + def set_session + #@session = Session.find(cookies[:remember_token]) + end + + # Never trust parameters from the scary internet, only allow the white list through. + def session_params + params.require(:session).permit(:session_email, :session_user_name, :session_password) + end end diff --git a/app/controllers/static_controller.rb b/app/controllers/static_controller.rb index c6df11e..6fc9490 100644 --- a/app/controllers/static_controller.rb +++ b/app/controllers/static_controller.rb @@ -1,2 +1,4 @@ class StaticController < ApplicationController + def homepage + end end diff --git a/app/controllers/tournaments_controller.rb b/app/controllers/tournaments_controller.rb index d7db632..8d90758 100644 --- a/app/controllers/tournaments_controller.rb +++ b/app/controllers/tournaments_controller.rb @@ -1,5 +1,6 @@ class TournamentsController < ApplicationController - before_action :set_tournament, only: [:show, :edit, :update, :destroy] + before_action :set_tournament, only: [:show, :edit, :update, :destroy, :join] + before_action :check_perms, only: [:new, :create, :edit, :destroy] # GET /tournaments # GET /tournaments.json @@ -10,24 +11,37 @@ class TournamentsController < ApplicationController # GET /tournaments/1 # GET /tournaments/1.json def show + case @tournament.status + when 0 + when 1..2 + redirect_to "/tournaments/" + @tournament.id.to_s + "/matches" #tournament_matches_page(@tournament) + end end # GET /tournaments/new def new - @tournament = Tournament.new + @games = Game.all + @tournament = Tournament.new(game: Game.find_by_id(params[:game])) end # GET /tournaments/1/edit def edit + if params['close_action'] == 'close' + @tournament.status = 1 + @tournament.save + @tournament.setup(@tournament) + redirect_to "/tournaments" + end end # POST /tournaments # POST /tournaments.json def create @tournament = Tournament.new(tournament_params) - + @tournament.status = 0 respond_to do |format| if @tournament.save + @tournament.hosts.push(current_user) format.html { redirect_to @tournament, notice: 'Tournament was successfully created.' } format.json { render action: 'show', status: :created, location: @tournament } else @@ -40,13 +54,45 @@ class TournamentsController < ApplicationController # PATCH/PUT /tournaments/1 # PATCH/PUT /tournaments/1.json def update - respond_to do |format| - if @tournament.update(tournament_params) - format.html { redirect_to @tournament, notice: 'Tournament was successfully updated.' } - format.json { head :no_content } + + if params[:update_action].nil? + check_perms + respond_to do |format| + if @tournament.update(tournament_params) + format.html { redirect_to @tournament, notice: 'Tournament was successfully updated.' } + format.json { head :no_content } + else + format.html { render action: 'edit' } + format.json { render json: @tournament.errors, status: :unprocessable_entity } + end + end + else + case params[:update_action] + when "join" + respond_to do |format| + if @tournament.join(current_user) + format.html { render action: 'show', notice: 'You have joined this tournament.' } + format.json { head :no_content } + end + format.html { render action: 'permission_denied', status: :forbidden } + format.json { render json: "Permission denied", status: :forbidden } + end + when "open" + respond_to do |format| + if @tournament.setup + format.html { render action: 'show', notice: 'You have joined this tournament.' } + format.json { head :no_content } + end + format.html { render action: 'permission_denied', status: :forbidden } + format.json { render json: "Permission denied", status: :forbidden } + end + #when "close" + # TODO else - format.html { render action: 'edit' } - format.json { render json: @tournament.errors, status: :unprocessable_entity } + respond_to do |format| + format.html { render action: 'show', notice: "Invalid action", status: :unprocessable_entity } + format.json { render json: @tournament.errors, status: :unprocessable_entity } + end end end end @@ -67,8 +113,19 @@ class TournamentsController < ApplicationController @tournament = Tournament.find(params[:id]) end + def check_perms + unless (signed_in? and current_user.in_group?(:host)) + respond_to do |format| + format.html { render action: 'permission_denied', status: :forbidden } + format.json { render json: "Permission denied", status: :forbidden } + end + end + end + # Never trust parameters from the scary internet, only allow the white list through. def tournament_params - params.require(:tournament).permit(:name, :game_id, :status, :min_players_per_team, :max_players_per_team, :min_teams_per_match, :max_teams_per_match, :set_rounds, :randomized_teams) + + params.require(:tournament).permit(:game, :name, :game_id, :status, :min_players_per_team, :max_players_per_team, :min_teams_per_match, :max_teams_per_match, :set_rounds, :randomized_teams) + end end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index b18efed..70facca 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -1,5 +1,7 @@ class UsersController < ApplicationController before_action :set_user, only: [:show, :edit, :update, :destroy] + before_action :perms_edit, only: [:edit, :update, :destroy] + before_action :perms_create, only: [:new, :create] # GET /users # GET /users.json @@ -10,6 +12,7 @@ class UsersController < ApplicationController # GET /users/1 # GET /users/1.json def show + @user = User.find(params[:id]) end # GET /users/new @@ -25,13 +28,14 @@ class UsersController < ApplicationController # POST /users.json def create @user = User.new(user_params) - + @user.groups = 0 respond_to do |format| if @user.save - format.html { redirect_to @user, notice: 'User was successfully created.' } + sign_in @user + format.html { redirect_to root_path, notice: 'User was successfully created.' } format.json { render action: 'show', status: :created, location: @user } else - format.html { render action: 'new' } + format.html { render action: 'new', status: :unprocessable_entity } format.json { render json: @user.errors, status: :unprocessable_entity } end end @@ -67,8 +71,26 @@ class UsersController < ApplicationController @user = User.find(params[:id]) end + def perms_edit + unless (current_user == @user) or (signed_in? and current_user.in_group? :admin) + respond_to do |format| + format.html { render action: 'permission_denied', status: :forbidden } + format.json { render json: "Permission denied", status: :forbidden } + end + end + end + + def perms_create + if signed_in? + respond_to do |format| + format.html { render action: 'already_signed_in', status: :unprocessable_entity } + format.json { render json: "Already signed in", status: :unprocessable_entity } + end + end + end + # Never trust parameters from the scary internet, only allow the white list through. def user_params - params.require(:user).permit(:name, :email, :user_name) + params.require(:user).permit(:name, :email, :user_name, :password, :password_confirmation) end end diff --git a/app/helpers/sessions_helper.rb b/app/helpers/sessions_helper.rb index 309f8b2..046ca6f 100644 --- a/app/helpers/sessions_helper.rb +++ b/app/helpers/sessions_helper.rb @@ -1,2 +1,73 @@ module SessionsHelper + + def sign_in(user) + #create a new remember token + remember_token = User.new_remember_token + #place token inside of the browser + cookies.permanent[:remember_token] = remember_token + #save the hashed token to the database + user.update_attribute(:remember_token, + User.hash(remember_token)) + #set the current user to be the given user + self.current_user = user + end + +# The curret_user=(user) is the conversion of self.current_user = user + def current_user=(user) + @current_user = user + end + +# sets the @current_user instance virable to the user corresponding +# to the remember token, but only if @current_user is undefined +# since the remember token is hashed, we need to hash the cookie +# to find match the remember token + def current_user + remember_token = User.hash(cookies[:remember_token]) + @current_user ||= User.find_by(remember_token: remember_token) + end + + # checks if someone is currently signed in + def signed_in? + !current_user.nil? + end + + def sign_out + current_user.update_attribute(:remember_token, User.hash(User.new_remember_token)) + cookies.delete(:remember_token) + self.current_user = nil + end + +=begin + +This is for anyone that cares about how long a user is signed +in: + +Currently I have a user to be signed in forever unless they +log out (cookies.permanent....). + +If you want to change that, change line 7 to this: + +cookies[:remember_token] = { value: remember_token, + expires: 20.years.from_now.utc } + +which will expire the cookie in 20 years from its date of +creation. + +Oddly enough, this line above is equivalent to the: + +cookies.permanent + +This is just a short cut for this line since most people +create permanent cookies these days. + +Other times are: + +10.weeks.from_now + +5.days.ago + +etc... + +=end + end diff --git a/app/models/match.rb b/app/models/match.rb index bb814c1..782dce8 100644 --- a/app/models/match.rb +++ b/app/models/match.rb @@ -1,4 +1,8 @@ class Match < ActiveRecord::Base belongs_to :tournament - belongs_to :winner + + has_and_belongs_to_many :teams + + belongs_to :winner, class_name: "Team" + end diff --git a/app/models/team.rb b/app/models/team.rb index 9e71557..2348de5 100644 --- a/app/models/team.rb +++ b/app/models/team.rb @@ -1,3 +1,5 @@ class Team < ActiveRecord::Base belongs_to :match + has_and_belongs_to_many :matches + has_and_belongs_to_many :users end diff --git a/app/models/tournament.rb b/app/models/tournament.rb index cc915a0..69bedf5 100644 --- a/app/models/tournament.rb +++ b/app/models/tournament.rb @@ -1,3 +1,42 @@ class Tournament < ActiveRecord::Base - belongs_to :game + belongs_to :game + has_many :matches + has_and_belongs_to_many :players, class_name: "User", association_foreign_key: "player_id", join_table: "players_tournaments" + has_and_belongs_to_many :hosts, class_name: "User", association_foreign_key: "host_id", join_table: "hosts_tournaments" + + def open? + return true + end + + def joinable_by?(user) + return ((not user.nil?) and user.in_group?(:player) and open?) + end + + def join(user) + unless joinable_by?(user) + return false + end + players.push(user) + end + + def setup(tournament) + num_teams = (self.players.count/self.max_players_per_team).floor + num_matches = num_teams - 1 + for i in 1..num_matches + self.matches.create(name: "Match #{i}") + end + match_num = 0 + team_num = 0 + self.players.each_slice(tournament.max_players_per_team) do |players| + self.matches[match_num].teams.push(Team.create(users: players)) + if (team_num != 0 and team_num % tournament.max_teams_per_match == 0) + match_num += 1 + team_num = 0 + else + team_num += 1 + end + end + end + + end diff --git a/app/models/user.rb b/app/models/user.rb index 4a57cf0..6e439fb 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,2 +1,151 @@ class User < ActiveRecord::Base + has_and_belongs_to_many :tournaments_played, class_name: "Tournament", foreign_key: "player_id", join_table: "players_tournaments" + has_and_belongs_to_many :tournaments_hosted, class_name: "Tournament", foreign_key: "host_id", join_table: "hosts_tournaments" + has_and_belongs_to_many :teams + + before_save { self.email = email.downcase } + before_save { self.user_name = user_name } + + ## + # Rails looks for the create_remember_token and runs the method + # before anything else. + # + # This method cannot be called by a user since it is denoted + # as private. + before_create :create_remember_token + + def in_group?(group) + case group + when :admin + return ((groups & 2) != 0) + when :host + return true #((groups & 1) != 0) + when :player + return true + when :specator + return true + else + return false + end + end + + def join_groups(join=[]) + # FIXME: race condition + join.each do |group| + case group + when :admin + groups |= 2 + when :host + groups |= 1 + else + end + end + end + + def leave_groups(leave=[]) + # FIXME: race condition + leave.each do |group| + case group + when :admin + groups &= ~ 2 + when :host + groups &= ~ 1 + else + end + end + end + + ## + # VAILD_EMAIL is the regex used to validate a user given email. + VALID_EMAIL_REG = /\A\S+@\S+\.\S+\z/i + + ## + # VALID_USER_NAME checks to make sure a user's user_name + # is in the proper format. + VALID_USER_NAME_REG = /\A[a-zA-Z0-9\-]+\z/ + + ## + # The following lines put a user account through a series of + # validations in order to make sure all of their information + # is in the proper format. + # + # validates :symbol_to_be_validated + # + # - presence: determines whether or not a symbol is filled or not + # - length: ensures there is a length limit on the symbol + # - format: checks the format of given information to ensure + # validity + validates(:name, presence: true, length: { maximum: 50 }) + validates(:email, presence: true, format: {with: + VALID_EMAIL_REG}, + uniqueness: { case_sensitive: false }) + validates(:user_name, presence: true, length:{maximum: 50}, + format: {with: VALID_USER_NAME_REG }, + uniqueness: {case_sensitive: false }) + + ## + # Instead of adding password and password_confirmation + # attributes, requiring the presence of a password, + # requiring that pw and pw_com match, and add an authenticate + # method to compare an encrypted password to the + # password_digest to authenticate users, I can just add + # has_secure_password which does all of this for me. + has_secure_password + + validates :password, length: { minimum: 6 } + + ## + # Create a random remember token for the user. This will be + # changed every time the user creates a new session. + # + # By changing the cookie every new session, any hijacked sessions + # (where the attacker steals a cookie to sign in as a certain + # user) will expire the next time the user signs back in. + # + # The random string is of length 16 composed of A-Z, a-z, 0-9 + # This is the browser's cookie value. + def User.new_remember_token + SecureRandom.urlsafe_base64 + end + + ## + # Encrypt the remember token. + # This is the encrypted version of the cookie stored on + # the database. + # + # The reasoning for storing a hashed token is so that even if + # the database is compromised, the attacker won't be able to use + # the remember tokens to sign in. + def User.hash(token) + Digest::SHA1.hexdigest(token.to_s) + end + + ## + # SHA-1 (Secure Hash Algorithm) is a US engineered hash + # function that produces a 20 byte hash value which typically + # forms a hexadecimal number 40 digits long. + # The reason I am not using the Bcrypt algorithm is because + # SHA-1 is much faster and I will be calling this on + # every page a user accesses. + # + # https://en.wikipedia.org/wiki/SHA-1 + + + # Everything under private is hidden so you cannot call. + private + + ## + # Create_remember_token in order to ensure a user always has + # a remember token. + def create_remember_token + self.remember_token = User.hash(User.new_remember_token) + end + + ## + # In order to ensure that someone did not accidentally submit + # two accounts rapidly (which would throw off the validates + # for user_name and email), I added an index to the Users + # email and user_name in the database to ensure uniqueness + # This also gives and index to the user_name and email + # so finding a user SHOULD be easier for the database. end diff --git a/app/views/alerts/show.html.erb b/app/views/alerts/show.html.erb index eeab7f7..5dda2c9 100644 --- a/app/views/alerts/show.html.erb +++ b/app/views/alerts/show.html.erb @@ -1,5 +1,3 @@ -

<%= notice %>

-

Author: <%= @alert.author %> diff --git a/app/views/application/permission_denied.html.erb b/app/views/application/permission_denied.html.erb new file mode 100644 index 0000000..1ef883c --- /dev/null +++ b/app/views/application/permission_denied.html.erb @@ -0,0 +1 @@ +

Permission denied

diff --git a/app/views/common/_error_messages.html.erb b/app/views/common/_error_messages.html.erb new file mode 100644 index 0000000..731f62c --- /dev/null +++ b/app/views/common/_error_messages.html.erb @@ -0,0 +1,11 @@ +<%# http://railscasts.com/episodes/211-validations-in-rails-3 %> +<% if target.errors.any? %> +
+

<%= pluralize(target.errors.count, "error") %> prohibited this form from being submitted:

+
    + <% target.errors.full_messages.each do |msg| %> +
  • <%= msg %>
  • + <% end %> +
+
+<% end %> diff --git a/app/views/games/index.html.erb b/app/views/games/index.html.erb index 27c5860..79acd1e 100644 --- a/app/views/games/index.html.erb +++ b/app/views/games/index.html.erb @@ -1,6 +1,6 @@

Listing games

-
Username Name Email User name
<%= link_to("#{user.user_name}", user, nil) %> <%= user.name %> ******* <%= user.email %> <%= user.user_name %> <%= link_to 'Show', user %> <%= link_to 'Edit', edit_user_path(user) %>
+
@@ -36,4 +36,6 @@
-<%= link_to 'New Game', new_game_path %> + +<%= link_to 'New Game', new_game_path, {:class => "btn btn-warning"} %> + diff --git a/app/views/games/show.html.erb b/app/views/games/show.html.erb index 1f1a154..39d4a97 100644 --- a/app/views/games/show.html.erb +++ b/app/views/games/show.html.erb @@ -1,5 +1,3 @@ -

<%= notice %>

-

Name: <%= @game.name %> diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index cefd1be..976ee85 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -5,10 +5,36 @@ <%= stylesheet_link_tag "application", media: "all", "data-turbolinks-track" => true %> <%= javascript_include_tag "application", "data-turbolinks-track" => true %> <%= csrf_meta_tags %> + <%= yield :head %> +

+<% if notice %>

<%= notice %>

<% end %> + +
<%= yield %>
+ +
+

Leaguer © 2014, Tomer Kimia, Andrew Murrell, Luke Shumaker, Nathaniel Foy, Davis Webb, and Guntas Grewal

+
+<%= debug(params) if Rails.env.development? %> diff --git a/app/views/matches/_form.html.erb b/app/views/matches/_form.html.erb index 727c002..015aed0 100644 --- a/app/views/matches/_form.html.erb +++ b/app/views/matches/_form.html.erb @@ -1,20 +1,5 @@ -<%= form_for(@match) do |f| %> - <% if @match.errors.any? %> -
-

<%= pluralize(@match.errors.count, "error") %> prohibited this match from being saved:

- -
    - <% @match.errors.full_messages.each do |msg| %> -
  • <%= msg %>
  • - <% end %> -
-
- <% end %> - -
- <%= f.label :status %>
- <%= f.number_field :status %> -
+<%= form_for([@tournament, @tournament.matches.build]) do |f| %> +
<%= f.label :tournament_id %>
<%= f.text_field :tournament_id %> @@ -23,10 +8,6 @@ <%= f.label :name %>
<%= f.text_field :name %>
-
- <%= f.label :winner_id %>
- <%= f.text_field :winner_id %> -
<%= f.submit %>
diff --git a/app/views/matches/index.html.erb b/app/views/matches/index.html.erb index 400efb4..60df1b5 100644 --- a/app/views/matches/index.html.erb +++ b/app/views/matches/index.html.erb @@ -3,7 +3,6 @@
Name
- @@ -14,15 +13,14 @@ - <% @matches.each do |match| %> + <% @tournament.matches.each do |match| %> - - + - - - + + + <% end %> @@ -30,4 +28,4 @@
-<%= link_to 'New Match', new_match_path %> +<%= link_to 'New Match', new_tournament_match_path %> diff --git a/app/views/matches/index.json.jbuilder b/app/views/matches/index.json.jbuilder index 1a63f5f..0b2bfcd 100644 --- a/app/views/matches/index.json.jbuilder +++ b/app/views/matches/index.json.jbuilder @@ -1,4 +1,4 @@ json.array!(@matches) do |match| - json.extract! match, :id, :status, :tournament_id, :name, :winner_id + json.extract! match, :id, :tournament_id, :name, :winner_id json.url match_url(match, format: :json) end diff --git a/app/views/matches/new.html.erb b/app/views/matches/new.html.erb index bd4c78c..74e7e3a 100644 --- a/app/views/matches/new.html.erb +++ b/app/views/matches/new.html.erb @@ -1,5 +1,3 @@

New match

<%= render 'form' %> - -<%= link_to 'Back', matches_path %> diff --git a/app/views/matches/show.html.erb b/app/views/matches/show.html.erb index f3fc822..b6930ea 100644 --- a/app/views/matches/show.html.erb +++ b/app/views/matches/show.html.erb @@ -1,13 +1,6 @@ -

<%= notice %>

- -

- Status: - <%= @match.status %> -

-

Tournament: - <%= @match.tournament %> + <%= @match.tournament.id %>

@@ -15,10 +8,23 @@ <%= @match.name %>

-

- Winner: - <%= @match.winner %> -

+<% if (@tournament.hosts.include?(current_user) and @match.winner.nil?) %> + <%= form_for([@tournament, @match], method: "put") do |f| %> + + <%= f.submit("Select winner") %> + <% end %> +<% end %> + +<% unless @match.winner.nil? %> +

+ Winner: + <%= @match.winner.users.collect{|u| u.user_name}.join(", ") %> +

+<% end %> -<%= link_to 'Edit', edit_match_path(@match) %> | -<%= link_to 'Back', matches_path %> +<%= link_to 'Back', tournament_matches_path %> diff --git a/app/views/matches/show.json.jbuilder b/app/views/matches/show.json.jbuilder index a3ef588..fe14010 100644 --- a/app/views/matches/show.json.jbuilder +++ b/app/views/matches/show.json.jbuilder @@ -1 +1 @@ -json.extract! @match, :id, :status, :tournament_id, :name, :winner_id, :created_at, :updated_at +json.extract! @match, :id, :tournament_id, :name, :winner_id, :created_at, :updated_at diff --git a/app/views/pms/show.html.erb b/app/views/pms/show.html.erb index 5ee483f..2a03716 100644 --- a/app/views/pms/show.html.erb +++ b/app/views/pms/show.html.erb @@ -1,5 +1,3 @@ -

<%= notice %>

-

Author: <%= @pm.author %> diff --git a/app/views/servers/show.html.erb b/app/views/servers/show.html.erb index 039cd8f..67f7647 100644 --- a/app/views/servers/show.html.erb +++ b/app/views/servers/show.html.erb @@ -1,4 +1,2 @@ -

<%= notice %>

- <%= link_to 'Edit', edit_server_path(@server) %> | <%= link_to 'Back', servers_path %> diff --git a/app/views/sessions/_form.html.erb b/app/views/sessions/_form.html.erb deleted file mode 100644 index 1b94e77..0000000 --- a/app/views/sessions/_form.html.erb +++ /dev/null @@ -1,21 +0,0 @@ -<%= form_for(@session) do |f| %> - <% if @session.errors.any? %> -
-

<%= pluralize(@session.errors.count, "error") %> prohibited this session from being saved:

- -
    - <% @session.errors.full_messages.each do |msg| %> -
  • <%= msg %>
  • - <% end %> -
-
- <% end %> - -
- <%= f.label :user_id %>
- <%= f.text_field :user_id %> -
-
- <%= f.submit %> -
-<% end %> diff --git a/app/views/sessions/edit.html.erb b/app/views/sessions/edit.html.erb deleted file mode 100644 index bbd8407..0000000 --- a/app/views/sessions/edit.html.erb +++ /dev/null @@ -1,6 +0,0 @@ -

Editing session

- -<%= render 'form' %> - -<%= link_to 'Show', @session %> | -<%= link_to 'Back', sessions_path %> diff --git a/app/views/sessions/index.html.erb b/app/views/sessions/index.html.erb deleted file mode 100644 index 707a47d..0000000 --- a/app/views/sessions/index.html.erb +++ /dev/null @@ -1,27 +0,0 @@ -

Listing sessions

- -
Status Tournament Name Winner
<%= match.status %><%= match.tournament %><%= match.tournament.id %> <%= match.name %> <%= match.winner %><%= link_to 'Show', match %><%= link_to 'Edit', edit_match_path(match) %><%= link_to 'Destroy', match, method: :delete, data: { confirm: 'Are you sure?' } %><%= link_to 'Show', tournament_match_path(@tournament, match) %><%= link_to 'Edit', edit_tournament_match_path(@tournament, match) %><%= link_to 'Destroy', tournament_match_path(@tournament, match), method: :delete, data: { confirm: 'Are you sure?' } %>
- - - - - - - - - - - <% @sessions.each do |session| %> - - - - - - - <% end %> - -
User
<%= session.user %><%= link_to 'Show', session %><%= link_to 'Edit', edit_session_path(session) %><%= link_to 'Destroy', session, method: :delete, data: { confirm: 'Are you sure?' } %>
- -
- -<%= link_to 'New Session', new_session_path %> diff --git a/app/views/sessions/index.json.jbuilder b/app/views/sessions/index.json.jbuilder deleted file mode 100644 index 18fd4fa..0000000 --- a/app/views/sessions/index.json.jbuilder +++ /dev/null @@ -1,4 +0,0 @@ -json.array!(@sessions) do |session| - json.extract! session, :id, :user_id - json.url session_url(session, format: :json) -end diff --git a/app/views/sessions/new.html.erb b/app/views/sessions/new.html.erb index 55c9eca..b4acf77 100644 --- a/app/views/sessions/new.html.erb +++ b/app/views/sessions/new.html.erb @@ -1,5 +1,23 @@ -

New session

+

Sign in

+<% if @user.nil? %> +

The email/username or password is incorrect. Verify that CAPS LOCK is not on, and then retype the current email/username and password.

+<% end %> -<%= render 'form' %> +
+ <%= form_for(:session, url: sessions_path) do |f| %> +

+ <%= f.label(:username_or_email, "Username/Email") %>
+ <%= f.text_field :username_or_email%> +

+

+ <%= f.label :password %>
+ <%= f.password_field :password %> +

+

+ <%= f.submit "Sign in", class: "btn btn-large btn-primary" %> +

+ <% end %> + +

New user? <%= link_to("Sign up now!", new_user_path) %>

+
-<%= link_to 'Back', sessions_path %> diff --git a/app/views/sessions/show.html.erb b/app/views/sessions/show.html.erb deleted file mode 100644 index 5176869..0000000 --- a/app/views/sessions/show.html.erb +++ /dev/null @@ -1,9 +0,0 @@ -

<%= notice %>

- -

- User: - <%= @session.user %> -

- -<%= link_to 'Edit', edit_session_path(@session) %> | -<%= link_to 'Back', sessions_path %> diff --git a/app/views/sessions/show.json.jbuilder b/app/views/sessions/show.json.jbuilder deleted file mode 100644 index 4ebf936..0000000 --- a/app/views/sessions/show.json.jbuilder +++ /dev/null @@ -1 +0,0 @@ -json.extract! @session, :id, :user_id, :created_at, :updated_at diff --git a/app/views/static/homepage.html.erb b/app/views/static/homepage.html.erb new file mode 100644 index 0000000..3ca8176 --- /dev/null +++ b/app/views/static/homepage.html.erb @@ -0,0 +1,18 @@ +
+ +
+

Welcome to Leaguer

+

This is a tournment management system designed to be used for any team sport. Our peer review system ensures that the best players move on to the next round! Try creating a new tournament and having people sign up for it.

+

+ <% if !signed_in? %> + <%= link_to 'Log In', new_session_path, :class => "btn btn-warning btn-lg", :role => "button" %> + <%= link_to 'Sign Up', new_user_path, :class => "btn btn-warning btn-lg", :role => "button" %> + <% else %> + <%= link_to 'Start a Tournament', new_tournament_path, :class => "btn btn-warning btn-lg", :role => "button" %> + <% end %> + <%= link_to 'See Ongoing Tournaments', tournaments_path, :class => "btn btn-warning btn-lg", :role => "button" %> + +

+
+ +
diff --git a/app/views/tournaments/_selected.html.erb b/app/views/tournaments/_selected.html.erb new file mode 100644 index 0000000..8734b14 --- /dev/null +++ b/app/views/tournaments/_selected.html.erb @@ -0,0 +1,21 @@ +<%= form_for(@tournament) do |f| %> + <%= render "common/error_messages", :target => @tournament %> + <%= f.hidden_field(:game_id) %> + + <% @chosen = Game.find_by(params[:game]) %> + <% @tournament.attributes.each do |name, value| %> + <% if (name == "id") or (name =~ /.*_at$/) or (name == "game_id") or (name == "status") %> + <% next %> + <% end %> +

+ <%= f.label name %>
+ <% if !@chosen.attributes[name].nil? %> + <%= f.text_field(name, :value => @chosen.attributes[name] ) %> + <% else %> + <%= f.text_field name %> + <% end %> +

+ <% end %> + + <%= f.submit %> +<% end %> diff --git a/app/views/tournaments/index.html.erb b/app/views/tournaments/index.html.erb index f8f21e7..90c3d7a 100644 --- a/app/views/tournaments/index.html.erb +++ b/app/views/tournaments/index.html.erb @@ -1,16 +1,14 @@ -

Listing tournaments

+

Listing Tournaments

- +<% if @tournaments.length > 0 %> +
- - - - - + + @@ -22,13 +20,28 @@ <% @tournaments.each do |tournament| %> - - - - - - - + + + @@ -37,7 +50,9 @@ <% end %>
Name Game StatusMin players per teamMax players per teamMin teams per matchMax teams per matchSet roundsPlayers per teamTeams per match Randomized teams
<%= tournament.name %><%= tournament.game %><%= tournament.status %><%= tournament.min_players_per_team %><%= tournament.max_players_per_team %><%= tournament.min_teams_per_match %><%= tournament.max_teams_per_match %><%= tournament.set_rounds %><% case tournament.status + when 0 %> + <%= form_tag(tournament_path(tournament), method: "put") do %> + + <%= submit_tag("Join") %> + <% end %> + <% when 1 %> + Ongoing + <% else %> + Closed + <%end %> + <%= tournament.min_players_per_team %> + <% if tournament.min_players_per_team != tournament.max_players_per_team %> + to <%= tournament.max_players_per_team %> + <% end %> + <%= tournament.min_teams_per_match %> + <% if tournament.min_teams_per_match != tournament.max_teams_per_match %> + to <%= tournament.max_teams_per_match %> + <% end %> + <%= tournament.randomized_teams %> <%= link_to 'Show', tournament %> <%= link_to 'Edit', edit_tournament_path(tournament) %>
- +<% else %> +

No tournaments going on right now... Why not start your own?

+<% end %>
-<%= link_to 'New Tournament', new_tournament_path %> +<%= link_to 'New Tournament', new_tournament_path, :class => "btn btn-warning btn-lg" %> diff --git a/app/views/tournaments/join.html.erb b/app/views/tournaments/join.html.erb new file mode 100644 index 0000000..1d38d68 --- /dev/null +++ b/app/views/tournaments/join.html.erb @@ -0,0 +1,2 @@ + <%= @user.name %> + diff --git a/app/views/tournaments/new.html.erb b/app/views/tournaments/new.html.erb index 2a60539..8c74068 100644 --- a/app/views/tournaments/new.html.erb +++ b/app/views/tournaments/new.html.erb @@ -1,5 +1,16 @@ -

New tournament

+

New Tournament

-<%= render 'form' %> +<%= form_tag(new_tournament_path, method: "get") do %> + <%= select_tag('game', + options_from_collection_for_select(@games, 'id', 'name', @tournament.game.nil? || @tournament.game.id), + :prompt => "Select a Game Type") %> + <%= submit_tag("Select", :class => "btn btn-success btn-xs") %> +<% end %> + +
+ <% if not @tournament.game.nil? %> + <%= render 'selected' %> + <% end %> +
<%= link_to 'Back', tournaments_path %> diff --git a/app/views/tournaments/show.html.erb b/app/views/tournaments/show.html.erb index 3cb6179..3de0623 100644 --- a/app/views/tournaments/show.html.erb +++ b/app/views/tournaments/show.html.erb @@ -1,5 +1,19 @@ -

<%= notice %>

+<% if @tournament.joinable_by?(current_user) %> + <%= form_tag(tournament_path(@tournament), method: "put") do %> + + <%= current_user.name %><%= submit_tag("Join") %> + <% end %> +<% end %> + +
+ <%= tag("div", {:class => "progress-bar progress-bar-warning", :style => "width: " +(@tournament.players.count * 100 / (@tournament.min_players_per_team * @tournament.min_teams_per_match)).to_s + "%", "aria-valuemax" => "100", "aria-valuemin" => "0", "aria-valuenow" => (@tournament.players.count * 100 / (@tournament.min_players_per_team * @tournament.min_teams_per_match)).to_s, "role" => "progressbar"}) %> + 60% Complete (warning) +
+ +

<%= @tournament.players.count %> have signed up. <%= @tournament.min_players_per_team * @tournament.min_teams_per_match %> needed.

+ +<% if current_user.in_group?(:host) %>

Name: <%= @tournament.name %> @@ -7,7 +21,7 @@

Game: - <%= @tournament.game %> + <%= @tournament.id %>

@@ -45,5 +59,22 @@ <%= @tournament.randomized_teams %>

+

+ Status: + <%= @tournament.status %> +

+ +<%= form_tag(tournaments_path.to_s + "/" + @tournament.id.to_s + "/edit", method: "get") do %> + + <% if @tournament.players.count >= @tournament.min_players_per_team * @tournament.min_teams_per_match %> + <%= submit_tag("Close Tournament Registration") %> + <% else %> + <%= submit_tag("Close Tournament Registration", disabled: true) %> + <% end %> +<% end %> + <%= link_to 'Edit', edit_tournament_path(@tournament) %> | <%= link_to 'Back', tournaments_path %> + +<% end %> + diff --git a/app/views/users/already_signed_in.html.erb b/app/views/users/already_signed_in.html.erb new file mode 100644 index 0000000..04b4248 --- /dev/null +++ b/app/views/users/already_signed_in.html.erb @@ -0,0 +1 @@ +

You are currently signed in

diff --git a/app/views/users/index.html.erb b/app/views/users/index.html.erb index 3692112..89e369a 100644 --- a/app/views/users/index.html.erb +++ b/app/views/users/index.html.erb @@ -1,8 +1,9 @@

Listing users

- +
+ @@ -15,8 +16,9 @@ <% @users.each do |user| %> + - + diff --git a/app/views/users/new.html.erb b/app/views/users/new.html.erb index efc0404..c23f76d 100644 --- a/app/views/users/new.html.erb +++ b/app/views/users/new.html.erb @@ -1,5 +1,32 @@ -

New user

+

Sign Up

-<%= render 'form' %> +<%= form_for @user do |f| %> + <%= render "common/error_messages", :target => @user %> +

+ <%= f.label :name %>
+ <%= f.text_field :name %> +

+

+ <%= f.label :email %>
+ <%= f.text_field :email %> +

+

+ <%= f.label :user_name %>
+ <%= f.text_field :user_name %> +

+

+ <%= f.label :password %>
+ <%= f.password_field :password %> +

+

+ <%= f.label(:password_confirmation, "Confirm Password") %>
+ <%= f.password_field :password_confirmation %> +

+

+ <%= f.submit("Be a Leaguer", :class => "signup") %> +

+<% end %> + + +<%= link_to 'Already Have an Account? Log in', new_session_path, :class => "signin" %> -<%= link_to 'Back', users_path %> diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb index 9455a3c..d8cc82b 100644 --- a/app/views/users/show.html.erb +++ b/app/views/users/show.html.erb @@ -1,5 +1,3 @@ -

<%= notice %>

-

Name: <%= @user.name %> diff --git a/config/routes.rb b/config/routes.rb index 97e82f8..5c5bece 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,21 +1,25 @@ Leaguer::Application.routes.draw do - resources :sessions + + #creates sessions as a resource but limits it to these actions + resources :sessions, only: [:new, :create, :destroy] resources :users resources :games - resources :tournaments - resources :pms resources :alerts + resource :server, only: [:show, :edit, :update] + resources :teams + resources :tournaments do + resources :matches + end - resources :matches - resources :servers + root to: 'static#homepage' # The priority is based upon order of creation: first created -> highest priority. # See how all your routes lay out with "rake routes". diff --git a/db/migrate/20140325202820_create_servers.rb b/db/migrate/20140325202820_create_servers.rb new file mode 100644 index 0000000..f33241a --- /dev/null +++ b/db/migrate/20140325202820_create_servers.rb @@ -0,0 +1,8 @@ +class CreateServers < ActiveRecord::Migration + def change + create_table :servers do |t| + + t.timestamps + end + end +end diff --git a/db/migrate/20140325202823_create_matches.rb b/db/migrate/20140325202823_create_matches.rb new file mode 100644 index 0000000..67a5b7b --- /dev/null +++ b/db/migrate/20140325202823_create_matches.rb @@ -0,0 +1,11 @@ +class CreateMatches < ActiveRecord::Migration + def change + create_table :matches do |t| + t.references :tournament, index: true + t.string :name + t.references :winner, index: true + + t.timestamps + end + end +end diff --git a/db/migrate/20140325202826_create_teams.rb b/db/migrate/20140325202826_create_teams.rb new file mode 100644 index 0000000..fdf9a68 --- /dev/null +++ b/db/migrate/20140325202826_create_teams.rb @@ -0,0 +1,9 @@ +class CreateTeams < ActiveRecord::Migration + def change + create_table :teams do |t| + t.references :match, index: true + + t.timestamps + end + end +end diff --git a/db/migrate/20140325202828_create_alerts.rb b/db/migrate/20140325202828_create_alerts.rb new file mode 100644 index 0000000..68a8e10 --- /dev/null +++ b/db/migrate/20140325202828_create_alerts.rb @@ -0,0 +1,10 @@ +class CreateAlerts < ActiveRecord::Migration + def change + create_table :alerts do |t| + t.references :author, index: true + t.text :message + + t.timestamps + end + end +end diff --git a/db/migrate/20140325202831_create_pms.rb b/db/migrate/20140325202831_create_pms.rb new file mode 100644 index 0000000..93bb5c6 --- /dev/null +++ b/db/migrate/20140325202831_create_pms.rb @@ -0,0 +1,11 @@ +class CreatePms < ActiveRecord::Migration + def change + create_table :pms do |t| + t.references :author, index: true + t.references :recipient, index: true + t.text :message + + t.timestamps + end + end +end diff --git a/db/migrate/20140325202833_create_tournaments.rb b/db/migrate/20140325202833_create_tournaments.rb new file mode 100644 index 0000000..c0d8929 --- /dev/null +++ b/db/migrate/20140325202833_create_tournaments.rb @@ -0,0 +1,17 @@ +class CreateTournaments < ActiveRecord::Migration + def change + create_table :tournaments do |t| + t.string :name + t.references :game, index: true + t.integer :status + t.integer :min_players_per_team + t.integer :max_players_per_team + t.integer :min_teams_per_match + t.integer :max_teams_per_match + t.integer :set_rounds + t.boolean :randomized_teams + + t.timestamps + end + end +end diff --git a/db/migrate/20140325202836_create_games.rb b/db/migrate/20140325202836_create_games.rb new file mode 100644 index 0000000..5e4f56f --- /dev/null +++ b/db/migrate/20140325202836_create_games.rb @@ -0,0 +1,15 @@ +class CreateGames < ActiveRecord::Migration + def change + create_table :games do |t| + t.text :name + t.integer :min_players_per_team + t.integer :max_players_per_team + t.integer :min_teams_per_match + t.integer :max_teams_per_match + t.integer :set_rounds + t.boolean :randomized_teams + + t.timestamps + end + end +end diff --git a/db/migrate/20140325202838_create_users.rb b/db/migrate/20140325202838_create_users.rb new file mode 100644 index 0000000..8032870 --- /dev/null +++ b/db/migrate/20140325202838_create_users.rb @@ -0,0 +1,13 @@ +class CreateUsers < ActiveRecord::Migration + def change + create_table :users do |t| + t.string :name + t.string :email + t.string :user_name + + t.timestamps + end + add_index :users, :email, unique: true + add_index :users, :user_name, unique: true + end +end diff --git a/db/migrate/20140325202841_create_sessions.rb b/db/migrate/20140325202841_create_sessions.rb new file mode 100644 index 0000000..fe25bf2 --- /dev/null +++ b/db/migrate/20140325202841_create_sessions.rb @@ -0,0 +1,9 @@ +class CreateSessions < ActiveRecord::Migration + def change + create_table :sessions do |t| + t.references :user, index: true + + t.timestamps + end + end +end diff --git a/db/migrate/20140325202843_create_server_settings.rb b/db/migrate/20140325202843_create_server_settings.rb new file mode 100644 index 0000000..dfdd91b --- /dev/null +++ b/db/migrate/20140325202843_create_server_settings.rb @@ -0,0 +1,8 @@ +class CreateServerSettings < ActiveRecord::Migration + def change + create_table :server_settings do |t| + + t.timestamps + end + end +end diff --git a/db/migrate/20140325202846_create_tournament_options.rb b/db/migrate/20140325202846_create_tournament_options.rb new file mode 100644 index 0000000..53b601c --- /dev/null +++ b/db/migrate/20140325202846_create_tournament_options.rb @@ -0,0 +1,12 @@ +class CreateTournamentOptions < ActiveRecord::Migration + def change + create_table :tournament_options do |t| + t.references :tournament, index: true + t.integer :vartype + t.string :name + t.text :value + + t.timestamps + end + end +end diff --git a/db/migrate/20140325202848_create_game_settings.rb b/db/migrate/20140325202848_create_game_settings.rb new file mode 100644 index 0000000..0ebbf18 --- /dev/null +++ b/db/migrate/20140325202848_create_game_settings.rb @@ -0,0 +1,15 @@ +class CreateGameSettings < ActiveRecord::Migration + def change + create_table :game_settings do |t| + t.references :game, index: true + t.integer :type + t.string :name + t.text :default + t.text :discription + t.text :type_opt + t.integer :display_order + + t.timestamps + end + end +end diff --git a/db/migrate/20140325202850_create_scores.rb b/db/migrate/20140325202850_create_scores.rb new file mode 100644 index 0000000..4ca0b0b --- /dev/null +++ b/db/migrate/20140325202850_create_scores.rb @@ -0,0 +1,11 @@ +class CreateScores < ActiveRecord::Migration + def change + create_table :scores do |t| + t.references :user, index: true + t.references :match, index: true + t.integer :value + + t.timestamps + end + end +end diff --git a/db/migrate/20140325202853_create_tournament_players_join_table.rb b/db/migrate/20140325202853_create_tournament_players_join_table.rb new file mode 100644 index 0000000..be240e8 --- /dev/null +++ b/db/migrate/20140325202853_create_tournament_players_join_table.rb @@ -0,0 +1,8 @@ +class CreateTournamentPlayersJoinTable < ActiveRecord::Migration + def change + create_join_table :players, :tournaments do |t| + # t.index [:player_id, :tournament_id] + # t.index [:tournament_id, :player_id] + end + end +end diff --git a/db/migrate/20140325202855_create_tournament_hosts_join_table.rb b/db/migrate/20140325202855_create_tournament_hosts_join_table.rb new file mode 100644 index 0000000..7521d89 --- /dev/null +++ b/db/migrate/20140325202855_create_tournament_hosts_join_table.rb @@ -0,0 +1,8 @@ +class CreateTournamentHostsJoinTable < ActiveRecord::Migration + def change + create_join_table :hosts, :tournaments do |t| + # t.index [:host_id, :tournament_id] + # t.index [:tournament_id, :host_id] + end + end +end diff --git a/db/migrate/20140325202858_create_team_user_join_table.rb b/db/migrate/20140325202858_create_team_user_join_table.rb new file mode 100644 index 0000000..f3b57fc --- /dev/null +++ b/db/migrate/20140325202858_create_team_user_join_table.rb @@ -0,0 +1,8 @@ +class CreateTeamUserJoinTable < ActiveRecord::Migration + def change + create_join_table :teams, :users do |t| + # t.index [:team_id, :user_id] + # t.index [:user_id, :team_id] + end + end +end diff --git a/db/migrate/20140325202900_create_match_team_join_table.rb b/db/migrate/20140325202900_create_match_team_join_table.rb new file mode 100644 index 0000000..c2ed1b7 --- /dev/null +++ b/db/migrate/20140325202900_create_match_team_join_table.rb @@ -0,0 +1,8 @@ +class CreateMatchTeamJoinTable < ActiveRecord::Migration + def change + create_join_table :matches, :teams do |t| + # t.index [:match_id, :team_id] + # t.index [:team_id, :match_id] + end + end +end diff --git a/db/migrate/20140325202910_add_hidden_attrs_to_user.rb b/db/migrate/20140325202910_add_hidden_attrs_to_user.rb new file mode 100644 index 0000000..2f1b0b2 --- /dev/null +++ b/db/migrate/20140325202910_add_hidden_attrs_to_user.rb @@ -0,0 +1,8 @@ +class AddHiddenAttrsToUser < ActiveRecord::Migration + def change + add_column :users, :password_digest, :string + add_column :users, :remember_token, :string + add_index :users, :remember_token, unique: true + add_column :users, :groups, :integer + end +end diff --git a/db/migrate/20140325212820_create_servers.rb b/db/migrate/20140325212820_create_servers.rb deleted file mode 100644 index f33241a..0000000 --- a/db/migrate/20140325212820_create_servers.rb +++ /dev/null @@ -1,8 +0,0 @@ -class CreateServers < ActiveRecord::Migration - def change - create_table :servers do |t| - - t.timestamps - end - end -end diff --git a/db/migrate/20140325212823_create_matches.rb b/db/migrate/20140325212823_create_matches.rb deleted file mode 100644 index 30949a8..0000000 --- a/db/migrate/20140325212823_create_matches.rb +++ /dev/null @@ -1,12 +0,0 @@ -class CreateMatches < ActiveRecord::Migration - def change - create_table :matches do |t| - t.integer :status - t.references :tournament, index: true - t.string :name - t.references :winner, index: true - - t.timestamps - end - end -end diff --git a/db/migrate/20140325212826_create_teams.rb b/db/migrate/20140325212826_create_teams.rb deleted file mode 100644 index fdf9a68..0000000 --- a/db/migrate/20140325212826_create_teams.rb +++ /dev/null @@ -1,9 +0,0 @@ -class CreateTeams < ActiveRecord::Migration - def change - create_table :teams do |t| - t.references :match, index: true - - t.timestamps - end - end -end diff --git a/db/migrate/20140325212828_create_alerts.rb b/db/migrate/20140325212828_create_alerts.rb deleted file mode 100644 index 68a8e10..0000000 --- a/db/migrate/20140325212828_create_alerts.rb +++ /dev/null @@ -1,10 +0,0 @@ -class CreateAlerts < ActiveRecord::Migration - def change - create_table :alerts do |t| - t.references :author, index: true - t.text :message - - t.timestamps - end - end -end diff --git a/db/migrate/20140325212831_create_pms.rb b/db/migrate/20140325212831_create_pms.rb deleted file mode 100644 index 93bb5c6..0000000 --- a/db/migrate/20140325212831_create_pms.rb +++ /dev/null @@ -1,11 +0,0 @@ -class CreatePms < ActiveRecord::Migration - def change - create_table :pms do |t| - t.references :author, index: true - t.references :recipient, index: true - t.text :message - - t.timestamps - end - end -end diff --git a/db/migrate/20140325212833_create_tournaments.rb b/db/migrate/20140325212833_create_tournaments.rb deleted file mode 100644 index c0d8929..0000000 --- a/db/migrate/20140325212833_create_tournaments.rb +++ /dev/null @@ -1,17 +0,0 @@ -class CreateTournaments < ActiveRecord::Migration - def change - create_table :tournaments do |t| - t.string :name - t.references :game, index: true - t.integer :status - t.integer :min_players_per_team - t.integer :max_players_per_team - t.integer :min_teams_per_match - t.integer :max_teams_per_match - t.integer :set_rounds - t.boolean :randomized_teams - - t.timestamps - end - end -end diff --git a/db/migrate/20140325212835_create_games.rb b/db/migrate/20140325212835_create_games.rb deleted file mode 100644 index 5e4f56f..0000000 --- a/db/migrate/20140325212835_create_games.rb +++ /dev/null @@ -1,15 +0,0 @@ -class CreateGames < ActiveRecord::Migration - def change - create_table :games do |t| - t.text :name - t.integer :min_players_per_team - t.integer :max_players_per_team - t.integer :min_teams_per_match - t.integer :max_teams_per_match - t.integer :set_rounds - t.boolean :randomized_teams - - t.timestamps - end - end -end diff --git a/db/migrate/20140325212838_create_users.rb b/db/migrate/20140325212838_create_users.rb deleted file mode 100644 index 8032870..0000000 --- a/db/migrate/20140325212838_create_users.rb +++ /dev/null @@ -1,13 +0,0 @@ -class CreateUsers < ActiveRecord::Migration - def change - create_table :users do |t| - t.string :name - t.string :email - t.string :user_name - - t.timestamps - end - add_index :users, :email, unique: true - add_index :users, :user_name, unique: true - end -end diff --git a/db/migrate/20140325212841_create_sessions.rb b/db/migrate/20140325212841_create_sessions.rb deleted file mode 100644 index fe25bf2..0000000 --- a/db/migrate/20140325212841_create_sessions.rb +++ /dev/null @@ -1,9 +0,0 @@ -class CreateSessions < ActiveRecord::Migration - def change - create_table :sessions do |t| - t.references :user, index: true - - t.timestamps - end - end -end diff --git a/db/migrate/20140325212844_create_server_settings.rb b/db/migrate/20140325212844_create_server_settings.rb deleted file mode 100644 index dfdd91b..0000000 --- a/db/migrate/20140325212844_create_server_settings.rb +++ /dev/null @@ -1,8 +0,0 @@ -class CreateServerSettings < ActiveRecord::Migration - def change - create_table :server_settings do |t| - - t.timestamps - end - end -end diff --git a/db/migrate/20140325212846_create_tournament_options.rb b/db/migrate/20140325212846_create_tournament_options.rb deleted file mode 100644 index 53b601c..0000000 --- a/db/migrate/20140325212846_create_tournament_options.rb +++ /dev/null @@ -1,12 +0,0 @@ -class CreateTournamentOptions < ActiveRecord::Migration - def change - create_table :tournament_options do |t| - t.references :tournament, index: true - t.integer :vartype - t.string :name - t.text :value - - t.timestamps - end - end -end diff --git a/db/migrate/20140325212849_create_game_settings.rb b/db/migrate/20140325212849_create_game_settings.rb deleted file mode 100644 index 0ebbf18..0000000 --- a/db/migrate/20140325212849_create_game_settings.rb +++ /dev/null @@ -1,15 +0,0 @@ -class CreateGameSettings < ActiveRecord::Migration - def change - create_table :game_settings do |t| - t.references :game, index: true - t.integer :type - t.string :name - t.text :default - t.text :discription - t.text :type_opt - t.integer :display_order - - t.timestamps - end - end -end diff --git a/db/migrate/20140325212851_create_scores.rb b/db/migrate/20140325212851_create_scores.rb deleted file mode 100644 index 4ca0b0b..0000000 --- a/db/migrate/20140325212851_create_scores.rb +++ /dev/null @@ -1,11 +0,0 @@ -class CreateScores < ActiveRecord::Migration - def change - create_table :scores do |t| - t.references :user, index: true - t.references :match, index: true - t.integer :value - - t.timestamps - end - end -end diff --git a/db/migrate/20140325212854_create_tournament_players_join_table.rb b/db/migrate/20140325212854_create_tournament_players_join_table.rb deleted file mode 100644 index be240e8..0000000 --- a/db/migrate/20140325212854_create_tournament_players_join_table.rb +++ /dev/null @@ -1,8 +0,0 @@ -class CreateTournamentPlayersJoinTable < ActiveRecord::Migration - def change - create_join_table :players, :tournaments do |t| - # t.index [:player_id, :tournament_id] - # t.index [:tournament_id, :player_id] - end - end -end diff --git a/db/migrate/20140325212855_create_tournament_hosts_join_table.rb b/db/migrate/20140325212855_create_tournament_hosts_join_table.rb deleted file mode 100644 index 7521d89..0000000 --- a/db/migrate/20140325212855_create_tournament_hosts_join_table.rb +++ /dev/null @@ -1,8 +0,0 @@ -class CreateTournamentHostsJoinTable < ActiveRecord::Migration - def change - create_join_table :hosts, :tournaments do |t| - # t.index [:host_id, :tournament_id] - # t.index [:tournament_id, :host_id] - end - end -end diff --git a/db/migrate/20140325212857_create_team_user_join_table.rb b/db/migrate/20140325212857_create_team_user_join_table.rb deleted file mode 100644 index f3b57fc..0000000 --- a/db/migrate/20140325212857_create_team_user_join_table.rb +++ /dev/null @@ -1,8 +0,0 @@ -class CreateTeamUserJoinTable < ActiveRecord::Migration - def change - create_join_table :teams, :users do |t| - # t.index [:team_id, :user_id] - # t.index [:user_id, :team_id] - end - end -end diff --git a/db/migrate/20140325212859_create_match_team_join_table.rb b/db/migrate/20140325212859_create_match_team_join_table.rb deleted file mode 100644 index c2ed1b7..0000000 --- a/db/migrate/20140325212859_create_match_team_join_table.rb +++ /dev/null @@ -1,8 +0,0 @@ -class CreateMatchTeamJoinTable < ActiveRecord::Migration - def change - create_join_table :matches, :teams do |t| - # t.index [:match_id, :team_id] - # t.index [:team_id, :match_id] - end - end -end diff --git a/db/migrate/20140325212906_add_hidden_attrs_to_user.rb b/db/migrate/20140325212906_add_hidden_attrs_to_user.rb deleted file mode 100644 index 2f1b0b2..0000000 --- a/db/migrate/20140325212906_add_hidden_attrs_to_user.rb +++ /dev/null @@ -1,8 +0,0 @@ -class AddHiddenAttrsToUser < ActiveRecord::Migration - def change - add_column :users, :password_digest, :string - add_column :users, :remember_token, :string - add_index :users, :remember_token, unique: true - add_column :users, :groups, :integer - end -end diff --git a/db/schema.rb b/db/schema.rb index e7bb933..952cb26 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20140325212906) do +ActiveRecord::Schema.define(version: 20140325202910) do create_table "alerts", force: true do |t| t.integer "author_id" @@ -54,7 +54,6 @@ ActiveRecord::Schema.define(version: 20140325212906) do end create_table "matches", force: true do |t| - t.integer "status" t.integer "tournament_id" t.string "name" t.integer "winner_id" diff --git a/generate.sh b/generate.sh index 2013703..1ff486f 100755 --- a/generate.sh +++ b/generate.sh @@ -18,7 +18,7 @@ git checkout clean-start -- app test config/routes.rb # The whole shebang, models, views, and controllers bundle exec rails generate scaffold server --force $NOTEST -bundle exec rails generate scaffold match status:integer tournament:references name:string winner:references --force $NOTEST +bundle exec rails generate scaffold match tournament:references name:string winner:references --force $NOTEST bundle exec rails generate scaffold team match:references $NOTEST bundle exec rails generate scaffold alert author:references message:text $NOTEST bundle exec rails generate scaffold pm author:references recipient:references message:text $NOTEST diff --git a/test/controllers/matches_controller_test.rb b/test/controllers/matches_controller_test.rb index c3cc7a4..51b7f37 100644 --- a/test/controllers/matches_controller_test.rb +++ b/test/controllers/matches_controller_test.rb @@ -18,7 +18,7 @@ class MatchesControllerTest < ActionController::TestCase test "should create match" do assert_difference('Match.count') do - post :create, match: { name: @match.name, status: @match.status, tournament_id: @match.tournament_id, winner_id: @match.winner_id } + post :create, match: { name: @match.name, tournament_id: @match.tournament_id, winner_id: @match.winner_id } end assert_redirected_to match_path(assigns(:match)) @@ -35,7 +35,7 @@ class MatchesControllerTest < ActionController::TestCase end test "should update match" do - patch :update, id: @match, match: { name: @match.name, status: @match.status, tournament_id: @match.tournament_id, winner_id: @match.winner_id } + patch :update, id: @match, match: { name: @match.name, tournament_id: @match.tournament_id, winner_id: @match.winner_id } assert_redirected_to match_path(assigns(:match)) end diff --git a/test/fixtures/matches.yml b/test/fixtures/matches.yml index 00af9f5..956229c 100644 --- a/test/fixtures/matches.yml +++ b/test/fixtures/matches.yml @@ -1,13 +1,11 @@ # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html one: - status: 1 tournament_id: name: MyString winner_id: two: - status: 1 tournament_id: name: MyString winner_id: -- cgit v1.2.3-54-g00ecf From 433fc302fe2943e89a36657affea39d578475d20 Mon Sep 17 00:00:00 2001 From: guntasgrewal Date: Tue, 25 Mar 2014 17:47:32 -0400 Subject: Match Status added --- app/controllers/matches_controller.rb | 2 +- app/views/matches/_form.html.erb | 4 ++++ app/views/matches/index.html.erb | 2 ++ app/views/matches/index.json.jbuilder | 2 +- app/views/matches/show.html.erb | 5 +++++ app/views/matches/show.json.jbuilder | 2 +- db/migrate/20140325202820_create_servers.rb | 8 -------- db/migrate/20140325202823_create_matches.rb | 11 ----------- db/migrate/20140325202826_create_teams.rb | 9 --------- db/migrate/20140325202828_create_alerts.rb | 10 ---------- db/migrate/20140325202831_create_pms.rb | 11 ----------- db/migrate/20140325202833_create_tournaments.rb | 17 ----------------- db/migrate/20140325202836_create_games.rb | 15 --------------- db/migrate/20140325202838_create_users.rb | 13 ------------- db/migrate/20140325202841_create_sessions.rb | 9 --------- db/migrate/20140325202843_create_server_settings.rb | 8 -------- db/migrate/20140325202846_create_tournament_options.rb | 12 ------------ db/migrate/20140325202848_create_game_settings.rb | 15 --------------- db/migrate/20140325202850_create_scores.rb | 11 ----------- ...140325202853_create_tournament_players_join_table.rb | 8 -------- ...20140325202855_create_tournament_hosts_join_table.rb | 8 -------- .../20140325202858_create_team_user_join_table.rb | 8 -------- .../20140325202900_create_match_team_join_table.rb | 8 -------- db/migrate/20140325202910_add_hidden_attrs_to_user.rb | 8 -------- db/migrate/20140325214513_create_servers.rb | 8 ++++++++ db/migrate/20140325214516_create_matches.rb | 12 ++++++++++++ db/migrate/20140325214518_create_teams.rb | 9 +++++++++ db/migrate/20140325214521_create_alerts.rb | 10 ++++++++++ db/migrate/20140325214523_create_pms.rb | 11 +++++++++++ db/migrate/20140325214525_create_tournaments.rb | 17 +++++++++++++++++ db/migrate/20140325214528_create_games.rb | 15 +++++++++++++++ db/migrate/20140325214531_create_users.rb | 13 +++++++++++++ db/migrate/20140325214533_create_sessions.rb | 9 +++++++++ db/migrate/20140325214536_create_server_settings.rb | 8 ++++++++ db/migrate/20140325214538_create_tournament_options.rb | 12 ++++++++++++ db/migrate/20140325214540_create_game_settings.rb | 15 +++++++++++++++ db/migrate/20140325214543_create_scores.rb | 11 +++++++++++ ...140325214545_create_tournament_players_join_table.rb | 8 ++++++++ ...20140325214548_create_tournament_hosts_join_table.rb | 8 ++++++++ .../20140325214550_create_team_user_join_table.rb | 8 ++++++++ .../20140325214553_create_match_team_join_table.rb | 8 ++++++++ db/migrate/20140325214602_add_hidden_attrs_to_user.rb | 8 ++++++++ db/schema.rb | 3 ++- generate.sh | 2 +- test/controllers/matches_controller_test.rb | 4 ++-- test/fixtures/matches.yml | 2 ++ 46 files changed, 211 insertions(+), 196 deletions(-) delete mode 100644 db/migrate/20140325202820_create_servers.rb delete mode 100644 db/migrate/20140325202823_create_matches.rb delete mode 100644 db/migrate/20140325202826_create_teams.rb delete mode 100644 db/migrate/20140325202828_create_alerts.rb delete mode 100644 db/migrate/20140325202831_create_pms.rb delete mode 100644 db/migrate/20140325202833_create_tournaments.rb delete mode 100644 db/migrate/20140325202836_create_games.rb delete mode 100644 db/migrate/20140325202838_create_users.rb delete mode 100644 db/migrate/20140325202841_create_sessions.rb delete mode 100644 db/migrate/20140325202843_create_server_settings.rb delete mode 100644 db/migrate/20140325202846_create_tournament_options.rb delete mode 100644 db/migrate/20140325202848_create_game_settings.rb delete mode 100644 db/migrate/20140325202850_create_scores.rb delete mode 100644 db/migrate/20140325202853_create_tournament_players_join_table.rb delete mode 100644 db/migrate/20140325202855_create_tournament_hosts_join_table.rb delete mode 100644 db/migrate/20140325202858_create_team_user_join_table.rb delete mode 100644 db/migrate/20140325202900_create_match_team_join_table.rb delete mode 100644 db/migrate/20140325202910_add_hidden_attrs_to_user.rb create mode 100644 db/migrate/20140325214513_create_servers.rb create mode 100644 db/migrate/20140325214516_create_matches.rb create mode 100644 db/migrate/20140325214518_create_teams.rb create mode 100644 db/migrate/20140325214521_create_alerts.rb create mode 100644 db/migrate/20140325214523_create_pms.rb create mode 100644 db/migrate/20140325214525_create_tournaments.rb create mode 100644 db/migrate/20140325214528_create_games.rb create mode 100644 db/migrate/20140325214531_create_users.rb create mode 100644 db/migrate/20140325214533_create_sessions.rb create mode 100644 db/migrate/20140325214536_create_server_settings.rb create mode 100644 db/migrate/20140325214538_create_tournament_options.rb create mode 100644 db/migrate/20140325214540_create_game_settings.rb create mode 100644 db/migrate/20140325214543_create_scores.rb create mode 100644 db/migrate/20140325214545_create_tournament_players_join_table.rb create mode 100644 db/migrate/20140325214548_create_tournament_hosts_join_table.rb create mode 100644 db/migrate/20140325214550_create_team_user_join_table.rb create mode 100644 db/migrate/20140325214553_create_match_team_join_table.rb create mode 100644 db/migrate/20140325214602_add_hidden_attrs_to_user.rb diff --git a/app/controllers/matches_controller.rb b/app/controllers/matches_controller.rb index 8329da5..d79a7fc 100644 --- a/app/controllers/matches_controller.rb +++ b/app/controllers/matches_controller.rb @@ -69,6 +69,6 @@ class MatchesController < ApplicationController # Never trust parameters from the scary internet, only allow the white list through. def match_params - params.require(:match).permit(:tournament_id, :name, :winner_id) + params.require(:match).permit(:status, :tournament_id, :name, :winner_id) end end diff --git a/app/views/matches/_form.html.erb b/app/views/matches/_form.html.erb index f1e6047..727c002 100644 --- a/app/views/matches/_form.html.erb +++ b/app/views/matches/_form.html.erb @@ -11,6 +11,10 @@ <% end %> +

+ <%= f.label :status %>
+ <%= f.number_field :status %> +
<%= f.label :tournament_id %>
<%= f.text_field :tournament_id %> diff --git a/app/views/matches/index.html.erb b/app/views/matches/index.html.erb index 71db08c..400efb4 100644 --- a/app/views/matches/index.html.erb +++ b/app/views/matches/index.html.erb @@ -3,6 +3,7 @@
Username Name Email User name
<%= link_to("#{user.user_name}", user, nil) %> <%= user.name %><%= user.email %> ******* <%= user.user_name %> <%= link_to 'Show', user %> <%= link_to 'Edit', edit_user_path(user) %>
+ @@ -15,6 +16,7 @@ <% @matches.each do |match| %> + diff --git a/app/views/matches/index.json.jbuilder b/app/views/matches/index.json.jbuilder index 0b2bfcd..1a63f5f 100644 --- a/app/views/matches/index.json.jbuilder +++ b/app/views/matches/index.json.jbuilder @@ -1,4 +1,4 @@ json.array!(@matches) do |match| - json.extract! match, :id, :tournament_id, :name, :winner_id + json.extract! match, :id, :status, :tournament_id, :name, :winner_id json.url match_url(match, format: :json) end diff --git a/app/views/matches/show.html.erb b/app/views/matches/show.html.erb index 3abb1f7..f3fc822 100644 --- a/app/views/matches/show.html.erb +++ b/app/views/matches/show.html.erb @@ -1,5 +1,10 @@

<%= notice %>

+

+ Status: + <%= @match.status %> +

+

Tournament: <%= @match.tournament %> diff --git a/app/views/matches/show.json.jbuilder b/app/views/matches/show.json.jbuilder index fe14010..a3ef588 100644 --- a/app/views/matches/show.json.jbuilder +++ b/app/views/matches/show.json.jbuilder @@ -1 +1 @@ -json.extract! @match, :id, :tournament_id, :name, :winner_id, :created_at, :updated_at +json.extract! @match, :id, :status, :tournament_id, :name, :winner_id, :created_at, :updated_at diff --git a/db/migrate/20140325202820_create_servers.rb b/db/migrate/20140325202820_create_servers.rb deleted file mode 100644 index f33241a..0000000 --- a/db/migrate/20140325202820_create_servers.rb +++ /dev/null @@ -1,8 +0,0 @@ -class CreateServers < ActiveRecord::Migration - def change - create_table :servers do |t| - - t.timestamps - end - end -end diff --git a/db/migrate/20140325202823_create_matches.rb b/db/migrate/20140325202823_create_matches.rb deleted file mode 100644 index 67a5b7b..0000000 --- a/db/migrate/20140325202823_create_matches.rb +++ /dev/null @@ -1,11 +0,0 @@ -class CreateMatches < ActiveRecord::Migration - def change - create_table :matches do |t| - t.references :tournament, index: true - t.string :name - t.references :winner, index: true - - t.timestamps - end - end -end diff --git a/db/migrate/20140325202826_create_teams.rb b/db/migrate/20140325202826_create_teams.rb deleted file mode 100644 index fdf9a68..0000000 --- a/db/migrate/20140325202826_create_teams.rb +++ /dev/null @@ -1,9 +0,0 @@ -class CreateTeams < ActiveRecord::Migration - def change - create_table :teams do |t| - t.references :match, index: true - - t.timestamps - end - end -end diff --git a/db/migrate/20140325202828_create_alerts.rb b/db/migrate/20140325202828_create_alerts.rb deleted file mode 100644 index 68a8e10..0000000 --- a/db/migrate/20140325202828_create_alerts.rb +++ /dev/null @@ -1,10 +0,0 @@ -class CreateAlerts < ActiveRecord::Migration - def change - create_table :alerts do |t| - t.references :author, index: true - t.text :message - - t.timestamps - end - end -end diff --git a/db/migrate/20140325202831_create_pms.rb b/db/migrate/20140325202831_create_pms.rb deleted file mode 100644 index 93bb5c6..0000000 --- a/db/migrate/20140325202831_create_pms.rb +++ /dev/null @@ -1,11 +0,0 @@ -class CreatePms < ActiveRecord::Migration - def change - create_table :pms do |t| - t.references :author, index: true - t.references :recipient, index: true - t.text :message - - t.timestamps - end - end -end diff --git a/db/migrate/20140325202833_create_tournaments.rb b/db/migrate/20140325202833_create_tournaments.rb deleted file mode 100644 index c0d8929..0000000 --- a/db/migrate/20140325202833_create_tournaments.rb +++ /dev/null @@ -1,17 +0,0 @@ -class CreateTournaments < ActiveRecord::Migration - def change - create_table :tournaments do |t| - t.string :name - t.references :game, index: true - t.integer :status - t.integer :min_players_per_team - t.integer :max_players_per_team - t.integer :min_teams_per_match - t.integer :max_teams_per_match - t.integer :set_rounds - t.boolean :randomized_teams - - t.timestamps - end - end -end diff --git a/db/migrate/20140325202836_create_games.rb b/db/migrate/20140325202836_create_games.rb deleted file mode 100644 index 5e4f56f..0000000 --- a/db/migrate/20140325202836_create_games.rb +++ /dev/null @@ -1,15 +0,0 @@ -class CreateGames < ActiveRecord::Migration - def change - create_table :games do |t| - t.text :name - t.integer :min_players_per_team - t.integer :max_players_per_team - t.integer :min_teams_per_match - t.integer :max_teams_per_match - t.integer :set_rounds - t.boolean :randomized_teams - - t.timestamps - end - end -end diff --git a/db/migrate/20140325202838_create_users.rb b/db/migrate/20140325202838_create_users.rb deleted file mode 100644 index 8032870..0000000 --- a/db/migrate/20140325202838_create_users.rb +++ /dev/null @@ -1,13 +0,0 @@ -class CreateUsers < ActiveRecord::Migration - def change - create_table :users do |t| - t.string :name - t.string :email - t.string :user_name - - t.timestamps - end - add_index :users, :email, unique: true - add_index :users, :user_name, unique: true - end -end diff --git a/db/migrate/20140325202841_create_sessions.rb b/db/migrate/20140325202841_create_sessions.rb deleted file mode 100644 index fe25bf2..0000000 --- a/db/migrate/20140325202841_create_sessions.rb +++ /dev/null @@ -1,9 +0,0 @@ -class CreateSessions < ActiveRecord::Migration - def change - create_table :sessions do |t| - t.references :user, index: true - - t.timestamps - end - end -end diff --git a/db/migrate/20140325202843_create_server_settings.rb b/db/migrate/20140325202843_create_server_settings.rb deleted file mode 100644 index dfdd91b..0000000 --- a/db/migrate/20140325202843_create_server_settings.rb +++ /dev/null @@ -1,8 +0,0 @@ -class CreateServerSettings < ActiveRecord::Migration - def change - create_table :server_settings do |t| - - t.timestamps - end - end -end diff --git a/db/migrate/20140325202846_create_tournament_options.rb b/db/migrate/20140325202846_create_tournament_options.rb deleted file mode 100644 index 53b601c..0000000 --- a/db/migrate/20140325202846_create_tournament_options.rb +++ /dev/null @@ -1,12 +0,0 @@ -class CreateTournamentOptions < ActiveRecord::Migration - def change - create_table :tournament_options do |t| - t.references :tournament, index: true - t.integer :vartype - t.string :name - t.text :value - - t.timestamps - end - end -end diff --git a/db/migrate/20140325202848_create_game_settings.rb b/db/migrate/20140325202848_create_game_settings.rb deleted file mode 100644 index 0ebbf18..0000000 --- a/db/migrate/20140325202848_create_game_settings.rb +++ /dev/null @@ -1,15 +0,0 @@ -class CreateGameSettings < ActiveRecord::Migration - def change - create_table :game_settings do |t| - t.references :game, index: true - t.integer :type - t.string :name - t.text :default - t.text :discription - t.text :type_opt - t.integer :display_order - - t.timestamps - end - end -end diff --git a/db/migrate/20140325202850_create_scores.rb b/db/migrate/20140325202850_create_scores.rb deleted file mode 100644 index 4ca0b0b..0000000 --- a/db/migrate/20140325202850_create_scores.rb +++ /dev/null @@ -1,11 +0,0 @@ -class CreateScores < ActiveRecord::Migration - def change - create_table :scores do |t| - t.references :user, index: true - t.references :match, index: true - t.integer :value - - t.timestamps - end - end -end diff --git a/db/migrate/20140325202853_create_tournament_players_join_table.rb b/db/migrate/20140325202853_create_tournament_players_join_table.rb deleted file mode 100644 index be240e8..0000000 --- a/db/migrate/20140325202853_create_tournament_players_join_table.rb +++ /dev/null @@ -1,8 +0,0 @@ -class CreateTournamentPlayersJoinTable < ActiveRecord::Migration - def change - create_join_table :players, :tournaments do |t| - # t.index [:player_id, :tournament_id] - # t.index [:tournament_id, :player_id] - end - end -end diff --git a/db/migrate/20140325202855_create_tournament_hosts_join_table.rb b/db/migrate/20140325202855_create_tournament_hosts_join_table.rb deleted file mode 100644 index 7521d89..0000000 --- a/db/migrate/20140325202855_create_tournament_hosts_join_table.rb +++ /dev/null @@ -1,8 +0,0 @@ -class CreateTournamentHostsJoinTable < ActiveRecord::Migration - def change - create_join_table :hosts, :tournaments do |t| - # t.index [:host_id, :tournament_id] - # t.index [:tournament_id, :host_id] - end - end -end diff --git a/db/migrate/20140325202858_create_team_user_join_table.rb b/db/migrate/20140325202858_create_team_user_join_table.rb deleted file mode 100644 index f3b57fc..0000000 --- a/db/migrate/20140325202858_create_team_user_join_table.rb +++ /dev/null @@ -1,8 +0,0 @@ -class CreateTeamUserJoinTable < ActiveRecord::Migration - def change - create_join_table :teams, :users do |t| - # t.index [:team_id, :user_id] - # t.index [:user_id, :team_id] - end - end -end diff --git a/db/migrate/20140325202900_create_match_team_join_table.rb b/db/migrate/20140325202900_create_match_team_join_table.rb deleted file mode 100644 index c2ed1b7..0000000 --- a/db/migrate/20140325202900_create_match_team_join_table.rb +++ /dev/null @@ -1,8 +0,0 @@ -class CreateMatchTeamJoinTable < ActiveRecord::Migration - def change - create_join_table :matches, :teams do |t| - # t.index [:match_id, :team_id] - # t.index [:team_id, :match_id] - end - end -end diff --git a/db/migrate/20140325202910_add_hidden_attrs_to_user.rb b/db/migrate/20140325202910_add_hidden_attrs_to_user.rb deleted file mode 100644 index 2f1b0b2..0000000 --- a/db/migrate/20140325202910_add_hidden_attrs_to_user.rb +++ /dev/null @@ -1,8 +0,0 @@ -class AddHiddenAttrsToUser < ActiveRecord::Migration - def change - add_column :users, :password_digest, :string - add_column :users, :remember_token, :string - add_index :users, :remember_token, unique: true - add_column :users, :groups, :integer - end -end diff --git a/db/migrate/20140325214513_create_servers.rb b/db/migrate/20140325214513_create_servers.rb new file mode 100644 index 0000000..f33241a --- /dev/null +++ b/db/migrate/20140325214513_create_servers.rb @@ -0,0 +1,8 @@ +class CreateServers < ActiveRecord::Migration + def change + create_table :servers do |t| + + t.timestamps + end + end +end diff --git a/db/migrate/20140325214516_create_matches.rb b/db/migrate/20140325214516_create_matches.rb new file mode 100644 index 0000000..30949a8 --- /dev/null +++ b/db/migrate/20140325214516_create_matches.rb @@ -0,0 +1,12 @@ +class CreateMatches < ActiveRecord::Migration + def change + create_table :matches do |t| + t.integer :status + t.references :tournament, index: true + t.string :name + t.references :winner, index: true + + t.timestamps + end + end +end diff --git a/db/migrate/20140325214518_create_teams.rb b/db/migrate/20140325214518_create_teams.rb new file mode 100644 index 0000000..fdf9a68 --- /dev/null +++ b/db/migrate/20140325214518_create_teams.rb @@ -0,0 +1,9 @@ +class CreateTeams < ActiveRecord::Migration + def change + create_table :teams do |t| + t.references :match, index: true + + t.timestamps + end + end +end diff --git a/db/migrate/20140325214521_create_alerts.rb b/db/migrate/20140325214521_create_alerts.rb new file mode 100644 index 0000000..68a8e10 --- /dev/null +++ b/db/migrate/20140325214521_create_alerts.rb @@ -0,0 +1,10 @@ +class CreateAlerts < ActiveRecord::Migration + def change + create_table :alerts do |t| + t.references :author, index: true + t.text :message + + t.timestamps + end + end +end diff --git a/db/migrate/20140325214523_create_pms.rb b/db/migrate/20140325214523_create_pms.rb new file mode 100644 index 0000000..93bb5c6 --- /dev/null +++ b/db/migrate/20140325214523_create_pms.rb @@ -0,0 +1,11 @@ +class CreatePms < ActiveRecord::Migration + def change + create_table :pms do |t| + t.references :author, index: true + t.references :recipient, index: true + t.text :message + + t.timestamps + end + end +end diff --git a/db/migrate/20140325214525_create_tournaments.rb b/db/migrate/20140325214525_create_tournaments.rb new file mode 100644 index 0000000..c0d8929 --- /dev/null +++ b/db/migrate/20140325214525_create_tournaments.rb @@ -0,0 +1,17 @@ +class CreateTournaments < ActiveRecord::Migration + def change + create_table :tournaments do |t| + t.string :name + t.references :game, index: true + t.integer :status + t.integer :min_players_per_team + t.integer :max_players_per_team + t.integer :min_teams_per_match + t.integer :max_teams_per_match + t.integer :set_rounds + t.boolean :randomized_teams + + t.timestamps + end + end +end diff --git a/db/migrate/20140325214528_create_games.rb b/db/migrate/20140325214528_create_games.rb new file mode 100644 index 0000000..5e4f56f --- /dev/null +++ b/db/migrate/20140325214528_create_games.rb @@ -0,0 +1,15 @@ +class CreateGames < ActiveRecord::Migration + def change + create_table :games do |t| + t.text :name + t.integer :min_players_per_team + t.integer :max_players_per_team + t.integer :min_teams_per_match + t.integer :max_teams_per_match + t.integer :set_rounds + t.boolean :randomized_teams + + t.timestamps + end + end +end diff --git a/db/migrate/20140325214531_create_users.rb b/db/migrate/20140325214531_create_users.rb new file mode 100644 index 0000000..8032870 --- /dev/null +++ b/db/migrate/20140325214531_create_users.rb @@ -0,0 +1,13 @@ +class CreateUsers < ActiveRecord::Migration + def change + create_table :users do |t| + t.string :name + t.string :email + t.string :user_name + + t.timestamps + end + add_index :users, :email, unique: true + add_index :users, :user_name, unique: true + end +end diff --git a/db/migrate/20140325214533_create_sessions.rb b/db/migrate/20140325214533_create_sessions.rb new file mode 100644 index 0000000..fe25bf2 --- /dev/null +++ b/db/migrate/20140325214533_create_sessions.rb @@ -0,0 +1,9 @@ +class CreateSessions < ActiveRecord::Migration + def change + create_table :sessions do |t| + t.references :user, index: true + + t.timestamps + end + end +end diff --git a/db/migrate/20140325214536_create_server_settings.rb b/db/migrate/20140325214536_create_server_settings.rb new file mode 100644 index 0000000..dfdd91b --- /dev/null +++ b/db/migrate/20140325214536_create_server_settings.rb @@ -0,0 +1,8 @@ +class CreateServerSettings < ActiveRecord::Migration + def change + create_table :server_settings do |t| + + t.timestamps + end + end +end diff --git a/db/migrate/20140325214538_create_tournament_options.rb b/db/migrate/20140325214538_create_tournament_options.rb new file mode 100644 index 0000000..53b601c --- /dev/null +++ b/db/migrate/20140325214538_create_tournament_options.rb @@ -0,0 +1,12 @@ +class CreateTournamentOptions < ActiveRecord::Migration + def change + create_table :tournament_options do |t| + t.references :tournament, index: true + t.integer :vartype + t.string :name + t.text :value + + t.timestamps + end + end +end diff --git a/db/migrate/20140325214540_create_game_settings.rb b/db/migrate/20140325214540_create_game_settings.rb new file mode 100644 index 0000000..0ebbf18 --- /dev/null +++ b/db/migrate/20140325214540_create_game_settings.rb @@ -0,0 +1,15 @@ +class CreateGameSettings < ActiveRecord::Migration + def change + create_table :game_settings do |t| + t.references :game, index: true + t.integer :type + t.string :name + t.text :default + t.text :discription + t.text :type_opt + t.integer :display_order + + t.timestamps + end + end +end diff --git a/db/migrate/20140325214543_create_scores.rb b/db/migrate/20140325214543_create_scores.rb new file mode 100644 index 0000000..4ca0b0b --- /dev/null +++ b/db/migrate/20140325214543_create_scores.rb @@ -0,0 +1,11 @@ +class CreateScores < ActiveRecord::Migration + def change + create_table :scores do |t| + t.references :user, index: true + t.references :match, index: true + t.integer :value + + t.timestamps + end + end +end diff --git a/db/migrate/20140325214545_create_tournament_players_join_table.rb b/db/migrate/20140325214545_create_tournament_players_join_table.rb new file mode 100644 index 0000000..be240e8 --- /dev/null +++ b/db/migrate/20140325214545_create_tournament_players_join_table.rb @@ -0,0 +1,8 @@ +class CreateTournamentPlayersJoinTable < ActiveRecord::Migration + def change + create_join_table :players, :tournaments do |t| + # t.index [:player_id, :tournament_id] + # t.index [:tournament_id, :player_id] + end + end +end diff --git a/db/migrate/20140325214548_create_tournament_hosts_join_table.rb b/db/migrate/20140325214548_create_tournament_hosts_join_table.rb new file mode 100644 index 0000000..7521d89 --- /dev/null +++ b/db/migrate/20140325214548_create_tournament_hosts_join_table.rb @@ -0,0 +1,8 @@ +class CreateTournamentHostsJoinTable < ActiveRecord::Migration + def change + create_join_table :hosts, :tournaments do |t| + # t.index [:host_id, :tournament_id] + # t.index [:tournament_id, :host_id] + end + end +end diff --git a/db/migrate/20140325214550_create_team_user_join_table.rb b/db/migrate/20140325214550_create_team_user_join_table.rb new file mode 100644 index 0000000..f3b57fc --- /dev/null +++ b/db/migrate/20140325214550_create_team_user_join_table.rb @@ -0,0 +1,8 @@ +class CreateTeamUserJoinTable < ActiveRecord::Migration + def change + create_join_table :teams, :users do |t| + # t.index [:team_id, :user_id] + # t.index [:user_id, :team_id] + end + end +end diff --git a/db/migrate/20140325214553_create_match_team_join_table.rb b/db/migrate/20140325214553_create_match_team_join_table.rb new file mode 100644 index 0000000..c2ed1b7 --- /dev/null +++ b/db/migrate/20140325214553_create_match_team_join_table.rb @@ -0,0 +1,8 @@ +class CreateMatchTeamJoinTable < ActiveRecord::Migration + def change + create_join_table :matches, :teams do |t| + # t.index [:match_id, :team_id] + # t.index [:team_id, :match_id] + end + end +end diff --git a/db/migrate/20140325214602_add_hidden_attrs_to_user.rb b/db/migrate/20140325214602_add_hidden_attrs_to_user.rb new file mode 100644 index 0000000..2f1b0b2 --- /dev/null +++ b/db/migrate/20140325214602_add_hidden_attrs_to_user.rb @@ -0,0 +1,8 @@ +class AddHiddenAttrsToUser < ActiveRecord::Migration + def change + add_column :users, :password_digest, :string + add_column :users, :remember_token, :string + add_index :users, :remember_token, unique: true + add_column :users, :groups, :integer + end +end diff --git a/db/schema.rb b/db/schema.rb index 952cb26..4704a45 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20140325202910) do +ActiveRecord::Schema.define(version: 20140325214602) do create_table "alerts", force: true do |t| t.integer "author_id" @@ -54,6 +54,7 @@ ActiveRecord::Schema.define(version: 20140325202910) do end create_table "matches", force: true do |t| + t.integer "status" t.integer "tournament_id" t.string "name" t.integer "winner_id" diff --git a/generate.sh b/generate.sh index 1ff486f..2013703 100755 --- a/generate.sh +++ b/generate.sh @@ -18,7 +18,7 @@ git checkout clean-start -- app test config/routes.rb # The whole shebang, models, views, and controllers bundle exec rails generate scaffold server --force $NOTEST -bundle exec rails generate scaffold match tournament:references name:string winner:references --force $NOTEST +bundle exec rails generate scaffold match status:integer tournament:references name:string winner:references --force $NOTEST bundle exec rails generate scaffold team match:references $NOTEST bundle exec rails generate scaffold alert author:references message:text $NOTEST bundle exec rails generate scaffold pm author:references recipient:references message:text $NOTEST diff --git a/test/controllers/matches_controller_test.rb b/test/controllers/matches_controller_test.rb index 51b7f37..c3cc7a4 100644 --- a/test/controllers/matches_controller_test.rb +++ b/test/controllers/matches_controller_test.rb @@ -18,7 +18,7 @@ class MatchesControllerTest < ActionController::TestCase test "should create match" do assert_difference('Match.count') do - post :create, match: { name: @match.name, tournament_id: @match.tournament_id, winner_id: @match.winner_id } + post :create, match: { name: @match.name, status: @match.status, tournament_id: @match.tournament_id, winner_id: @match.winner_id } end assert_redirected_to match_path(assigns(:match)) @@ -35,7 +35,7 @@ class MatchesControllerTest < ActionController::TestCase end test "should update match" do - patch :update, id: @match, match: { name: @match.name, tournament_id: @match.tournament_id, winner_id: @match.winner_id } + patch :update, id: @match, match: { name: @match.name, status: @match.status, tournament_id: @match.tournament_id, winner_id: @match.winner_id } assert_redirected_to match_path(assigns(:match)) end diff --git a/test/fixtures/matches.yml b/test/fixtures/matches.yml index 956229c..00af9f5 100644 --- a/test/fixtures/matches.yml +++ b/test/fixtures/matches.yml @@ -1,11 +1,13 @@ # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html one: + status: 1 tournament_id: name: MyString winner_id: two: + status: 1 tournament_id: name: MyString winner_id: -- cgit v1.2.3-54-g00ecf

Status Tournament Name Winner
<%= match.status %> <%= match.tournament %> <%= match.name %> <%= match.winner %>