| Class | Admin::EventsController |
| In: |
app/controllers/admin/events_controller.rb
|
| Parent: | Admin::AdminController |
Add missing child Events to this Event (their parent)
# File app/controllers/admin/events_controller.rb, line 251
251: def add_children
252: parent = Event.find(params[:parent_id])
253: parent.missing_children.each do |child|
254: child.parent = parent
255: child.save!
256: end
257: redirect_to(edit_admin_event_path(parent))
258: end
Create new SingleDayEvent
# File app/controllers/admin/events_controller.rb, line 72
72: def create
73: assign_new_event
74: if @event.save
75: expire_cache
76: flash[:notice] = "Created #{@event.name}"
77: redirect_to edit_admin_event_path(@event)
78: else
79: flash[:warn] = @event.errors.full_messages
80: render :edit
81: end
82: end
Create new MultiDayEvent from ‘prototype’ SingleDayEvent
# File app/controllers/admin/events_controller.rb, line 89
89: def create_from_children
90: single_day_event = Event.find(params[:id])
91: new_parent = MultiDayEvent.create_from_children(single_day_event.multi_day_event_children_with_no_parent)
92: expire_cache
93: redirect_to(:action => :edit, :id => new_parent.to_param)
94: end
# File app/controllers/admin/events_controller.rb, line 207
207: def destroy
208: @event = Event.find(params[:id])
209: if @event.destroy
210: expire_cache
211: respond_to do |format|
212: format.html {
213: flash[:notice] = "Deleted #{@event.name}"
214: if @event.parent
215: redirect_to(edit_admin_event_path(@event.parent))
216: else
217: redirect_to(admin_events_path(:year => @event.date.year))
218: end
219: }
220: format.js
221: end
222: else
223: respond_to do |format|
224: format.html {
225: flash[:notice] = "Could not delete #{@event.name}: #{@event.errors.full_messages}"
226: redirect_to(admin_events_path(:year => @event.date.year))
227: }
228: format.js { render "destroy_error" }
229: end
230: end
231: end
# File app/controllers/admin/events_controller.rb, line 233
233: def destroy_races
234: @event = Event.find(params[:id])
235: # Remember races for view
236: @races = @event.races.dup
237: @combined_results = @event.combined_results
238: @event.destroy_races
239: expire_cache
240: end
Show results for Event
# File app/controllers/admin/events_controller.rb, line 35
35: def edit
36: if params['promoter_id'].present? && current_person.administrator?
37: @event.promoter = Person.find(params['promoter_id'])
38: end
39: end
schedule calendar with links to admin Event pages
# File app/controllers/admin/events_controller.rb, line 18
18: def index
19: @year = params["year"].to_i
20: @year = RacingAssociation.current.effective_year if @year == 0
21: @competitions = Event.find(
22: :all,
23: :conditions => ["type in (?) and date between ? and ?", Competition::TYPES, "#{@year}-01-01", "#{@year}-12-31"]
24: )
25: events = SingleDayEvent.find(:all, :conditions => ["date between ? and ?", "#{@year}-01-01", "#{@year}-12-31"])
26: @schedule = Schedule::Schedule.new(@year, events)
27: end
# File app/controllers/admin/events_controller.rb, line 46
46: def new
47: if params[:year].blank?
48: date = RacingAssociation.current.effective_year
49: else
50: year = params[:year]
51: date = Date.new(year.to_i)
52: end
53: assign_new_event
54: association_number_issuer = NumberIssuer.find_by_name(RacingAssociation.current.short_name)
55: if association_number_issuer
56: @event.number_issuer_id = association_number_issuer.id
57: end
58:
59: respond_to do |format|
60: format.html { render :action => :edit }
61: format.js { render(:update) { |page| page.redirect_to(:action => :new, :event => params[:event]) } }
62: end
63: end
# File app/controllers/admin/events_controller.rb, line 242
242: def set_parent
243: child = Event.find(params[:child_id])
244: parent = Event.find(params[:parent_id])
245: child.parent = parent
246: child.save!
247: redirect_to(edit_admin_event_path(child))
248: end
Update existing Event
# File app/controllers/admin/events_controller.rb, line 104
104: def update
105: # TODO consolidate code
106: event_params = params[:event].clone
107: event_type = event_params.delete(:type)
108:
109: @event = Event.update(params[:id], event_params)
110:
111: if event_type == ""
112: event_type = "Event"
113: end
114: if !event_type.blank? && event_type != @event.type
115: raise "Unknown event type: #{event_type}" unless ['Event', 'SingleDayEvent', 'MultiDayEvent', 'Series', 'WeeklySeries'].include?(event_type)
116: if event_type == 'SingleDayEvent' && @event.is_a?(MultiDayEvent)
117: @event.children.each do |child|
118: child.parent = nil
119: child.save!
120: end
121: end
122: if @event.save
123: Event.connection.execute("update events set type = '#{event_type}' where id = #{@event.id}")
124: @event = Event.find(@event.id)
125: end
126: end
127:
128: if @event.errors.empty?
129: expire_cache
130: flash[:notice] = "Updated #{@event.name}"
131: redirect_to(edit_admin_event_path(@event))
132: else
133: render(:action => :edit)
134: end
135: end
Upload results from Excel spreadsheet. Expects column headers in first row Expects Race names in first column before set of results: Senior Women Category 3 | 1 | Leitheiser | Ann | HFV |
# File app/controllers/admin/events_controller.rb, line 148
148: def upload
149: uploaded_file = params[:results_file]
150:
151: path = "#{Dir.tmpdir}/#{uploaded_file.original_filename}"
152: File.open(path, "wb") do |f|
153: f.print(uploaded_file.read)
154: end
155:
156: temp_file = File.new(path)
157: event = Event.find(params[:id])
158:
159: if File.extname(path) == ".lif"
160: results_file = Results::LifFile.new(temp_file, event)
161: else
162: results_file = Results::ResultsFile.new(temp_file, event)
163: end
164:
165: results_file.import
166: expire_cache
167: FileUtils.rm temp_file rescue nil
168:
169: flash[:notice] = "Imported #{uploaded_file.original_filename}. "
170: unless results_file.custom_columns.empty?
171: flash[:notice] = flash[:notice] + "Found custom columns: #{results_file.custom_columns.map(&:humanize).join(", ")}. "
172: flash[:notice] = flash[:notice] + "(If import file is USAC format, you should expect errors on Organization, Event Year, Event #, Race Date and Discipline.)" if RacingAssociation.current.usac_results_format?
173: end
174:
175: redirect_to(edit_admin_event_path(event))
176: end
Upload new Excel Schedule See Schedule::Schedule.import for details Redirects to schedule index if succesful
# File app/controllers/admin/events_controller.rb, line 186
186: def upload_schedule
187: uploaded_file = params[:schedule_file]
188: path = "#{Dir.tmpdir}/#{uploaded_file.original_filename}"
189: File.open(path, "wb") do |f|
190: f.print(uploaded_file.read)
191: end
192:
193: date = Schedule::Schedule.import(path)
194: expire_cache
195: flash[:notice] = "Uploaded schedule from #{uploaded_file.original_filename}"
196:
197: redirect_to(admin_events_path)
198: end
# File app/controllers/admin/events_controller.rb, line 262
262: def assign_disciplines
263: @disciplines = Discipline.find_all_names
264: end
# File app/controllers/admin/events_controller.rb, line 266
266: def assign_event
267: @event = Event.find(params[:id])
268: end
# File app/controllers/admin/events_controller.rb, line 270
270: def assign_new_event
271: if params[:event] && params[:event][:type].present?
272: event_type = params[:event][:type]
273: elsif params[:event] && params[:event][:parent_id].present?
274: event_type = "Event"
275: else
276: event_type = "SingleDayEvent"
277: end
278: raise "Unknown event type: #{event_type}" unless ['Event', 'SingleDayEvent', 'MultiDayEvent', 'Series', 'WeeklySeries'].include?(event_type)
279: @event = eval(event_type).new(params[:event])
280: end