diff options
Diffstat (limited to 'app')
57 files changed, 74 insertions, 58 deletions
diff --git a/app/assets/javascripts/common/.keep b/app/assets/javascripts/alerts/edit.js.coffee index e69de29..e69de29 100644 --- a/app/assets/javascripts/common/.keep +++ b/app/assets/javascripts/alerts/edit.js.coffee diff --git a/app/assets/javascripts/alerts/index.js.coffee b/app/assets/javascripts/alerts/index.js.coffee new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/app/assets/javascripts/alerts/index.js.coffee diff --git a/app/assets/javascripts/alerts/new.js.coffee b/app/assets/javascripts/alerts/new.js.coffee new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/app/assets/javascripts/alerts/new.js.coffee diff --git a/app/assets/javascripts/alerts/show.js.coffee b/app/assets/javascripts/alerts/show.js.coffee new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/app/assets/javascripts/alerts/show.js.coffee diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index e9430a3..1130838 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -17,4 +17,4 @@ //= require 'dragsort.js' //= require 'coordinates.js' // -//= require_tree ./common +//= require_tree ./application diff --git a/app/assets/javascripts/application/.keep b/app/assets/javascripts/application/.keep new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/app/assets/javascripts/application/.keep diff --git a/app/assets/javascripts/brackets/edit.js.coffee b/app/assets/javascripts/brackets/edit.js.coffee new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/app/assets/javascripts/brackets/edit.js.coffee diff --git a/app/assets/javascripts/brackets/index.js.coffee b/app/assets/javascripts/brackets/index.js.coffee new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/app/assets/javascripts/brackets/index.js.coffee diff --git a/app/assets/javascripts/brackets/new.js.coffee b/app/assets/javascripts/brackets/new.js.coffee new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/app/assets/javascripts/brackets/new.js.coffee diff --git a/app/assets/javascripts/brackets/show.js.coffee b/app/assets/javascripts/brackets/show.js.coffee new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/app/assets/javascripts/brackets/show.js.coffee diff --git a/app/assets/javascripts/games/edit.js.coffee b/app/assets/javascripts/games/edit.js.coffee new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/app/assets/javascripts/games/edit.js.coffee diff --git a/app/assets/javascripts/games/index.js.coffee b/app/assets/javascripts/games/index.js.coffee new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/app/assets/javascripts/games/index.js.coffee diff --git a/app/assets/javascripts/games/new.js.coffee b/app/assets/javascripts/games/new.js.coffee new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/app/assets/javascripts/games/new.js.coffee diff --git a/app/assets/javascripts/games/show.js.coffee b/app/assets/javascripts/games/show.js.coffee new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/app/assets/javascripts/games/show.js.coffee diff --git a/app/assets/javascripts/main/homepage.js.coffee b/app/assets/javascripts/main/homepage.js.coffee new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/app/assets/javascripts/main/homepage.js.coffee diff --git a/app/assets/javascripts/matches_show.js.coffee b/app/assets/javascripts/matches/show.js.coffee index 2609a69..2609a69 100644 --- a/app/assets/javascripts/matches_show.js.coffee +++ b/app/assets/javascripts/matches/show.js.coffee diff --git a/app/assets/javascripts/pms/edit.js.coffee b/app/assets/javascripts/pms/edit.js.coffee new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/app/assets/javascripts/pms/edit.js.coffee diff --git a/app/assets/javascripts/pms/index.js.coffee b/app/assets/javascripts/pms/index.js.coffee new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/app/assets/javascripts/pms/index.js.coffee diff --git a/app/assets/javascripts/pms/new.js.coffee b/app/assets/javascripts/pms/new.js.coffee new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/app/assets/javascripts/pms/new.js.coffee diff --git a/app/assets/javascripts/pms/show.js.coffee b/app/assets/javascripts/pms/show.js.coffee new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/app/assets/javascripts/pms/show.js.coffee diff --git a/app/assets/javascripts/search/go.js.coffee b/app/assets/javascripts/search/go.js.coffee new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/app/assets/javascripts/search/go.js.coffee diff --git a/app/assets/javascripts/server/edit.js.coffee b/app/assets/javascripts/server/edit.js.coffee new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/app/assets/javascripts/server/edit.js.coffee diff --git a/app/assets/javascripts/server/show.js.coffee b/app/assets/javascripts/server/show.js.coffee new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/app/assets/javascripts/server/show.js.coffee diff --git a/app/assets/javascripts/sessions/new.js.coffee b/app/assets/javascripts/sessions/new.js.coffee new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/app/assets/javascripts/sessions/new.js.coffee diff --git a/app/assets/javascripts/static.js.coffee b/app/assets/javascripts/static.js.coffee deleted file mode 100644 index 24f83d1..0000000 --- a/app/assets/javascripts/static.js.coffee +++ /dev/null @@ -1,3 +0,0 @@ -# Place all the behaviors and hooks related to the matching controller here. -# All this logic will automatically be available in application.js. -# You can use CoffeeScript in this file: http://coffeescript.org/ diff --git a/app/assets/javascripts/teams/edit.js.coffee b/app/assets/javascripts/teams/edit.js.coffee new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/app/assets/javascripts/teams/edit.js.coffee diff --git a/app/assets/javascripts/teams/index.js.coffee b/app/assets/javascripts/teams/index.js.coffee new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/app/assets/javascripts/teams/index.js.coffee diff --git a/app/assets/javascripts/teams/new.js.coffee b/app/assets/javascripts/teams/new.js.coffee new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/app/assets/javascripts/teams/new.js.coffee diff --git a/app/assets/javascripts/teams/show.js.coffee b/app/assets/javascripts/teams/show.js.coffee new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/app/assets/javascripts/teams/show.js.coffee diff --git a/app/assets/javascripts/tournaments/edit.js.coffee b/app/assets/javascripts/tournaments/edit.js.coffee new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/app/assets/javascripts/tournaments/edit.js.coffee diff --git a/app/assets/javascripts/tournaments/index.js.coffee b/app/assets/javascripts/tournaments/index.js.coffee new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/app/assets/javascripts/tournaments/index.js.coffee diff --git a/app/assets/javascripts/tournaments/new.js.coffee b/app/assets/javascripts/tournaments/new.js.coffee new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/app/assets/javascripts/tournaments/new.js.coffee diff --git a/app/assets/javascripts/tournaments_show.js.coffee b/app/assets/javascripts/tournaments/show.js.coffee index 1e91d3a..ef6bb82 100644 --- a/app/assets/javascripts/tournaments_show.js.coffee +++ b/app/assets/javascripts/tournaments/show.js.coffee @@ -1,4 +1,6 @@ -Update = (tournament) -> +json_url = window.location.href.replace(/\.[^/]*$/,'')+".json" + +update = (tournament) -> here = tournament["players"].length needed = (tournament["min_teams_per_match"] * tournament["min_players_per_team"]) pct_complete = here / needed @@ -21,10 +23,10 @@ Update = (tournament) -> # Do it all again setTimeout (-> - $.ajax(url: window.location.href.replace(/\..*/,'')+".json").done Update + $.ajax(url: json_url).done update return ), 2000 # Now kick off the whole process window.onload = -> - $.ajax(url: window.location.href.replace(/\..*/,'')+".json").done Update + $.ajax(url: json_url).done update diff --git a/app/assets/javascripts/users/edit.js.coffee b/app/assets/javascripts/users/edit.js.coffee new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/app/assets/javascripts/users/edit.js.coffee diff --git a/app/assets/javascripts/users/index.js.coffee b/app/assets/javascripts/users/index.js.coffee new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/app/assets/javascripts/users/index.js.coffee diff --git a/app/assets/javascripts/users/new.js.coffee b/app/assets/javascripts/users/new.js.coffee new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/app/assets/javascripts/users/new.js.coffee diff --git a/app/assets/javascripts/users/show.js.coffee b/app/assets/javascripts/users/show.js.coffee new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/app/assets/javascripts/users/show.js.coffee diff --git a/app/assets/stylesheets/main.css.scss b/app/assets/stylesheets/main.css.scss index a0d94c1..3859f53 100644 --- a/app/assets/stylesheets/main.css.scss +++ b/app/assets/stylesheets/main.css.scss @@ -1,3 +1,14 @@ // Place all the styles related to the main controller here. // They will automatically be included in application.css. // You can use Sass (SCSS) here: http://sass-lang.com/ + +.jumbotron { + background-color: #FFF; + box-shadow: 1px 1px 20px black; + width: 93%; + + p { + line-height: 1.5em; + } + +} diff --git a/app/assets/stylesheets/static.css.scss b/app/assets/stylesheets/static.css.scss deleted file mode 100644 index 6732370..0000000 --- a/app/assets/stylesheets/static.css.scss +++ /dev/null @@ -1,14 +0,0 @@ -// 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; - box-shadow: 1px 1px 20px black; - width: 93%; - - p { - line-height: 1.5em; - } - -} diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb index 1f0bdd8..aec5294 100644 --- a/app/controllers/games_controller.rb +++ b/app/controllers/games_controller.rb @@ -67,6 +67,6 @@ class GamesController < ApplicationController # Never trust parameters from the scary internet, only allow the white list through. def game_params - params.require(:game).permit(:name, :min_players_per_team, :max_players_per_team, :min_teams_per_match, :max_teams_per_match, :set_rounds, :randomized_teams, :sampling_method) + params.require(:game).permit(:parent_id, :name, :min_players_per_team, :max_players_per_team, :min_teams_per_match, :max_teams_per_match, :set_rounds, :randomized_teams, :sampling_method) end end diff --git a/app/controllers/main_controller.rb b/app/controllers/main_controller.rb index 6519d7b..0ba4d94 100644 --- a/app/controllers/main_controller.rb +++ b/app/controllers/main_controller.rb @@ -1,2 +1,4 @@ class MainController < ApplicationController + def homepage + end end diff --git a/app/controllers/static_controller.rb b/app/controllers/static_controller.rb deleted file mode 100644 index 038cc19..0000000 --- a/app/controllers/static_controller.rb +++ /dev/null @@ -1,7 +0,0 @@ -class StaticController < ApplicationController - def homepage - end - - def test - end -end diff --git a/app/controllers/tournaments_controller.rb b/app/controllers/tournaments_controller.rb index b276368..0390051 100644 --- a/app/controllers/tournaments_controller.rb +++ b/app/controllers/tournaments_controller.rb @@ -33,7 +33,7 @@ class TournamentsController < ApplicationController def new @games = Game.all if params[:tournament] - @tournament = Tournament.new(game: Game.find(params[:tournament][:game_id])) + @tournament = Tournament.new(tournament_params) else @tournament = Tournament.new() end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index cfa5d67..4c36148 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -56,8 +56,25 @@ class UsersController < ApplicationController # PATCH/PUT /users/1 # PATCH/PUT /users/1.json def update + ok = true + if params[:user][:remote_usernames].nil? + ok &= @user.update(user_params) + else + params[:user][:remote_usernames].each do |game_name,user_name| + game = Game.find_by_name(game_name) + remote_username = HTTParty.get("https://prod.api.pvp.net/api/lol/na/v1.3/summoner/by-name/#{user_name}?api_key=ad539f86-22fd-474d-9279-79a7a296ac38") + + remote = @user.remote_usernames.where(:game => game).first + if remote.nil? + ok &= @user.remote_usernames.create(game: game, value: remote_username) + else + remote.value = remote_username + ok &= remote.save + end + end + end respond_to do |format| - if @user.update(user_params) + if ok format.html { redirect_to @user, notice: 'User was successfully updated.' } format.json { head :no_content } else @@ -77,19 +94,6 @@ class UsersController < ApplicationController end end - def set_remote - game = Game.find_by_name("League of Legends") - - remote_username = HTTParty.get("https://prod.api.pvp.net/api/lol/na/v1.3/summoner/by-name/#{@name.downcase}?api_key=ad539f86-22fd-474d-9279-79a7a296ac38") - - remote = @user.find_remote_username(game) - if remote.nil? - @user.remote_username.create(game: game, value: remote_username) - else - remote.value = remote_username - remote.save - end - end private # Use callbacks to share common setup or constraints between actions. diff --git a/app/helpers/static_helper.rb b/app/helpers/static_helper.rb deleted file mode 100644 index 8cfc9af..0000000 --- a/app/helpers/static_helper.rb +++ /dev/null @@ -1,2 +0,0 @@ -module StaticHelper -end diff --git a/app/models/game.rb b/app/models/game.rb index 345877e..5f4c46d 100644 --- a/app/models/game.rb +++ b/app/models/game.rb @@ -1,3 +1,5 @@ class Game < ActiveRecord::Base + belongs_to :parent, class_name: "Game" + has_many :children, class_name: "Game" has_many :settings, class_name: "GameSetting" end diff --git a/app/models/remote_username.rb b/app/models/remote_username.rb index c2c3d20..8c1ce26 100644 --- a/app/models/remote_username.rb +++ b/app/models/remote_username.rb @@ -3,7 +3,11 @@ class RemoteUsername < ActiveRecord::Base belongs_to :user def value - JSON.parse(self.json_value) + begin + return JSON.parse(self.json_value) + rescue + return {} + end end def value=(v) diff --git a/app/models/tournament.rb b/app/models/tournament.rb index e21ccb1..686e066 100644 --- a/app/models/tournament.rb +++ b/app/models/tournament.rb @@ -40,6 +40,7 @@ class Tournament < ActiveRecord::Base end def []=(setting_name, val) + @tournament.save tournament_setting = @tournament.settings_raw.find_by_name(setting_name) if tournament_setting.nil? game_setting = @tournament.game.settings.find_by_name(setting_name) diff --git a/app/models/user.rb b/app/models/user.rb index 138f73e..5c0b5b1 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -24,9 +24,13 @@ class User < ActiveRecord::Base end def find_remote_username(game) - obj = remote_username.where(:game => game) - if obj.nil? and not game.parent.nil? - return find_remote_username(game.parent) + obj = self.remote_usernames.where(:game => game).first + if obj.nil? + if game.parent.nil? + return nil + else + return find_remote_username(game.parent) + end else return obj.value end diff --git a/app/views/games/_form.html.erb b/app/views/games/_form.html.erb index ef250ad..20cb214 100644 --- a/app/views/games/_form.html.erb +++ b/app/views/games/_form.html.erb @@ -12,6 +12,10 @@ <% end %> <div class="field"> + <%= f.label :parent_id %><br> + <%= f.text_field :parent_id %> + </div> + <div class="field"> <%= f.label :name %><br> <%= f.text_field :name %> </div> diff --git a/app/views/games/index.html.erb b/app/views/games/index.html.erb index abb0d8a..bcd10dd 100644 --- a/app/views/games/index.html.erb +++ b/app/views/games/index.html.erb @@ -3,6 +3,7 @@ <table class="table table-hover"> <thead> <tr> + <th>Parent</th> <th>Name</th> <th>Min players per team</th> <th>Max players per team</th> @@ -20,6 +21,7 @@ <tbody> <% @games.each do |game| %> <tr> + <td><%= game.parent %></td> <td><%= game.name %></td> <td><%= game.min_players_per_team %></td> <td><%= game.max_players_per_team %></td> diff --git a/app/views/games/index.json.jbuilder b/app/views/games/index.json.jbuilder index cc0afc9..6b20f60 100644 --- a/app/views/games/index.json.jbuilder +++ b/app/views/games/index.json.jbuilder @@ -1,4 +1,4 @@ json.array!(@games) do |game| - json.extract! game, :id, :name, :min_players_per_team, :max_players_per_team, :min_teams_per_match, :max_teams_per_match, :set_rounds, :randomized_teams, :sampling_method + json.extract! game, :id, :parent_id, :name, :min_players_per_team, :max_players_per_team, :min_teams_per_match, :max_teams_per_match, :set_rounds, :randomized_teams, :sampling_method json.url game_url(game, format: :json) end diff --git a/app/views/games/show.html.erb b/app/views/games/show.html.erb index d731e3d..1250cbd 100644 --- a/app/views/games/show.html.erb +++ b/app/views/games/show.html.erb @@ -1,4 +1,9 @@ <p> + <strong>Parent:</strong> + <%= @game.parent %> +</p> + +<p> <strong>Name:</strong> <%= @game.name %> </p> diff --git a/app/views/games/show.json.jbuilder b/app/views/games/show.json.jbuilder index 60d0a4a..087a156 100644 --- a/app/views/games/show.json.jbuilder +++ b/app/views/games/show.json.jbuilder @@ -1 +1 @@ -json.extract! @game, :id, :name, :min_players_per_team, :max_players_per_team, :min_teams_per_match, :max_teams_per_match, :set_rounds, :randomized_teams, :sampling_method, :created_at, :updated_at +json.extract! @game, :id, :parent_id, :name, :min_players_per_team, :max_players_per_team, :min_teams_per_match, :max_teams_per_match, :set_rounds, :randomized_teams, :sampling_method, :created_at, :updated_at diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 15eba29..dd0ea91 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -5,7 +5,7 @@ <%= stylesheet_link_tag "application", media: "all", "data-turbolinks-track" => true %> <%= javascript_include_tag "application", "data-turbolinks-track" => true %> <%= javascript_include_tag "#{params[:controller]}", "data-turbolinks-track" => true %> - <%= javascript_include_tag "#{params[:controller]}_#{params[:action]}", "data-turbolinks-track" => true %> + <%= javascript_include_tag "#{params[:controller]}/#{params[:action]}", "data-turbolinks-track" => true %> <%= csrf_meta_tags %> <%= yield :head %> </head> diff --git a/app/views/static/homepage.html.erb b/app/views/main/homepage.html.erb index 3ca8176..3ca8176 100644 --- a/app/views/static/homepage.html.erb +++ b/app/views/main/homepage.html.erb diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb index 81eee6f..dfebf08 100644 --- a/app/views/users/show.html.erb +++ b/app/views/users/show.html.erb @@ -21,11 +21,12 @@ </p> <p> - <%= label :username %><br> - <%= text_field %> - - <br><input type="submit" value="Submit"><br> - + <%= form_for @user do |f| %> + <label>Have a League of Legends Account? + <input type=text name="user[remote_usernames][League of Legends]"> + </label> + <%= f.submit "Add Username", :class => 'signup' %> + <% end %> </p> <div class="row"> |