Class: AccessionsController

Inherits:
ApplicationController show all
Includes:
ExportHelper, ResultInfo
Defined in:
frontend/app/controllers/accessions_controller.rb,
public/app/controllers/accessions_controller.rb

Constant Summary collapse

DEFAULT_AC_TYPES =
%w{accession}
DEFAULT_AC_FACET_TYPES =
%w{primary_type subjects published_agents repository}
DEFAULT_AC_SEARCH_OPTS =
{
  'sort' => 'title_sort asc',
  'resolve[]' => ['repository:id', 'resource:id@compact_resource', 'ancestors:id@compact_resource'],
  'facet.mincount' => 1
}
DEFAULT_AC_SEARCH_PARAMS =
{
  :q => ['*'],
  :limit => 'accession',
  :op => ['OR'],
  :field => ['title']
}

Constants included from Searchable

Searchable::ABSTRACT

Instance Method Summary collapse

Methods included from ResultInfo

#breadcrumb_info, #fill_request_info, #get_rep_image, #handle_dates, #handle_external_docs, #process_agents, #process_digital, #process_digital_instance, #process_extents, #process_file_versions, #process_repo_info, #process_subjects

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



109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'frontend/app/controllers/accessions_controller.rb', line 109

def create
  handle_crud(:instance => :accession,
              :model => Accession,
              :on_invalid => ->() { render action: "new" },
              :on_valid => ->(id) {
                  flash[:success] = I18n.t("accession._frontend.messages.created", JSONModelI18nWrapper.new(:accession => @accession))
                  if @accession["is_slug_auto"] == false &&
                     @accession["slug"] == nil &&
                     params["accession"] &&
                     params["accession"]["is_slug_auto"] == "1"

                    flash[:warning] = I18n.t("slug.autogen_disabled")
                  end
                  redirect_to(:controller => :accessions,
                              :action => :edit,
                              :id => id) })
end

#current_recordObject



27
28
29
# File 'frontend/app/controllers/accessions_controller.rb', line 27

def current_record
  @accession
end

#defaultsObject



58
59
60
61
62
63
64
65
66
# File 'frontend/app/controllers/accessions_controller.rb', line 58

def defaults
  defaults = DefaultValues.get 'accession'

  values = defaults ? defaults.form_values : {:accession_date => Date.today.strftime('%Y-%m-%d')}

  @accession = Accession.new(values)._always_valid!

  render "defaults"
end

#deleteObject



166
167
168
169
170
171
172
173
174
175
176
177
# File 'frontend/app/controllers/accessions_controller.rb', line 166

def delete
  accession = Accession.find(params[:id])
  begin
    accession.delete
  rescue ConflictException => e
    flash[:error] = I18n.t("accession._frontend.messages.delete_conflict", :error => I18n.t("errors.#{e.conflicts}", :default => e.message))
    return redirect_to(:controller => :accessions, :action => :show, :id => params[:id])
  end

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

#editObject



89
90
91
92
93
94
95
96
# File 'frontend/app/controllers/accessions_controller.rb', line 89

def edit
  @accession = fetch_resolved(:accession, params[:id], excludes: ['linked_events', 'linked_events::linked_records'])
  @accession['accession_date'] = '' if @accession['accession_date'] == "9999-12-31"

  if @accession.suppressed
    redirect_to(:controller => :accessions, :action => :show, :id => params[:id])
  end
end

#indexObject



13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'frontend/app/controllers/accessions_controller.rb', line 13

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

#newObject



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'frontend/app/controllers/accessions_controller.rb', line 41

def new
  @accession = Accession.new({:accession_date => Date.today.strftime('%Y-%m-%d')})._always_valid!
  defaults = user_defaults('accession')
  @accession.update(defaults.values) if defaults

  if params[:accession_id]
    acc = Accession.find(params[:accession_id], find_opts)

    if acc
      @accession.populate_from_accession(acc)
      flash.now[:info] = I18n.t("accession._frontend.messages.spawned", JSONModelI18nWrapper.new(:accession => acc))
      flash[:spawned_from_accession] = acc.id
    end
  end
end

#searchObject



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'public/app/controllers/accessions_controller.rb', line 68

def search
    # need at least q[]=WHATEVER&op[]=OR&field[]=title&from_year[]=&to_year[]=&limit=accession
  @base_search = '/accessions/search?'
  page = Integer(params.fetch(:page, "1"))
  begin
    set_up_and_run_search( DEFAULT_AC_TYPES, DEFAULT_AC_FACET_TYPES, DEFAULT_AC_SEARCH_OPTS, params)
  rescue NoResultsError
    flash[:error] = I18n.t('search_results.no_results')
    redirect_back(fallback_location: '/') and return
  rescue Exception => error
    flash[:error] = I18n.t('errors.unexpected_error')
    redirect_back(fallback_location: '/') and return
  end
  @page_title = I18n.t('accession._plural')
  @results_type = @page_title
  @search_title = I18n.t('search_results.search_for', {:type => I18n.t('accession._plural'), :term => params.fetch(:q)[0]})
  render 'search/search_results'
end

#showObject



31
32
33
34
35
36
37
38
39
# File 'frontend/app/controllers/accessions_controller.rb', line 31

def show
  event_hits = fetch_linked_events_count(:accession, params[:id])
  excludes = event_hits > AppConfig[:max_linked_events_to_resolve] ? ['linked_events', 'linked_events::linked_records'] : []
  @accession = fetch_resolved(:accession, params[:id], excludes: excludes)

  @accession['accession_date'] = I18n.t('accession.accession_date_unknown') if @accession['accession_date'] == "9999-12-31"

  flash[:info] = I18n.t("accession._frontend.messages.suppressed_info", JSONModelI18nWrapper.new(:accession => @accession)) if @accession.suppressed
end

#suppressObject



148
149
150
151
152
153
154
# File 'frontend/app/controllers/accessions_controller.rb', line 148

def suppress
  accession = Accession.find(params[:id])
  accession.set_suppressed(true)

  flash[:success] = I18n.t("accession._frontend.messages.suppressed", JSONModelI18nWrapper.new(:accession => accession))
  redirect_to(:controller => :accessions, :action => :show, :id => params[:id])
end

#transferObject



98
99
100
101
102
103
104
105
106
# File 'frontend/app/controllers/accessions_controller.rb', line 98

def transfer
  begin
    handle_transfer(Accession)
  rescue ArchivesSpace::TransferConflictException => e
    @transfer_errors = e.errors
    show
    render :action => :show
  end
end

#unsuppressObject



157
158
159
160
161
162
163
# File 'frontend/app/controllers/accessions_controller.rb', line 157

def unsuppress
  accession = Accession.find(params[:id])
  accession.set_suppressed(false)

  flash[:success] = I18n.t("accession._frontend.messages.unsuppressed", JSONModelI18nWrapper.new(:accession => accession))
  redirect_to(:controller => :accessions, :action => :show, :id => params[:id])
end

#updateObject



127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# File 'frontend/app/controllers/accessions_controller.rb', line 127

def update
  handle_crud(:instance => :accession,
              :model => Accession,
              :obj => fetch_resolved(:accession, params[:id], excludes: ['linked_events', 'linked_events::linked_records']),
              :on_invalid => ->() {
                return render action: "edit"
              },
              :on_valid => ->(id) {
                flash[:success] = I18n.t("accession._frontend.messages.updated", JSONModelI18nWrapper.new(:accession => @accession))
                if @accession["is_slug_auto"] == false &&
                   @accession["slug"] == nil &&
                   params["accession"] &&
                   params["accession"]["is_slug_auto"] == "1"

                  flash[:warning] = I18n.t("slug.autogen_disabled")
                end

                redirect_to :controller => :accessions, :action => :edit, :id => id
              })
end

#update_defaultsObject



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'frontend/app/controllers/accessions_controller.rb', line 69

def update_defaults
  begin
    DefaultValues.from_hash({
                              "record_type" => "accession",
                              "lock_version" => params[:accession].delete('lock_version'),
                              "defaults" => cleanup_params_for_schema(
                                                                      params[:accession],
                                                                      JSONModel(:accession).schema
                                                                      )
                            }).save

    flash[:success] = I18n.t("default_values.messages.defaults_updated")

    redirect_to :controller => :accessions, :action => :defaults
  rescue Exception => e
    flash[:error] = e.message
    redirect_to :controller => :accessions, :action => :defaults
  end
end