Class: DateCalculatorController

Inherits:
ApplicationController show all
Defined in:
frontend/app/controllers/date_calculator_controller.rb

Constant Summary

Constants included from Searchable

Searchable::ABSTRACT

Instance Method Summary collapse

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

#calculateObject



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

def calculate
  if params['record_uri']
    calculator_params = {
      'record_uri' => params['record_uri'],
      'label' => params['label'].blank? ? nil : params['label']
    }

    results = JSONModel::HTTP::get_json("/date_calculator", calculator_params)

    if results['min_begin'] == results['max_end'] || results['max_end'].nil?
      date_type = 'single'
    else
      date_type = 'inclusive'
    end

    date = {
      'jsonmodel_type' => 'date',
      'date_type' => date_type,
      'label' => results['label'] || 'creation',
      'begin' => results['min_begin'],
      'end' => date_type == 'inclusive' ? results['max_end'] : nil
    }

    render_aspace_partial :partial => "date_calculator/results", :locals => {:results => results, :date => date}
  else
    render_aspace_partial :partial => "date_calculator/no_object"
  end
end

#create_dateObject



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

def create_date
  begin
    date = params.require(:date).permit(JSONModel(:date).schema["properties"].keys).to_hash
    date = JSONModel(:date).from_hash(date)

    record = JSONModel(params[:record_type].intern).find(params[:record_id])

    record.dates ||= []
    record.dates << date
    record.save

    render :plain => 'success'
  rescue ValidationException => e
    render :json => e.errors, :status => 400
  end
end