Class: AccessionsController
- Inherits:
-
ApplicationController
show all
- 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']
}
Instance Method Summary
collapse
#archivesspace, can_access?, permission_mappings, set_access_control
Instance Method Details
#create ⇒ Object
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] = t("accession._frontend.messages.created", accession_display_string: @accession.title)
if @accession["is_slug_auto"] == false &&
@accession["slug"] == nil &&
params["accession"] &&
params["accession"]["is_slug_auto"] == "1"
flash[:warning] = t("slug.autogen_disabled")
end
redirect_to(:controller => :accessions,
:action => :edit,
:id => id) })
end
|
#current_record ⇒ Object
27
28
29
|
# File 'frontend/app/controllers/accessions_controller.rb', line 27
def current_record
@accession
end
|
#defaults ⇒ Object
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
|
#delete ⇒ Object
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] = t("accession._frontend.messages.delete_conflict", :error => t("errors.#{e.conflicts}", :default => e.message))
return redirect_to(:controller => :accessions, :action => :show, :id => params[:id])
end
flash[:success] = t("accession._frontend.messages.deleted", accession_display_string: accession.title)
redirect_to(:controller => :accessions, :action => :index, :deleted_uri => accession.uri)
end
|
#edit ⇒ Object
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
|
#index ⇒ Object
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), "#{t('accession._plural').downcase}." )
}
end
end
|
#new ⇒ Object
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] = t("accession._frontend.messages.spawned", accession_display_string: acc.title)
flash[:spawned_from_accession] = acc.id
end
end
end
|
#search ⇒ Object
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
@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
|
#show ⇒ Object
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'] = t('accession.accession_date_unknown') if @accession['accession_date'] == "9999-12-31"
flash[:info] = t("accession._frontend.messages.suppressed_info") if @accession.suppressed
end
|
#suppress ⇒ Object
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] = t("accession._frontend.messages.suppressed", accession_display_string: accession.title)
redirect_to(:controller => :accessions, :action => :show, :id => params[:id])
end
|
#transfer ⇒ Object
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
|
#unsuppress ⇒ Object
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] = t("accession._frontend.messages.unsuppressed", accession_display_string: accession.title)
redirect_to(:controller => :accessions, :action => :show, :id => params[:id])
end
|
#update ⇒ Object
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] = t("accession._frontend.messages.updated", accession_display_string: @accession.title)
if @accession["is_slug_auto"] == false &&
@accession["slug"] == nil &&
params["accession"] &&
params["accession"]["is_slug_auto"] == "1"
flash[:warning] = t("slug.autogen_disabled")
end
redirect_to :controller => :accessions, :action => :edit, :id => id
})
end
|
#update_defaults ⇒ Object
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] = 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
|