Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 0 additions & 48 deletions app/controllers/workshops_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,54 +28,6 @@ def index
end
end

def summary
authorize! :workshop, to: :summary?
@year = params[:year] ? params[:year].to_i : Date.current.year.to_i
@month = params[:month] ? params[:month].to_i : Date.current.month.to_i

reports = build_report
@report = reports[0]

types = reports.map do |r|
r.windows_type
end
@workshop_logs = current_user.organization_monthly_workshop_logs(
reports.first.date, *types,
)

logs = @workshop_logs.map { |_k, v| v }.flatten
@total_ongoing = logs.reduce(0) { |sum, l| sum += l.num_ongoing }
@total_first_time = logs.reduce(0) { |sum, l| sum += l.num_first_time }

combined_windows_type = WindowsType.where(short_name: "Combined").first
@combined_workshop_logs = current_user.organization_workshop_logs(
@report.date, combined_windows_type, nil
)
authorize! @combined_workshop_logs
end

def build_report
authorize! :workshop, to: :summary?
date = Date.new(@year, @month)

form_builder = FormBuilder
.monthly

report = form_builder.map do |f|
Report.new(
type: f.report_type,
windows_type: f.windows_type,
date: date
)
end

report.each do |r|
r.media_files.build
end

report
end

def new
if params[:workshop_idea_id].present?
@workshop_idea = WorkshopIdea.find(params[:workshop_idea_id])
Expand Down
11 changes: 0 additions & 11 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -193,17 +193,6 @@ def organization_monthly_workshop_logs(date, *windows_type)
logs.uniq.group_by { |log| log.workshop_held_on }
end

def organization_workshop_logs(date, windows_type, organization_id)
if organization_id
logs = workshop_logs.where(organization_id: organization_id, windows_type_id: windows_type.id)
logs = logs.select do |log|
log.workshop_held_on && log.workshop_held_on.month == date.month.to_i &&
log.workshop_held_on.year == date.year.to_i
end.flatten
logs.uniq.group_by { |log| log.workshop_held_on }
end
end

def deletable?
!reports.exists? &&
!workshop_logs.exists? &&
Expand Down