Class: EnumerationsController
Constant Summary
Constants included
from Searchable
Searchable::ABSTRACT
Instance Method Summary
collapse
#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
#fetch_only_facets, #get_pretty_facet_value, #strip_facets
#inheritance, #process_mixed_content, #strip_mixed_content
Instance Method Details
#create ⇒ Object
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
|
# File 'frontend/app/controllers/enumerations_controller.rb', line 127
def create
@enumeration = JSONModel(:enumeration).find(params[:id])
if params[:enumeration].blank? or params[:enumeration][:value].blank?
flash.now[:error] = "#{I18n.t("enumeration.value")} is required"
return render_aspace_partial :partial => "new"
end
begin
@enumeration.values += [params[:enumeration][:value]]
@enumeration.save
flash[:success] = I18n.t("enumeration._frontend.messages.created")
render :plain => "Success"
rescue
flash.now[:error] = I18n.t("enumeration._frontend.messages.create_error")
render_aspace_partial :partial => "new"
end
end
|
#csv ⇒ Object
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
|
# File 'frontend/app/controllers/enumerations_controller.rb', line 148
def csv
@enumerations = JSONModel(:enumeration).all
self.response.['Content-Type'] = 'text/csv'
self.response.['Content-Disposition'] = "attachment; filename=enumerations_#{Time.now.strftime('%Y%m%dT%H%M%S')}.csv"
self.response.['Last-Modified'] = Time.now.ctime
self.response_body = Enumerator.new do |stream|
JSONModel::HTTP.stream("/config/enumerations/csv") do |response|
response.read_body do |chunk|
stream << chunk
end
end
end
end
|
#current_record ⇒ Object
19
20
21
|
# File 'frontend/app/controllers/enumerations_controller.rb', line 19
def current_record
@enumeration
end
|
#delete ⇒ Object
24
25
26
27
28
29
30
31
32
33
34
|
# File 'frontend/app/controllers/enumerations_controller.rb', line 24
def delete
@merge = !params["merge"].blank?
@enumeration = JSONModel(:enumeration).find(params[:id])
@value = params[:value]
if @merge
render_aspace_partial :partial => "merge"
else
render_aspace_partial :partial => "delete"
end
end
|
#destroy ⇒ Object
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
# File 'frontend/app/controllers/enumerations_controller.rb', line 73
def destroy
@enumeration = JSONModel(:enumeration).find(params[:id])
@value = params["enumeration"]["value"]
@enumeration_value = JSONModel(:enumeration_value).find( params["enumeration"]["enumeration_value_id"])
begin
@enumeration_value.set_suppressed(false) if @enumeration_value["suppressed"] == true
@enumeration.values -= [@value]
@enumeration.save
flash[:success] = I18n.t("enumeration._frontend.messages.deleted")
render :plain => "Success"
rescue ConflictException
flash.now[:error] = I18n.t("enumeration._frontend.messages.delete_conflict")
flash.now[:info] = I18n.t("enumeration._frontend.messages.merge_tip")
render_aspace_partial :partial => "merge"
rescue
flash.now[:error] = I18n.t("enumeration._frontend.messages.delete_error")
render_aspace_partial :partial => "delete"
end
end
|
#index ⇒ Object
12
13
14
15
16
|
# File 'frontend/app/controllers/enumerations_controller.rb', line 12
def index
@enumerations = JSONModel(:enumeration).all
@enumeration = JSONModel(:enumeration).find(params[:id]) if params[:id] and not params[:id].blank?
end
|
#merge ⇒ Object
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
|
# File 'frontend/app/controllers/enumerations_controller.rb', line 100
def merge
@enumeration = JSONModel(:enumeration).find(params[:id])
@value = params["enumeration"]["value"]
@merge = params["merge_into"]
if @merge.blank?
flash.now[:error] = "#{I18n.t("enumeration.merge_into")} - is required"
return render_aspace_partial :partial => "merge"
elsif @value.blank?
flash.now[:error] = "#{I18n.t("enumeration.value")} - is required"
return render_aspace_partial :partial => "merge"
end
begin
request = JSONModel(:enumeration_migration).from_hash(:enum_uri => @enumeration.uri,
:from => @value,
:to => @merge)
request.save
flash[:success] = I18n.t("enumeration._frontend.messages.merged")
render :plain => "Success"
rescue
flash.now[:error] = I18n.t("enumeration._frontend.messages.merge_error")
render_aspace_partial :partial => "merge"
end
end
|
#new ⇒ Object
6
7
8
9
|
# File 'frontend/app/controllers/enumerations_controller.rb', line 6
def new
@enumeration = JSONModel(:enumeration).find(params[:id])
render_aspace_partial :partial => "new"
end
|
#set_default ⇒ Object
36
37
38
39
40
41
42
43
44
45
46
47
|
# File 'frontend/app/controllers/enumerations_controller.rb', line 36
def set_default
begin
@enumeration = JSONModel(:enumeration).find(params[:id])
@enumeration['default_value'] = params[:value]
@enumeration.save
flash[:success] = I18n.t("enumeration._frontend.messages.default_set")
rescue
flash.now[:error] = I18n.t("enumeration._frontend.messages.default_set_error")
end
redirect_to(:controller => :enumerations, :action => :index, :id => params[:id])
end
|
#update_value ⇒ Object
we only update position and suppression here
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
# File 'frontend/app/controllers/enumerations_controller.rb', line 51
def update_value
@enumeration_value = JSONModel(:enumeration_value).find( params[:enumeration_value_id])
begin
if params[:suppressed]
suppress = ( params[:suppressed] == "1" )
@enumeration_value.set_suppressed(suppress)
end
if params[:position]
JSONModel::HTTP.post_form("#{@enumeration_value.uri}/position", :position => params[:position])
end
flash[:success] = I18n.t("enumeration._frontend.messages.value_updated")
rescue
flash.now[:error] = I18n.t("enumeration._frontend.messages.value_update_error")
end
redirect_to(:controller => :enumerations, :action => :index, :id => params[:id])
end
|