2019-07-30 21:29:24 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-03-25 16:15:39 +00:00
|
|
|
# License: AGPL-3.0-or-later WITH Web-Template-Output-Additional-Permission-3.0-or-later
|
2018-03-25 17:30:42 +00:00
|
|
|
class EventsController < ApplicationController
|
2020-05-11 18:38:50 +00:00
|
|
|
include Controllers::Event::Current
|
|
|
|
include Controllers::Event::Authorization
|
2018-03-25 17:30:42 +00:00
|
|
|
|
2019-07-30 21:29:24 +00:00
|
|
|
helper_method :current_event_editor?
|
2019-07-13 07:53:59 +00:00
|
|
|
before_action :authenticate_nonprofit_user!, only: :name_and_id
|
2019-07-30 21:29:24 +00:00
|
|
|
before_action :authenticate_event_editor!, only: %i[update soft_delete stats create duplicate]
|
2018-03-25 17:30:42 +00:00
|
|
|
|
2019-07-30 21:29:24 +00:00
|
|
|
def index
|
2018-03-25 17:30:42 +00:00
|
|
|
@nonprofit = current_nonprofit
|
2019-07-30 21:29:24 +00:00
|
|
|
end
|
2018-03-25 17:30:42 +00:00
|
|
|
|
|
|
|
def listings
|
|
|
|
render json: QueryEventMetrics.for_listings('nonprofit', current_nonprofit.id, params)
|
|
|
|
end
|
|
|
|
|
2019-07-30 21:29:24 +00:00
|
|
|
def show
|
2018-03-25 17:30:42 +00:00
|
|
|
@event = params[:event_slug] ? Event.find_by_slug!(params[:event_slug]) : Event.find_by_id!(params[:id])
|
|
|
|
@event_background_image = FetchBackgroundImage.with_model(@event)
|
|
|
|
@nonprofit = @event.nonprofit
|
|
|
|
if @event.deleted && !current_event_editor?
|
|
|
|
redirect_to nonprofit_path(current_nonprofit)
|
|
|
|
flash[:notice] = "Sorry, we couldn't find that event"
|
|
|
|
return
|
|
|
|
end
|
2019-07-30 21:29:24 +00:00
|
|
|
@organizer = QueryEventOrganizer.with_event(@event.id)
|
|
|
|
end
|
2018-03-25 17:30:42 +00:00
|
|
|
|
2019-07-30 21:29:24 +00:00
|
|
|
def create
|
2018-03-25 17:30:42 +00:00
|
|
|
render_json do
|
|
|
|
Time.use_zone(current_nonprofit.timezone || 'UTC') do
|
2019-08-06 14:05:43 +00:00
|
|
|
event_params[:start_datetime] = Chronic.parse(event_params[:start_datetime]) if event_params[:start_datetime].present?
|
|
|
|
event_params[:end_datetime] = Chronic.parse(event_params[:end_datetime]) if event_params[:end_datetime].present?
|
2018-03-25 17:30:42 +00:00
|
|
|
end
|
|
|
|
flash[:notice] = 'Your draft event has been created! Well done.'
|
2019-08-06 14:05:43 +00:00
|
|
|
ev = current_nonprofit.events.create(event_params)
|
2019-07-30 21:29:24 +00:00
|
|
|
{ url: "/events/#{ev.slug}", event: ev }
|
2018-03-25 17:30:42 +00:00
|
|
|
end
|
2019-07-30 21:29:24 +00:00
|
|
|
end
|
2018-03-25 17:30:42 +00:00
|
|
|
|
2019-07-30 21:29:24 +00:00
|
|
|
def update
|
2018-03-25 17:30:42 +00:00
|
|
|
Time.use_zone(current_nonprofit.timezone || 'UTC') do
|
2019-08-06 14:05:43 +00:00
|
|
|
event_params[:start_datetime] = Chronic.parse(event_params[:start_datetime]) if event_params[:start_datetime].present?
|
|
|
|
event_params[:end_datetime] = Chronic.parse(event_params[:end_datetime]) if event_params[:end_datetime].present?
|
2018-03-25 17:30:42 +00:00
|
|
|
end
|
2019-08-06 14:05:43 +00:00
|
|
|
current_event.update_attributes(event_params)
|
2019-07-30 21:29:24 +00:00
|
|
|
json_saved current_event, 'Successfully updated'
|
|
|
|
end
|
2018-03-25 17:30:42 +00:00
|
|
|
|
|
|
|
# post 'nonprofits/:np_id/events/:event_id/duplicate'
|
|
|
|
def duplicate
|
2019-07-30 21:29:24 +00:00
|
|
|
render_json { InsertDuplicate.event(current_event.id, current_user.profile.id) }
|
2018-03-25 17:30:42 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def activities
|
|
|
|
render json: QueryTickets.for_event_activities(params[:id])
|
|
|
|
end
|
|
|
|
|
|
|
|
def soft_delete
|
2019-07-30 21:29:24 +00:00
|
|
|
current_event.update_attribute(:deleted, params[:delete])
|
|
|
|
render json: {}
|
|
|
|
end
|
2018-03-25 17:30:42 +00:00
|
|
|
|
2019-07-30 21:29:24 +00:00
|
|
|
def metrics
|
2018-03-25 17:30:42 +00:00
|
|
|
render json: QueryEventMetrics.with_event_ids([current_event.id]).first
|
2019-07-30 21:29:24 +00:00
|
|
|
end
|
2018-03-25 17:30:42 +00:00
|
|
|
|
2019-07-30 21:29:24 +00:00
|
|
|
def stats
|
|
|
|
@event = current_event
|
|
|
|
@url = Format::Url.concat(root_url, @event.url)
|
|
|
|
@event_background_image = FetchBackgroundImage.with_model(@event)
|
|
|
|
render layout: 'layouts/embed'
|
|
|
|
end
|
2018-03-25 17:30:42 +00:00
|
|
|
|
|
|
|
def name_and_id
|
|
|
|
render json: QueryEvents.name_and_id(current_nonprofit.id)
|
|
|
|
end
|
2019-08-06 14:05:43 +00:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def event_params
|
|
|
|
params.require(:event).permit(:deleted, :name, :tagline, :summary, :body, :end_datetime, :start_datetime, :latitude, :longitude, :location, :city, :state_code, :address, :zip_code, :main_image, :remove_main_image, :background_image, :remove_background_image, :published, :slug, :directions, :venue_name, :profile_id, :ticket_levels_attributes, :show_total_raised, :show_total_count, :hide_activity_feed, :nonprofit_id, :hide_title, :organizer_email, :receipt_message)
|
|
|
|
end
|
2018-03-25 17:30:42 +00:00
|
|
|
end
|