Class: ShowsController

Inherits:
ArtfullyOseController show all
Defined in:
app/controllers/shows_controller.rb

Instance Method Summary collapse

Instance Method Details

#calendarObject



38
39
40
# File 'app/controllers/shows_controller.rb', line 38

def calendar
  authorize! :manage, @event
end

#createObject



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'app/controllers/shows_controller.rb', line 42

def create
  datetimes = params[:show][:datetime]
  show_params = params[:show].except!(:datetime)
  chart_params = Chart.polish_params(show_params.delete(:chart))
  @event = current_organization.events.find(params[:event_id])

  #TODO: Move these checks into ShowCreator
  if(datetimes.blank?)
    flash[:error] = "We need to know when your shows will be played! Click on the calendar to pick a date for your show."
    redirect_to new_event_show_path(@event) and return
  end

  #TODO: This is supposed to check to see if they're setting prices on tickets, but it doesn't
  if(chart_params.nil? || chart_params.empty?)
    flash[:error] = "Please specify at least one ticket type for your show."
    redirect_to new_event_show_path(@event) and return
  end
  
  redirect_to calendar_event_shows_path(@event) and return if @event.nil?

  ShowCreator.enqueue(datetimes, show_params, chart_params, @event, current_organization, publishing_show?)
  
  flash[:notice] = "We're creating your shows and will be done shortly. Reload this page to see our progress"
  redirect_to calendar_event_shows_path(@event)
end

#destroyObject



109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'app/controllers/shows_controller.rb', line 109

def destroy
  @show = Show.find(params[:id])
  authorize! :destroy, @show

  if @show.delayed_destroy
    respond_to do |format|
      format.html do |f|
        redirect_to event_shows_url(@show.event), :notice => 'Your show will be deleted in a few minutes.'
      end
      format.json { render :nothing => true, :status => 204 and return  }
    end
  else
    flash[:error] = "Sorry, this show can not be deleted. Contact support for further help."
    redirect_to event_path(@event)
  end
end

#door_listObject



126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# File 'app/controllers/shows_controller.rb', line 126

def door_list
  @show = Show.find(params[:id])
  @event = @show.event
  authorize! :view, @show
  @current_time = DateTime.now.in_time_zone(@show.event.time_zone)
  @door_list = DoorList.new(@show)

  respond_to do |format|
    format.html

    format.csv do
      @filename = [ @event.name, @show.datetime_local_to_event.to_s(:db_date), "door-list.csv" ].join("-")
      @csv_string = @door_list.items.to_comma
      send_data @csv_string, :filename => @filename, :type => "text/csv", :disposition => "attachment"
    end
    
    format.pdf do
      pdf = render_to_string :pdf => "door_list.pdf.haml"
      send_data pdf, :filename => @filename, :type => "application/pdf", :disposition => "attachment"
    end
  end
end

#editObject



86
87
88
89
# File 'app/controllers/shows_controller.rb', line 86

def edit
  @show = Show.find(params[:id])
  authorize! :edit, @show
end

#indexObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'app/controllers/shows_controller.rb', line 10

def index
  authorize! :manage, @event
  set_page_vars

  @month_years =  @event.shows.pluck(:datetime).group_by {|d| d.strftime "%b %Y"}.keys

  shows_rel = Show.where(:event_id => @event.id)
  page_size = 25


  if monthly? && valid_month?
    start = DateTime.now
                    .change(:year => year, :month => month, :day => 1, :offset => offset)
                    .beginning_of_day
    shows_rel = shows_rel.where('datetime > ?', start).where('datetime < ?', start + 1.month)
    page_size = 1000
  elsif upcoming?
    shows_rel = shows_rel.where('datetime > ?', Time.now - 2.days)
  end

  @shows = shows_rel.order('datetime ASC')
                    .paginate(:page => params[:page], :per_page => page_size)
end

#newObject



34
35
36
# File 'app/controllers/shows_controller.rb', line 34

def new
  @show = @event.next_show
end

#off_saleObject



181
182
183
184
185
186
187
188
189
# File 'app/controllers/shows_controller.rb', line 181

def off_sale
  @qty = params[:quantity].to_i
  @show = Show.find(params[:id])
  @section = @show.chart.sections.first
  @section.take_off_sale @qty
  @show.refresh_stats
  flash[:notice] = "Tickets are now off sale"
  redirect_to request.referer
end

#on_saleObject



171
172
173
174
175
176
177
178
179
# File 'app/controllers/shows_controller.rb', line 171

def on_sale
  @qty = params[:quantity].to_i
  @show = Show.find(params[:id])
  @section = @show.chart.sections.first
  @section.put_on_sale @qty
  @show.refresh_stats
  flash[:notice] = "Tickets are now on sale"
  redirect_to request.referer
end

#publishedObject



149
150
151
152
153
154
155
156
157
158
# File 'app/controllers/shows_controller.rb', line 149

def published
  @show = Show.find(params[:id])
  authorize! :show, @show

  @show.publish!
  respond_to do |format|
    format.html { redirect_to event_show_url(@show.event, @show), :notice => 'Your show is now published.' }
    format.json { render :json => @show.as_json }
  end
end

#publishing_show?Boolean

Returns:

  • (Boolean)


76
77
78
# File 'app/controllers/shows_controller.rb', line 76

def publishing_show?
  ("Save & Publish" == params[:commit])
end

#showObject



80
81
82
83
84
# File 'app/controllers/shows_controller.rb', line 80

def show
  @show = Show.includes(:event => :venue, :tickets => :section).find(params[:id])
  authorize! :view, @show
  @tickets = @show.tickets
end

#unpublishedObject



160
161
162
163
164
165
166
167
168
169
# File 'app/controllers/shows_controller.rb', line 160

def unpublished
  @show = Show.find(params[:id])
  authorize! :hide, @show

  @show.unpublish!
  respond_to do |format|
    format.html { redirect_to event_show_url(@show.event, @show), :notice => 'Your show is now unpublished.' }
    format.json { render :json => @show.as_json }
  end
end

#updateObject



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'app/controllers/shows_controller.rb', line 91

def update
  @show = Show.find(params[:id])
  authorize! :edit, @show
  if @show.live?
    flash[:alert] = 'Tickets have already been created for this performance'
    redirect_to event_url(@performance.event) and return
  else
    @show.datetime = ActiveSupport::TimeZone.create(@show.event.time_zone).parse(params[:show][:datetime])
    @show.chart_id = params[:show][:chart_id]
    if @show.save
      redirect_to event_path(@show.event)
    else
      flash[:alert] = 'This performance cannot be edited'
      render :edit
    end
  end
end

#valid_datetime?Boolean

Returns:

  • (Boolean)


68
69
70
71
72
73
74
# File 'app/controllers/shows_controller.rb', line 68

def valid_datetime?
  if ActiveSupport::TimeZone.create(@event.time_zone).parse(params[:show][:datetime]) < Time.now
    flash[:error] = "Please pick a date and time that is in the future."
    return false
  end
  true
end