Class: ClassificationsController
- Inherits:
-
ApplicationController
show all
- Defined in:
- frontend/app/controllers/classifications_controller.rb,
public/app/controllers/classifications_controller.rb
Constant Summary
collapse
- DEFAULT_CL_TYPES =
%w{pui_record_group}
- DEFAULT_CL_FACET_TYPES =
%w{primary_type subjects published_agents repository resource}
- DEFAULT_CL_SEARCH_OPTS =
{
'resolve[]' => ['repository:id', 'resource:id@compact_resource', 'ancestors:id@compact_resource'],
'facet.mincount' => 1
}
- DEFAULT_CL_SEARCH_PARAMS =
{
:q => ['*'],
:limit => 'pui_record_group',
:op => ['OR'],
:field => ['title']
}
Instance Method Summary
collapse
#archivesspace, can_access?, permission_mappings, set_access_control
Instance Method Details
#accept_children ⇒ Object
153
154
155
|
# File 'frontend/app/controllers/classifications_controller.rb', line 153
def accept_children
handle_accept_children(JSONModel(:classification))
end
|
#create ⇒ Object
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
# File 'frontend/app/controllers/classifications_controller.rb', line 64
def create
flash.keep(:spawned_from_accession)
handle_crud(:instance => :classification,
:on_invalid => ->() {
render action: "new"
},
:on_valid => ->(id) {
flash[:success] = t("classification._frontend.messages.created", classification_title: @classification.title)
if @classification["is_slug_auto"] == false &&
@classification["slug"] == nil &&
params["classification"] &&
params["classification"]["is_slug_auto"] == "1"
flash[:warning] = t("slug.autogen_disabled")
end
redirect_to({
:controller => :classifications,
:action => :edit,
:id => id
})
})
end
|
#current_record ⇒ Object
24
25
26
|
# File 'frontend/app/controllers/classifications_controller.rb', line 24
def current_record
@classification
end
|
#defaults ⇒ Object
123
124
125
126
127
128
129
130
131
132
|
# File 'frontend/app/controllers/classifications_controller.rb', line 123
def defaults
defaults = DefaultValues.get 'classification'
values = defaults ? defaults.form_values : {}
@classification = JSONModel(:classification).new(values)._always_valid!
@form_title = t("default_values.form_title.classification")
render "defaults"
end
|
#delete ⇒ Object
114
115
116
117
118
119
120
|
# File 'frontend/app/controllers/classifications_controller.rb', line 114
def delete
classification = JSONModel(:classification).find(params[:id])
classification.delete
flash[:success] = t("classification._frontend.messages.deleted", classification_title: classification.title)
redirect_to(:controller => :classifications, :action => :index, :deleted_uri => classification.uri)
end
|
#edit ⇒ Object
52
53
54
55
56
57
58
59
60
61
|
# File 'frontend/app/controllers/classifications_controller.rb', line 52
def edit
flash.keep if not flash.empty?
if params[:inline]
@classification = JSONModel(:classification).find(params[:id], find_opts)
return render_aspace_partial :partial => "classifications/edit_inline"
end
@classification = JSONModel(:classification).find(params[:id])
end
|
#fetch_and_process(uri) ⇒ Object
we use this to get and process both classifications and classification terms
114
115
116
117
118
119
|
# File 'public/app/controllers/classifications_controller.rb', line 114
def fetch_and_process(uri)
@criteria = {}
@criteria['resolve[]'] = ['repository:id', 'resource:id@compact_resource', 'agent_uris:id']
@result = archivesspace.get_record(uri, @criteria)
@context = @result.breadcrumb
end
|
#fetch_linked_records(uri) ⇒ Object
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
|
# File 'public/app/controllers/classifications_controller.rb', line 121
def fetch_linked_records(uri)
qry = "classification_uris:\"#{uri}\""
@base_search = "#{uri}?"
search_opts = default_search_opts(DEFAULT_CL_SEARCH_OPTS)
search_opts['fq']=[qry]
set_up_search(['pui'], DEFAULT_CL_FACET_TYPES, search_opts, params, qry)
@base_search= @base_search.sub("q=#{qry}", '')
page = Integer(params.fetch(:page, "1"))
@results = archivesspace.search(@query, page, @criteria)
if @results['total_hits'] > 0
process_search_results(@base_search)
else
@results = []
end
end
|
#index ⇒ Object
10
11
12
13
14
15
16
17
18
19
20
21
22
|
# File 'frontend/app/controllers/classifications_controller.rb', line 10
def index
respond_to do |format|
format.html {
@search_data = Search.for_type(session[:repo_id], "classification", params_for_backend_search.merge({"facet[]" => SearchResultData.CLASSIFICATION_FACETS}))
}
format.csv {
search_params = params_for_backend_search.merge({"facet[]" => SearchResultData.CLASSIFICATION_FACETS})
search_params["type[]"] = "classification"
uri = "/repositories/#{session[:repo_id]}/search"
csv_response( uri, Search.build_filters(search_params), "#{t('classification._plural').downcase}." )
}
end
end
|
#new ⇒ Object
39
40
41
42
43
44
45
46
47
48
49
|
# File 'frontend/app/controllers/classifications_controller.rb', line 39
def new
@classification = JSONModel(:classification).new(:title => t("classification.title_default", :default => ""))._always_valid!
if user_prefs['default_values']
defaults = DefaultValues.get 'classification'
@classification.update(defaults.values) if defaults
end
return render_aspace_partial :partial => "classifications/new_inline" if params[:inline]
end
|
#node_from_root ⇒ Object
170
171
172
173
174
175
|
# File 'frontend/app/controllers/classifications_controller.rb', line 170
def node_from_root
classification_uri = JSONModel(:classification).uri_for(params[:id])
render :json => JSONModel::HTTP.get_json("#{classification_uri}/tree/node_from_root",
'node_ids[]' => params[:node_ids])
end
|
#search ⇒ Object
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
# File 'public/app/controllers/classifications_controller.rb', line 65
def search
@base_search = '/classifications/search?'
page = Integer(params.fetch(:page, "1"))
begin
set_up_and_run_search( DEFAULT_CL_TYPES, DEFAULT_CL_FACET_TYPES, DEFAULT_CL_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('classification._plural')
@results_type = @page_title
@search_title = I18n.t('search_results.search_for', {:type => I18n.t('classification._plural'), :term => params.fetch(:q)[0]})
render 'search/search_results'
end
|
#show ⇒ Object
28
29
30
31
32
33
34
35
36
37
|
# File 'frontend/app/controllers/classifications_controller.rb', line 28
def show
flash.keep
if params[:inline]
@classification = JSONModel(:classification).find(params[:id], find_opts)
return render_aspace_partial :partial => "classifications/show_inline"
end
@classification = JSONModel(:classification).find(params[:id])
end
|
#term ⇒ Object
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
# File 'public/app/controllers/classifications_controller.rb', line 98
def term
begin
uri = "/repositories/#{params[:rid]}/classification_terms/#{params[:id]}"
fetch_and_process(uri)
fetch_linked_records(uri)
@has_children = true
render 'classifications/show'
rescue RecordNotFound
record_not_found(uri, 'classification_term')
end
end
|
#tree ⇒ Object
158
159
160
161
162
|
# File 'frontend/app/controllers/classifications_controller.rb', line 158
def tree
flash.keep
render :json => fetch_tree
end
|
#tree_node ⇒ Object
177
178
179
180
181
182
183
184
185
186
187
|
# File 'frontend/app/controllers/classifications_controller.rb', line 177
def tree_node
classification_uri = JSONModel(:classification).uri_for(params[:id])
node_uri = if !params[:node].blank?
params[:node]
else
nil
end
render :json => JSONModel::HTTP.get_json("#{classification_uri}/tree/node",
:node_uri => node_uri)
end
|
#tree_node_from_root ⇒ Object
164
165
166
167
168
169
170
|
# File 'public/app/controllers/classifications_controller.rb', line 164
def tree_node_from_root
@root_uri = "/repositories/#{params[:rid]}/classifications/#{params[:id]}"
url = @root_uri + '/tree/node_from_root_' + params[:node_ids].first
render json: archivesspace.get_raw_record(url)
rescue RecordNotFound
render json: {}, status: 404
end
|
#tree_root ⇒ Object
164
165
166
167
168
|
# File 'frontend/app/controllers/classifications_controller.rb', line 164
def tree_root
classification_uri = JSONModel(:classification).uri_for(params[:id])
render :json => JSONModel::HTTP.get_json("#{classification_uri}/tree/root")
end
|
#tree_waypoint ⇒ Object
189
190
191
192
193
194
195
196
197
198
199
200
|
# File 'frontend/app/controllers/classifications_controller.rb', line 189
def tree_waypoint
classification_uri = JSONModel(:classification).uri_for(params[:id])
node_uri = if !params[:node].blank?
params[:node]
else
nil
end
render :json => JSONModel::HTTP.get_json("#{classification_uri}/tree/waypoint",
:parent_node => node_uri,
:offset => params[:offset])
end
|
#update ⇒ Object
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
# File 'frontend/app/controllers/classifications_controller.rb', line 92
def update
handle_crud(:instance => :classification,
:obj => JSONModel(:classification).find(params[:id], find_opts),
:on_invalid => ->() {
render_aspace_partial :partial => "edit_inline"
},
:on_valid => ->(id) {
flash.now[:success] = t("classification._frontend.messages.updated", classification_title: @classification.title)
if @classification["is_slug_auto"] == false &&
@classification["slug"] == nil &&
params["classification"] &&
params["classification"]["is_slug_auto"] == "1"
flash.now[:warning] = t("slug.autogen_disabled")
end
render_aspace_partial :partial => "edit_inline"
})
end
|
#update_defaults ⇒ Object
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
|
# File 'frontend/app/controllers/classifications_controller.rb', line 134
def update_defaults
begin
DefaultValues.from_hash({
"record_type" => "classification",
"lock_version" => params[:classification].delete('lock_version'),
"defaults" => cleanup_params_for_schema(
params[:classification],
JSONModel(:classification).schema)
}).save
flash[:success] = t("default_values.messages.defaults_updated")
redirect_to :controller => :classifications, :action => :defaults
rescue Exception => e
flash[:error] = e.message
redirect_to :controller => :classifications, :action => :defaults
end
end
|