Class: SubmissionsController

Inherits:
BaseJsonController show all
Defined in:
app/controllers/submissions_controller.rb

Instance Method Summary (collapse)

Methods inherited from BaseJsonController

#destroy, #update

Instance Method Details

- (Object) create



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'app/controllers/submissions_controller.rb', line 33

def create
  @submission.attempt_auto_map = true
  if @submission.save
    flash[:notice] = "#{@submission.survey_data_identifier} saved!"
    respond_with @submission and return
  else
    respond_to do |format|
      format.html do
        @submissions = Submission.accessible_by current_ability
        @dictionaries = Dictionary.accessible_by current_ability
        render :index
      end
    end
  end
end

- (Object) index



24
25
26
27
28
29
30
31
32
# File 'app/controllers/submissions_controller.rb', line 24

def index
  @dictionaries = Dictionary.accessible_by current_ability
  if Dictionary.count < 1
    @dictionary = Dictionary.new({
      :title => "#{Time.now.year} Dictionary",
      :default => true
    })
  end
end

- (Object) presentation



79
80
81
82
83
84
85
86
87
88
# File 'app/controllers/submissions_controller.rb', line 79

def presentation
  @submission = Submission.find params[:id]
  @presentation = PresentationTemplate.find params[:presentation_id]
  @reports = []
  report_templates = ReportTemplate.where(:id => @presentation.report_template_ids)
  report_templates.each do |report_template|
    @reports << Report.generate(current_user.team_id, @submission, report_template)
  end
  @reports
end

- (Object) show



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'app/controllers/submissions_controller.rb', line 56

def show
  @metrics = Metric.roots
  @dictionaries = Dictionary.accessible_by(current_ability)
  if @submission.auto_map_dictionary_id.present?
    @active_dictionary = @submission.auto_map_dictionary
  elsif params[:dictionary_id]
    @active_dictionary = @dictionaries.find(params[:dictionary_id])
  elsif !@dictionaries.count.zero?
    @active_dictionary = @dictionaries.default.first
    @active_dictionary = @dictionaries.first if @active_dictionary.nil?
  else
    @active_dictionary = Dictionary.new({
      :title => "#{Time.now.year} Dictionary",
      :default => true,
      :team_id => current_user.team_id,
      :submitted_by_id => current_user.id
    })
    @active_dictionary.manual_definitions = true
    @active_dictionary.save!
  end
  @metric_maps = @active_dictionary.definitions
  @presentations = PresentationTemplate.order('audience, name')
end

- (Object) survey_data



48
49
50
51
52
53
54
55
# File 'app/controllers/submissions_controller.rb', line 48

def survey_data
  survey_data = File.open(@submission.survey_data.current_path, 'r')
  send_data(survey_data.read, {
    :filename => @submission.survey_data_identifier,
    :stream => true,
    :buffer_size => 1.megabyte
  })
end