Class: Spotlight::ExhibitsController

Inherits:
ApplicationController show all
Includes:
Blacklight::SearchHelper
Defined in:
app/controllers/spotlight/exhibits_controller.rb

Overview

Administrative CRUD actions for an exhibit

Instance Method Summary collapse

Methods included from Controller

#blacklight_config, #current_masthead, #current_masthead=, #current_site, #exhibit_masthead?, #exhibit_search_action_url, #exhibit_search_facet_url, #resource_masthead?, #search_action_url, #search_facet_url

Methods included from Config

#exhibit_specific_blacklight_config

Instance Method Details

#createObject



34
35
36
37
38
39
40
41
42
43
# File 'app/controllers/spotlight/exhibits_controller.rb', line 34

def create
  @exhibit.attributes = exhibit_params

  if @exhibit.save
    @exhibit.roles.create user: current_user, role: 'admin' if current_user
    redirect_to spotlight.exhibit_dashboard_path(@exhibit), notice: t(:'helpers.submit.exhibit.created', model: @exhibit.class.model_name.human.downcase)
  else
    render action: :new
  end
end

#destroyObject



73
74
75
76
77
# File 'app/controllers/spotlight/exhibits_controller.rb', line 73

def destroy
  @exhibit.destroy

  redirect_to main_app.root_url, notice: t(:'helpers.submit.exhibit.destroyed', model: @exhibit.class.model_name.human.downcase)
end

#editObject



57
58
59
60
61
62
# File 'app/controllers/spotlight/exhibits_controller.rb', line 57

def edit
  add_breadcrumb t(:'spotlight.exhibits.breadcrumb', title: @exhibit.title), @exhibit
  add_breadcrumb t(:'spotlight.configuration.sidebar.header'), exhibit_dashboard_path(@exhibit)
  add_breadcrumb t(:'spotlight.configuration.sidebar.settings'), edit_exhibit_path(@exhibit)
  build_initial_exhibit_contact_emails
end

#indexObject



10
11
12
13
14
15
16
17
18
19
# File 'app/controllers/spotlight/exhibits_controller.rb', line 10

def index
  @published_exhibits = @exhibits.published.page(params[:page])
  @published_exhibits = @published_exhibits.tagged_with(params[:tag]) if params[:tag]

  if @exhibits.one?
    redirect_to @exhibits.first
  else
    render layout: 'spotlight/home'
  end
end

#newObject



21
22
23
# File 'app/controllers/spotlight/exhibits_controller.rb', line 21

def new
  build_initial_exhibit_contact_emails
end

#process_importObject



25
26
27
28
29
30
31
32
# File 'app/controllers/spotlight/exhibits_controller.rb', line 25

def process_import
  @exhibit.import(JSON.parse(import_exhibit_params.read))
  if @exhibit.save && @exhibit.reindex_later
    redirect_to spotlight.exhibit_dashboard_path(@exhibit), notice: t(:'helpers.submit.exhibit.updated', model: @exhibit.class.model_name.human.downcase)
  else
    render action: :import
  end
end

#showObject



45
46
47
48
49
50
51
52
53
54
55
# File 'app/controllers/spotlight/exhibits_controller.rb', line 45

def show
  respond_to do |format|
    format.json do
      authorize! :export, @exhibit
      send_data JSON.pretty_generate(Spotlight::ExhibitExportSerializer.new(@exhibit).as_json),
                type: 'application/json',
                disposition: 'attachment',
                filename: "#{@exhibit.friendly_id}-export.json"
    end
  end
end

#updateObject



64
65
66
67
68
69
70
71
# File 'app/controllers/spotlight/exhibits_controller.rb', line 64

def update
  if @exhibit.update(exhibit_params)
    redirect_to edit_exhibit_path(@exhibit), notice: t(:'helpers.submit.exhibit.updated', model: @exhibit.class.model_name.human.downcase)
  else
    flash[:alert] = @exhibit.errors.full_messages.join('<br>'.html_safe)
    render action: :edit
  end
end