From d91a2eae52676afba079c54268bb93991001f8f5 Mon Sep 17 00:00:00 2001 From: Ari Timonen Date: Sat, 10 May 2014 11:44:48 +0300 Subject: [PATCH] Add match admin page and casting --- Gemfile | 1 + Gemfile.lock | 3 + app/assets/javascripts/application.js.coffee | 4 ++ app/controllers/matches_controller.rb | 14 ++++- app/models/group.rb | 14 ++--- app/models/match.rb | 2 + app/models/profile.rb | 2 + app/models/user.rb | 4 ++ app/views/about/staff.html.erb | 4 +- app/views/matches/admin.html.haml | 42 +++++++++++++ app/views/matches/show.html.erb | 9 +++ app/views/users/edit.html.erb | 5 ++ config/routes.rb | 5 +- db/migrate/20140509231817_add_stream.rb | 7 +++ db/migrate/20140510080652_add_caster.rb | 7 +++ db/schema.rb | 62 +++++--------------- db/seeds.rb | 2 +- 17 files changed, 126 insertions(+), 61 deletions(-) create mode 100644 app/views/matches/admin.html.haml create mode 100644 db/migrate/20140509231817_add_stream.rb create mode 100644 db/migrate/20140510080652_add_caster.rb diff --git a/Gemfile b/Gemfile index 565cbfd..e5f811a 100644 --- a/Gemfile +++ b/Gemfile @@ -35,6 +35,7 @@ gem 'sass-rails', '~> 3.2.6' gem 'font-awesome-sass', '~> 4.0.3.1' gem 'bourbon', '~> 3.1.8' gem 'neat', '~> 1.6.0' +gem 'haml' group :assets do gem 'uglifier', '~> 2.5.0' diff --git a/Gemfile.lock b/Gemfile.lock index 960f152..91e8fde 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -114,6 +114,8 @@ GEM font-awesome-sass (4.0.3.1) sass (~> 3.2) gruff (0.3.7) + haml (4.0.5) + tilt hike (1.2.3) i18n (0.6.9) journey (1.0.4) @@ -277,6 +279,7 @@ DEPENDENCIES faraday (~> 0.9.0) font-awesome-sass (~> 4.0.3.1) gruff (~> 0.3.6) + haml jquery-rails (~> 2.0.2) mysql2 (~> 0.3.15) neat (~> 1.6.0) diff --git a/app/assets/javascripts/application.js.coffee b/app/assets/javascripts/application.js.coffee index dd04dd1..fa73e42 100644 --- a/app/assets/javascripts/application.js.coffee +++ b/app/assets/javascripts/application.js.coffee @@ -27,4 +27,8 @@ $ -> $select.trigger 'DOMSubtreeModified' + $('a[href=#form_submit]').click -> + $(this).closest('form').submit() + return false + $('#notification').delay(3000).fadeOut() \ No newline at end of file diff --git a/app/controllers/matches_controller.rb b/app/controllers/matches_controller.rb index 9827dfe..5066916 100644 --- a/app/controllers/matches_controller.rb +++ b/app/controllers/matches_controller.rb @@ -1,5 +1,5 @@ class MatchesController < ApplicationController - before_filter :get_match, except: [:index, :new, :create] + before_filter :get_match, except: [:index, :new, :create, :admin] def index @matches = Match.active @@ -16,6 +16,11 @@ class MatchesController < ApplicationController raise AccessError unless @match.can_create? cuser end + def admin + @matches = Match.active.includes(:contest, :contester1, :contester2, :map1, :map2, :referee).all.group_by {|t| t.week.to_s }.to_a.reverse + render :layout => "full" + end + def extra end @@ -64,8 +69,11 @@ class MatchesController < ApplicationController format.xml { head :ok } format.html do flash[:notice] = t(:matches_update) - #redirect_to_back - redirect_to @match + if URI(request.referer).path.include?("admin") + redirect_to_back + else + redirect_to @match + end end end else diff --git a/app/models/group.rb b/app/models/group.rb index df76445..734ea38 100644 --- a/app/models/group.rb +++ b/app/models/group.rb @@ -17,7 +17,7 @@ class Group < ActiveRecord::Base MOVIES = 3 DONORS = 4 MOVIEMAKERS = 5 - SHOUTCASTERS = 6 + CASTERS = 6 CHAMPIONS = 7 PREDICTORS = 8 STAFF = 10 @@ -48,7 +48,7 @@ class Group < ActiveRecord::Base def self.staff staff = [] - (find(ADMINS).groupers + find(PREDICTORS).groupers + find(SHOUTCASTERS).groupers + find(STAFF).groupers + find(REFEREES).groupers).each do |g| + (find(ADMINS).groupers + find(PREDICTORS).groupers + find(CASTERS).groupers + find(STAFF).groupers + find(REFEREES).groupers).each do |g| staff << g unless staff.include? g end staff @@ -78,11 +78,11 @@ class Group < ActiveRecord::Base extras end - def self.shoutcasters - shoutcasters = [] - (find(SHOUTCASTERS).groupers).each do |g| - shoutcasters << g unless shoutcasters.include? g + def self.casters + casters = [] + (find(CASTERS).groupers).each do |g| + casters << g unless casters.include? g end - shoutcasters + casters end end diff --git a/app/models/match.rb b/app/models/match.rb index c49c468..8e453d3 100644 --- a/app/models/match.rb +++ b/app/models/match.rb @@ -54,6 +54,7 @@ class Match < ActiveRecord::Base belongs_to :week belongs_to :hltv, :class_name => "Server" belongs_to :stream, :class_name => "Movie" + belongs_to :caster, :class_name => "User" scope :future, :conditions => ["match_time > UTC_TIMESTAMP()"] scope :future5, :conditions => ["match_time > UTC_TIMESTAMP()"], :limit => 5 @@ -293,6 +294,7 @@ class Match < ActiveRecord::Base def can_update? cuser, params = {} return false unless cuser return true if cuser.admin? + return true if cuser.caster? and Verification.contain params, [:caster_id] return true if cuser.ref? and !referee and Verification.contain params, [:referee_id] return true if cuser.ref? and referee == cuser \ and Verification.contain params, [:score1, :score2, :forfeit, :report, :demo_id, :motm_name, :matchers_attributes, :server_id] diff --git a/app/models/profile.rb b/app/models/profile.rb index 20c5178..194e0f8 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -74,6 +74,8 @@ class Profile < ActiveRecord::Base validates_length_of :achievements, :maximum => 65000 validates_format_of :steam_profile, :with => /\A[A-Za-z0-9_\-\+]{1,40}\z/, :allow_blank => true + validates :stream, :length => {:maximum => 30} + before_validation :init_steam_profile before_save :parse_text diff --git a/app/models/user.rb b/app/models/user.rb index f56319e..1f06540 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -193,6 +193,10 @@ class User < ActiveRecord::Base groups.exists? :id => Group::REFEREES end + def caster? + group.exists? :id => Group::CASTERS + end + def verified? # created_at < DateTime.now.ago(VERIFICATION_TIME) true diff --git a/app/views/about/staff.html.erb b/app/views/about/staff.html.erb index bad9e40..ae75282 100644 --- a/app/views/about/staff.html.erb +++ b/app/views/about/staff.html.erb @@ -80,7 +80,7 @@
-

Shoutcasters

+

CASTERS

@@ -89,7 +89,7 @@ - <% Group.shoutcasters.each do |grouper| %> + <% Group.casters.each do |grouper| %> diff --git a/app/views/matches/admin.html.haml b/app/views/matches/admin.html.haml new file mode 100644 index 0000000..66dfd63 --- /dev/null +++ b/app/views/matches/admin.html.haml @@ -0,0 +1,42 @@ +- @matches.each do |week, matches| + %h2=week + %table.striped#matches + %tr + %th.opponent Teams + %th.date Date + %th.maps Maps + %th Score + %th Caster + %th Referee + %th.actions Actions + - matches.each do |match| + %tr + %td + = namelink match.contester1.team + vs + = namelink match.contester2.team + %td + = shorttime match.match_time + %td + = match.map1.to_s + " " + match.map2.to_s + %td + = link_to match, :class => "bold #{match.score_color}" do + = h match.score1 + \- #{h match.score2} + %td + - if match.caster + = namelink match.caster + - elsif match.can_update?(cuser, {:caster_id => 1}) + = form_for match do |f| + = f.hidden_field :caster_id, {:value => cuser.id} + = link_to "Take!", "#form_submit" + %td + - if match.referee + = namelink match.referee + - elsif match.can_update?(cuser, {:referee_id => 1}) + = form_for match do |f| + = f.hidden_field :referee_id, {:value => cuser.id} + = link_to "Take!", "#form_submit" + %td.actions + - if cuser.ref? || cuser.admin? + = link_to "Admin", match_ref_path(match) \ No newline at end of file diff --git a/app/views/matches/show.html.erb b/app/views/matches/show.html.erb index 8907892..0bd455b 100644 --- a/app/views/matches/show.html.erb +++ b/app/views/matches/show.html.erb @@ -99,6 +99,15 @@ <%= cascade @match, [:server, :demo, :referee] %> Maps
<%= namelink @match.map1 %>, <%= namelink @match.map2 %> + + <% if @match.caster && @match.caster.profile.stream %> +
+
Stream
+
+ <%= link_to @match.caster.profile.stream, @match.caster.profile.stream %> +
+
+ <% end %> <% unless @match.report.nil? or @match.report.empty? %> diff --git a/app/views/users/edit.html.erb b/app/views/users/edit.html.erb index 8748e3b..45188eb 100644 --- a/app/views/users/edit.html.erb +++ b/app/views/users/edit.html.erb @@ -84,6 +84,11 @@ <%= p.file_field :avatar %> + +
+ <%= p.label :stream %> + <%= p.text_field :stream %> +
diff --git a/config/routes.rb b/config/routes.rb index 806b92f..8898bce 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -47,7 +47,10 @@ Ensl::Application.routes.draw do resources :servers resources :predictions resources :rounds - resources :matches + resources :matches do |m| + get :admin, :to => "matches#admin", :on => :collection + get :ref, :to => "matches#ref" + end resources :maps resources :logs resources :log_files diff --git a/db/migrate/20140509231817_add_stream.rb b/db/migrate/20140509231817_add_stream.rb new file mode 100644 index 0000000..3e7232f --- /dev/null +++ b/db/migrate/20140509231817_add_stream.rb @@ -0,0 +1,7 @@ +class AddStream < ActiveRecord::Migration + def change + change_table :profiles do |p| + p.string :stream + end + end +end diff --git a/db/migrate/20140510080652_add_caster.rb b/db/migrate/20140510080652_add_caster.rb new file mode 100644 index 0000000..d4bb517 --- /dev/null +++ b/db/migrate/20140510080652_add_caster.rb @@ -0,0 +1,7 @@ +class AddCaster < ActiveRecord::Migration + def change + change_table :matches do |m| + m.string :caster_id + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 59983ad..bc13abc 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,21 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20140330152235) do - - create_table "admin_requests", :force => true do |t| - t.string "addr" - t.string "pwd" - t.integer "server_id" - t.string "player" - t.integer "user_id" - t.string "msg" - t.datetime "created_at" - t.datetime "updated_at" - end - - add_index "admin_requests", ["server_id"], :name => "index_admin_requests_on_server_id" - add_index "admin_requests", ["user_id"], :name => "index_admin_requests_on_user_id" +ActiveRecord::Schema.define(:version => 20140510080652) do create_table "article_versions", :force => true do |t| t.integer "article_id" @@ -214,16 +200,6 @@ ActiveRecord::Schema.define(:version => 20140330152235) do add_index "data_files", ["directory_id"], :name => "index_data_files_on_directory_id" add_index "data_files", ["related_id"], :name => "index_data_files_on_related_id" - create_table "deleteds", :force => true do |t| - t.integer "deletable_id" - t.string "deletable_type" - t.integer "user_id" - t.text "reason" - t.datetime "created_at" - t.datetime "updated_at" - t.integer "related_id" - end - create_table "directories", :force => true do |t| t.string "name" t.string "description" @@ -236,21 +212,6 @@ ActiveRecord::Schema.define(:version => 20140330152235) do add_index "directories", ["parent_id"], :name => "index_directories_on_parent_id" - create_table "firms", :force => true do |t| - t.string "name" - t.string "y_code" - t.string "email" - t.string "website" - t.string "phone" - t.string "address" - t.integer "zipcode" - t.string "town" - t.integer "owner" - t.string "opentime" - t.datetime "created_at" - t.datetime "updated_at" - end - create_table "forumers", :force => true do |t| t.integer "forum_id" t.integer "group_id" @@ -462,6 +423,7 @@ ActiveRecord::Schema.define(:version => 20140330152235) do t.integer "points1" t.integer "points2" t.integer "hltv_id" + t.string "caster_id" end add_index "matches", ["challenge_id"], :name => "index_matches_on_challenge_id" @@ -516,13 +478,6 @@ ActiveRecord::Schema.define(:version => 20140330152235) do add_index "movies", ["status"], :name => "index_movies_on_status" add_index "movies", ["user_id"], :name => "index_movies_on_user_id" - create_table "nodes", :force => true do |t| - t.string "name" - t.integer "foreign_key" - t.datetime "created_at" - t.datetime "updated_at" - end - create_table "options", :force => true do |t| t.string "option" t.integer "poll_id" @@ -631,6 +586,7 @@ ActiveRecord::Schema.define(:version => 20140330152235) do t.string "steam_profile" t.string "achievements_parsed" t.string "signature_parsed" + t.string "stream" end add_index "profiles", ["user_id"], :name => "index_profiles_on_user_id" @@ -755,6 +711,18 @@ ActiveRecord::Schema.define(:version => 20140330152235) do add_index "sessions", ["session_id"], :name => "index_sessions_on_session_id" add_index "sessions", ["updated_at"], :name => "index_sessions_on_updated_at" + create_table "shoutmsg_archive", :force => true do |t| + t.integer "user_id" + t.string "text" + t.datetime "created_at" + t.datetime "updated_at" + t.string "shoutable_type" + t.integer "shoutable_id" + end + + add_index "shoutmsg_archive", ["shoutable_type", "shoutable_id"], :name => "index_shoutmsgs_on_shoutable_type_and_shoutable_id" + add_index "shoutmsg_archive", ["user_id"], :name => "index_shoutmsgs_on_user_id" + create_table "shoutmsgs", :force => true do |t| t.integer "user_id" t.string "text" diff --git a/db/seeds.rb b/db/seeds.rb index 702bfde..204dd1c 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -10,7 +10,7 @@ Group.create!(id: Group::REFEREES, name: "Referees", founder: User.first) Group.create!(id: Group::MOVIES, name: "Movies", founder: User.first) Group.create!(id: Group::DONORS, name: "Donors", founder: User.first) Group.create!(id: Group::MOVIEMAKERS, name: "Movie Makers", founder: User.first) -Group.create!(id: Group::SHOUTCASTERS, name: "Casters", founder: User.first) +Group.create!(id: Group::CASTERS, name: "Streamers", founder: User.first) Group.create!(id: Group::CHAMPIONS, name: "Champions", founder: User.first) Group.create!(id: Group::PREDICTORS, name: "Predictors", founder: User.first) Group.create!(id: Group::STAFF, name: "Staff", founder: User.first)
Task Age
<%= flag grouper.user.country %> <%= namelink grouper.user %>