Class: AssessmentsController

Inherits:
ApplicationController show all
Includes:
ExportHelper
Defined in:
frontend/app/controllers/assessments_controller.rb

Constant Summary

Constants included from Searchable

Searchable::ABSTRACT

Instance Method Summary collapse

Methods included from ExportHelper

#csv_response, #xml_response

Methods inherited from ApplicationController

#archivesspace, can_access?, permission_mappings, set_access_control

Methods included from JsonHelper

#merge_notes, #process_json_notes

Methods included from Searchable

#default_search_opts, #get_filter_years, #handle_results, #html_notes, #process_results, #process_search_results, #repo_context, #search_terms, #set_up_advanced_search, #set_up_and_run_search, #set_up_search, #strip_facet_fields

Methods included from HandleFaceting

#fetch_only_facets, #get_pretty_facet_value, #strip_facets

Methods included from ManipulateNode

#inheritance, #process_mixed_content, #strip_mixed_content

Instance Method Details

#createObject



60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'frontend/app/controllers/assessments_controller.rb', line 60

def create
  handle_crud(:instance => :assessment,
              :model => JSONModel(:assessment),
              :on_invalid => ->() {
                @assessment_attribute_definitions = AssessmentAttributeDefinitions.find(nil)
                render action: "new"
              },
              :on_valid => ->(id) {
                  flash[:success] = I18n.t("assessment._frontend.messages.created", JSONModelI18nWrapper.new(:assessment => @assessment))
                  redirect_to(:controller => :assessments,
                              :action => :edit,
                              :id => id) })
end

#current_recordObject



24
25
26
# File 'frontend/app/controllers/assessments_controller.rb', line 24

def current_record
  @assessment
end

#deleteObject



91
92
93
94
95
96
97
# File 'frontend/app/controllers/assessments_controller.rb', line 91

def delete
  assessment = JSONModel(:assessment).find(params[:id])
  assessment.delete

  flash[:success] = I18n.t("assessment._frontend.messages.deleted", JSONModelI18nWrapper.new(:assessment => assessment))
  redirect_to(:controller => :assessments, :action => :index, :deleted_uri => assessment.uri)
end

#editObject



54
55
56
57
# File 'frontend/app/controllers/assessments_controller.rb', line 54

def edit
  @assessment = JSONModel(:assessment).find(params[:id], 'resolve[]' => ['surveyed_by', 'records', 'reviewer'])
  @assessment_attribute_definitions = AssessmentAttributeDefinitions.find(nil)
end

#embedded_searchObject



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'frontend/app/controllers/assessments_controller.rb', line 100

def embedded_search
  @search_data = Search.all(session[:repo_id], params_for_backend_search.merge({'facet[]' => SearchResultData.ASSESSMENT_FACETS, 'type[]' => ['assessment']}))
  respond_to do |format|
    format.js {
      if params[:listing_only]
        render_aspace_partial :partial => "assessments/search_listing"
      else
        render_aspace_partial :partial => "search/results"
      end
    }
    format.html {
      # default render
    }
  end
end

#indexObject



9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'frontend/app/controllers/assessments_controller.rb', line 9

def index
  respond_to do |format|
    format.html {
      @search_data = Search.for_type(session[:repo_id], "assessment", params_for_backend_search.merge({"facet[]" => SearchResultData.ASSESSMENT_FACETS}))
    }
    format.csv {
      search_params = params_for_backend_search.merge({"facet[]" => SearchResultData.ASSESSMENT_FACETS})
      search_params["type[]"] = "assessment"
      uri = "/repositories/#{session[:repo_id]}/search"
      csv_response( uri, Search.build_filters(search_params), "#{I18n.t('assessment._plural').downcase}." )
    }
  end
end

#newObject



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'frontend/app/controllers/assessments_controller.rb', line 35

def new
  if params[:record_uri]
    uri_bits = JSONModel.parse_reference(params[:record_uri])
    record = JSONModel(uri_bits.fetch(:type)).find(uri_bits.fetch(:id))

    @assessment = JSONModel(:assessment).new({
      'records' => [{
        'ref' => params[:record_uri],
        '_resolved' => record
      }]
    })._always_valid!
  end

  @assessment ||= JSONModel(:assessment).new._always_valid!
  @assessment.survey_begin ||= Date.today.strftime('%Y-%m-%d')
  @assessment_attribute_definitions = AssessmentAttributeDefinitions.find(nil)
end

#showObject



29
30
31
32
# File 'frontend/app/controllers/assessments_controller.rb', line 29

def show
  @assessment = JSONModel(:assessment).find(params[:id], 'resolve[]' => ['surveyed_by', 'records', 'reviewer'])
  @assessment_attribute_definitions = AssessmentAttributeDefinitions.find(nil)
end

#updateObject



75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'frontend/app/controllers/assessments_controller.rb', line 75

def update
  handle_crud(:instance => :assessment,
              :model => JSONModel(:assessment),
              :obj => JSONModel(:assessment).find(params[:id]),
              :on_invalid => ->() {
                @assessment_attribute_definitions = AssessmentAttributeDefinitions.find(nil)
                @assessment.display_string = params[:id]
                return render action: "edit"
              },
              :on_valid => ->(id) {
                flash[:success] = I18n.t("assessment._frontend.messages.updated", JSONModelI18nWrapper.new(:assessment => @assessment))
                redirect_to :controller => :assessments, :action => :edit, :id => id
              })
end