Class: DateCalculatorController

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

Instance Method Summary collapse

Methods inherited from ApplicationController

#archivesspace, can_access?, permission_mappings, set_access_control

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