Permalink
Browse files

Big refactor

  • Loading branch information...
1 parent 28ba1f4 commit ff09be856baf079da1c7e991c6ca06d6d3571a7b JRod committed Apr 19, 2012
@@ -28,7 +28,6 @@ class ClubsController < ApplicationController
}
end
-
end
@@ -47,8 +46,18 @@ def object
end
- def show_termine
- @season=params[:season]
+ def show_umpiretermine
+ @einteilung=current_object.umpire_games
+ respond_to do |format|
+ format.html
+ format.csv {
+ temp=current_object.umpire_games.to_csv
+ send_data temp , :disposition => 'inline'
+ }
+ format.json {
+ render :json=>current_object.umpire_games.to_json
+ }
+ end
end
@@ -8,30 +8,40 @@ class GamesController < ApplicationController
actions :all
belongs_to :schedule,:division,:field
-after :update do
-
- #self.update_attribute(:umpire_club,_umps)
- _umps=current_object.umpire_club
- if current_object.is_interleague?
- interleague=current_object.division.interleague
- il_game=interleague.games.find_by_spielnummer(current_object.spielnummer)
- il_game.update_attribute(:umpire_club,_umps)
- if il_game.division.playing_time.doubleHeader?
- s=current_object.spielnummer.slice(-2,2)=="-1" ? current_object.spielnummer.slice(0,8)+"-2" : current_object.spielnummer.slice(0,8)+"-1"
- g2=interleague.games.find_by_spielnummer(s)
- g2.update_attribute(:umpire_club,_umps)
- end
- end
+ after :update do
+ #self.update_attribute(:umpire_club,_umps)
+ _umps=current_object.umpire_club
+ if current_object.is_interleague?
+ interleague=current_object.division.interleague
+ il_game=interleague.games.find_by_spielnummer(current_object.spielnummer)
+ il_game.update_attribute(:umpire_club,_umps)
+ if il_game.division.playing_time.doubleHeader?
+ s=current_object.spielnummer.slice(-2,2)=="-1" ? current_object.spielnummer.slice(0,8)+"-2" : current_object.spielnummer.slice(0,8)+"-1"
+ g2=interleague.games.find_by_spielnummer(s)
+ g2.update_attribute(:umpire_club,_umps)
+ end
+ end
- if current_object.schedule.division.playing_time.doubleHeader? #Falls DH das zweite Spiel auch einteilen
- s=current_object.spielnummer.slice(-2,2)=="-1" ? current_object.spielnummer.slice(0,8)+"-2" : current_object.spielnummer.slice(0,8)+"-1"
- g3=current_object.schedule.division.games.find_by_spielnummer(s)
- g3.update_attribute(:umpire_club,_umps)
- end
+ if current_object.schedule.division.playing_time.doubleHeader? #Falls DH das zweite Spiel auch einteilen
+ s=current_object.spielnummer.slice(-2,2)=="-1" ? current_object.spielnummer.slice(0,8)+"-2" : current_object.spielnummer.slice(0,8)+"-1"
+ g3=current_object.schedule.division.games.find_by_spielnummer(s)
+ g3.update_attribute(:umpire_club,_umps)
+ end
- end
+ end
+
+ response_for :show do |format|
+ format.html
+ format.json {
+ render :json=>current_object.to_json(:only => [ :heim_team, :gast_team,:datum,:uhrzeit,:spielnummer,:runs_home,:runs_guest],:methods=>:uhrzeit_to_s,:include=>{
+ :heim_team=>{:methods=>[:full_name]},
+ :gast_team=>{:methods=>[:full_name]},
+ :umpire_club=>{:methods=>[:full_name]}
+ })
+ }
+ end
@@ -63,12 +73,17 @@ class GamesController < ApplicationController
def add_umpire
- if current_object.umpires.find(params[:umpire])
+ #unless current_object.umpires.find(params[:umpire])
current_object.umpires<<Umpire.find(params[:umpire])
- end
- redirect_to division_game_path(current_object.division,current_object)
+ #end
+ redirect_to division_game_path(current_object.schedule.division,current_object)
end
+ def remove_umpire
+
+ end
+
+
def update_sxl
spiel=current_object
s=Sxl::SxlSchedule.find(:first,:select=>"id,umpire",:conditions=>['no=?',spiel.spielnummer])
@@ -93,13 +108,13 @@ def update_results
rg=params[:game][spiel.spielnummer][:runs_guest]
if params[:game][spiel.spielnummer][:reset]=="no" and (rh!="" and rg!="")
-
- if spiel.status.id!=1
- _status=Status.find_by_bezeichnung('not_tweeted')
- else
- _status=Status.find_by_bezeichnung('beendet')
- end
-
+ _status=Status.find_by_bezeichnung('beendet')
+ #if spiel.status.id!=1
+ # _status=Status.find_by_bezeichnung('not_tweeted')
+ #else
+ # _status=Status.find_by_bezeichnung('beendet')
+ #end
+ _comment="gemeldet #{Time.now}"
else
rh=""
rg=""
@@ -146,21 +161,22 @@ def update_results
spiel.update_attributes(attr)
# In Production muss das auskommentiert werden
- s=find_in_sxl(spiel)
- s.each do |s_sxl|
- s_sxl.update_attributes(attr_sxl)
+ if ENV['RAILS_ENV']=='production'
+ s=find_in_sxl(spiel)
+ s.each do |s_sxl|
+ s_sxl.update_attributes(attr_sxl)
+ end
end
-
- if (spiel.status.id==99)
- #Mail an ifttt wg Twitter senden
-# email = Mail::Egd.create_send_tweet(spiel)
-# Mail::Egd.deliver(email)
- #puts email.encoded
- spiel.status=Status.find_by_bezeichnung('beendet')
- spiel.save
- end
+# if (spiel.status.id==99)
+# #Mail an ifttt wg Twitter senden
+## email = Mail::Egd.create_send_tweet(spiel)
+## Mail::Egd.deliver(email)
+# #puts email.encoded
+# spiel.status=Status.find_by_bezeichnung('beendet')
+# spiel.save
+# end
end
@@ -222,8 +238,9 @@ def update_result_sms
if s!=nil
if infos[spiele.index(s)+1]!="ppd"
ergebnis=infos[spiele.index(s)+1].split(":")
- attr={:runs_home=>ergebnis[0],:runs_guest=>ergebnis[1],:status=>Status.find_by_bezeichnung('beendet')}
- attr_sxl={:runs_home=>ergebnis[0],:runs_visitor=>ergebnis[1]}
+ _comment="gemeldet #{Time.now}"
+ attr={:runs_home=>ergebnis[0],:runs_guest=>ergebnis[1],:status=>Status.find_by_bezeichnung('beendet'),:kommentar=>_comment}
+ attr_sxl={:runs_home=>ergebnis[0],:runs_visitor=>ergebnis[1],:memo=>_comment}
s.update_result(attr,attr_sxl)
# email = Mail::Egd.create_send_tweet(s)
# Mail::Egd.deliver(email)
@@ -257,9 +274,11 @@ def update_result
attr_sxl={:runs_home=>params[:game][:runs_home],:runs_visitor=>params[:game][:runs_guest]}
spiel.update_attributes(attr)
# In Production muss das auskommentiert werden
- s=find_in_sxl(spiel)
- s.each do |s_sxl|
- s_sxl.update_attributes(attr_sxl)
+ if ENV['RAILS_ENV']=='production'
+ s=find_in_sxl(spiel)
+ s.each do |s_sxl|
+ s_sxl.update_attributes(attr_sxl)
+ end
end
if params[:game][:tweet]=="yes"
email = Mail::Egd.create_send_tweet(spiel)
@@ -268,7 +287,7 @@ def update_result
end
respond_to do |format|
- format.html { redirect_to(division_game_path(spiel.division,spiel)) }
+ format.html { redirect_to(game_path(spiel)) }
end
end
@@ -277,6 +296,13 @@ def search
@result=Game.find_by_spielnummer(params[:game][:spielnummer])
respond_to do |format|
format.html { redirect_to(division_game_path(@result.schedule.division,@result)) }
+ format.json {
+ render :json=>@result.to_json(:only => [ :heim_team, :gast_team,:datum,:uhrzeit,:spielnummer,:runs_home,:runs_guest],:methods=>:uhrzeit_to_s,:include=>{
+ :heim_team=>{:methods=>[:full_name]},
+ :gast_team=>{:methods=>[:full_name]},
+ :umpire_club=>{:methods=>[:full_name]}
+ })
+ }
end
end
@@ -19,6 +19,7 @@ class SchedulesController < ApplicationController
end
end
+
after :create do
flash[:info]="SPIELPLAN wurde erstellt"
end
@@ -37,7 +38,7 @@ class SchedulesController < ApplicationController
#redirect_to league_division_path(parent_object.league,parent_object)
}
format.json {
- render :json=>(parent_object.schedules.first).to_json
+ render :json=>parent_object.schedules.first.to_json
#flash[:notice] = "JSOn ist OK"
#redirect_to league_division_path(current_object.division.league,current_object.division)
#redirect_to division_schedules_path(current_object)
@@ -69,14 +70,15 @@ def create_schedule
end
+
def show
respond_to do |format|
format.html
format.csv {
temp=current_object.to_csv
send_data temp , :disposition => 'attachement'
- redirect_to show_schedule_division_url(current_object)
+
}
format.json {
render :json=>current_object.to_json
@@ -84,6 +84,7 @@ def copy_sxl
end
#TODO Refactor
def plan
+
respond_to do |format|
format.html
format.xls {
@@ -6,9 +6,11 @@ class UmpiresController < ApplicationController
belongs_to :club
before :index do
- @umps=Umpire.all(:order=>'club_id').group_by do |u|
- u.club
- end
+ #umpire=Umpire.all(:order=>'club_id').group_by do |u|
+ # u.club
+ #end
+ #@ump= current_object.nil? ? umpire : current_objects
+
end
end
@@ -23,15 +25,20 @@ def import
end
def push_to_sxl
- Season.find(current_season).divisions(:include=>[:league],:order=>'leagues.nummer,nummer)').each do |division|
+ saison=Season.find(current_season)
+ saison.divisions(:include=>[:league],:order=>'leagues.nummer,nummer)').each do |division|
+ d=Sxl::SxlLeague.find(:first,:conditions=>['league_short=? and season=?',division.short,saison.year])
division.games.all(:order=>'datum').each do |spiel|
- s=Sxl::SxlSchedule.find(:first,:select=>"id,umpire,memo",:conditions=>['no=?',spiel.spielnummer])
+ s=Sxl::SxlSchedule.find(:first,:select=>"id,umpire,memo",:conditions=>['no=? and league_id=?',spiel.spielnummer,d.id])
if spiel.umpire_club!=nil
#s_umpire_club=Sxl::SxlClub.find(:first,:conditions=>['club_loc=? and name=?',Iconv.iconv('ISO-8859-1','UTF-8',spiel.umpire_club.ort),Iconv.iconv('ISO-8859-1','UTF-8',spiel.umpire_club.name)])
+
s_umpire_club=Sxl::SxlClub.find(:first,:conditions=>['club_short=?',spiel.umpire_club.club_short])
+
else
s_umpire_club=Sxl::SxlClub.find('00000048')
end
+
attr={ :umpire=>sprintf("%08d",s_umpire_club.id),
:memo=>"Import #{division.full_name} #{Time.now.strftime("%d.%m.%y")}"
}
View
@@ -31,6 +31,20 @@ class Club < ActiveRecord::Base
has_many :umpire_games, :class_name=>'Game', :foreign_key=>'umpire_club_id',:order=>'datum, spielnummer,uhrzeit' do
+ def to_csv
+ export_file = "#{RAILS_ROOT}/temp/#{proxy_owner}_einteilung.csv"
+
+ CSV::Writer.generate(export_file) do |writer|
+ writer<< %w(Liga Datum Uhrzeit Spielnummer Heim Gast)
+ find(:all,:order=>'datum,spielnummer,uhrzeit').each do |spiel|
+ writer<< spiel.to_csv(0)
+ end
+
+ end
+ return export_file
+ end
+
+
def mindestanzahl_erreicht(bereich)
anz=proxy_owner.mindesteinsaetze(bereich)
einteilungen=find(:all,:include=>[:division=>[:league]],:conditions=>['leagues.bereich_id=?',bereich.id])
View
@@ -17,6 +17,7 @@ class Division < ActiveRecord::Base
belongs_to :league_fixture
+
def size
(teams.count)%2 == 0 ? teams.count : teams.count+1
end
@@ -135,7 +136,7 @@ def next_games(von, bis)
#datum= spiel!=nil ? spiel.datum : Date.parse('01-01-01')
#self.angesetzte_spiele.find(:all,:conditions=>['datum BETWEEN ? and ?',von,bis])
count=self.playing_time.doubleHeader==true ? self.anzahlTeams : self.anzahlTeams/2
- self.angesetzte_spiele.find(:all,:conditions=>['datum>= ?',von],:limit=>count)
+ self.games.angesetzte_spiele.find(:all,:conditions=>['datum>= ?',von],:limit=>count)
end
View
@@ -24,6 +24,8 @@ class Game < ActiveRecord::Base
{ :include => [:schedule=>:division],:conditions => ['divisions.season_id=?',saison ],:order=>'datum,spielnummer,uhrzeit' }
}
+ named_scope :angesetzte_spiele, :order=>'datum,spielnummer,uhrzeit',:include=>:status,:conditions=>['statuses.bezeichnung=?','angesetzt']
+ named_scope :beendete_spiele, :order=>'datum,spielnummer,uhrzeit',:include=>:status,:conditions=>['statuses.bezeichnung=? or statuses.bezeichnung=? or statuses.bezeichnung=?','beendet','ke','ausgefallen']
named_scope :konflikt, :condition=>'status=7'
@@ -33,7 +35,7 @@ def change_comment(comment)
live=true
self.update_attribute(:kommentar,comment)
self.save
- if live==true
+ if ENV['RAILS_ENV']=='production'
s=Sxl::SxlSchedule.find(:first,:select=>"id,memo",:conditions=>['no=?',self.spielnummer])
s.memo=comment
s.save
@@ -34,6 +34,9 @@ class Permissions < Aegis::Permissions
action :index do
allow :everyone
end
+ action :spielplan , :collection=>true do
+ allow :everyone
+ end
end
@@ -92,12 +95,13 @@ class Permissions < Aegis::Permissions
allow :ligadirektor
end
- action :show,:team_meldung,:add_to_collab, :assign_field do
+ action :show,:team_meldung,:add_to_collab, :assign_field ,:show_umpiretermine do
allow :verein do
object.email == user.email
end
allow :ligadirektor
end
+
action :index do
allow :everyone
end
Oops, something went wrong.

0 comments on commit ff09be8

Please sign in to comment.