Class: Spotlight::TagsController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/spotlight/tags_controller.rb

Overview

CRUD actions for document tags

Instance Method Summary collapse

Instance Method Details

#destroy ⇒ Object



27
28
29
30
31
# File 'app/controllers/spotlight/tags_controller.rb', line 27

def destroy
  Spotlight::RenameTagsJob.perform_later(@exhibit, @tag, to: nil)

  redirect_to exhibit_tags_path(@exhibit)
end

#index ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
# File 'app/controllers/spotlight/tags_controller.rb', line 15

def index
  @tags = @exhibit.owned_tags
  add_breadcrumb(t(:'spotlight.exhibits.breadcrumb', title: @exhibit.title), @exhibit)
  add_breadcrumb(t(:'spotlight.curation.sidebar.header'), exhibit_dashboard_path(@exhibit))
  add_breadcrumb(t(:'spotlight.curation.sidebar.tags'), exhibit_tags_path(@exhibit))

  respond_to do |format|
    format.html
    format.json { render json: @tags.map(&:name) }
  end
end

#rename ⇒ Object



33
34
35
36
37
# File 'app/controllers/spotlight/tags_controller.rb', line 33

def rename
  Spotlight::RenameTagsJob.perform_later(@exhibit, @tag, to: params[:new_tag])

  redirect_to exhibit_tags_path(@exhibit)
end

#update_all ⇒ Object



39
40
41
42
43
44
45
46
47
# File 'app/controllers/spotlight/tags_controller.rb', line 39

def update_all
  tags_to_rename = batch_update_params['owned_tags_attributes'].values.select do |tag|
    tag[:name].present? && tag[:current_name]&.strip != tag[:name]&.strip
  end

  rename_tags_later!(tags_to_rename)

  redirect_back_or_to(fallback_url, notice: t(:'helpers.submit.tags.batch_updated', count: tags_to_rename.count))
end