Class: Nquery::CollectionsController

Inherits:
ApplicationController show all
Includes:
Browsable
Defined in:
app/controllers/nquery/collections_controller.rb

Constant Summary

Constants included from AuthorizesCollection

AuthorizesCollection::COLLECTION_REQUIREMENTS

Instance Method Summary collapse

Methods included from Breadcrumbs

#breadcrumbs, #set_breadcrumbs

Instance Method Details

#archiveObject



63
64
65
66
# File 'app/controllers/nquery/collections_controller.rb', line 63

def archive
  @collection.archive!
  redirect_to collections_path, notice: "Collection archived."
end

#createObject



29
30
31
32
33
34
35
36
37
38
# File 'app/controllers/nquery/collections_controller.rb', line 29

def create
  @collection = Collection.new(collection_params.merge(kind: "standard", parent: @parent_collection))
  @parent_collections = assignable_collections

  if @collection.save
    redirect_to collection_path(@collection), notice: "Collection created."
  else
    render :new, status: :unprocessable_content
  end
end

#destroyObject



58
59
60
61
# File 'app/controllers/nquery/collections_controller.rb', line 58

def destroy
  @collection.destroy
  redirect_to collections_path, notice: "Collection deleted."
end

#editObject



40
41
42
# File 'app/controllers/nquery/collections_controller.rb', line 40

def edit
  @parent_collections = assignable_collections.reject { |c| c.id == @collection.id }
end

#indexObject



16
17
18
# File 'app/controllers/nquery/collections_controller.rb', line 16

def index
  @collections = viewable_collections
end

#newObject



24
25
26
27
# File 'app/controllers/nquery/collections_controller.rb', line 24

def new
  @collection = Collection.new(kind: "standard", parent: @parent_collection)
  @parent_collections = assignable_collections
end

#showObject



20
21
22
# File 'app/controllers/nquery/collections_controller.rb', line 20

def show
  load_collection_contents(@collection)
end

#unarchiveObject



68
69
70
71
# File 'app/controllers/nquery/collections_controller.rb', line 68

def unarchive
  @collection.unarchive!
  redirect_to collection_path(@collection), notice: "Collection unarchived."
end

#updateObject



44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'app/controllers/nquery/collections_controller.rb', line 44

def update
  @parent_collections = assignable_collections.reject { |c| c.id == @collection.id }
  if collection_params[:parent_id].present?
    parent = Collection.find_by(id: collection_params[:parent_id])
    authorize_collection_access!(parent, required: :curate) if parent
  end

  if @collection.update(collection_params)
    redirect_to collection_path(@collection), notice: "Collection updated."
  else
    render :edit, status: :unprocessable_content
  end
end