Class: DigitalObjectComponentsController

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

Constant Summary

Constants included from Searchable

Searchable::ABSTRACT

Instance Method Summary collapse

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

#accept_childrenObject



122
123
124
# File 'frontend/app/controllers/digital_object_components_controller.rb', line 122

def accept_children
  handle_accept_children(JSONModel(:digital_object_component))
end

#add_childrenObject



182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
# File 'frontend/app/controllers/digital_object_components_controller.rb', line 182

def add_children
  @parent = JSONModel(:digital_object_component).find(params[:id])
  @digital_object_uri = @parent['digital_object']['ref']

  if params[:digital_record_children].blank? or params[:digital_record_children]["children"].blank?

    @children = DigitalObjectComponentChildren.new
    flash.now[:error] = I18n.t("rde.messages.no_rows")

  else
    children_data = cleanup_params_for_schema(params[:digital_record_children], JSONModel(:digital_record_children).schema)

    begin
      @children = DigitalObjectComponentChildren.from_hash(children_data, false)

      if params["validate_only"] == "true"
        @exceptions = @children.children.collect {|c| JSONModel(:digital_object_component).from_hash(c, false)._exceptions}

        error_count = @exceptions.select {|e| !e.empty?}.length
        if error_count > 0
          flash.now[:error] = I18n.t("rde.messages.rows_with_errors", :count => error_count)
        else
          flash.now[:success] = I18n.t("rde.messages.rows_no_errors")
        end

        return render_aspace_partial :partial => "shared/rde"
      else
        @children.save(:digital_object_component_id => @parent.id)
      end

      return render :plain => I18n.t("rde.messages.success")
    rescue JSONModel::ValidationException => e
      @exceptions = @children.children.collect {|c| JSONModel(:digital_object_component).from_hash(c, false)._exceptions}

      if @exceptions.all?(&:blank?)
        e.errors.each { |key, vals| flash.now[:error] = "#{key} : #{vals.join('<br/>')}" }
      else
        flash.now[:error] = I18n.t("rde.messages.rows_with_errors", :count => @exceptions.select {|e| !e.empty?}.length)
      end
    end

  end

  render_aspace_partial :partial => "shared/rde"
end

#createObject



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'frontend/app/controllers/digital_object_components_controller.rb', line 41

def create
  handle_crud(:instance => :digital_object_component,
              :find_opts => find_opts,
              :on_invalid => ->() { render_aspace_partial :partial => "new_inline" },
              :on_valid => ->(id) {
                # Refetch the record to ensure all sub records are resolved
                # (this object isn't marked as stale upon create like Archival Objects,
                # so need to do it manually)
                @digital_object_component = JSONModel(:digital_object_component).find(id, find_opts)

                flash[:success] = @digital_object_component.parent ?
                  I18n.t("digital_object_component._frontend.messages.created_with_parent", JSONModelI18nWrapper.new(:digital_object_component => @digital_object_component, :digital_object => @digital_object_component['digital_object']['_resolved'], :parent => @digital_object_component['parent']['_resolved']).enable_parse_mixed_content!(url_for(:root))) :
                  I18n.t("digital_object_component._frontend.messages.created", JSONModelI18nWrapper.new(:digital_object_component => @digital_object_component, :digital_object => @digital_object_component['digital_object']['_resolved']).enable_parse_mixed_content!(url_for(:root)))

                if @digital_object_component["is_slug_auto"] == false &&
                   @digital_object_component["slug"] == nil &&
                   params["digital_object_component"] &&
                   params["digital_object_component"]["is_slug_auto"] == "1"

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

                render_aspace_partial :partial => "digital_object_components/edit_inline"
              })
end

#current_recordObject



96
97
98
# File 'frontend/app/controllers/digital_object_components_controller.rb', line 96

def current_record
  @digital_object_component
end

#defaultsObject



126
127
128
129
130
131
132
133
134
135
136
# File 'frontend/app/controllers/digital_object_components_controller.rb', line 126

def defaults
  defaults = DefaultValues.get 'digital_object_component'

  values = defaults ? defaults.form_values : {}

  @digital_object_component = JSONModel(:digital_object_component).new(values)._always_valid!

  @digital_object_component.display_string = I18n.t("default_values.form_title.digital_object_component")

  render "defaults"
end

#deleteObject



111
112
113
114
115
116
117
118
119
# File 'frontend/app/controllers/digital_object_components_controller.rb', line 111

def delete
  digital_object_component = JSONModel(:digital_object_component).find(params[:id])
  digital_object_component.delete

  flash[:success] = I18n.t("digital_object_component._frontend.messages.deleted", JSONModelI18nWrapper.new(:digital_object_component => digital_object_component).enable_parse_mixed_content!(url_for(:root)))

  resolver = Resolver.new(digital_object_component['digital_object']['ref'])
  redirect_to resolver.view_uri
end

#editObject



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

def edit
  @digital_object_component = JSONModel(:digital_object_component).find(params[:id], find_opts)

  if @digital_object_component.suppressed
    return redirect_to(:action => :show, :id => params[:id], :inline => params[:inline])
  end

  render_aspace_partial :partial => "digital_object_components/edit_inline" if inline?
end

#newObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'frontend/app/controllers/digital_object_components_controller.rb', line 10

def new
  @digital_object_component = JSONModel(:digital_object_component).new._always_valid!
  @digital_object_component.title = I18n.t("digital_object_component.title_default", :default => "")
  @digital_object_component.parent = {'ref' => JSONModel(:digital_object_component).uri_for(params[:digital_object_component_id])} if params.has_key?(:digital_object_component_id)
  @digital_object_component.digital_object = {'ref' => JSONModel(:digital_object).uri_for(params[:digital_object_id])} if params.has_key?(:digital_object_id)
  @digital_object_component.position = params[:position]

  if user_prefs['default_values']
    defaults = DefaultValues.get 'digital_object_component'

    @digital_object_component.update(defaults.values) if defaults
    @form_title = I18n.t("digital_object_component.title_default")
  end


  return render_aspace_partial :partial => "digital_object_components/new_inline" if inline?

  # render the full DOC form
end

#rdeObject



160
161
162
163
164
165
166
167
168
169
# File 'frontend/app/controllers/digital_object_components_controller.rb', line 160

def rde
  flash.clear

  @parent = JSONModel(:digital_object_component).find(params[:id])
  @digital_object_uri = @parent['digital_object']['ref']
  @children = DigitalObjectComponentChildren.new
  @exceptions = []

  render_aspace_partial :partial => "shared/rde"
end

#showObject



101
102
103
104
105
106
107
108
# File 'frontend/app/controllers/digital_object_components_controller.rb', line 101

def show
  @digital_object_id = params['digital_object_id']
  @digital_object_component = JSONModel(:digital_object_component).find(params[:id], find_opts)

  flash.now[:info] = I18n.t("digital_object_component._frontend.messages.suppressed_info", JSONModelI18nWrapper.new(:digital_object_component => @digital_object_component).enable_parse_mixed_content!(url_for(:root))) if @digital_object_component.suppressed

  render_aspace_partial :partial => "digital_object_components/show_inline" if inline?
end

#suppressObject



229
230
231
232
233
234
235
# File 'frontend/app/controllers/digital_object_components_controller.rb', line 229

def suppress
  digital_object_component = JSONModel(:digital_object_component).find(params[:id])
  digital_object_component.set_suppressed(true)

  flash[:success] = I18n.t("digital_object_component._frontend.messages.suppressed", JSONModelI18nWrapper.new(:digital_object_component => digital_object_component).enable_parse_mixed_content!(url_for(:root)))
  redirect_to(:controller => :digital_objects, :action => :show, :id => JSONModel(:digital_object).id_for(digital_object_component['digital_object']['ref']), :anchor => "tree::digital_object_component_#{params[:id]}")
end

#unsuppressObject



238
239
240
241
242
243
244
# File 'frontend/app/controllers/digital_object_components_controller.rb', line 238

def unsuppress
  digital_object_component = JSONModel(:digital_object_component).find(params[:id])
  digital_object_component.set_suppressed(false)

  flash[:success] = I18n.t("digital_object_component._frontend.messages.unsuppressed", JSONModelI18nWrapper.new(:digital_object_component => digital_object_component).enable_parse_mixed_content!(url_for(:root)))
  redirect_to(:controller => :digital_objects, :action => :show, :id => JSONModel(:digital_object).id_for(digital_object_component['digital_object']['ref']), :anchor => "tree::digital_object_component_#{params[:id]}")
end

#updateObject



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'frontend/app/controllers/digital_object_components_controller.rb', line 68

def update
  params['digital_object_component']['position'] = params['digital_object_component']['position'].to_i if params['digital_object_component']['position']

  @digital_object_component = JSONModel(:digital_object_component).find(params[:id], find_opts)
  digital_object = @digital_object_component['digital_object']['_resolved']
  parent = @digital_object_component['parent'] ? @digital_object_component['parent']['_resolved'] : false

  handle_crud(:instance => :digital_object_component,
              :obj => @digital_object_component,
              :on_invalid => ->() { return render_aspace_partial :partial => "edit_inline" },
              :on_valid => ->(id) {
                flash.now[:success] = parent ?
                  I18n.t("digital_object_component._frontend.messages.updated_with_parent", JSONModelI18nWrapper.new(:digital_object_component => @digital_object_component, :digital_object => digital_object, :parent => parent).enable_parse_mixed_content!(url_for(:root))) :
                  I18n.t("digital_object_component._frontend.messages.updated", JSONModelI18nWrapper.new(:digital_object_component => @digital_object_component, :digital_object => digital_object).enable_parse_mixed_content!(url_for(:root)))

                if @digital_object_component["is_slug_auto"] == false &&
                   @digital_object_component["slug"] == nil &&
                   params["digital_object_component"] &&
                   params["digital_object_component"]["is_slug_auto"] == "1"

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

                render_aspace_partial :partial => "edit_inline"
              })
end

#update_defaultsObject



139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# File 'frontend/app/controllers/digital_object_components_controller.rb', line 139

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

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

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

#validate_rowsObject



172
173
174
175
176
177
178
179
180
# File 'frontend/app/controllers/digital_object_components_controller.rb', line 172

def validate_rows
  row_data = cleanup_params_for_schema(params[:digital_record_children], JSONModel(:digital_record_children).schema)

  # build the DOC record but don't bother validating it yet...
  do_children = DigitalObjectComponentChildren.from_hash(row_data, false, true)

  # validate each row individually (to avoid weird indexes in the error paths)
  render :json => do_children.children.collect {|c| JSONModel(:digital_object_component).from_hash(c, false)._exceptions}
end